@maximem/synap-js-sdk 0.5.10 → 0.5.12
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/{chunk-BWMPKLFG.js → chunk-4GE7SORD.js} +17 -1
- package/dist/chunk-4GE7SORD.js.map +1 -0
- package/dist/{chunk-I7TWR4S6.js → chunk-LJ66WCV3.js} +2 -2
- package/dist/{chunk-RE4DDIWO.cjs → chunk-QHPVLTQ7.cjs} +6 -6
- package/dist/{chunk-RE4DDIWO.cjs.map → chunk-QHPVLTQ7.cjs.map} +1 -1
- package/dist/{chunk-T372OL3Q.cjs → chunk-UXNVTP4D.cjs} +33 -17
- package/dist/chunk-UXNVTP4D.cjs.map +1 -0
- package/dist/{errors-Bdayqlzy.d.cts → errors-BvUA5EW8.d.cts} +14 -2
- package/dist/{errors-Bdayqlzy.d.ts → errors-BvUA5EW8.d.ts} +14 -2
- package/dist/grpc/index.cjs +7 -7
- package/dist/grpc/index.d.cts +1 -1
- package/dist/grpc/index.d.ts +1 -1
- package/dist/grpc/index.js +3 -3
- package/dist/index.cjs +189 -150
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +73 -34
- package/dist/index.js.map +1 -1
- package/dist/stream-client-5GYUWETN.cjs +16 -0
- package/dist/{stream-client-L6OQPZN7.cjs.map → stream-client-5GYUWETN.cjs.map} +1 -1
- package/dist/{stream-client-3WHXGW4U.js → stream-client-ZBCKRU7S.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-BWMPKLFG.js.map +0 -1
- package/dist/chunk-T372OL3Q.cjs.map +0 -1
- package/dist/stream-client-L6OQPZN7.cjs +0 -16
- /package/dist/{chunk-I7TWR4S6.js.map → chunk-LJ66WCV3.js.map} +0 -0
- /package/dist/{stream-client-3WHXGW4U.js.map → stream-client-ZBCKRU7S.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -39,7 +39,8 @@ var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
var _chunkUXNVTP4Dcjs = require('./chunk-UXNVTP4D.cjs');
|
|
43
44
|
|
|
44
45
|
// src/transport/endpoints.ts
|
|
45
46
|
var ENDPOINTS = {
|
|
@@ -102,7 +103,7 @@ function shouldRetry(input) {
|
|
|
102
103
|
if (attempt >= policy.maxAttempts) {
|
|
103
104
|
return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
|
|
104
105
|
}
|
|
105
|
-
if (!
|
|
106
|
+
if (!_chunkUXNVTP4Dcjs.isSynapError.call(void 0, error) || !error.transient) {
|
|
106
107
|
return { retry: false, delaySeconds: 0, reason: "not_transient" };
|
|
107
108
|
}
|
|
108
109
|
const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
|
|
@@ -120,7 +121,7 @@ function shouldRetry(input) {
|
|
|
120
121
|
};
|
|
121
122
|
}
|
|
122
123
|
function backoffDelay(error, attempt, policy) {
|
|
123
|
-
if (error instanceof
|
|
124
|
+
if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError && error.retryAfterSeconds != null) {
|
|
124
125
|
return Math.min(error.retryAfterSeconds, policy.backoffMax);
|
|
125
126
|
}
|
|
126
127
|
const exponential = policy.backoffBase * 2 ** (attempt - 1);
|
|
@@ -194,9 +195,7 @@ var B2C_ISOLATION = "equals_customer";
|
|
|
194
195
|
function checkCustomerId(isolation, customerId, where, instanceId) {
|
|
195
196
|
if (customerId === void 0 || customerId === null || customerId === "") return;
|
|
196
197
|
if (isolation !== B2C_ISOLATION) return;
|
|
197
|
-
throw new (0,
|
|
198
|
-
`${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)}.`
|
|
199
|
-
);
|
|
198
|
+
throw new (0, _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
|
|
200
199
|
}
|
|
201
200
|
|
|
202
201
|
// src/transport/http.ts
|
|
@@ -278,8 +277,13 @@ var HttpTransport = (_class2 = class {
|
|
|
278
277
|
async ready() {
|
|
279
278
|
if (this.identityResolver !== void 0) await this.identityResolver();
|
|
280
279
|
}
|
|
281
|
-
/**
|
|
282
|
-
|
|
280
|
+
/**
|
|
281
|
+
* Refuse a customer_id on a B2C instance, at the call site. Resolves identity
|
|
282
|
+
* first: the isolation comes from whoami, so on the first call of a client
|
|
283
|
+
* that skipped initialize() the check would otherwise see nothing and pass.
|
|
284
|
+
*/
|
|
285
|
+
async checkCustomerId(customerId, where) {
|
|
286
|
+
await this.ready();
|
|
283
287
|
checkCustomerId(
|
|
284
288
|
this.userContextIsolation,
|
|
285
289
|
customerId,
|
|
@@ -307,7 +311,7 @@ var HttpTransport = (_class2 = class {
|
|
|
307
311
|
}
|
|
308
312
|
async request(name, options = {}) {
|
|
309
313
|
const spec = ENDPOINTS[name];
|
|
310
|
-
const correlationId = _nullishCoalesce(options.correlationId, () => (
|
|
314
|
+
const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, )));
|
|
311
315
|
const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
|
|
312
316
|
if (name !== "whoami") await this.ready();
|
|
313
317
|
let attempt = 0;
|
|
@@ -330,7 +334,7 @@ var HttpTransport = (_class2 = class {
|
|
|
330
334
|
await sleep(decision.delaySeconds * 1e3, options.signal);
|
|
331
335
|
}
|
|
332
336
|
}
|
|
333
|
-
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0,
|
|
337
|
+
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _9 => _9.error]), () => ( new (0, _chunkUXNVTP4Dcjs.SynapError)("Request failed with no recorded error")));
|
|
334
338
|
}
|
|
335
339
|
async attempt(name, options, correlationId) {
|
|
336
340
|
const spec = ENDPOINTS[name];
|
|
@@ -363,7 +367,7 @@ var HttpTransport = (_class2 = class {
|
|
|
363
367
|
try {
|
|
364
368
|
return JSON.parse(text);
|
|
365
369
|
} catch (e3) {
|
|
366
|
-
throw new (0,
|
|
370
|
+
throw new (0, _chunkUXNVTP4Dcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
|
|
367
371
|
}
|
|
368
372
|
}
|
|
369
373
|
buildUrl(path, query) {
|
|
@@ -397,14 +401,14 @@ var HttpTransport = (_class2 = class {
|
|
|
397
401
|
}
|
|
398
402
|
}, _class2);
|
|
399
403
|
function isOutcomeUnknown(error) {
|
|
400
|
-
if (error instanceof
|
|
401
|
-
if (error instanceof
|
|
402
|
-
if (error instanceof
|
|
403
|
-
if (error instanceof
|
|
404
|
-
if (error instanceof
|
|
405
|
-
if (error instanceof
|
|
406
|
-
if (error instanceof
|
|
407
|
-
if (error instanceof
|
|
404
|
+
if (error instanceof _chunkUXNVTP4Dcjs.RateLimitError) return false;
|
|
405
|
+
if (error instanceof _chunkUXNVTP4Dcjs.ServiceUnavailableError) return false;
|
|
406
|
+
if (error instanceof _chunkUXNVTP4Dcjs.AuthenticationError) return false;
|
|
407
|
+
if (error instanceof _chunkUXNVTP4Dcjs.InvalidInputError) return false;
|
|
408
|
+
if (error instanceof _chunkUXNVTP4Dcjs.ConflictError) return false;
|
|
409
|
+
if (error instanceof _chunkUXNVTP4Dcjs.InsufficientCreditsError) return false;
|
|
410
|
+
if (error instanceof _chunkUXNVTP4Dcjs.ContextNotFoundError) return false;
|
|
411
|
+
if (error instanceof _chunkUXNVTP4Dcjs.NetworkTimeoutError) return true;
|
|
408
412
|
if (isConnectionRefusal(error)) return false;
|
|
409
413
|
return true;
|
|
410
414
|
}
|
|
@@ -413,12 +417,12 @@ function isConnectionRefusal(error) {
|
|
|
413
417
|
return code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "ECONNRESET" || code === "EHOSTUNREACH";
|
|
414
418
|
}
|
|
415
419
|
function toTransportError(error, correlationId) {
|
|
416
|
-
if (error instanceof
|
|
420
|
+
if (error instanceof _chunkUXNVTP4Dcjs.SynapError) return error;
|
|
417
421
|
const name = _optionalChain([error, 'optionalAccess', _13 => _13.name]);
|
|
418
422
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
419
|
-
return new (0,
|
|
423
|
+
return new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
|
|
420
424
|
}
|
|
421
|
-
return new (0,
|
|
425
|
+
return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(
|
|
422
426
|
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _14 => _14.message]), () => ( String(error)))}`,
|
|
423
427
|
{ correlationId, cause: error }
|
|
424
428
|
);
|
|
@@ -448,15 +452,15 @@ async function toHttpError(response, correlationId) {
|
|
|
448
452
|
switch (response.status) {
|
|
449
453
|
case 400:
|
|
450
454
|
case 422:
|
|
451
|
-
return new (0,
|
|
455
|
+
return new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(message, opts);
|
|
452
456
|
case 401:
|
|
453
457
|
case 403:
|
|
454
|
-
return new (0,
|
|
458
|
+
return new (0, _chunkUXNVTP4Dcjs.AuthenticationError)(message, opts);
|
|
455
459
|
case 404:
|
|
456
|
-
return new (0,
|
|
460
|
+
return new (0, _chunkUXNVTP4Dcjs.ContextNotFoundError)(message, opts);
|
|
457
461
|
case 402: {
|
|
458
462
|
const credit = creditPayload(parsed, detailObject);
|
|
459
|
-
return new (0,
|
|
463
|
+
return new (0, _chunkUXNVTP4Dcjs.InsufficientCreditsError)(message, {
|
|
460
464
|
...opts,
|
|
461
465
|
balanceCredits: numberOrNull(credit["balance_credits"]),
|
|
462
466
|
requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
|
|
@@ -468,14 +472,14 @@ async function toHttpError(response, correlationId) {
|
|
|
468
472
|
}
|
|
469
473
|
case 409:
|
|
470
474
|
if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
|
|
471
|
-
return new (0,
|
|
475
|
+
return new (0, _chunkUXNVTP4Dcjs.TranscriptConflictError)(message, opts);
|
|
472
476
|
}
|
|
473
|
-
return new (0,
|
|
477
|
+
return new (0, _chunkUXNVTP4Dcjs.ConflictError)(message, opts);
|
|
474
478
|
case 429: {
|
|
475
479
|
const header = response.headers.get("retry-after");
|
|
476
480
|
const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
|
|
477
481
|
const credit = creditPayload(parsed, detailObject);
|
|
478
|
-
return new (0,
|
|
482
|
+
return new (0, _chunkUXNVTP4Dcjs.RateLimitError)(message, {
|
|
479
483
|
...opts,
|
|
480
484
|
retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
|
|
481
485
|
reason: creditReason(credit),
|
|
@@ -484,12 +488,12 @@ async function toHttpError(response, correlationId) {
|
|
|
484
488
|
});
|
|
485
489
|
}
|
|
486
490
|
case 503:
|
|
487
|
-
return new (0,
|
|
491
|
+
return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
|
|
488
492
|
case 504:
|
|
489
|
-
return new (0,
|
|
493
|
+
return new (0, _chunkUXNVTP4Dcjs.AgentUnavailableError)(message, opts);
|
|
490
494
|
default:
|
|
491
|
-
if (response.status >= 500) return new (0,
|
|
492
|
-
return new (0,
|
|
495
|
+
if (response.status >= 500) return new (0, _chunkUXNVTP4Dcjs.ServiceUnavailableError)(message, opts);
|
|
496
|
+
return new (0, _chunkUXNVTP4Dcjs.SynapError)(message, opts);
|
|
493
497
|
}
|
|
494
498
|
}
|
|
495
499
|
function numberOrNull(v) {
|
|
@@ -502,7 +506,7 @@ function withTimeout(ms, external) {
|
|
|
502
506
|
const controller = new AbortController();
|
|
503
507
|
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _15 => _15.reason]));
|
|
504
508
|
const timer = setTimeout(() => {
|
|
505
|
-
controller.abort(new (0,
|
|
509
|
+
controller.abort(new (0, _chunkUXNVTP4Dcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
|
|
506
510
|
}, ms);
|
|
507
511
|
_optionalChain([timer, 'access', _16 => _16.unref, 'optionalCall', _17 => _17()]);
|
|
508
512
|
if (external) {
|
|
@@ -635,11 +639,12 @@ function buildFetchRequest(scope, options) {
|
|
|
635
639
|
const perQuery = opt(options, "max_results_per_query", "maxResultsPerQuery");
|
|
636
640
|
const responseShape = responseShapeOf(options);
|
|
637
641
|
const { mode, precisionLevel } = retrievalOptionsOf(options);
|
|
642
|
+
const { contextMode, lastN } = scopeOptionsOf(scope, options);
|
|
638
643
|
if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
|
|
639
|
-
throw new (0,
|
|
644
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("search_query must be an array when provided");
|
|
640
645
|
}
|
|
641
646
|
if (options.types !== void 0 && !Array.isArray(options.types)) {
|
|
642
|
-
throw new (0,
|
|
647
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("types must be an array when provided");
|
|
643
648
|
}
|
|
644
649
|
const body = {
|
|
645
650
|
conversation_id: _nullishCoalesce(conversationId, () => ( null)),
|
|
@@ -662,21 +667,7 @@ function buildFetchRequest(scope, options) {
|
|
|
662
667
|
switch (scope) {
|
|
663
668
|
case "user":
|
|
664
669
|
{
|
|
665
|
-
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
666
670
|
body["user_id"] = userId;
|
|
667
|
-
const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
|
|
668
|
-
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
669
|
-
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
670
|
-
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
|
|
674
|
-
if (!Number.isInteger(lastN)) {
|
|
675
|
-
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be an integer");
|
|
676
|
-
}
|
|
677
|
-
if (lastN < 0 || lastN > 20) {
|
|
678
|
-
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
|
|
679
|
-
}
|
|
680
671
|
if (contextMode === "conversation-summary") {
|
|
681
672
|
body["context_mode"] = contextMode;
|
|
682
673
|
body["include_profile"] = _nullishCoalesce(opt(options, "include_profile", "includeProfile"), () => ( true));
|
|
@@ -687,11 +678,9 @@ function buildFetchRequest(scope, options) {
|
|
|
687
678
|
}
|
|
688
679
|
break;
|
|
689
680
|
case "customer":
|
|
690
|
-
if (!customerId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("customer_id is required");
|
|
691
681
|
body["customer_id"] = customerId;
|
|
692
682
|
break;
|
|
693
683
|
case "conversation":
|
|
694
|
-
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
695
684
|
if (userId !== void 0) body["user_id"] = userId;
|
|
696
685
|
if (customerId !== void 0) body["customer_id"] = customerId;
|
|
697
686
|
break;
|
|
@@ -704,24 +693,51 @@ var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
|
|
|
704
693
|
function responseShapeOf(options) {
|
|
705
694
|
const shape = _nullishCoalesce(opt(options, "response_shape", "responseShape"), () => ( "by_type"));
|
|
706
695
|
if (!RESPONSE_SHAPES.includes(shape)) {
|
|
707
|
-
throw new (0,
|
|
696
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
708
697
|
`Invalid response_shape '${shape}'. Must be one of: ${RESPONSE_SHAPES.join(", ")}`
|
|
709
698
|
);
|
|
710
699
|
}
|
|
711
700
|
return shape;
|
|
712
701
|
}
|
|
702
|
+
var REQUIRED_ID = {
|
|
703
|
+
user: ["user_id", "userId"],
|
|
704
|
+
customer: ["customer_id", "customerId"],
|
|
705
|
+
conversation: ["conversation_id", "conversationId"],
|
|
706
|
+
client: null
|
|
707
|
+
};
|
|
708
|
+
function scopeOptionsOf(scope, options) {
|
|
709
|
+
const required = REQUIRED_ID[scope];
|
|
710
|
+
if (required !== null && !opt(options, required[0], required[1])) {
|
|
711
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`${required[0]} is required`);
|
|
712
|
+
}
|
|
713
|
+
const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
|
|
714
|
+
const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
|
|
715
|
+
if (scope !== "user") return { contextMode, lastN };
|
|
716
|
+
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
717
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
718
|
+
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
if (!Number.isInteger(lastN)) {
|
|
722
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be an integer");
|
|
723
|
+
}
|
|
724
|
+
if (lastN < 0 || lastN > 20) {
|
|
725
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
|
|
726
|
+
}
|
|
727
|
+
return { contextMode, lastN };
|
|
728
|
+
}
|
|
713
729
|
var VALID_MODES = ["fast", "accurate"];
|
|
714
730
|
var VALID_PRECISION = ["high", "medium"];
|
|
715
731
|
function retrievalOptionsOf(options) {
|
|
716
732
|
const mode = _nullishCoalesce(options.mode, () => ( "fast"));
|
|
717
733
|
if (!VALID_MODES.includes(mode)) {
|
|
718
|
-
throw new (0,
|
|
734
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
719
735
|
`Invalid mode '${mode}'. Must be one of: ${VALID_MODES.join(", ")}`
|
|
720
736
|
);
|
|
721
737
|
}
|
|
722
738
|
const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
|
|
723
739
|
if (!VALID_PRECISION.includes(precisionLevel)) {
|
|
724
|
-
throw new (0,
|
|
740
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
725
741
|
`Invalid precision_level '${precisionLevel}'. Must be one of: ${VALID_PRECISION.join(", ")}`
|
|
726
742
|
);
|
|
727
743
|
}
|
|
@@ -730,18 +746,24 @@ function retrievalOptionsOf(options) {
|
|
|
730
746
|
async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
731
747
|
const startedAt = Date.now();
|
|
732
748
|
await _optionalChain([transport, 'access', _25 => _25.ready, 'optionalCall', _26 => _26()]);
|
|
733
|
-
transport.checkCustomerId(
|
|
749
|
+
await transport.checkCustomerId(
|
|
734
750
|
opt(options, "customer_id", "customerId"),
|
|
735
751
|
`${scope}.context.fetch`
|
|
736
752
|
);
|
|
737
753
|
const responseShape = responseShapeOf(options);
|
|
738
754
|
retrievalOptionsOf(options);
|
|
755
|
+
const { contextMode } = scopeOptionsOf(scope, options);
|
|
756
|
+
const summaryMode = scope === "user" && contextMode === "conversation-summary";
|
|
757
|
+
const finish = (response2) => {
|
|
758
|
+
_optionalChain([hooks, 'access', _27 => _27.onResponse, 'optionalCall', _28 => _28(scope, options, response2)]);
|
|
759
|
+
return response2;
|
|
760
|
+
};
|
|
739
761
|
const network = async () => {
|
|
740
762
|
const { endpoint, body } = buildFetchRequest(scope, options);
|
|
741
763
|
const result = await transport.request(endpoint, { body });
|
|
742
|
-
return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
764
|
+
return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _29 => _29["context"]]), () => ( {})), responseShape);
|
|
743
765
|
};
|
|
744
|
-
const anticipated = await _asyncNullishCoalesce(await _optionalChain([hooks, 'access',
|
|
766
|
+
const anticipated = summaryMode ? null : await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _30 => _30.beforeFetch, 'optionalCall', _31 => _31(scope, options)]), async () => ( null));
|
|
745
767
|
if (anticipated !== null && anticipated.borderline) {
|
|
746
768
|
const pending = network();
|
|
747
769
|
pending.catch(() => void 0);
|
|
@@ -752,18 +774,18 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
|
752
774
|
const won = await Promise.race([pending.then((r) => r, () => null), late]);
|
|
753
775
|
if (timer !== void 0) clearTimeout(timer);
|
|
754
776
|
if (won !== null) {
|
|
755
|
-
_optionalChain([hooks, 'access',
|
|
756
|
-
return won;
|
|
777
|
+
_optionalChain([hooks, 'access', _32 => _32.onAssembled, 'optionalCall', _33 => _33(scope, options, won, startedAt)]);
|
|
778
|
+
return finish(won);
|
|
757
779
|
}
|
|
758
780
|
}
|
|
759
781
|
if (anticipated !== null) {
|
|
760
|
-
_optionalChain([hooks, 'access',
|
|
761
|
-
_optionalChain([hooks, 'access',
|
|
762
|
-
return applyResponseShape(anticipated.response, responseShape);
|
|
782
|
+
_optionalChain([hooks, 'access', _34 => _34.onServedFromCache, 'optionalCall', _35 => _35(scope, options, anticipated)]);
|
|
783
|
+
_optionalChain([hooks, 'access', _36 => _36.onAssembled, 'optionalCall', _37 => _37(scope, options, anticipated.response, startedAt)]);
|
|
784
|
+
return finish(applyResponseShape(anticipated.response, responseShape));
|
|
763
785
|
}
|
|
764
786
|
const response = await network();
|
|
765
|
-
_optionalChain([hooks, 'access',
|
|
766
|
-
return response;
|
|
787
|
+
_optionalChain([hooks, 'access', _38 => _38.onAssembled, 'optionalCall', _39 => _39(scope, options, response, startedAt)]);
|
|
788
|
+
return finish(response);
|
|
767
789
|
}
|
|
768
790
|
|
|
769
791
|
// src/context/normalize.ts
|
|
@@ -1017,17 +1039,17 @@ function isoOrNull(v) {
|
|
|
1017
1039
|
return v instanceof Date ? v.toISOString() : v;
|
|
1018
1040
|
}
|
|
1019
1041
|
function buildCreateBody(options) {
|
|
1020
|
-
if (!options.document) throw new (0,
|
|
1042
|
+
if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
|
|
1021
1043
|
const o2 = options;
|
|
1022
1044
|
const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
|
|
1023
1045
|
const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
|
|
1024
1046
|
if (!DOCUMENT_TYPES.includes(documentType)) {
|
|
1025
|
-
throw new (0,
|
|
1047
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1026
1048
|
`Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
|
|
1027
1049
|
);
|
|
1028
1050
|
}
|
|
1029
1051
|
if (!INGEST_MODES.includes(mode)) {
|
|
1030
|
-
throw new (0,
|
|
1052
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1031
1053
|
`Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
|
|
1032
1054
|
);
|
|
1033
1055
|
}
|
|
@@ -1054,13 +1076,13 @@ var FORGET_DESCRIPTION_MAX = 500;
|
|
|
1054
1076
|
function buildForgetBody(options) {
|
|
1055
1077
|
const description = options.description;
|
|
1056
1078
|
if (typeof description !== "string" || description.length < FORGET_DESCRIPTION_MIN || description.length > FORGET_DESCRIPTION_MAX) {
|
|
1057
|
-
throw new (0,
|
|
1079
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1058
1080
|
`description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
|
|
1059
1081
|
);
|
|
1060
1082
|
}
|
|
1061
1083
|
const mode = _nullishCoalesce(options.mode, () => ( "preview"));
|
|
1062
1084
|
if (!FORGET_MODES.includes(mode)) {
|
|
1063
|
-
throw new (0,
|
|
1085
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1064
1086
|
`Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
|
|
1065
1087
|
);
|
|
1066
1088
|
}
|
|
@@ -1078,13 +1100,13 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1078
1100
|
return {
|
|
1079
1101
|
async create(options) {
|
|
1080
1102
|
const o2 = options;
|
|
1081
|
-
transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.create");
|
|
1103
|
+
await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.create");
|
|
1082
1104
|
return transport.request("memories_create", { body: buildCreateBody(options) });
|
|
1083
1105
|
},
|
|
1084
1106
|
async batch_create(options) {
|
|
1085
1107
|
const docs = options.documents;
|
|
1086
1108
|
if (!Array.isArray(docs) || docs.length === 0) {
|
|
1087
|
-
throw new (0,
|
|
1109
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("documents must be a non-empty array");
|
|
1088
1110
|
}
|
|
1089
1111
|
const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
|
|
1090
1112
|
return transport.request("memories_batch", {
|
|
@@ -1094,15 +1116,15 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1094
1116
|
async create_from_file(options) {
|
|
1095
1117
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
1096
1118
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
1097
|
-
if (!userId) throw new (0,
|
|
1098
|
-
transport.checkCustomerId(customerId, "memories.create_from_file");
|
|
1119
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
1120
|
+
await transport.checkCustomerId(customerId, "memories.create_from_file");
|
|
1099
1121
|
const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
|
|
1100
1122
|
const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
|
|
1101
1123
|
if (sources.length === 0) {
|
|
1102
|
-
throw new (0,
|
|
1124
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
|
|
1103
1125
|
}
|
|
1104
1126
|
if (sources.length > 1) {
|
|
1105
|
-
throw new (0,
|
|
1127
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1106
1128
|
"Provide exactly one of file_path, file, or text, not several."
|
|
1107
1129
|
);
|
|
1108
1130
|
}
|
|
@@ -1133,13 +1155,13 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1133
1155
|
});
|
|
1134
1156
|
},
|
|
1135
1157
|
async get(memoryId) {
|
|
1136
|
-
if (!memoryId) throw new (0,
|
|
1158
|
+
if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
|
|
1137
1159
|
return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
|
|
1138
1160
|
},
|
|
1139
1161
|
async update(options) {
|
|
1140
1162
|
const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
|
|
1141
|
-
if (!memoryId) throw new (0,
|
|
1142
|
-
if (!options.document) throw new (0,
|
|
1163
|
+
if (!memoryId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("memory_id is required");
|
|
1164
|
+
if (!options.document) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("document is required");
|
|
1143
1165
|
const body = {
|
|
1144
1166
|
document: options.document,
|
|
1145
1167
|
merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
|
|
@@ -1154,7 +1176,7 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1154
1176
|
},
|
|
1155
1177
|
async delete(memoryId) {
|
|
1156
1178
|
if (!memoryId) {
|
|
1157
|
-
throw new (0,
|
|
1179
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
1158
1180
|
"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."
|
|
1159
1181
|
);
|
|
1160
1182
|
}
|
|
@@ -1162,10 +1184,10 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1162
1184
|
},
|
|
1163
1185
|
async forget(options) {
|
|
1164
1186
|
const o2 = options;
|
|
1165
|
-
transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
|
|
1187
|
+
await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
|
|
1166
1188
|
const body = buildForgetBody(options);
|
|
1167
1189
|
const result = await transport.request("memories_forget", { body });
|
|
1168
|
-
const removed = !!_optionalChain([result, 'optionalAccess',
|
|
1190
|
+
const removed = !!_optionalChain([result, 'optionalAccess', _40 => _40.deleted_ids, 'optionalAccess', _41 => _41.length]) || _optionalChain([result, 'optionalAccess', _42 => _42.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _43 => _43.status]) === "partial";
|
|
1169
1191
|
if (removed && onForgotten) {
|
|
1170
1192
|
try {
|
|
1171
1193
|
onForgotten({
|
|
@@ -1178,13 +1200,13 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1178
1200
|
return result;
|
|
1179
1201
|
},
|
|
1180
1202
|
async status(ingestionId) {
|
|
1181
|
-
if (!ingestionId) throw new (0,
|
|
1203
|
+
if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
|
|
1182
1204
|
return transport.request("memories_status", {
|
|
1183
1205
|
pathParams: { ingestion_id: ingestionId }
|
|
1184
1206
|
});
|
|
1185
1207
|
},
|
|
1186
1208
|
async wait_for_completion(ingestionId, options = {}) {
|
|
1187
|
-
if (!ingestionId) throw new (0,
|
|
1209
|
+
if (!ingestionId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("ingestion_id is required");
|
|
1188
1210
|
const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
|
|
1189
1211
|
const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
|
|
1190
1212
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -1205,14 +1227,14 @@ function sleep2(ms, signal) {
|
|
|
1205
1227
|
if (ms <= 0) return Promise.resolve();
|
|
1206
1228
|
return new Promise((resolve, reject) => {
|
|
1207
1229
|
const timer = setTimeout(() => {
|
|
1208
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1230
|
+
_optionalChain([signal, 'optionalAccess', _44 => _44.removeEventListener, 'call', _45 => _45("abort", onAbort)]);
|
|
1209
1231
|
resolve();
|
|
1210
1232
|
}, ms);
|
|
1211
1233
|
function onAbort() {
|
|
1212
1234
|
clearTimeout(timer);
|
|
1213
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
1235
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _46 => _46.reason]), () => ( new Error("Aborted"))));
|
|
1214
1236
|
}
|
|
1215
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1237
|
+
_optionalChain([signal, 'optionalAccess', _47 => _47.addEventListener, 'call', _48 => _48("abort", onAbort, { once: true })]);
|
|
1216
1238
|
});
|
|
1217
1239
|
}
|
|
1218
1240
|
|
|
@@ -1222,13 +1244,13 @@ 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
|
|
|
1222
1244
|
function validateConversationId(conversationId) {
|
|
1223
1245
|
if (conversationId === void 0 || conversationId === null || conversationId === "") return;
|
|
1224
1246
|
if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
|
|
1225
|
-
throw new (0,
|
|
1247
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
|
|
1226
1248
|
}
|
|
1227
1249
|
}
|
|
1228
1250
|
function validateInstanceId(instanceId) {
|
|
1229
1251
|
if (instanceId === void 0 || instanceId === null || instanceId === "") return;
|
|
1230
1252
|
if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
|
|
1231
|
-
throw new (0,
|
|
1253
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
|
|
1232
1254
|
}
|
|
1233
1255
|
}
|
|
1234
1256
|
|
|
@@ -1278,13 +1300,13 @@ function buildRecordMessageBody(options) {
|
|
|
1278
1300
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1279
1301
|
const userId = either2(o2, "user_id", "userId");
|
|
1280
1302
|
const customerId = either2(o2, "customer_id", "customerId");
|
|
1281
|
-
if (!conversationId) throw new (0,
|
|
1303
|
+
if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
|
|
1282
1304
|
validateConversationId(conversationId);
|
|
1283
|
-
if (!options.role) throw new (0,
|
|
1305
|
+
if (!options.role) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("role is required");
|
|
1284
1306
|
if (options.content === void 0 || options.content === null) {
|
|
1285
|
-
throw new (0,
|
|
1307
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("content is required");
|
|
1286
1308
|
}
|
|
1287
|
-
if (!userId) throw new (0,
|
|
1309
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
1288
1310
|
const body = {
|
|
1289
1311
|
conversation_id: conversationId,
|
|
1290
1312
|
role: options.role,
|
|
@@ -1304,10 +1326,10 @@ function buildIngestTranscriptBody(options) {
|
|
|
1304
1326
|
const o2 = options;
|
|
1305
1327
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1306
1328
|
const userId = either2(o2, "user_id", "userId");
|
|
1307
|
-
if (!conversationId) throw new (0,
|
|
1308
|
-
if (!userId) throw new (0,
|
|
1329
|
+
if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
|
|
1330
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
1309
1331
|
if (options.transcript === void 0 || options.transcript === null) {
|
|
1310
|
-
throw new (0,
|
|
1332
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("transcript is required");
|
|
1311
1333
|
}
|
|
1312
1334
|
const body = {
|
|
1313
1335
|
conversation_id: conversationId,
|
|
@@ -1331,7 +1353,7 @@ function buildIngestTranscriptBody(options) {
|
|
|
1331
1353
|
function buildCompactBody(options) {
|
|
1332
1354
|
const o2 = options;
|
|
1333
1355
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1334
|
-
if (!conversationId) throw new (0,
|
|
1356
|
+
if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
|
|
1335
1357
|
validateConversationId(conversationId);
|
|
1336
1358
|
const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
|
|
1337
1359
|
const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
|
|
@@ -1385,7 +1407,7 @@ function storedBatchRows(bodies, result) {
|
|
|
1385
1407
|
const r = _nullishCoalesce(result, () => ( {}));
|
|
1386
1408
|
const results = Array.isArray(r["results"]) ? r["results"] : [];
|
|
1387
1409
|
const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
|
|
1388
|
-
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess',
|
|
1410
|
+
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _49 => _49["index"]])));
|
|
1389
1411
|
const stored = bodies.filter((_, index) => !failed.has(index));
|
|
1390
1412
|
if (stored.length !== results.length) return [];
|
|
1391
1413
|
const pairs = [];
|
|
@@ -1427,13 +1449,13 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1427
1449
|
};
|
|
1428
1450
|
const convId = (v) => {
|
|
1429
1451
|
const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
|
|
1430
|
-
if (!id) throw new (0,
|
|
1452
|
+
if (!id) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
|
|
1431
1453
|
validateConversationId(id);
|
|
1432
1454
|
return id;
|
|
1433
1455
|
};
|
|
1434
1456
|
return {
|
|
1435
1457
|
async record_message(options) {
|
|
1436
|
-
transport.checkCustomerId(
|
|
1458
|
+
await transport.checkCustomerId(
|
|
1437
1459
|
_nullishCoalesce(options["customer_id"], () => ( options["customerId"])),
|
|
1438
1460
|
"conversation.record_message"
|
|
1439
1461
|
);
|
|
@@ -1461,11 +1483,11 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1461
1483
|
},
|
|
1462
1484
|
async record_messages_batch(messages) {
|
|
1463
1485
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
1464
|
-
throw new (0,
|
|
1486
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("messages must be a non-empty array");
|
|
1465
1487
|
}
|
|
1466
1488
|
for (const m of messages) {
|
|
1467
1489
|
const mo = m;
|
|
1468
|
-
transport.checkCustomerId(
|
|
1490
|
+
await transport.checkCustomerId(
|
|
1469
1491
|
_nullishCoalesce(mo["customer_id"], () => ( mo["customerId"])),
|
|
1470
1492
|
"conversation.record_messages_batch"
|
|
1471
1493
|
);
|
|
@@ -1531,8 +1553,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1531
1553
|
pathParams: { conversation_id: id },
|
|
1532
1554
|
query: { style: _nullishCoalesce(options.style, () => ( "structured")) }
|
|
1533
1555
|
});
|
|
1534
|
-
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
1535
|
-
_optionalChain([localShortTerm, 'access',
|
|
1556
|
+
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _50 => _50["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
1557
|
+
_optionalChain([localShortTerm, 'access', _51 => _51.reseed, 'optionalCall', _52 => _52(id, response)]);
|
|
1536
1558
|
return withHistory(response);
|
|
1537
1559
|
},
|
|
1538
1560
|
async compact(options) {
|
|
@@ -1572,8 +1594,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1572
1594
|
* Returns an idempotent unsubscribe thunk, matching Python.
|
|
1573
1595
|
*/
|
|
1574
1596
|
subscribe_to_compaction_updates(conversationId, callback) {
|
|
1575
|
-
if (!conversationId) throw new (0,
|
|
1576
|
-
if (typeof callback !== "function") throw new (0,
|
|
1597
|
+
if (!conversationId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("conversation_id is required");
|
|
1598
|
+
if (typeof callback !== "function") throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("callback is required");
|
|
1577
1599
|
return subscribers.add(conversationId, callback);
|
|
1578
1600
|
},
|
|
1579
1601
|
/** Remove subscribers for one conversation, or all of them. Returns the count removed. */
|
|
@@ -1589,7 +1611,7 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
1589
1611
|
return {
|
|
1590
1612
|
async get_profile(options) {
|
|
1591
1613
|
const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
1592
|
-
if (!userId) throw new (0,
|
|
1614
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
1593
1615
|
const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
1594
1616
|
return transport.request("user_profile", {
|
|
1595
1617
|
pathParams: { user_id: userId },
|
|
@@ -1638,7 +1660,7 @@ function createCreditsNamespace(transport) {
|
|
|
1638
1660
|
});
|
|
1639
1661
|
},
|
|
1640
1662
|
async redeem(code) {
|
|
1641
|
-
if (!code) throw new (0,
|
|
1663
|
+
if (!code) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("code is required");
|
|
1642
1664
|
return transport.request("credits_redeem", { body: { code } });
|
|
1643
1665
|
}
|
|
1644
1666
|
};
|
|
@@ -1649,11 +1671,11 @@ function createCacheNamespace(cache) {
|
|
|
1649
1671
|
return {
|
|
1650
1672
|
clear: () => cache.clear(),
|
|
1651
1673
|
clear_user: (userId) => {
|
|
1652
|
-
if (!userId) throw new (0,
|
|
1674
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
1653
1675
|
cache.dropEntity(userId);
|
|
1654
1676
|
},
|
|
1655
1677
|
clear_customer: (customerId) => {
|
|
1656
|
-
if (!customerId) throw new (0,
|
|
1678
|
+
if (!customerId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("customer_id is required");
|
|
1657
1679
|
cache.dropEntity(customerId);
|
|
1658
1680
|
},
|
|
1659
1681
|
stats: () => ({ bundles: cache.size, items: cache.itemCount })
|
|
@@ -1725,8 +1747,8 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1725
1747
|
let onConversationState = null;
|
|
1726
1748
|
const internals = {
|
|
1727
1749
|
onCompactionUpdate(conversationId, bundle) {
|
|
1728
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
1729
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
1750
|
+
_optionalChain([applyCompaction, 'optionalCall', _53 => _53(bundle)]);
|
|
1751
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _54 => _54(conversationId, bundle)]);
|
|
1730
1752
|
},
|
|
1731
1753
|
setCompactionApplier(apply) {
|
|
1732
1754
|
applyCompaction = apply;
|
|
@@ -1738,10 +1760,10 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1738
1760
|
onConversationState = handle;
|
|
1739
1761
|
},
|
|
1740
1762
|
sendContextUsed(event) {
|
|
1741
|
-
_optionalChain([client, 'optionalAccess',
|
|
1763
|
+
_optionalChain([client, 'optionalAccess', _55 => _55.sendContextUsed, 'call', _56 => _56(event)]);
|
|
1742
1764
|
},
|
|
1743
1765
|
sendContextAssembled(event) {
|
|
1744
|
-
_optionalChain([client, 'optionalAccess',
|
|
1766
|
+
_optionalChain([client, 'optionalAccess', _57 => _57.sendContextAssembled, 'call', _58 => _58(event)]);
|
|
1745
1767
|
},
|
|
1746
1768
|
setCompactionDispatcher(dispatch) {
|
|
1747
1769
|
dispatchCompaction = dispatch;
|
|
@@ -1753,7 +1775,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1753
1775
|
function ensureSession(conversationId, userId, customerId) {
|
|
1754
1776
|
if (!conversationId || !userId || client === null) return;
|
|
1755
1777
|
if (openSessions.has(conversationId)) return;
|
|
1756
|
-
const sessionId =
|
|
1778
|
+
const sessionId = _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, );
|
|
1757
1779
|
try {
|
|
1758
1780
|
client.sendSessionControl({
|
|
1759
1781
|
action: "start",
|
|
@@ -1769,13 +1791,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1769
1791
|
const namespace = {
|
|
1770
1792
|
async listen(options = {}) {
|
|
1771
1793
|
if (client !== null) {
|
|
1772
|
-
throw new (0,
|
|
1794
|
+
throw new (0, _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
1773
1795
|
}
|
|
1774
1796
|
try {
|
|
1775
|
-
_optionalChain([onListen, 'optionalCall',
|
|
1797
|
+
_optionalChain([onListen, 'optionalCall', _59 => _59()]);
|
|
1776
1798
|
} catch (e10) {
|
|
1777
1799
|
}
|
|
1778
|
-
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-
|
|
1800
|
+
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-5GYUWETN.cjs")));
|
|
1779
1801
|
const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
|
|
1780
1802
|
const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
|
|
1781
1803
|
const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
|
|
@@ -1790,17 +1812,17 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1790
1812
|
internals.onCompactionUpdate(conversationId, bundle);
|
|
1791
1813
|
},
|
|
1792
1814
|
onConversationState: (conversationId, messageCount) => {
|
|
1793
|
-
_optionalChain([onConversationState, 'optionalCall',
|
|
1815
|
+
_optionalChain([onConversationState, 'optionalCall', _60 => _60(conversationId, messageCount)]);
|
|
1794
1816
|
},
|
|
1795
1817
|
onStateChange: (state) => {
|
|
1796
1818
|
if (state !== "connected") openSessions.clear();
|
|
1797
1819
|
if (state === "reconnecting") {
|
|
1798
1820
|
reconnectAttempts += 1;
|
|
1799
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
1821
|
+
_optionalChain([onReconnect, 'optionalCall', _61 => _61(reconnectAttempts)]);
|
|
1800
1822
|
} else if (state === "disconnected") {
|
|
1801
|
-
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
1823
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _62 => _62.lastError]), () => ( null));
|
|
1802
1824
|
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
1803
|
-
_optionalChain([onDisconnect, 'optionalCall',
|
|
1825
|
+
_optionalChain([onDisconnect, 'optionalCall', _63 => _63(reason)]);
|
|
1804
1826
|
}
|
|
1805
1827
|
}
|
|
1806
1828
|
});
|
|
@@ -1808,9 +1830,9 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1808
1830
|
try {
|
|
1809
1831
|
await created.connect();
|
|
1810
1832
|
} catch (error) {
|
|
1811
|
-
if (error instanceof
|
|
1812
|
-
throw new (0,
|
|
1813
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1833
|
+
if (error instanceof _chunkUXNVTP4Dcjs.SynapError) throw error;
|
|
1834
|
+
throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
|
|
1835
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _64 => _64.message]), () => ( String(error)))}`,
|
|
1814
1836
|
{ cause: error }
|
|
1815
1837
|
);
|
|
1816
1838
|
}
|
|
@@ -1839,13 +1861,13 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1839
1861
|
}
|
|
1840
1862
|
},
|
|
1841
1863
|
async send_message(options) {
|
|
1842
|
-
if (client === null) throw new (0,
|
|
1864
|
+
if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
|
|
1843
1865
|
if (options.content === void 0) {
|
|
1844
|
-
throw new (0,
|
|
1866
|
+
throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("content is required");
|
|
1845
1867
|
}
|
|
1846
1868
|
const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
|
|
1847
1869
|
if (!KNOWN_EVENT_TYPES.has(eventType)) {
|
|
1848
|
-
throw new (0,
|
|
1870
|
+
throw new (0, _chunkUXNVTP4Dcjs.SynapError)(
|
|
1849
1871
|
`unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
|
|
1850
1872
|
);
|
|
1851
1873
|
}
|
|
@@ -1856,7 +1878,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1856
1878
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
1857
1879
|
);
|
|
1858
1880
|
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
1859
|
-
_optionalChain([onTurn, 'optionalCall',
|
|
1881
|
+
_optionalChain([onTurn, 'optionalCall', _65 => _65({
|
|
1860
1882
|
conversationId,
|
|
1861
1883
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
1862
1884
|
content: options.content
|
|
@@ -1902,7 +1924,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1902
1924
|
async record_tool_result(options) {
|
|
1903
1925
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1904
1926
|
if (conversationId) {
|
|
1905
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
1927
|
+
_optionalChain([onToolResult, 'optionalCall', _66 => _66({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
|
|
1906
1928
|
}
|
|
1907
1929
|
await namespace.send_message({
|
|
1908
1930
|
content: "",
|
|
@@ -1919,7 +1941,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1919
1941
|
});
|
|
1920
1942
|
},
|
|
1921
1943
|
async record_thinking(options) {
|
|
1922
|
-
if (client === null) throw new (0,
|
|
1944
|
+
if (client === null) throw new (0, _chunkUXNVTP4Dcjs.ListeningNotActiveError)("Listening is not active");
|
|
1923
1945
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1924
1946
|
ensureSession(
|
|
1925
1947
|
conversationId,
|
|
@@ -1954,7 +1976,7 @@ function createInstanceNamespace(credentials, cache, onTurn, agentModel = () =>
|
|
|
1954
1976
|
}
|
|
1955
1977
|
|
|
1956
1978
|
// src/version.ts
|
|
1957
|
-
var SDK_VERSION = "0.5.
|
|
1979
|
+
var SDK_VERSION = "0.5.12";
|
|
1958
1980
|
|
|
1959
1981
|
// src/registry.ts
|
|
1960
1982
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -2422,7 +2444,7 @@ var TurnStore = (_class3 = class {
|
|
|
2422
2444
|
}
|
|
2423
2445
|
/** Turns the server also holds: archived tool results are local only. Python: `count`. */
|
|
2424
2446
|
count(conversationId) {
|
|
2425
|
-
return (_nullishCoalesce(_optionalChain([this, 'access',
|
|
2447
|
+
return (_nullishCoalesce(_optionalChain([this, 'access', _67 => _67.#conversations, 'access', _68 => _68.get, 'call', _69 => _69(conversationId), 'optionalAccess', _70 => _70.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
|
|
2426
2448
|
}
|
|
2427
2449
|
sizeBytes() {
|
|
2428
2450
|
let n2 = 0;
|
|
@@ -2601,7 +2623,7 @@ function askedKinds(query) {
|
|
|
2601
2623
|
}
|
|
2602
2624
|
function asksHowItStarted(query) {
|
|
2603
2625
|
const spec = _chunkICUFS3B5cjs.HISTORY_SEARCH.early_query;
|
|
2604
|
-
if (!_optionalChain([spec, 'optionalAccess',
|
|
2626
|
+
if (!_optionalChain([spec, 'optionalAccess', _71 => _71.pattern])) return false;
|
|
2605
2627
|
return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
|
|
2606
2628
|
}
|
|
2607
2629
|
async function searchTurns(turns, query, options = {}) {
|
|
@@ -3617,7 +3639,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
3617
3639
|
const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
|
|
3618
3640
|
if (!VALID_SCOPES.includes(scope)) {
|
|
3619
3641
|
const sorted = [...VALID_SCOPES].sort();
|
|
3620
|
-
throw new (0,
|
|
3642
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
3621
3643
|
`scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
|
|
3622
3644
|
);
|
|
3623
3645
|
}
|
|
@@ -3625,10 +3647,10 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
3625
3647
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
3626
3648
|
const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
|
|
3627
3649
|
if (scope === "user" && (userId === void 0 || userId === "")) {
|
|
3628
|
-
throw new (0,
|
|
3650
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='user' requires user_id");
|
|
3629
3651
|
}
|
|
3630
3652
|
if (scope === "customer" && (customerId === void 0 || customerId === "")) {
|
|
3631
|
-
throw new (0,
|
|
3653
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("scope='customer' requires customer_id");
|
|
3632
3654
|
}
|
|
3633
3655
|
if (scope === "conversation" && (userId === void 0 || userId === "")) {
|
|
3634
3656
|
onWarning(
|
|
@@ -3637,7 +3659,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
3637
3659
|
}
|
|
3638
3660
|
const style = String(_nullishCoalesce(options.style, () => ( "openai")));
|
|
3639
3661
|
if (style !== "openai" && style !== "anthropic") {
|
|
3640
|
-
throw new (0,
|
|
3662
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
|
|
3641
3663
|
}
|
|
3642
3664
|
const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
|
|
3643
3665
|
const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
|
|
@@ -3772,6 +3794,21 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
3772
3794
|
},
|
|
3773
3795
|
onServedFromCache: (_scope, options2, served) => {
|
|
3774
3796
|
this.#emitContextUsed(options2, _scope, served);
|
|
3797
|
+
},
|
|
3798
|
+
// The periodic user-summary splice, as Python runs it at the end of the
|
|
3799
|
+
// user, customer and client fetches (the conversation fetch does its own
|
|
3800
|
+
// through `onFetched`). Until 0.5.12 only the conversation fetch had it,
|
|
3801
|
+
// so the same usage gave the model different context in JS.
|
|
3802
|
+
onResponse: (scope, options2, response) => {
|
|
3803
|
+
if (scope === "conversation") return;
|
|
3804
|
+
const o2 = options2;
|
|
3805
|
+
const owner = scope === "user" ? _nullishCoalesce(o2["user_id"], () => ( o2["userId"])) : scope === "customer" ? _nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])) : "_client";
|
|
3806
|
+
this.#injectUserSummary(
|
|
3807
|
+
response,
|
|
3808
|
+
_nullishCoalesce(o2["conversation_id"], () => ( o2["conversationId"])),
|
|
3809
|
+
owner,
|
|
3810
|
+
_chunkICUFS3B5cjs.rungKey.call(void 0, _nullishCoalesce(o2["scope_path"], () => ( o2["scopePath"])))
|
|
3811
|
+
);
|
|
3775
3812
|
}
|
|
3776
3813
|
};
|
|
3777
3814
|
this.user = createUserNamespace(this.#transport, this.#fetchHooks);
|
|
@@ -3791,7 +3828,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
3791
3828
|
this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
|
|
3792
3829
|
const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
|
|
3793
3830
|
this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
|
|
3794
|
-
if (_optionalChain([this, 'access',
|
|
3831
|
+
if (_optionalChain([this, 'access', _72 => _72.#localEncoder, 'optionalAccess', _73 => _73.model]) === _chunkICUFS3B5cjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
|
|
3795
3832
|
this.#turns = new TurnCounter();
|
|
3796
3833
|
this.conversation = createConversationNamespace(
|
|
3797
3834
|
this.#transport,
|
|
@@ -3885,9 +3922,9 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
3885
3922
|
*/
|
|
3886
3923
|
async searchMemory(options) {
|
|
3887
3924
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
3888
|
-
if (!userId) throw new (0,
|
|
3925
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
3889
3926
|
if (options.query === void 0 || options.query === null) {
|
|
3890
|
-
throw new (0,
|
|
3927
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("query is required");
|
|
3891
3928
|
}
|
|
3892
3929
|
const context = await fetchContext(this.#transport, "user", {
|
|
3893
3930
|
user_id: userId,
|
|
@@ -3908,7 +3945,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
3908
3945
|
*/
|
|
3909
3946
|
async getMemories(options) {
|
|
3910
3947
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
3911
|
-
if (!userId) throw new (0,
|
|
3948
|
+
if (!userId) throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("user_id is required");
|
|
3912
3949
|
const context = await fetchContext(this.#transport, "user", {
|
|
3913
3950
|
user_id: userId,
|
|
3914
3951
|
...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
|
|
@@ -4013,7 +4050,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4013
4050
|
*/
|
|
4014
4051
|
configure(options = {}) {
|
|
4015
4052
|
if (this.#initialized) {
|
|
4016
|
-
throw new (0,
|
|
4053
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)("Cannot reconfigure after initialization");
|
|
4017
4054
|
}
|
|
4018
4055
|
if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
|
|
4019
4056
|
if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
|
|
@@ -4064,6 +4101,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4064
4101
|
last_n_conversations: lastNConversations = 1,
|
|
4065
4102
|
response_shape: responseShape = "by_type"
|
|
4066
4103
|
} = options;
|
|
4104
|
+
await this.#transport.checkCustomerId(customerId, "sdk.fetch");
|
|
4067
4105
|
validateConversationId(conversationId);
|
|
4068
4106
|
responseShapeOf({ response_shape: responseShape });
|
|
4069
4107
|
const wants = (scope) => scopes === void 0 || scopes.includes(scope);
|
|
@@ -4131,7 +4169,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4131
4169
|
successful.push([label, result.value]);
|
|
4132
4170
|
continue;
|
|
4133
4171
|
}
|
|
4134
|
-
if (result.reason instanceof
|
|
4172
|
+
if (result.reason instanceof _chunkUXNVTP4Dcjs.InvalidInputError) throw result.reason;
|
|
4135
4173
|
this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
|
|
4136
4174
|
}
|
|
4137
4175
|
const merged = mergeScopeResults(successful);
|
|
@@ -4210,7 +4248,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4210
4248
|
if (!this.instance.is_listening) return;
|
|
4211
4249
|
this.instance._internal.sendContextAssembled({
|
|
4212
4250
|
...buildAssembledEvent({
|
|
4213
|
-
correlationId:
|
|
4251
|
+
correlationId: _chunkUXNVTP4Dcjs.newCorrelationId.call(void 0, ),
|
|
4214
4252
|
response,
|
|
4215
4253
|
conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
|
|
4216
4254
|
userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
|
|
@@ -4281,14 +4319,14 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4281
4319
|
}))
|
|
4282
4320
|
);
|
|
4283
4321
|
const entry = this.#shortTerm.get(conversationId);
|
|
4284
|
-
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess',
|
|
4322
|
+
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _74 => _74.serverMessageCount]), () => ( 0))) || 0);
|
|
4285
4323
|
this.#maybeBackfillTurns(conversationId, total);
|
|
4286
4324
|
if (!r["context_block"]) return response;
|
|
4287
4325
|
const turns = store.turns(conversationId);
|
|
4288
4326
|
let q = query;
|
|
4289
4327
|
if (!q) {
|
|
4290
4328
|
const latest = [...recent].reverse().find((m) => m["role"] === "user");
|
|
4291
|
-
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access',
|
|
4329
|
+
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _75 => _75.reverse, 'call', _76 => _76(), 'access', _77 => _77.find, 'call', _78 => _78((t) => t.role === "user"), 'optionalAccess', _79 => _79.content]), () => ( ""));
|
|
4292
4330
|
}
|
|
4293
4331
|
if (!q) return response;
|
|
4294
4332
|
const exclude = /* @__PURE__ */ new Set();
|
|
@@ -4432,13 +4470,13 @@ function pick3(o2, snake, camel) {
|
|
|
4432
4470
|
function resolveBaseUrl(options) {
|
|
4433
4471
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
4434
4472
|
if (explicit !== void 0) return explicit;
|
|
4435
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
4473
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()]);
|
|
4436
4474
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
4437
4475
|
}
|
|
4438
4476
|
function resolveCredentials(options) {
|
|
4439
4477
|
const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
|
|
4440
4478
|
if (!apiKey) {
|
|
4441
|
-
throw new (0,
|
|
4479
|
+
throw new (0, _chunkUXNVTP4Dcjs.InvalidInputError)(
|
|
4442
4480
|
"No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
|
|
4443
4481
|
);
|
|
4444
4482
|
}
|
|
@@ -4506,5 +4544,6 @@ function resolveCredentials(options) {
|
|
|
4506
4544
|
|
|
4507
4545
|
|
|
4508
4546
|
|
|
4509
|
-
|
|
4547
|
+
|
|
4548
|
+
exports.ANY_SCOPE = _chunkICUFS3B5cjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkUXNVTP4Dcjs.AgentUnavailableError; exports.AnticipationCache = _chunkICUFS3B5cjs.AnticipationCache; exports.AuthenticationError = _chunkUXNVTP4Dcjs.AuthenticationError; exports.BM25 = _chunkICUFS3B5cjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkICUFS3B5cjs.CONTRACT; exports.ConflictError = _chunkUXNVTP4Dcjs.ConflictError; exports.ConnectionError = _chunkUXNVTP4Dcjs.ConnectionError; exports.ContextNotFoundError = _chunkUXNVTP4Dcjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunkUXNVTP4Dcjs.CustomerIdNotAcceptedError; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.EXCERPT_CATEGORY = EXCERPT_CATEGORY; exports.FORGET_MODES = FORGET_MODES; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunkUXNVTP4Dcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkUXNVTP4Dcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkUXNVTP4Dcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkUXNVTP4Dcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkUXNVTP4Dcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkUXNVTP4Dcjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkUXNVTP4Dcjs.NetworkTimeoutError; exports.PermanentError = _chunkUXNVTP4Dcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkUXNVTP4Dcjs.RateLimitError; exports.SDKError = _chunkUXNVTP4Dcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunkUXNVTP4Dcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkUXNVTP4Dcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkUXNVTP4Dcjs.SynapError; exports.SynapPermanentError = _chunkUXNVTP4Dcjs.SynapPermanentError; exports.SynapTransientError = _chunkUXNVTP4Dcjs.SynapTransientError; exports.THRESHOLDS = _chunkICUFS3B5cjs.THRESHOLDS; exports.TranscriptConflictError = _chunkUXNVTP4Dcjs.TranscriptConflictError; exports.TransientError = _chunkUXNVTP4Dcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkICUFS3B5cjs.isRecallQuery; exports.isSynapError = _chunkUXNVTP4Dcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkICUFS3B5cjs.stem; exports.tokenize = _chunkICUFS3B5cjs.tokenize; exports.wireRankScore = wireRankScore;
|
|
4510
4549
|
//# sourceMappingURL=index.cjs.map
|