@maximem/synap-js-sdk 0.4.3 → 0.4.5
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 +402 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +234 -27
- package/dist/index.d.ts +234 -27
- package/dist/index.js +317 -30
- 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.cjs
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var _chunk2TVL5IPQcjs = require('./chunk-2TVL5IPQ.cjs');
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
|
|
@@ -113,7 +113,7 @@ function shouldRetry(input) {
|
|
|
113
113
|
if (attempt >= policy.maxAttempts) {
|
|
114
114
|
return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
|
|
115
115
|
}
|
|
116
|
-
if (!
|
|
116
|
+
if (!_chunk2TVL5IPQcjs.isSynapError.call(void 0, error) || !error.transient) {
|
|
117
117
|
return { retry: false, delaySeconds: 0, reason: "not_transient" };
|
|
118
118
|
}
|
|
119
119
|
const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
|
|
@@ -131,7 +131,7 @@ function shouldRetry(input) {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
function backoffDelay(error, attempt, policy) {
|
|
134
|
-
if (error instanceof
|
|
134
|
+
if (error instanceof _chunk2TVL5IPQcjs.RateLimitError && error.retryAfterSeconds != null) {
|
|
135
135
|
return Math.min(error.retryAfterSeconds, policy.backoffMax);
|
|
136
136
|
}
|
|
137
137
|
const exponential = policy.backoffBase * 2 ** (attempt - 1);
|
|
@@ -205,14 +205,19 @@ var B2C_ISOLATION = "equals_customer";
|
|
|
205
205
|
function checkCustomerId(isolation, customerId, where, instanceId) {
|
|
206
206
|
if (customerId === void 0 || customerId === null || customerId === "") return;
|
|
207
207
|
if (isolation !== B2C_ISOLATION) return;
|
|
208
|
-
throw new (0,
|
|
208
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
209
209
|
`${where}: customer_id is not accepted on this instance${instanceId ? ` (${instanceId})` : ""}, which is B2C (user_context_isolation='${B2C_ISOLATION}'). Send user_id only; it is the whole identity, and the server files and reads your data under it. Received customer_id=${JSON.stringify(customerId)}.`
|
|
210
210
|
);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
// src/transport/http.ts
|
|
214
214
|
var DEFAULT_BASE_URL = "https://synap-cloud-prod.maximem.ai";
|
|
215
|
-
var DEFAULT_TIMEOUTS = {
|
|
215
|
+
var DEFAULT_TIMEOUTS = {
|
|
216
|
+
connect: 5,
|
|
217
|
+
read: 30,
|
|
218
|
+
write: 10,
|
|
219
|
+
streamIdle: 60
|
|
220
|
+
};
|
|
216
221
|
var HttpTransport = (_class2 = class {
|
|
217
222
|
|
|
218
223
|
// Mutable so `configure()` can adjust them before the first request, and so
|
|
@@ -229,7 +234,7 @@ var HttpTransport = (_class2 = class {
|
|
|
229
234
|
this.#credentials = options.credentials;
|
|
230
235
|
this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "");
|
|
231
236
|
this.timeouts = { ...DEFAULT_TIMEOUTS, ...options.timeouts };
|
|
232
|
-
this.retryPolicy = { ...DEFAULT_RETRY_POLICY, ...options.retryPolicy };
|
|
237
|
+
this.retryPolicy = options.retryPolicy === null ? { ...DEFAULT_RETRY_POLICY, maxAttempts: 1 } : { ...DEFAULT_RETRY_POLICY, ...options.retryPolicy };
|
|
233
238
|
this.userAgent = _nullishCoalesce(options.userAgent, () => ( "@maximem/synap-js-sdk"));
|
|
234
239
|
this.fetchImpl = _nullishCoalesce(options.fetchImpl, () => ( globalThis.fetch.bind(globalThis)));
|
|
235
240
|
this.keepAliveOptions = _nullishCoalesce(options.keepAlive, () => ( {}));
|
|
@@ -285,9 +290,16 @@ var HttpTransport = (_class2 = class {
|
|
|
285
290
|
setTimeouts(timeouts) {
|
|
286
291
|
this.timeouts = { ...this.timeouts, ...timeouts };
|
|
287
292
|
}
|
|
288
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* `null` DISABLES retries, matching Python.
|
|
295
|
+
*
|
|
296
|
+
* Python's `SDKConfig(retry_policy=None)` leaves `self.retry_policy` unset and
|
|
297
|
+
* `max_attempts` falls to 1 (http_client.py:180). We restored the default
|
|
298
|
+
* policy instead, so a caller following the "Disabling Retries" documentation
|
|
299
|
+
* got three attempts and no way to turn them off.
|
|
300
|
+
*/
|
|
289
301
|
setRetryPolicy(policy) {
|
|
290
|
-
this.retryPolicy = policy === null ? { ...DEFAULT_RETRY_POLICY } : { ...this.retryPolicy, ...policy };
|
|
302
|
+
this.retryPolicy = policy === null ? { ...DEFAULT_RETRY_POLICY, maxAttempts: 1 } : { ...this.retryPolicy, ...policy };
|
|
291
303
|
}
|
|
292
304
|
close() {
|
|
293
305
|
this.closed = true;
|
|
@@ -317,7 +329,7 @@ var HttpTransport = (_class2 = class {
|
|
|
317
329
|
await sleep(decision.delaySeconds * 1e3, options.signal);
|
|
318
330
|
}
|
|
319
331
|
}
|
|
320
|
-
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _10 => _10.error]), () => ( new (0,
|
|
332
|
+
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _10 => _10.error]), () => ( new (0, _chunk2TVL5IPQcjs.SynapError)("Request failed with no recorded error")));
|
|
321
333
|
}
|
|
322
334
|
async attempt(name, options, correlationId) {
|
|
323
335
|
const spec = ENDPOINTS[name];
|
|
@@ -350,7 +362,7 @@ var HttpTransport = (_class2 = class {
|
|
|
350
362
|
try {
|
|
351
363
|
return JSON.parse(text);
|
|
352
364
|
} catch (e3) {
|
|
353
|
-
throw new (0,
|
|
365
|
+
throw new (0, _chunk2TVL5IPQcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
|
|
354
366
|
}
|
|
355
367
|
}
|
|
356
368
|
buildUrl(path, query) {
|
|
@@ -384,14 +396,14 @@ var HttpTransport = (_class2 = class {
|
|
|
384
396
|
}
|
|
385
397
|
}, _class2);
|
|
386
398
|
function isOutcomeUnknown(error) {
|
|
387
|
-
if (error instanceof
|
|
388
|
-
if (error instanceof
|
|
389
|
-
if (error instanceof
|
|
390
|
-
if (error instanceof
|
|
391
|
-
if (error instanceof
|
|
392
|
-
if (error instanceof
|
|
393
|
-
if (error instanceof
|
|
394
|
-
if (error instanceof
|
|
399
|
+
if (error instanceof _chunk2TVL5IPQcjs.RateLimitError) return false;
|
|
400
|
+
if (error instanceof _chunk2TVL5IPQcjs.ServiceUnavailableError) return false;
|
|
401
|
+
if (error instanceof _chunk2TVL5IPQcjs.AuthenticationError) return false;
|
|
402
|
+
if (error instanceof _chunk2TVL5IPQcjs.InvalidInputError) return false;
|
|
403
|
+
if (error instanceof _chunk2TVL5IPQcjs.ConflictError) return false;
|
|
404
|
+
if (error instanceof _chunk2TVL5IPQcjs.InsufficientCreditsError) return false;
|
|
405
|
+
if (error instanceof _chunk2TVL5IPQcjs.ContextNotFoundError) return false;
|
|
406
|
+
if (error instanceof _chunk2TVL5IPQcjs.NetworkTimeoutError) return true;
|
|
395
407
|
if (isConnectionRefusal(error)) return false;
|
|
396
408
|
return true;
|
|
397
409
|
}
|
|
@@ -400,12 +412,12 @@ function isConnectionRefusal(error) {
|
|
|
400
412
|
return code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "ECONNRESET" || code === "EHOSTUNREACH";
|
|
401
413
|
}
|
|
402
414
|
function toTransportError(error, correlationId) {
|
|
403
|
-
if (error instanceof
|
|
415
|
+
if (error instanceof _chunk2TVL5IPQcjs.SynapError) return error;
|
|
404
416
|
const name = _optionalChain([error, 'optionalAccess', _14 => _14.name]);
|
|
405
417
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
406
|
-
return new (0,
|
|
418
|
+
return new (0, _chunk2TVL5IPQcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
|
|
407
419
|
}
|
|
408
|
-
return new (0,
|
|
420
|
+
return new (0, _chunk2TVL5IPQcjs.ServiceUnavailableError)(
|
|
409
421
|
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _15 => _15.message]), () => ( String(error)))}`,
|
|
410
422
|
{ correlationId, cause: error }
|
|
411
423
|
);
|
|
@@ -425,48 +437,53 @@ async function toHttpError(response, correlationId) {
|
|
|
425
437
|
switch (response.status) {
|
|
426
438
|
case 400:
|
|
427
439
|
case 422:
|
|
428
|
-
return new (0,
|
|
440
|
+
return new (0, _chunk2TVL5IPQcjs.InvalidInputError)(message, opts);
|
|
429
441
|
case 401:
|
|
430
442
|
case 403:
|
|
431
|
-
return new (0,
|
|
443
|
+
return new (0, _chunk2TVL5IPQcjs.AuthenticationError)(message, opts);
|
|
432
444
|
case 404:
|
|
433
|
-
return new (0,
|
|
445
|
+
return new (0, _chunk2TVL5IPQcjs.ContextNotFoundError)(message, opts);
|
|
434
446
|
case 402:
|
|
435
|
-
return new (0,
|
|
447
|
+
return new (0, _chunk2TVL5IPQcjs.InsufficientCreditsError)(message, {
|
|
436
448
|
...opts,
|
|
437
449
|
balanceCredits: numberOrNull(parsed["balance_credits"]),
|
|
438
|
-
requiredCredits: numberOrNull(parsed["required_credits"])
|
|
450
|
+
requiredCredits: _nullishCoalesce(numberOrNull(parsed["minimum_required_credits"]), () => ( numberOrNull(parsed["required_credits"]))),
|
|
451
|
+
recoveryUrl: stringOrNull(parsed["recovery_url"]),
|
|
452
|
+
redeemUrl: stringOrNull(parsed["redeem_url"])
|
|
439
453
|
});
|
|
440
454
|
case 409:
|
|
441
455
|
if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
|
|
442
|
-
return new (0,
|
|
456
|
+
return new (0, _chunk2TVL5IPQcjs.TranscriptConflictError)(message, opts);
|
|
443
457
|
}
|
|
444
|
-
return new (0,
|
|
458
|
+
return new (0, _chunk2TVL5IPQcjs.ConflictError)(message, opts);
|
|
445
459
|
case 429: {
|
|
446
460
|
const header = response.headers.get("retry-after");
|
|
447
461
|
const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
|
|
448
|
-
return new (0,
|
|
462
|
+
return new (0, _chunk2TVL5IPQcjs.RateLimitError)(message, {
|
|
449
463
|
...opts,
|
|
450
464
|
retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null
|
|
451
465
|
});
|
|
452
466
|
}
|
|
453
467
|
case 503:
|
|
454
|
-
return new (0,
|
|
468
|
+
return new (0, _chunk2TVL5IPQcjs.ServiceUnavailableError)(message, opts);
|
|
455
469
|
case 504:
|
|
456
|
-
return new (0,
|
|
470
|
+
return new (0, _chunk2TVL5IPQcjs.AgentUnavailableError)(message, opts);
|
|
457
471
|
default:
|
|
458
|
-
if (response.status >= 500) return new (0,
|
|
459
|
-
return new (0,
|
|
472
|
+
if (response.status >= 500) return new (0, _chunk2TVL5IPQcjs.ServiceUnavailableError)(message, opts);
|
|
473
|
+
return new (0, _chunk2TVL5IPQcjs.SynapError)(message, opts);
|
|
460
474
|
}
|
|
461
475
|
}
|
|
462
476
|
function numberOrNull(v) {
|
|
463
477
|
return typeof v === "number" && Number.isFinite(v) ? v : null;
|
|
464
478
|
}
|
|
479
|
+
function stringOrNull(v) {
|
|
480
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
481
|
+
}
|
|
465
482
|
function withTimeout(ms, external) {
|
|
466
483
|
const controller = new AbortController();
|
|
467
484
|
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _16 => _16.reason]));
|
|
468
485
|
const timer = setTimeout(() => {
|
|
469
|
-
controller.abort(new (0,
|
|
486
|
+
controller.abort(new (0, _chunk2TVL5IPQcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
|
|
470
487
|
}, ms);
|
|
471
488
|
_optionalChain([timer, 'access', _17 => _17.unref, 'optionalCall', _18 => _18()]);
|
|
472
489
|
if (external) {
|
|
@@ -518,10 +535,10 @@ function buildFetchRequest(scope, options) {
|
|
|
518
535
|
const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
|
|
519
536
|
const mode = _nullishCoalesce(options.mode, () => ( "fast"));
|
|
520
537
|
if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
|
|
521
|
-
throw new (0,
|
|
538
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("search_query must be an array when provided");
|
|
522
539
|
}
|
|
523
540
|
if (options.types !== void 0 && !Array.isArray(options.types)) {
|
|
524
|
-
throw new (0,
|
|
541
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("types must be an array when provided");
|
|
525
542
|
}
|
|
526
543
|
const body = {
|
|
527
544
|
conversation_id: _nullishCoalesce(conversationId, () => ( null)),
|
|
@@ -536,16 +553,39 @@ function buildFetchRequest(scope, options) {
|
|
|
536
553
|
}
|
|
537
554
|
switch (scope) {
|
|
538
555
|
case "user":
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
556
|
+
{
|
|
557
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
558
|
+
body["user_id"] = userId;
|
|
559
|
+
const scopePath = opt(options, "scope_path", "scopePath");
|
|
560
|
+
if (scopePath !== void 0) body["scope"] = scopePath;
|
|
561
|
+
const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
|
|
562
|
+
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
563
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
564
|
+
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
|
|
568
|
+
if (!Number.isInteger(lastN)) {
|
|
569
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("last_n_conversations must be an integer");
|
|
570
|
+
}
|
|
571
|
+
if (lastN < 0 || lastN > 20) {
|
|
572
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
|
|
573
|
+
}
|
|
574
|
+
if (contextMode === "conversation-summary") {
|
|
575
|
+
body["context_mode"] = contextMode;
|
|
576
|
+
body["include_profile"] = _nullishCoalesce(opt(options, "include_profile", "includeProfile"), () => ( true));
|
|
577
|
+
body["last_n_conversations"] = lastN;
|
|
578
|
+
}
|
|
579
|
+
if (customerId !== void 0) body["customer_id"] = customerId;
|
|
580
|
+
break;
|
|
581
|
+
}
|
|
542
582
|
break;
|
|
543
583
|
case "customer":
|
|
544
|
-
if (!customerId) throw new (0,
|
|
584
|
+
if (!customerId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("customer_id is required");
|
|
545
585
|
body["customer_id"] = customerId;
|
|
546
586
|
break;
|
|
547
587
|
case "conversation":
|
|
548
|
-
if (!conversationId) throw new (0,
|
|
588
|
+
if (!conversationId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
549
589
|
if (userId !== void 0) body["user_id"] = userId;
|
|
550
590
|
if (customerId !== void 0) body["customer_id"] = customerId;
|
|
551
591
|
break;
|
|
@@ -554,6 +594,7 @@ function buildFetchRequest(scope, options) {
|
|
|
554
594
|
}
|
|
555
595
|
return { endpoint: ENDPOINT_BY_SCOPE[scope], body };
|
|
556
596
|
}
|
|
597
|
+
var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
|
|
557
598
|
async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
558
599
|
const startedAt = Date.now();
|
|
559
600
|
transport.checkCustomerId(
|
|
@@ -789,17 +830,17 @@ function isoOrNull(v) {
|
|
|
789
830
|
return v instanceof Date ? v.toISOString() : v;
|
|
790
831
|
}
|
|
791
832
|
function buildCreateBody(options) {
|
|
792
|
-
if (!options.document) throw new (0,
|
|
833
|
+
if (!options.document) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("document is required");
|
|
793
834
|
const o2 = options;
|
|
794
835
|
const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
|
|
795
836
|
const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
|
|
796
837
|
if (!DOCUMENT_TYPES.includes(documentType)) {
|
|
797
|
-
throw new (0,
|
|
838
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
798
839
|
`Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
|
|
799
840
|
);
|
|
800
841
|
}
|
|
801
842
|
if (!INGEST_MODES.includes(mode)) {
|
|
802
|
-
throw new (0,
|
|
843
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
803
844
|
`Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
|
|
804
845
|
);
|
|
805
846
|
}
|
|
@@ -827,7 +868,7 @@ function createMemoriesInterface(transport) {
|
|
|
827
868
|
async batch_create(options) {
|
|
828
869
|
const docs = options.documents;
|
|
829
870
|
if (!Array.isArray(docs) || docs.length === 0) {
|
|
830
|
-
throw new (0,
|
|
871
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("documents must be a non-empty array");
|
|
831
872
|
}
|
|
832
873
|
const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
|
|
833
874
|
return transport.request("memories_batch", {
|
|
@@ -837,15 +878,15 @@ function createMemoriesInterface(transport) {
|
|
|
837
878
|
async create_from_file(options) {
|
|
838
879
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
839
880
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
840
|
-
if (!userId) throw new (0,
|
|
881
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
841
882
|
transport.checkCustomerId(customerId, "memories.create_from_file");
|
|
842
883
|
const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
|
|
843
884
|
const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
|
|
844
885
|
if (sources.length === 0) {
|
|
845
|
-
throw new (0,
|
|
886
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
|
|
846
887
|
}
|
|
847
888
|
if (sources.length > 1) {
|
|
848
|
-
throw new (0,
|
|
889
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
849
890
|
"Provide exactly one of file_path, file, or text, not several."
|
|
850
891
|
);
|
|
851
892
|
}
|
|
@@ -876,13 +917,13 @@ function createMemoriesInterface(transport) {
|
|
|
876
917
|
});
|
|
877
918
|
},
|
|
878
919
|
async get(memoryId) {
|
|
879
|
-
if (!memoryId) throw new (0,
|
|
920
|
+
if (!memoryId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("memory_id is required");
|
|
880
921
|
return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
|
|
881
922
|
},
|
|
882
923
|
async update(options) {
|
|
883
924
|
const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
|
|
884
|
-
if (!memoryId) throw new (0,
|
|
885
|
-
if (!options.document) throw new (0,
|
|
925
|
+
if (!memoryId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("memory_id is required");
|
|
926
|
+
if (!options.document) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("document is required");
|
|
886
927
|
const body = {
|
|
887
928
|
document: options.document,
|
|
888
929
|
merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
|
|
@@ -897,20 +938,20 @@ function createMemoriesInterface(transport) {
|
|
|
897
938
|
},
|
|
898
939
|
async delete(memoryId) {
|
|
899
940
|
if (!memoryId) {
|
|
900
|
-
throw new (0,
|
|
941
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
901
942
|
"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."
|
|
902
943
|
);
|
|
903
944
|
}
|
|
904
945
|
return transport.request("memories_delete", { pathParams: { memory_id: memoryId } });
|
|
905
946
|
},
|
|
906
947
|
async status(ingestionId) {
|
|
907
|
-
if (!ingestionId) throw new (0,
|
|
948
|
+
if (!ingestionId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("ingestion_id is required");
|
|
908
949
|
return transport.request("memories_status", {
|
|
909
950
|
pathParams: { ingestion_id: ingestionId }
|
|
910
951
|
});
|
|
911
952
|
},
|
|
912
953
|
async wait_for_completion(ingestionId, options = {}) {
|
|
913
|
-
if (!ingestionId) throw new (0,
|
|
954
|
+
if (!ingestionId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("ingestion_id is required");
|
|
914
955
|
const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
|
|
915
956
|
const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
|
|
916
957
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -948,17 +989,26 @@ var UUID_RE = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9
|
|
|
948
989
|
function validateConversationId(conversationId) {
|
|
949
990
|
if (conversationId === void 0 || conversationId === null || conversationId === "") return;
|
|
950
991
|
if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
|
|
951
|
-
throw new (0,
|
|
992
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
|
|
952
993
|
}
|
|
953
994
|
}
|
|
954
995
|
function validateInstanceId(instanceId) {
|
|
955
996
|
if (instanceId === void 0 || instanceId === null || instanceId === "") return;
|
|
956
997
|
if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
|
|
957
|
-
throw new (0,
|
|
998
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
|
|
958
999
|
}
|
|
959
1000
|
}
|
|
960
1001
|
|
|
961
1002
|
// src/conversation/interface.ts
|
|
1003
|
+
var COMPACTION_LEVELS = [
|
|
1004
|
+
"low",
|
|
1005
|
+
"medium",
|
|
1006
|
+
"high",
|
|
1007
|
+
"adaptive",
|
|
1008
|
+
"aggressive",
|
|
1009
|
+
"balanced",
|
|
1010
|
+
"conservative"
|
|
1011
|
+
];
|
|
962
1012
|
function either2(o2, snake, camel) {
|
|
963
1013
|
const a = o2[snake];
|
|
964
1014
|
if (a !== void 0) return a;
|
|
@@ -974,13 +1024,13 @@ function buildRecordMessageBody(options) {
|
|
|
974
1024
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
975
1025
|
const userId = either2(o2, "user_id", "userId");
|
|
976
1026
|
const customerId = either2(o2, "customer_id", "customerId");
|
|
977
|
-
if (!conversationId) throw new (0,
|
|
1027
|
+
if (!conversationId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
978
1028
|
validateConversationId(conversationId);
|
|
979
|
-
if (!options.role) throw new (0,
|
|
1029
|
+
if (!options.role) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("role is required");
|
|
980
1030
|
if (options.content === void 0 || options.content === null) {
|
|
981
|
-
throw new (0,
|
|
1031
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("content is required");
|
|
982
1032
|
}
|
|
983
|
-
if (!userId) throw new (0,
|
|
1033
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
984
1034
|
const body = {
|
|
985
1035
|
conversation_id: conversationId,
|
|
986
1036
|
role: options.role,
|
|
@@ -998,10 +1048,10 @@ function buildIngestTranscriptBody(options) {
|
|
|
998
1048
|
const o2 = options;
|
|
999
1049
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1000
1050
|
const userId = either2(o2, "user_id", "userId");
|
|
1001
|
-
if (!conversationId) throw new (0,
|
|
1002
|
-
if (!userId) throw new (0,
|
|
1051
|
+
if (!conversationId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
1052
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
1003
1053
|
if (options.transcript === void 0 || options.transcript === null) {
|
|
1004
|
-
throw new (0,
|
|
1054
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("transcript is required");
|
|
1005
1055
|
}
|
|
1006
1056
|
const body = {
|
|
1007
1057
|
conversation_id: conversationId,
|
|
@@ -1023,7 +1073,7 @@ function buildIngestTranscriptBody(options) {
|
|
|
1023
1073
|
function buildCompactBody(options) {
|
|
1024
1074
|
const o2 = options;
|
|
1025
1075
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1026
|
-
if (!conversationId) throw new (0,
|
|
1076
|
+
if (!conversationId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
1027
1077
|
validateConversationId(conversationId);
|
|
1028
1078
|
const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
|
|
1029
1079
|
const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
|
|
@@ -1076,10 +1126,10 @@ var CompactionSubscribers = class {
|
|
|
1076
1126
|
function createConversationNamespace(transport, subscribers = new CompactionSubscribers(), onWrite = () => {
|
|
1077
1127
|
}, onTurn = () => {
|
|
1078
1128
|
}, onFetched = () => {
|
|
1079
|
-
}) {
|
|
1129
|
+
}, localShortTerm = { prompt: () => null, compacted: () => null }) {
|
|
1080
1130
|
const convId = (v) => {
|
|
1081
1131
|
const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
|
|
1082
|
-
if (!id) throw new (0,
|
|
1132
|
+
if (!id) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
1083
1133
|
validateConversationId(id);
|
|
1084
1134
|
return id;
|
|
1085
1135
|
};
|
|
@@ -1105,7 +1155,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1105
1155
|
},
|
|
1106
1156
|
async record_messages_batch(messages) {
|
|
1107
1157
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
1108
|
-
throw new (0,
|
|
1158
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("messages must be a non-empty array");
|
|
1109
1159
|
}
|
|
1110
1160
|
for (const m of messages) {
|
|
1111
1161
|
const mo = m;
|
|
@@ -1157,6 +1207,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1157
1207
|
},
|
|
1158
1208
|
get_context_for_prompt: async (options = {}) => {
|
|
1159
1209
|
const id = convId(options);
|
|
1210
|
+
const local = localShortTerm.prompt(id, _nullishCoalesce(options.style, () => ( "structured")));
|
|
1211
|
+
if (local !== null) return local;
|
|
1160
1212
|
const result = await transport.request("context_for_prompt", {
|
|
1161
1213
|
pathParams: { conversation_id: id },
|
|
1162
1214
|
query: { style: _nullishCoalesce(options.style, () => ( "structured")) }
|
|
@@ -1168,6 +1220,10 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1168
1220
|
},
|
|
1169
1221
|
get_compacted: async (options) => {
|
|
1170
1222
|
const id = convId(options);
|
|
1223
|
+
if (options.version === void 0) {
|
|
1224
|
+
const local = localShortTerm.compacted(id, _nullishCoalesce(options.format, () => ( "structured")));
|
|
1225
|
+
if (local !== null) return local;
|
|
1226
|
+
}
|
|
1171
1227
|
const query = { format: _nullishCoalesce(options.format, () => ( "structured")) };
|
|
1172
1228
|
if (options.version !== void 0) query["version"] = options.version;
|
|
1173
1229
|
try {
|
|
@@ -1196,8 +1252,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1196
1252
|
* Returns an idempotent unsubscribe thunk, matching Python.
|
|
1197
1253
|
*/
|
|
1198
1254
|
subscribe_to_compaction_updates(conversationId, callback) {
|
|
1199
|
-
if (!conversationId) throw new (0,
|
|
1200
|
-
if (typeof callback !== "function") throw new (0,
|
|
1255
|
+
if (!conversationId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("conversation_id is required");
|
|
1256
|
+
if (typeof callback !== "function") throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("callback is required");
|
|
1201
1257
|
return subscribers.add(conversationId, callback);
|
|
1202
1258
|
},
|
|
1203
1259
|
/** Remove subscribers for one conversation, or all of them. Returns the count removed. */
|
|
@@ -1213,7 +1269,7 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
1213
1269
|
return {
|
|
1214
1270
|
async get_profile(options) {
|
|
1215
1271
|
const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
1216
|
-
if (!userId) throw new (0,
|
|
1272
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
1217
1273
|
const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
1218
1274
|
return transport.request("user_profile", {
|
|
1219
1275
|
pathParams: { user_id: userId },
|
|
@@ -1229,15 +1285,26 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
1229
1285
|
}
|
|
1230
1286
|
|
|
1231
1287
|
// src/credits/interface.ts
|
|
1288
|
+
function iso2(v) {
|
|
1289
|
+
return v instanceof Date ? v.toISOString() : v;
|
|
1290
|
+
}
|
|
1232
1291
|
function createCreditsNamespace(transport) {
|
|
1233
1292
|
return {
|
|
1234
1293
|
async get_balance() {
|
|
1235
1294
|
return transport.request("credits_balance");
|
|
1236
1295
|
},
|
|
1237
1296
|
async get_ledger(options = {}) {
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1297
|
+
const query = {
|
|
1298
|
+
limit: _nullishCoalesce(options.limit, () => ( 100)),
|
|
1299
|
+
offset: _nullishCoalesce(options.offset, () => ( 0))
|
|
1300
|
+
};
|
|
1301
|
+
const entryType = _nullishCoalesce(options.entry_type, () => ( options.entryType));
|
|
1302
|
+
if (entryType !== void 0) query["entry_type"] = entryType;
|
|
1303
|
+
const from = _nullishCoalesce(options.from_time, () => ( options.fromTime));
|
|
1304
|
+
if (from !== void 0) query["from"] = iso2(from);
|
|
1305
|
+
const to = _nullishCoalesce(options.to_time, () => ( options.toTime));
|
|
1306
|
+
if (to !== void 0) query["to"] = iso2(to);
|
|
1307
|
+
return transport.request("credits_ledger", { query });
|
|
1241
1308
|
},
|
|
1242
1309
|
async estimate(options) {
|
|
1243
1310
|
return transport.request("credits_estimate", {
|
|
@@ -1251,7 +1318,7 @@ function createCreditsNamespace(transport) {
|
|
|
1251
1318
|
});
|
|
1252
1319
|
},
|
|
1253
1320
|
async redeem(code) {
|
|
1254
|
-
if (!code) throw new (0,
|
|
1321
|
+
if (!code) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("code is required");
|
|
1255
1322
|
return transport.request("credits_redeem", { body: { code } });
|
|
1256
1323
|
}
|
|
1257
1324
|
};
|
|
@@ -1262,11 +1329,11 @@ function createCacheNamespace(cache) {
|
|
|
1262
1329
|
return {
|
|
1263
1330
|
clear: () => cache.clear(),
|
|
1264
1331
|
clear_user: (userId) => {
|
|
1265
|
-
if (!userId) throw new (0,
|
|
1332
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
1266
1333
|
cache.dropEntity(userId);
|
|
1267
1334
|
},
|
|
1268
1335
|
clear_customer: (customerId) => {
|
|
1269
|
-
if (!customerId) throw new (0,
|
|
1336
|
+
if (!customerId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("customer_id is required");
|
|
1270
1337
|
cache.dropEntity(customerId);
|
|
1271
1338
|
},
|
|
1272
1339
|
stats: () => ({ bundles: cache.size, items: cache.itemCount })
|
|
@@ -1287,6 +1354,18 @@ function envTls() {
|
|
|
1287
1354
|
if (raw === void 0 || raw === "") return void 0;
|
|
1288
1355
|
return !["0", "false", "no", "off"].includes(raw.trim().toLowerCase());
|
|
1289
1356
|
}
|
|
1357
|
+
function thinkingMetadata(options) {
|
|
1358
|
+
const md = { ..._nullishCoalesce(options.metadata, () => ( {})) };
|
|
1359
|
+
const step = _nullishCoalesce(options.step_index, () => ( options.stepIndex));
|
|
1360
|
+
if (step !== void 0 && md["step_index"] === void 0) {
|
|
1361
|
+
md["step_index"] = String(step);
|
|
1362
|
+
}
|
|
1363
|
+
const kind = _nullishCoalesce(options.thought_type, () => ( options.thoughtType));
|
|
1364
|
+
if (kind && md["thought_type"] === void 0) {
|
|
1365
|
+
md["thought_type"] = kind;
|
|
1366
|
+
}
|
|
1367
|
+
return md;
|
|
1368
|
+
}
|
|
1290
1369
|
function createInstanceNamespace(credentials, cache, onTurn) {
|
|
1291
1370
|
let client = null;
|
|
1292
1371
|
let dispatchCompaction = null;
|
|
@@ -1315,9 +1394,9 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1315
1394
|
const namespace = {
|
|
1316
1395
|
async listen(options = {}) {
|
|
1317
1396
|
if (client !== null) {
|
|
1318
|
-
throw new (0,
|
|
1397
|
+
throw new (0, _chunk2TVL5IPQcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
1319
1398
|
}
|
|
1320
|
-
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-
|
|
1399
|
+
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-PRTOH62B.cjs")));
|
|
1321
1400
|
const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
|
|
1322
1401
|
const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
|
|
1323
1402
|
const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
|
|
@@ -1342,8 +1421,8 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1342
1421
|
try {
|
|
1343
1422
|
await created.connect();
|
|
1344
1423
|
} catch (error) {
|
|
1345
|
-
if (error instanceof
|
|
1346
|
-
throw new (0,
|
|
1424
|
+
if (error instanceof _chunk2TVL5IPQcjs.SynapError) throw error;
|
|
1425
|
+
throw new (0, _chunk2TVL5IPQcjs.SynapError)(
|
|
1347
1426
|
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _49 => _49.message]), () => ( String(error)))}`,
|
|
1348
1427
|
{ cause: error }
|
|
1349
1428
|
);
|
|
@@ -1357,9 +1436,9 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1357
1436
|
await active.disconnect();
|
|
1358
1437
|
},
|
|
1359
1438
|
async send_message(options) {
|
|
1360
|
-
if (client === null) throw new (0,
|
|
1439
|
+
if (client === null) throw new (0, _chunk2TVL5IPQcjs.ListeningNotActiveError)("Listening is not active");
|
|
1361
1440
|
if (options.content === void 0) {
|
|
1362
|
-
throw new (0,
|
|
1441
|
+
throw new (0, _chunk2TVL5IPQcjs.ListeningNotActiveError)("content is required");
|
|
1363
1442
|
}
|
|
1364
1443
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1365
1444
|
_optionalChain([onTurn, 'optionalCall', _50 => _50({
|
|
@@ -1377,12 +1456,18 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1377
1456
|
session_id: _nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( "")),
|
|
1378
1457
|
metadata: _nullishCoalesce(options.metadata, () => ( {})),
|
|
1379
1458
|
timestamp_ms: Date.now(),
|
|
1459
|
+
tool_name: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")),
|
|
1460
|
+
// Python serialises tool_args with json.dumps into tool_args_json.
|
|
1461
|
+
tool_args_json: (() => {
|
|
1462
|
+
const a = _nullishCoalesce(options.tool_args, () => ( options.toolArgs));
|
|
1463
|
+
return a === void 0 ? "" : JSON.stringify(a);
|
|
1464
|
+
})(),
|
|
1380
1465
|
search_queries: _nullishCoalesce(_nullishCoalesce(options.search_queries, () => ( options.searchQueries)), () => ( [])),
|
|
1381
1466
|
context_types: _nullishCoalesce(_nullishCoalesce(options.context_types, () => ( options.contextTypes)), () => ( []))
|
|
1382
1467
|
});
|
|
1383
1468
|
},
|
|
1384
1469
|
async record_thinking(options) {
|
|
1385
|
-
if (client === null) throw new (0,
|
|
1470
|
+
if (client === null) throw new (0, _chunk2TVL5IPQcjs.ListeningNotActiveError)("Listening is not active");
|
|
1386
1471
|
client.sendConversationEvent({
|
|
1387
1472
|
// Python emits reasoning as an `agent_thinking` conversation event.
|
|
1388
1473
|
event_type: "agent_thinking",
|
|
@@ -1392,7 +1477,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1392
1477
|
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1393
1478
|
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
1394
1479
|
session_id: _nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( "")),
|
|
1395
|
-
metadata:
|
|
1480
|
+
metadata: thinkingMetadata(options),
|
|
1396
1481
|
timestamp_ms: Date.now()
|
|
1397
1482
|
});
|
|
1398
1483
|
},
|
|
@@ -1575,11 +1660,11 @@ var ShortTermStore = class {
|
|
|
1575
1660
|
// src/context/overlay.ts
|
|
1576
1661
|
var MAX_TURNS = 20;
|
|
1577
1662
|
var TOKEN_BUDGET = 2e3;
|
|
1578
|
-
function verbatimOverlayEnabled() {
|
|
1663
|
+
function verbatimOverlayEnabled(configured) {
|
|
1579
1664
|
const raw = (_nullishCoalesce(_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_ST_VERBATIM_OVERLAY"), () => ( ""))).trim().toLowerCase();
|
|
1580
1665
|
if (["0", "false", "no", "off"].includes(raw)) return false;
|
|
1581
1666
|
if (["1", "true", "yes", "on"].includes(raw)) return true;
|
|
1582
|
-
return true;
|
|
1667
|
+
return _nullishCoalesce(configured, () => ( true));
|
|
1583
1668
|
}
|
|
1584
1669
|
function estimateTokens(turn) {
|
|
1585
1670
|
return Math.max(1, Math.floor(String(_nullishCoalesce(turn.content, () => ( ""))).length / 4));
|
|
@@ -1593,13 +1678,13 @@ function budgetRecentTurns(turns) {
|
|
|
1593
1678
|
}
|
|
1594
1679
|
return windowed;
|
|
1595
1680
|
}
|
|
1596
|
-
function overlayLocalRecentTurns(response, store, conversationId) {
|
|
1681
|
+
function overlayLocalRecentTurns(response, store, conversationId, configured) {
|
|
1597
1682
|
if (conversationId === void 0 || conversationId === "") return;
|
|
1598
1683
|
try {
|
|
1599
1684
|
const entry = store.get(conversationId);
|
|
1600
1685
|
if (entry === null) return;
|
|
1601
1686
|
const existing = _nullishCoalesce(response.conversation_context, () => ( null));
|
|
1602
|
-
if (existing !== null && !verbatimOverlayEnabled()) return;
|
|
1687
|
+
if (existing !== null && !verbatimOverlayEnabled(configured)) return;
|
|
1603
1688
|
const localTurns = budgetRecentTurns(entry.recentTurns);
|
|
1604
1689
|
const serverField = (name) => existing === null ? void 0 : existing[name];
|
|
1605
1690
|
const orLocal = (name, local) => {
|
|
@@ -1621,6 +1706,158 @@ function overlayLocalRecentTurns(response, store, conversationId) {
|
|
|
1621
1706
|
}
|
|
1622
1707
|
}
|
|
1623
1708
|
|
|
1709
|
+
// src/context/local-prompt.ts
|
|
1710
|
+
var SUPPORTED_STYLES = ["structured", "narrative", "bullet_points"];
|
|
1711
|
+
var DEFAULT_STYLE = "structured";
|
|
1712
|
+
function stringify(value) {
|
|
1713
|
+
if (value === null || value === void 0) return "";
|
|
1714
|
+
const t = typeof value;
|
|
1715
|
+
if (t === "string" || t === "number" || t === "boolean") return String(value);
|
|
1716
|
+
try {
|
|
1717
|
+
return _nullishCoalesce(JSON.stringify(value), () => ( ""));
|
|
1718
|
+
} catch (e6) {
|
|
1719
|
+
return String(value);
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1722
|
+
function asListOfObjects(value) {
|
|
1723
|
+
if (!value) return [];
|
|
1724
|
+
if (Array.isArray(value)) {
|
|
1725
|
+
const out = [];
|
|
1726
|
+
for (const v of value) {
|
|
1727
|
+
if (v && typeof v === "object" && !Array.isArray(v)) out.push(v);
|
|
1728
|
+
else if (typeof v === "string") out.push({ content: v });
|
|
1729
|
+
}
|
|
1730
|
+
return out;
|
|
1731
|
+
}
|
|
1732
|
+
if (typeof value === "object") return [value];
|
|
1733
|
+
return [];
|
|
1734
|
+
}
|
|
1735
|
+
function itemText(item) {
|
|
1736
|
+
return item["content"] || item["text"] || stringify(item);
|
|
1737
|
+
}
|
|
1738
|
+
function buildRecentMessages(turns) {
|
|
1739
|
+
return (_nullishCoalesce(turns, () => ( []))).map((t, idx) => ({
|
|
1740
|
+
role: t.role || "user",
|
|
1741
|
+
content: _nullishCoalesce(t.content, () => ( "")),
|
|
1742
|
+
timestamp: t.timestamp,
|
|
1743
|
+
message_id: `local-${idx}`
|
|
1744
|
+
}));
|
|
1745
|
+
}
|
|
1746
|
+
function compactedMessageCount(_entry) {
|
|
1747
|
+
return 0;
|
|
1748
|
+
}
|
|
1749
|
+
function formatStructured(entry, recent) {
|
|
1750
|
+
const parts = [];
|
|
1751
|
+
if (entry.summary) {
|
|
1752
|
+
parts.push("## Summary");
|
|
1753
|
+
parts.push(entry.summary.trim());
|
|
1754
|
+
}
|
|
1755
|
+
if (entry.factualParagraph) {
|
|
1756
|
+
parts.push("## Facts");
|
|
1757
|
+
parts.push(entry.factualParagraph.trim());
|
|
1758
|
+
}
|
|
1759
|
+
if (entry.conversationalParagraph) {
|
|
1760
|
+
parts.push("## Conversation");
|
|
1761
|
+
parts.push(entry.conversationalParagraph.trim());
|
|
1762
|
+
}
|
|
1763
|
+
const cs = _nullishCoalesce(entry.currentState, () => ( {}));
|
|
1764
|
+
if (Object.keys(cs).length > 0) {
|
|
1765
|
+
parts.push("## Current State");
|
|
1766
|
+
for (const [k, v] of Object.entries(cs)) parts.push(`- ${k}: ${stringify(v)}`);
|
|
1767
|
+
}
|
|
1768
|
+
const ke = _nullishCoalesce(entry.keyExtractions, () => ( {}));
|
|
1769
|
+
if (Object.keys(ke).length > 0) {
|
|
1770
|
+
parts.push("## Key Extractions");
|
|
1771
|
+
for (const [cat, items] of Object.entries(ke)) {
|
|
1772
|
+
if (!items) continue;
|
|
1773
|
+
parts.push(`### ${cat}`);
|
|
1774
|
+
for (const it of asListOfObjects(items)) parts.push(`- ${itemText(it)}`);
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
if (recent.length > 0) {
|
|
1778
|
+
parts.push(`## Recent Turns (${recent.length})`);
|
|
1779
|
+
for (const m of recent) parts.push(`**${m.role}**: ${m.content}`);
|
|
1780
|
+
}
|
|
1781
|
+
return parts.filter(Boolean).join("\n\n").trim();
|
|
1782
|
+
}
|
|
1783
|
+
function formatNarrative(entry, recent) {
|
|
1784
|
+
const parts = [];
|
|
1785
|
+
if (entry.summary) parts.push(entry.summary.trim());
|
|
1786
|
+
if (entry.conversationalParagraph) parts.push(entry.conversationalParagraph.trim());
|
|
1787
|
+
else if (entry.factualParagraph) parts.push(entry.factualParagraph.trim());
|
|
1788
|
+
if (recent.length > 0) {
|
|
1789
|
+
const tail = recent.map((m) => `${m.role}: ${m.content}`).join("\n");
|
|
1790
|
+
parts.push(`Recent exchanges:
|
|
1791
|
+
${tail}`);
|
|
1792
|
+
}
|
|
1793
|
+
return parts.filter(Boolean).join("\n\n").trim();
|
|
1794
|
+
}
|
|
1795
|
+
function formatBullets(entry, recent) {
|
|
1796
|
+
const parts = [];
|
|
1797
|
+
if (entry.summary) parts.push(`- Summary: ${entry.summary.trim()}`);
|
|
1798
|
+
for (const [k, v] of Object.entries(_nullishCoalesce(entry.currentState, () => ( {})))) {
|
|
1799
|
+
parts.push(`- ${k}: ${stringify(v)}`);
|
|
1800
|
+
}
|
|
1801
|
+
for (const [cat, items] of Object.entries(_nullishCoalesce(entry.keyExtractions, () => ( {})))) {
|
|
1802
|
+
for (const it of asListOfObjects(items)) parts.push(`- (${cat}) ${itemText(it)}`);
|
|
1803
|
+
}
|
|
1804
|
+
for (const m of recent) parts.push(`- ${m.role}: ${m.content}`);
|
|
1805
|
+
return parts.join("\n").trim();
|
|
1806
|
+
}
|
|
1807
|
+
function formatBlock(entry, recent, style) {
|
|
1808
|
+
if (style === "narrative") return formatNarrative(entry, recent);
|
|
1809
|
+
if (style === "bullet_points") return formatBullets(entry, recent);
|
|
1810
|
+
return formatStructured(entry, recent);
|
|
1811
|
+
}
|
|
1812
|
+
function renderForPrompt(entry, style = DEFAULT_STYLE, now = Date.now) {
|
|
1813
|
+
const chosen = SUPPORTED_STYLES.includes(style) ? style : DEFAULT_STYLE;
|
|
1814
|
+
const recent = buildRecentMessages(entry.recentTurns);
|
|
1815
|
+
const formatted = formatBlock(entry, recent, chosen);
|
|
1816
|
+
const available = entry.compactionId !== null || entry.recentTurns.length > 0;
|
|
1817
|
+
let compactionAge = null;
|
|
1818
|
+
if (entry.compactedAt !== null) {
|
|
1819
|
+
const parsed = Date.parse(entry.compactedAt);
|
|
1820
|
+
if (!Number.isNaN(parsed)) compactionAge = Math.floor((now() - parsed) / 1e3);
|
|
1821
|
+
}
|
|
1822
|
+
const compacted = compactedMessageCount(entry);
|
|
1823
|
+
return {
|
|
1824
|
+
formatted_context: available ? formatted : null,
|
|
1825
|
+
available,
|
|
1826
|
+
is_stale: false,
|
|
1827
|
+
compression_ratio: null,
|
|
1828
|
+
validation_score: null,
|
|
1829
|
+
compaction_age_seconds: compactionAge,
|
|
1830
|
+
quality_warning: false,
|
|
1831
|
+
recent_messages: recent,
|
|
1832
|
+
recent_message_count: recent.length,
|
|
1833
|
+
compacted_message_count: compacted,
|
|
1834
|
+
total_message_count: recent.length + compacted
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
function renderCompacted(entry, format = "structured", correlationId = "") {
|
|
1838
|
+
if (entry.compactionId === null) return null;
|
|
1839
|
+
const formatted = formatBlock(
|
|
1840
|
+
entry,
|
|
1841
|
+
buildRecentMessages(entry.recentTurns),
|
|
1842
|
+
format === "narrative" ? "narrative" : "structured"
|
|
1843
|
+
);
|
|
1844
|
+
return {
|
|
1845
|
+
compacted_context: formatted,
|
|
1846
|
+
compaction_id: entry.compactionId,
|
|
1847
|
+
compacted_at: entry.compactedAt,
|
|
1848
|
+
conversation_id: entry.conversationId,
|
|
1849
|
+
current_state: entry.currentState,
|
|
1850
|
+
correlation_id: correlationId,
|
|
1851
|
+
original_token_count: null,
|
|
1852
|
+
compacted_token_count: null,
|
|
1853
|
+
compression_ratio: null,
|
|
1854
|
+
level_applied: null,
|
|
1855
|
+
validation_score: null,
|
|
1856
|
+
validation_passed: null,
|
|
1857
|
+
quality_warning: false
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1624
1861
|
// src/context/user-summary.ts
|
|
1625
1862
|
var USER_SUMMARY_INTERVAL = 5;
|
|
1626
1863
|
var MAX_SUMMARY_ITEMS = 3;
|
|
@@ -1751,7 +1988,7 @@ function tryServeFromCache(cache, scope, params, maxItems) {
|
|
|
1751
1988
|
});
|
|
1752
1989
|
if (hit === null) return { response: null, hit: null };
|
|
1753
1990
|
return { response: buildAnticipationResponse(hit), hit };
|
|
1754
|
-
} catch (
|
|
1991
|
+
} catch (e7) {
|
|
1755
1992
|
return { response: null, hit: null };
|
|
1756
1993
|
}
|
|
1757
1994
|
}
|
|
@@ -2146,7 +2383,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2146
2383
|
const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
|
|
2147
2384
|
if (!VALID_SCOPES.includes(scope)) {
|
|
2148
2385
|
const sorted = [...VALID_SCOPES].sort();
|
|
2149
|
-
throw new (0,
|
|
2386
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
2150
2387
|
`scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
|
|
2151
2388
|
);
|
|
2152
2389
|
}
|
|
@@ -2154,10 +2391,10 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2154
2391
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
2155
2392
|
const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
|
|
2156
2393
|
if (scope === "user" && (userId === void 0 || userId === "")) {
|
|
2157
|
-
throw new (0,
|
|
2394
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("scope='user' requires user_id");
|
|
2158
2395
|
}
|
|
2159
2396
|
if (scope === "customer" && (customerId === void 0 || customerId === "")) {
|
|
2160
|
-
throw new (0,
|
|
2397
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("scope='customer' requires customer_id");
|
|
2161
2398
|
}
|
|
2162
2399
|
if (scope === "conversation" && (userId === void 0 || userId === "")) {
|
|
2163
2400
|
onWarning(
|
|
@@ -2166,7 +2403,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2166
2403
|
}
|
|
2167
2404
|
const style = String(_nullishCoalesce(options.style, () => ( "openai")));
|
|
2168
2405
|
if (style !== "openai" && style !== "anthropic") {
|
|
2169
|
-
throw new (0,
|
|
2406
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
|
|
2170
2407
|
}
|
|
2171
2408
|
const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
|
|
2172
2409
|
const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
|
|
@@ -2209,6 +2446,9 @@ var SynapClient = class {
|
|
|
2209
2446
|
#registryKeys;
|
|
2210
2447
|
#compactionSubscribers;
|
|
2211
2448
|
#shortTerm;
|
|
2449
|
+
#stVerbatimOverlay;
|
|
2450
|
+
#logger;
|
|
2451
|
+
#stAuthoritative;
|
|
2212
2452
|
#turns;
|
|
2213
2453
|
#fetchHooks;
|
|
2214
2454
|
constructor(options = {}) {
|
|
@@ -2279,6 +2519,9 @@ var SynapClient = class {
|
|
|
2279
2519
|
this.client = { context: { fetch: async (o2 = {}) => fetchContext(this.#transport, "client", o2, this.#fetchHooks) } };
|
|
2280
2520
|
this.#compactionSubscribers = new CompactionSubscribers();
|
|
2281
2521
|
this.#shortTerm = new ShortTermStore();
|
|
2522
|
+
this.#stVerbatimOverlay = _nullishCoalesce(options.st_verbatim_overlay, () => ( options.stVerbatimOverlay));
|
|
2523
|
+
this.#logger = options.logger;
|
|
2524
|
+
this.#stAuthoritative = _nullishCoalesce(options.sdk_st_authoritative, () => ( options.sdkStAuthoritative));
|
|
2282
2525
|
this.#turns = new TurnCounter();
|
|
2283
2526
|
this.conversation = createConversationNamespace(
|
|
2284
2527
|
this.#transport,
|
|
@@ -2299,8 +2542,12 @@ var SynapClient = class {
|
|
|
2299
2542
|
this.#shortTerm.appendTurn(conversationId, role, content, timestamp);
|
|
2300
2543
|
},
|
|
2301
2544
|
(response, conversationId, userId) => {
|
|
2302
|
-
overlayLocalRecentTurns(response, this.#shortTerm, conversationId);
|
|
2545
|
+
overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
|
|
2303
2546
|
this.#injectUserSummary(response, conversationId, userId);
|
|
2547
|
+
},
|
|
2548
|
+
{
|
|
2549
|
+
prompt: (conversationId, style) => this.#localPrompt(conversationId, style),
|
|
2550
|
+
compacted: (conversationId, format) => this.#localCompacted(conversationId, format)
|
|
2304
2551
|
}
|
|
2305
2552
|
);
|
|
2306
2553
|
this.memories = createMemoriesInterface(this.#transport);
|
|
@@ -2351,9 +2598,9 @@ var SynapClient = class {
|
|
|
2351
2598
|
*/
|
|
2352
2599
|
async searchMemory(options) {
|
|
2353
2600
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
2354
|
-
if (!userId) throw new (0,
|
|
2601
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
2355
2602
|
if (options.query === void 0 || options.query === null) {
|
|
2356
|
-
throw new (0,
|
|
2603
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("query is required");
|
|
2357
2604
|
}
|
|
2358
2605
|
const context = await fetchContext(this.#transport, "user", {
|
|
2359
2606
|
user_id: userId,
|
|
@@ -2374,7 +2621,7 @@ var SynapClient = class {
|
|
|
2374
2621
|
*/
|
|
2375
2622
|
async getMemories(options) {
|
|
2376
2623
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
2377
|
-
if (!userId) throw new (0,
|
|
2624
|
+
if (!userId) throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("user_id is required");
|
|
2378
2625
|
const context = await fetchContext(this.#transport, "user", {
|
|
2379
2626
|
user_id: userId,
|
|
2380
2627
|
...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
|
|
@@ -2422,8 +2669,8 @@ var SynapClient = class {
|
|
|
2422
2669
|
const whoami = await this.#transport.request("whoami", {});
|
|
2423
2670
|
const resolvedClientId = String(_nullishCoalesce(whoami["client_id"], () => ( "")));
|
|
2424
2671
|
const resolvedInstanceId = String(_nullishCoalesce(whoami["instance_id"], () => ( "")));
|
|
2425
|
-
const
|
|
2426
|
-
this.#transport.userContextIsolation = typeof
|
|
2672
|
+
const iso3 = whoami["user_context_isolation"];
|
|
2673
|
+
this.#transport.userContextIsolation = typeof iso3 === "string" ? iso3 : void 0;
|
|
2427
2674
|
this.#transport.updateCredentials({
|
|
2428
2675
|
...resolvedClientId !== "" && credentials.clientId === "" ? { clientId: resolvedClientId } : {},
|
|
2429
2676
|
...resolvedInstanceId !== "" && credentials.instanceId === "" ? { instanceId: resolvedInstanceId } : {}
|
|
@@ -2433,7 +2680,7 @@ var SynapClient = class {
|
|
|
2433
2680
|
this.#registryKeys.push(resolvedInstanceId);
|
|
2434
2681
|
}
|
|
2435
2682
|
}
|
|
2436
|
-
} catch (
|
|
2683
|
+
} catch (e8) {
|
|
2437
2684
|
}
|
|
2438
2685
|
}
|
|
2439
2686
|
/**
|
|
@@ -2459,20 +2706,22 @@ var SynapClient = class {
|
|
|
2459
2706
|
* initialization: the transport and cache are already built by then and a
|
|
2460
2707
|
* half-applied config is worse than a rejected one.
|
|
2461
2708
|
*
|
|
2462
|
-
*
|
|
2463
|
-
* `
|
|
2464
|
-
*
|
|
2465
|
-
*
|
|
2466
|
-
*
|
|
2709
|
+
* `logger` is honoured here as well as on the constructor. The remaining
|
|
2710
|
+
* Python-only keys (`storage_path`, `cache_backend`,
|
|
2711
|
+
* `session_timeout_minutes`, `log_level`) are accepted and ignored rather
|
|
2712
|
+
* than rejected, because this SDK has no SQLite cache backend and no global
|
|
2713
|
+
* logging framework whose level there would be to set. Ignoring them keeps
|
|
2714
|
+
* a shared config object portable between the two SDKs.
|
|
2467
2715
|
*/
|
|
2468
2716
|
configure(options = {}) {
|
|
2469
2717
|
if (this.#initialized) {
|
|
2470
|
-
throw new (0,
|
|
2718
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)("Cannot reconfigure after initialization");
|
|
2471
2719
|
}
|
|
2472
2720
|
if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
|
|
2473
2721
|
if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
|
|
2474
2722
|
this.#transport.setRetryPolicy(_nullishCoalesce(_nullishCoalesce(options.retryPolicy, () => ( options.retry_policy)), () => ( null)));
|
|
2475
2723
|
}
|
|
2724
|
+
if (options.logger !== void 0) this.#logger = options.logger;
|
|
2476
2725
|
}
|
|
2477
2726
|
/**
|
|
2478
2727
|
* Fetch and merge context across every scope with an identifier, in one call.
|
|
@@ -2565,19 +2814,19 @@ var SynapClient = class {
|
|
|
2565
2814
|
successful.push([label, result.value]);
|
|
2566
2815
|
continue;
|
|
2567
2816
|
}
|
|
2568
|
-
if (result.reason instanceof
|
|
2817
|
+
if (result.reason instanceof _chunk2TVL5IPQcjs.InvalidInputError) throw result.reason;
|
|
2569
2818
|
this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
|
|
2570
2819
|
}
|
|
2571
2820
|
const merged = mergeScopeResults(successful);
|
|
2572
2821
|
for (const [, response] of successful) {
|
|
2573
|
-
overlayLocalRecentTurns(response, this.#shortTerm, conversationId);
|
|
2822
|
+
overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
|
|
2574
2823
|
}
|
|
2575
2824
|
if (includeConversationContext && conversationId !== void 0 && conversationId !== "") {
|
|
2576
2825
|
try {
|
|
2577
2826
|
merged.conversation_context = await this.conversation.context.get_context_for_prompt({
|
|
2578
2827
|
conversation_id: conversationId
|
|
2579
2828
|
});
|
|
2580
|
-
} catch (
|
|
2829
|
+
} catch (e9) {
|
|
2581
2830
|
}
|
|
2582
2831
|
}
|
|
2583
2832
|
merged.formatted_context = formatForPrompt(merged, {
|
|
@@ -2624,7 +2873,7 @@ var SynapClient = class {
|
|
|
2624
2873
|
source_bundle_ids: served.bundleId ? [served.bundleId] : [],
|
|
2625
2874
|
timestamp_ms: Date.now()
|
|
2626
2875
|
});
|
|
2627
|
-
} catch (
|
|
2876
|
+
} catch (e10) {
|
|
2628
2877
|
}
|
|
2629
2878
|
}
|
|
2630
2879
|
/**
|
|
@@ -2649,7 +2898,7 @@ var SynapClient = class {
|
|
|
2649
2898
|
}),
|
|
2650
2899
|
scope
|
|
2651
2900
|
});
|
|
2652
|
-
} catch (
|
|
2901
|
+
} catch (e11) {
|
|
2653
2902
|
}
|
|
2654
2903
|
}
|
|
2655
2904
|
/**
|
|
@@ -2667,8 +2916,44 @@ var SynapClient = class {
|
|
|
2667
2916
|
if (summary === null) return;
|
|
2668
2917
|
mergeUserSummary(response, summary);
|
|
2669
2918
|
}
|
|
2670
|
-
/**
|
|
2919
|
+
/**
|
|
2920
|
+
* Whether the SDK is authoritative for short-term context.
|
|
2921
|
+
*
|
|
2922
|
+
* Resolution order matches Python's `_is_st_authoritative`: the explicit
|
|
2923
|
+
* option first, then `SYNAP_SDK_ST_AUTHORITATIVE` (truthy strings only).
|
|
2924
|
+
* Defaults to false, so nothing changes for a caller who never sets it.
|
|
2925
|
+
*/
|
|
2926
|
+
#isStAuthoritative() {
|
|
2927
|
+
if (this.#stAuthoritative === true) return true;
|
|
2928
|
+
const raw = (_nullishCoalesce(_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_SDK_ST_AUTHORITATIVE"), () => ( ""))).trim().toLowerCase();
|
|
2929
|
+
return ["1", "true", "yes", "on"].includes(raw);
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Render `get_context_for_prompt` from the local store, or null to fall
|
|
2933
|
+
* through to the network. Warm means a compaction landed OR raw turns are
|
|
2934
|
+
* buffered: with neither there is nothing to render and the server's answer
|
|
2935
|
+
* is the only real one.
|
|
2936
|
+
*/
|
|
2937
|
+
#localPrompt(conversationId, style) {
|
|
2938
|
+
if (!this.#isStAuthoritative()) return null;
|
|
2939
|
+
const entry = this.#shortTerm.get(conversationId);
|
|
2940
|
+
if (entry === null) return null;
|
|
2941
|
+
if (entry.compactionId === null && entry.recentTurns.length === 0) return null;
|
|
2942
|
+
return renderForPrompt(entry, style);
|
|
2943
|
+
}
|
|
2944
|
+
/** Same, for `get_compacted`. Requires an actual compaction, not just turns. */
|
|
2945
|
+
#localCompacted(conversationId, format) {
|
|
2946
|
+
if (!this.#isStAuthoritative()) return null;
|
|
2947
|
+
const entry = this.#shortTerm.get(conversationId);
|
|
2948
|
+
if (entry === null || entry.compactionId === null) return null;
|
|
2949
|
+
return renderCompacted(entry, format);
|
|
2950
|
+
}
|
|
2951
|
+
/** Every diagnostic the SDK emits passes through here. */
|
|
2671
2952
|
#warn(message) {
|
|
2953
|
+
if (this.#logger !== void 0) {
|
|
2954
|
+
this.#logger("warn", message);
|
|
2955
|
+
return;
|
|
2956
|
+
}
|
|
2672
2957
|
console.warn(`[synap] ${message}`);
|
|
2673
2958
|
}
|
|
2674
2959
|
/** Release timers and connections. Safe to call more than once. */
|
|
@@ -2689,14 +2974,15 @@ function pick3(o2, snake, camel) {
|
|
|
2689
2974
|
return a !== void 0 ? a : o2[camel];
|
|
2690
2975
|
}
|
|
2691
2976
|
function resolveBaseUrl(options) {
|
|
2692
|
-
|
|
2977
|
+
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
2978
|
+
if (explicit !== void 0) return explicit;
|
|
2693
2979
|
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _51 => _51.trim, 'call', _52 => _52()]);
|
|
2694
2980
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
2695
2981
|
}
|
|
2696
2982
|
function resolveCredentials(options) {
|
|
2697
2983
|
const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
|
|
2698
2984
|
if (!apiKey) {
|
|
2699
|
-
throw new (0,
|
|
2985
|
+
throw new (0, _chunk2TVL5IPQcjs.InvalidInputError)(
|
|
2700
2986
|
"No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
|
|
2701
2987
|
);
|
|
2702
2988
|
}
|
|
@@ -2756,5 +3042,6 @@ function resolveCredentials(options) {
|
|
|
2756
3042
|
|
|
2757
3043
|
|
|
2758
3044
|
|
|
2759
|
-
|
|
3045
|
+
|
|
3046
|
+
exports.ANY_SCOPE = _chunkRB57I2IQcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunk2TVL5IPQcjs.AgentUnavailableError; exports.AnticipationCache = _chunkRB57I2IQcjs.AnticipationCache; exports.AuthenticationError = _chunk2TVL5IPQcjs.AuthenticationError; exports.BM25 = _chunkRB57I2IQcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkRB57I2IQcjs.CONTRACT; exports.ConflictError = _chunk2TVL5IPQcjs.ConflictError; exports.ConnectionError = _chunk2TVL5IPQcjs.ConnectionError; exports.ContextNotFoundError = _chunk2TVL5IPQcjs.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.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunk2TVL5IPQcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunk2TVL5IPQcjs.InvalidConversationIdError; exports.InvalidInputError = _chunk2TVL5IPQcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunk2TVL5IPQcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunk2TVL5IPQcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunk2TVL5IPQcjs.ListeningNotActiveError; exports.NetworkTimeoutError = _chunk2TVL5IPQcjs.NetworkTimeoutError; exports.PermanentError = _chunk2TVL5IPQcjs.PermanentError; exports.RateLimitError = _chunk2TVL5IPQcjs.RateLimitError; exports.SDKError = _chunk2TVL5IPQcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunk2TVL5IPQcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunk2TVL5IPQcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunk2TVL5IPQcjs.SynapError; exports.SynapPermanentError = _chunk2TVL5IPQcjs.SynapPermanentError; exports.SynapTransientError = _chunk2TVL5IPQcjs.SynapTransientError; exports.THRESHOLDS = _chunkRB57I2IQcjs.THRESHOLDS; exports.TranscriptConflictError = _chunk2TVL5IPQcjs.TranscriptConflictError; exports.TransientError = _chunk2TVL5IPQcjs.TransientError; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkRB57I2IQcjs.isRecallQuery; exports.isSynapError = _chunk2TVL5IPQcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkRB57I2IQcjs.stem; exports.tokenize = _chunkRB57I2IQcjs.tokenize;
|
|
2760
3047
|
//# sourceMappingURL=index.cjs.map
|