@maximem/synap-js-sdk 0.4.7 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anticipation-cache-LRE3TLK4.cjs +14 -0
- package/dist/anticipation-cache-LRE3TLK4.cjs.map +1 -0
- package/dist/anticipation-cache-WLU4NMD5.js +14 -0
- package/dist/{chunk-ZU6ZC4SU.js → chunk-ASM2OIIG.js} +305 -7
- package/dist/chunk-ASM2OIIG.js.map +1 -0
- package/dist/{chunk-OCMM2Z5P.js → chunk-BWMPKLFG.js} +40 -2
- package/dist/chunk-BWMPKLFG.js.map +1 -0
- package/dist/{chunk-3JSE64GW.cjs → chunk-IA2N5NUY.cjs} +315 -17
- package/dist/chunk-IA2N5NUY.cjs.map +1 -0
- package/dist/{chunk-6LDUDKHS.js → chunk-ODVOQOSO.js} +124 -8
- package/dist/chunk-ODVOQOSO.js.map +1 -0
- package/dist/{chunk-2TVL5IPQ.cjs → chunk-T372OL3Q.cjs} +41 -3
- package/dist/chunk-T372OL3Q.cjs.map +1 -0
- package/dist/{chunk-RB57I2IQ.cjs → chunk-T6U5PVAD.cjs} +125 -9
- package/dist/chunk-T6U5PVAD.cjs.map +1 -0
- package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
- package/dist/env-55ULHNJZ.cjs.map +1 -1
- package/dist/errors-Bl3vY1eb.d.cts +382 -0
- package/dist/errors-Bl3vY1eb.d.ts +382 -0
- package/dist/grpc/index.cjs +8 -8
- package/dist/grpc/index.cjs.map +1 -1
- package/dist/grpc/index.d.cts +44 -4
- package/dist/grpc/index.d.ts +44 -4
- package/dist/grpc/index.js +6 -6
- package/dist/index.cjs +301 -173
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -146
- package/dist/index.d.ts +102 -146
- package/dist/index.js +192 -64
- package/dist/index.js.map +1 -1
- package/dist/stream-client-6OWRYOA4.js +16 -0
- package/dist/stream-client-Y5JGSF2R.cjs +16 -0
- package/dist/stream-client-Y5JGSF2R.cjs.map +1 -0
- package/package.json +6 -1
- package/dist/anticipation-cache-ARYEEKMU.cjs +0 -10
- package/dist/anticipation-cache-ARYEEKMU.cjs.map +0 -1
- package/dist/anticipation-cache-BMVF5sXb.d.cts +0 -190
- package/dist/anticipation-cache-BMVF5sXb.d.ts +0 -190
- package/dist/anticipation-cache-H7HEVWQC.js +0 -10
- package/dist/chunk-2TVL5IPQ.cjs.map +0 -1
- package/dist/chunk-3JSE64GW.cjs.map +0 -1
- package/dist/chunk-6LDUDKHS.js.map +0 -1
- package/dist/chunk-OCMM2Z5P.js.map +0 -1
- package/dist/chunk-RB57I2IQ.cjs.map +0 -1
- package/dist/chunk-ZU6ZC4SU.js.map +0 -1
- package/dist/stream-client-6V4FGKZ3.js +0 -7
- package/dist/stream-client-PRTOH62B.cjs +0 -7
- package/dist/stream-client-PRTOH62B.cjs.map +0 -1
- /package/dist/{anticipation-cache-H7HEVWQC.js.map → anticipation-cache-WLU4NMD5.js.map} +0 -0
- /package/dist/{stream-client-6V4FGKZ3.js.map → stream-client-6OWRYOA4.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
var _chunkT6U5PVADcjs = require('./chunk-T6U5PVAD.cjs');
|
|
11
12
|
|
|
12
13
|
|
|
14
|
+
var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
|
|
@@ -22,7 +24,6 @@
|
|
|
22
24
|
|
|
23
25
|
|
|
24
26
|
|
|
25
|
-
var _chunk2TVL5IPQcjs = require('./chunk-2TVL5IPQ.cjs');
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
|
|
@@ -32,27 +33,11 @@ var _chunk2TVL5IPQcjs = require('./chunk-2TVL5IPQ.cjs');
|
|
|
32
33
|
|
|
33
34
|
|
|
34
35
|
|
|
35
|
-
var _chunkRB57I2IQcjs = require('./chunk-RB57I2IQ.cjs');
|
|
36
36
|
|
|
37
37
|
|
|
38
|
-
var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const c = globalThis.crypto;
|
|
43
|
-
if (typeof _optionalChain([c, 'optionalAccess', _ => _.randomUUID]) === "function") return c.randomUUID();
|
|
44
|
-
if (typeof _optionalChain([c, 'optionalAccess', _2 => _2.getRandomValues]) === "function") {
|
|
45
|
-
const b = c.getRandomValues(new Uint8Array(16));
|
|
46
|
-
b[6] = (_nullishCoalesce(b[6], () => ( 0))) & 15 | 64;
|
|
47
|
-
b[8] = (_nullishCoalesce(b[8], () => ( 0))) & 63 | 128;
|
|
48
|
-
const h = Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
49
|
-
return `${h.slice(0, 8)}-${h.slice(8, 12)}-${h.slice(12, 16)}-${h.slice(16, 20)}-${h.slice(20)}`;
|
|
50
|
-
}
|
|
51
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => {
|
|
52
|
-
const r = Math.random() * 16 | 0;
|
|
53
|
-
return (ch === "x" ? r : r & 3 | 8).toString(16);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
39
|
+
|
|
40
|
+
var _chunkT372OL3Qcjs = require('./chunk-T372OL3Q.cjs');
|
|
56
41
|
|
|
57
42
|
// src/transport/endpoints.ts
|
|
58
43
|
var ENDPOINTS = {
|
|
@@ -113,7 +98,7 @@ function shouldRetry(input) {
|
|
|
113
98
|
if (attempt >= policy.maxAttempts) {
|
|
114
99
|
return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
|
|
115
100
|
}
|
|
116
|
-
if (!
|
|
101
|
+
if (!_chunkT372OL3Qcjs.isSynapError.call(void 0, error) || !error.transient) {
|
|
117
102
|
return { retry: false, delaySeconds: 0, reason: "not_transient" };
|
|
118
103
|
}
|
|
119
104
|
const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
|
|
@@ -131,7 +116,7 @@ function shouldRetry(input) {
|
|
|
131
116
|
};
|
|
132
117
|
}
|
|
133
118
|
function backoffDelay(error, attempt, policy) {
|
|
134
|
-
if (error instanceof
|
|
119
|
+
if (error instanceof _chunkT372OL3Qcjs.RateLimitError && error.retryAfterSeconds != null) {
|
|
135
120
|
return Math.min(error.retryAfterSeconds, policy.backoffMax);
|
|
136
121
|
}
|
|
137
122
|
const exponential = policy.backoffBase * 2 ** (attempt - 1);
|
|
@@ -146,7 +131,7 @@ var HEARTBEAT_INTERVAL_MS = 24e4;
|
|
|
146
131
|
var MAX_CONNECTIONS = 20;
|
|
147
132
|
var cached;
|
|
148
133
|
function supportsDispatcher() {
|
|
149
|
-
return typeof process !== "undefined" && _optionalChain([process, 'access',
|
|
134
|
+
return typeof process !== "undefined" && _optionalChain([process, 'access', _ => _.versions, 'optionalAccess', _2 => _2.node]) !== void 0 && // Edge builds of Next expose a partial `process` shim, but no real Node.
|
|
150
135
|
typeof globalThis.EdgeRuntime === "undefined";
|
|
151
136
|
}
|
|
152
137
|
async function getKeepAliveDispatcher(options = {}) {
|
|
@@ -187,7 +172,7 @@ var Heartbeat = (_class = class {
|
|
|
187
172
|
void Promise.resolve(this.ping()).catch(() => {
|
|
188
173
|
});
|
|
189
174
|
}, this.intervalMs);
|
|
190
|
-
_optionalChain([this, 'access',
|
|
175
|
+
_optionalChain([this, 'access', _3 => _3.timer, 'access', _4 => _4.unref, 'optionalCall', _5 => _5()]);
|
|
191
176
|
}
|
|
192
177
|
stop() {
|
|
193
178
|
if (this.timer !== null) {
|
|
@@ -205,7 +190,7 @@ var B2C_ISOLATION = "equals_customer";
|
|
|
205
190
|
function checkCustomerId(isolation, customerId, where, instanceId) {
|
|
206
191
|
if (customerId === void 0 || customerId === null || customerId === "") return;
|
|
207
192
|
if (isolation !== B2C_ISOLATION) return;
|
|
208
|
-
throw new (0,
|
|
193
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
209
194
|
`${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
195
|
);
|
|
211
196
|
}
|
|
@@ -240,7 +225,7 @@ var HttpTransport = (_class2 = class {
|
|
|
240
225
|
this.keepAliveOptions = _nullishCoalesce(options.keepAlive, () => ( {}));
|
|
241
226
|
this.heartbeat = new Heartbeat(
|
|
242
227
|
() => this.pingHealth(),
|
|
243
|
-
_nullishCoalesce(_optionalChain([options, 'access',
|
|
228
|
+
_nullishCoalesce(_optionalChain([options, 'access', _6 => _6.keepAlive, 'optionalAccess', _7 => _7.heartbeatIntervalMs]), () => ( HEARTBEAT_INTERVAL_MS))
|
|
244
229
|
);
|
|
245
230
|
}
|
|
246
231
|
/** Start keeping the connection warm. Opt-in: it is pointless in serverless. */
|
|
@@ -307,7 +292,7 @@ var HttpTransport = (_class2 = class {
|
|
|
307
292
|
}
|
|
308
293
|
async request(name, options = {}) {
|
|
309
294
|
const spec = ENDPOINTS[name];
|
|
310
|
-
const correlationId = _nullishCoalesce(options.correlationId, () => ( newCorrelationId()));
|
|
295
|
+
const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkT372OL3Qcjs.newCorrelationId.call(void 0, )));
|
|
311
296
|
const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
|
|
312
297
|
let attempt = 0;
|
|
313
298
|
let last = null;
|
|
@@ -329,7 +314,7 @@ var HttpTransport = (_class2 = class {
|
|
|
329
314
|
await sleep(decision.delaySeconds * 1e3, options.signal);
|
|
330
315
|
}
|
|
331
316
|
}
|
|
332
|
-
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess',
|
|
317
|
+
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _8 => _8.error]), () => ( new (0, _chunkT372OL3Qcjs.SynapError)("Request failed with no recorded error")));
|
|
333
318
|
}
|
|
334
319
|
async attempt(name, options, correlationId) {
|
|
335
320
|
const spec = ENDPOINTS[name];
|
|
@@ -362,7 +347,7 @@ var HttpTransport = (_class2 = class {
|
|
|
362
347
|
try {
|
|
363
348
|
return JSON.parse(text);
|
|
364
349
|
} catch (e3) {
|
|
365
|
-
throw new (0,
|
|
350
|
+
throw new (0, _chunkT372OL3Qcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
|
|
366
351
|
}
|
|
367
352
|
}
|
|
368
353
|
buildUrl(path, query) {
|
|
@@ -396,32 +381,42 @@ var HttpTransport = (_class2 = class {
|
|
|
396
381
|
}
|
|
397
382
|
}, _class2);
|
|
398
383
|
function isOutcomeUnknown(error) {
|
|
399
|
-
if (error instanceof
|
|
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
|
|
384
|
+
if (error instanceof _chunkT372OL3Qcjs.RateLimitError) return false;
|
|
385
|
+
if (error instanceof _chunkT372OL3Qcjs.ServiceUnavailableError) return false;
|
|
386
|
+
if (error instanceof _chunkT372OL3Qcjs.AuthenticationError) return false;
|
|
387
|
+
if (error instanceof _chunkT372OL3Qcjs.InvalidInputError) return false;
|
|
388
|
+
if (error instanceof _chunkT372OL3Qcjs.ConflictError) return false;
|
|
389
|
+
if (error instanceof _chunkT372OL3Qcjs.InsufficientCreditsError) return false;
|
|
390
|
+
if (error instanceof _chunkT372OL3Qcjs.ContextNotFoundError) return false;
|
|
391
|
+
if (error instanceof _chunkT372OL3Qcjs.NetworkTimeoutError) return true;
|
|
407
392
|
if (isConnectionRefusal(error)) return false;
|
|
408
393
|
return true;
|
|
409
394
|
}
|
|
410
395
|
function isConnectionRefusal(error) {
|
|
411
|
-
const code = _nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
396
|
+
const code = _nullishCoalesce(_optionalChain([error, 'optionalAccess', _9 => _9.cause, 'optionalAccess', _10 => _10.code]), () => ( _optionalChain([error, 'optionalAccess', _11 => _11.code])));
|
|
412
397
|
return code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN" || code === "ECONNRESET" || code === "EHOSTUNREACH";
|
|
413
398
|
}
|
|
414
399
|
function toTransportError(error, correlationId) {
|
|
415
|
-
if (error instanceof
|
|
416
|
-
const name = _optionalChain([error, 'optionalAccess',
|
|
400
|
+
if (error instanceof _chunkT372OL3Qcjs.SynapError) return error;
|
|
401
|
+
const name = _optionalChain([error, 'optionalAccess', _12 => _12.name]);
|
|
417
402
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
418
|
-
return new (0,
|
|
403
|
+
return new (0, _chunkT372OL3Qcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
|
|
419
404
|
}
|
|
420
|
-
return new (0,
|
|
421
|
-
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
405
|
+
return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(
|
|
406
|
+
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _13 => _13.message]), () => ( String(error)))}`,
|
|
422
407
|
{ correlationId, cause: error }
|
|
423
408
|
);
|
|
424
409
|
}
|
|
410
|
+
var CREDIT_ERRORS = /* @__PURE__ */ new Set(["insufficient_credits", "trial_limit_reached"]);
|
|
411
|
+
function creditPayload(parsed, detailObject) {
|
|
412
|
+
return _nullishCoalesce(detailObject, () => ( parsed));
|
|
413
|
+
}
|
|
414
|
+
function creditReason(payload) {
|
|
415
|
+
const reason = stringOrNull(payload["reason"]);
|
|
416
|
+
if (reason !== null) return reason;
|
|
417
|
+
const error = stringOrNull(payload["error"]);
|
|
418
|
+
return error !== null && CREDIT_ERRORS.has(error) ? error : null;
|
|
419
|
+
}
|
|
425
420
|
async function toHttpError(response, correlationId) {
|
|
426
421
|
const body = await response.text().catch(() => "");
|
|
427
422
|
let parsed = {};
|
|
@@ -437,40 +432,48 @@ async function toHttpError(response, correlationId) {
|
|
|
437
432
|
switch (response.status) {
|
|
438
433
|
case 400:
|
|
439
434
|
case 422:
|
|
440
|
-
return new (0,
|
|
435
|
+
return new (0, _chunkT372OL3Qcjs.InvalidInputError)(message, opts);
|
|
441
436
|
case 401:
|
|
442
437
|
case 403:
|
|
443
|
-
return new (0,
|
|
438
|
+
return new (0, _chunkT372OL3Qcjs.AuthenticationError)(message, opts);
|
|
444
439
|
case 404:
|
|
445
|
-
return new (0,
|
|
446
|
-
case 402:
|
|
447
|
-
|
|
440
|
+
return new (0, _chunkT372OL3Qcjs.ContextNotFoundError)(message, opts);
|
|
441
|
+
case 402: {
|
|
442
|
+
const credit = creditPayload(parsed, detailObject);
|
|
443
|
+
return new (0, _chunkT372OL3Qcjs.InsufficientCreditsError)(message, {
|
|
448
444
|
...opts,
|
|
449
|
-
balanceCredits: numberOrNull(
|
|
450
|
-
requiredCredits: _nullishCoalesce(numberOrNull(
|
|
451
|
-
recoveryUrl: stringOrNull(
|
|
452
|
-
redeemUrl: stringOrNull(
|
|
445
|
+
balanceCredits: numberOrNull(credit["balance_credits"]),
|
|
446
|
+
requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
|
|
447
|
+
recoveryUrl: stringOrNull(credit["recovery_url"]),
|
|
448
|
+
redeemUrl: stringOrNull(credit["redeem_url"]),
|
|
449
|
+
reason: creditReason(credit),
|
|
450
|
+
manageUrl: stringOrNull(credit["manage_url"])
|
|
453
451
|
});
|
|
452
|
+
}
|
|
454
453
|
case 409:
|
|
455
454
|
if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
|
|
456
|
-
return new (0,
|
|
455
|
+
return new (0, _chunkT372OL3Qcjs.TranscriptConflictError)(message, opts);
|
|
457
456
|
}
|
|
458
|
-
return new (0,
|
|
457
|
+
return new (0, _chunkT372OL3Qcjs.ConflictError)(message, opts);
|
|
459
458
|
case 429: {
|
|
460
459
|
const header = response.headers.get("retry-after");
|
|
461
460
|
const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
|
|
462
|
-
|
|
461
|
+
const credit = creditPayload(parsed, detailObject);
|
|
462
|
+
return new (0, _chunkT372OL3Qcjs.RateLimitError)(message, {
|
|
463
463
|
...opts,
|
|
464
|
-
retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null
|
|
464
|
+
retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
|
|
465
|
+
reason: creditReason(credit),
|
|
466
|
+
upgradeUrl: stringOrNull(credit["upgrade_url"]),
|
|
467
|
+
manageUrl: stringOrNull(credit["manage_url"])
|
|
465
468
|
});
|
|
466
469
|
}
|
|
467
470
|
case 503:
|
|
468
|
-
return new (0,
|
|
471
|
+
return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(message, opts);
|
|
469
472
|
case 504:
|
|
470
|
-
return new (0,
|
|
473
|
+
return new (0, _chunkT372OL3Qcjs.AgentUnavailableError)(message, opts);
|
|
471
474
|
default:
|
|
472
|
-
if (response.status >= 500) return new (0,
|
|
473
|
-
return new (0,
|
|
475
|
+
if (response.status >= 500) return new (0, _chunkT372OL3Qcjs.ServiceUnavailableError)(message, opts);
|
|
476
|
+
return new (0, _chunkT372OL3Qcjs.SynapError)(message, opts);
|
|
474
477
|
}
|
|
475
478
|
}
|
|
476
479
|
function numberOrNull(v) {
|
|
@@ -481,11 +484,11 @@ function stringOrNull(v) {
|
|
|
481
484
|
}
|
|
482
485
|
function withTimeout(ms, external) {
|
|
483
486
|
const controller = new AbortController();
|
|
484
|
-
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess',
|
|
487
|
+
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _14 => _14.reason]));
|
|
485
488
|
const timer = setTimeout(() => {
|
|
486
|
-
controller.abort(new (0,
|
|
489
|
+
controller.abort(new (0, _chunkT372OL3Qcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
|
|
487
490
|
}, ms);
|
|
488
|
-
_optionalChain([timer, 'access',
|
|
491
|
+
_optionalChain([timer, 'access', _15 => _15.unref, 'optionalCall', _16 => _16()]);
|
|
489
492
|
if (external) {
|
|
490
493
|
if (external.aborted) onExternalAbort();
|
|
491
494
|
else external.addEventListener("abort", onExternalAbort, { once: true });
|
|
@@ -494,7 +497,7 @@ function withTimeout(ms, external) {
|
|
|
494
497
|
signal: controller.signal,
|
|
495
498
|
dispose() {
|
|
496
499
|
clearTimeout(timer);
|
|
497
|
-
_optionalChain([external, 'optionalAccess',
|
|
500
|
+
_optionalChain([external, 'optionalAccess', _17 => _17.removeEventListener, 'call', _18 => _18("abort", onExternalAbort)]);
|
|
498
501
|
}
|
|
499
502
|
};
|
|
500
503
|
}
|
|
@@ -502,14 +505,14 @@ function sleep(ms, signal) {
|
|
|
502
505
|
if (ms <= 0) return Promise.resolve();
|
|
503
506
|
return new Promise((resolve, reject) => {
|
|
504
507
|
const timer = setTimeout(() => {
|
|
505
|
-
_optionalChain([signal, 'optionalAccess',
|
|
508
|
+
_optionalChain([signal, 'optionalAccess', _19 => _19.removeEventListener, 'call', _20 => _20("abort", onAbort)]);
|
|
506
509
|
resolve();
|
|
507
510
|
}, ms);
|
|
508
511
|
function onAbort() {
|
|
509
512
|
clearTimeout(timer);
|
|
510
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
513
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _21 => _21.reason]), () => ( new Error("Aborted"))));
|
|
511
514
|
}
|
|
512
|
-
_optionalChain([signal, 'optionalAccess',
|
|
515
|
+
_optionalChain([signal, 'optionalAccess', _22 => _22.addEventListener, 'call', _23 => _23("abort", onAbort, { once: true })]);
|
|
513
516
|
});
|
|
514
517
|
}
|
|
515
518
|
|
|
@@ -535,10 +538,10 @@ function buildFetchRequest(scope, options) {
|
|
|
535
538
|
const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
|
|
536
539
|
const mode = _nullishCoalesce(options.mode, () => ( "fast"));
|
|
537
540
|
if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
|
|
538
|
-
throw new (0,
|
|
541
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("search_query must be an array when provided");
|
|
539
542
|
}
|
|
540
543
|
if (options.types !== void 0 && !Array.isArray(options.types)) {
|
|
541
|
-
throw new (0,
|
|
544
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("types must be an array when provided");
|
|
542
545
|
}
|
|
543
546
|
const body = {
|
|
544
547
|
conversation_id: _nullishCoalesce(conversationId, () => ( null)),
|
|
@@ -554,22 +557,22 @@ function buildFetchRequest(scope, options) {
|
|
|
554
557
|
switch (scope) {
|
|
555
558
|
case "user":
|
|
556
559
|
{
|
|
557
|
-
if (!userId) throw new (0,
|
|
560
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
558
561
|
body["user_id"] = userId;
|
|
559
562
|
const scopePath = opt(options, "scope_path", "scopePath");
|
|
560
563
|
if (scopePath !== void 0) body["scope"] = scopePath;
|
|
561
564
|
const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
|
|
562
565
|
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
563
|
-
throw new (0,
|
|
566
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
564
567
|
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
565
568
|
);
|
|
566
569
|
}
|
|
567
570
|
const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
|
|
568
571
|
if (!Number.isInteger(lastN)) {
|
|
569
|
-
throw new (0,
|
|
572
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be an integer");
|
|
570
573
|
}
|
|
571
574
|
if (lastN < 0 || lastN > 20) {
|
|
572
|
-
throw new (0,
|
|
575
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
|
|
573
576
|
}
|
|
574
577
|
if (contextMode === "conversation-summary") {
|
|
575
578
|
body["context_mode"] = contextMode;
|
|
@@ -581,11 +584,11 @@ function buildFetchRequest(scope, options) {
|
|
|
581
584
|
}
|
|
582
585
|
break;
|
|
583
586
|
case "customer":
|
|
584
|
-
if (!customerId) throw new (0,
|
|
587
|
+
if (!customerId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("customer_id is required");
|
|
585
588
|
body["customer_id"] = customerId;
|
|
586
589
|
break;
|
|
587
590
|
case "conversation":
|
|
588
|
-
if (!conversationId) throw new (0,
|
|
591
|
+
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
589
592
|
if (userId !== void 0) body["user_id"] = userId;
|
|
590
593
|
if (customerId !== void 0) body["customer_id"] = customerId;
|
|
591
594
|
break;
|
|
@@ -601,16 +604,16 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
|
601
604
|
opt(options, "customer_id", "customerId"),
|
|
602
605
|
`${scope}.context.fetch`
|
|
603
606
|
);
|
|
604
|
-
const anticipated = _nullishCoalesce(_optionalChain([hooks, 'access',
|
|
607
|
+
const anticipated = _nullishCoalesce(_optionalChain([hooks, 'access', _24 => _24.beforeFetch, 'optionalCall', _25 => _25(scope, options)]), () => ( null));
|
|
605
608
|
if (anticipated !== null) {
|
|
606
|
-
_optionalChain([hooks, 'access',
|
|
607
|
-
_optionalChain([hooks, 'access',
|
|
609
|
+
_optionalChain([hooks, 'access', _26 => _26.onServedFromCache, 'optionalCall', _27 => _27(scope, options, anticipated)]);
|
|
610
|
+
_optionalChain([hooks, 'access', _28 => _28.onAssembled, 'optionalCall', _29 => _29(scope, options, anticipated.response, startedAt)]);
|
|
608
611
|
return anticipated.response;
|
|
609
612
|
}
|
|
610
613
|
const { endpoint, body } = buildFetchRequest(scope, options);
|
|
611
614
|
const result = await transport.request(endpoint, { body });
|
|
612
|
-
const response = _nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
613
|
-
_optionalChain([hooks, 'access',
|
|
615
|
+
const response = _nullishCoalesce(_optionalChain([result, 'optionalAccess', _30 => _30["context"]]), () => ( {}));
|
|
616
|
+
_optionalChain([hooks, 'access', _31 => _31.onAssembled, 'optionalCall', _32 => _32(scope, options, response, startedAt)]);
|
|
614
617
|
return response;
|
|
615
618
|
}
|
|
616
619
|
|
|
@@ -830,17 +833,17 @@ function isoOrNull(v) {
|
|
|
830
833
|
return v instanceof Date ? v.toISOString() : v;
|
|
831
834
|
}
|
|
832
835
|
function buildCreateBody(options) {
|
|
833
|
-
if (!options.document) throw new (0,
|
|
836
|
+
if (!options.document) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("document is required");
|
|
834
837
|
const o2 = options;
|
|
835
838
|
const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( DEFAULT_DOCUMENT_TYPE));
|
|
836
839
|
const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
|
|
837
840
|
if (!DOCUMENT_TYPES.includes(documentType)) {
|
|
838
|
-
throw new (0,
|
|
841
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
839
842
|
`Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
|
|
840
843
|
);
|
|
841
844
|
}
|
|
842
845
|
if (!INGEST_MODES.includes(mode)) {
|
|
843
|
-
throw new (0,
|
|
846
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
844
847
|
`Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
|
|
845
848
|
);
|
|
846
849
|
}
|
|
@@ -872,7 +875,7 @@ function createMemoriesInterface(transport) {
|
|
|
872
875
|
async batch_create(options) {
|
|
873
876
|
const docs = options.documents;
|
|
874
877
|
if (!Array.isArray(docs) || docs.length === 0) {
|
|
875
|
-
throw new (0,
|
|
878
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("documents must be a non-empty array");
|
|
876
879
|
}
|
|
877
880
|
const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
|
|
878
881
|
return transport.request("memories_batch", {
|
|
@@ -882,15 +885,15 @@ function createMemoriesInterface(transport) {
|
|
|
882
885
|
async create_from_file(options) {
|
|
883
886
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
884
887
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
885
|
-
if (!userId) throw new (0,
|
|
888
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
886
889
|
transport.checkCustomerId(customerId, "memories.create_from_file");
|
|
887
890
|
const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
|
|
888
891
|
const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
|
|
889
892
|
if (sources.length === 0) {
|
|
890
|
-
throw new (0,
|
|
893
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
|
|
891
894
|
}
|
|
892
895
|
if (sources.length > 1) {
|
|
893
|
-
throw new (0,
|
|
896
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
894
897
|
"Provide exactly one of file_path, file, or text, not several."
|
|
895
898
|
);
|
|
896
899
|
}
|
|
@@ -921,13 +924,13 @@ function createMemoriesInterface(transport) {
|
|
|
921
924
|
});
|
|
922
925
|
},
|
|
923
926
|
async get(memoryId) {
|
|
924
|
-
if (!memoryId) throw new (0,
|
|
927
|
+
if (!memoryId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("memory_id is required");
|
|
925
928
|
return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
|
|
926
929
|
},
|
|
927
930
|
async update(options) {
|
|
928
931
|
const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
|
|
929
|
-
if (!memoryId) throw new (0,
|
|
930
|
-
if (!options.document) throw new (0,
|
|
932
|
+
if (!memoryId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("memory_id is required");
|
|
933
|
+
if (!options.document) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("document is required");
|
|
931
934
|
const body = {
|
|
932
935
|
document: options.document,
|
|
933
936
|
merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
|
|
@@ -942,20 +945,20 @@ function createMemoriesInterface(transport) {
|
|
|
942
945
|
},
|
|
943
946
|
async delete(memoryId) {
|
|
944
947
|
if (!memoryId) {
|
|
945
|
-
throw new (0,
|
|
948
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
946
949
|
"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."
|
|
947
950
|
);
|
|
948
951
|
}
|
|
949
952
|
return transport.request("memories_delete", { pathParams: { memory_id: memoryId } });
|
|
950
953
|
},
|
|
951
954
|
async status(ingestionId) {
|
|
952
|
-
if (!ingestionId) throw new (0,
|
|
955
|
+
if (!ingestionId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("ingestion_id is required");
|
|
953
956
|
return transport.request("memories_status", {
|
|
954
957
|
pathParams: { ingestion_id: ingestionId }
|
|
955
958
|
});
|
|
956
959
|
},
|
|
957
960
|
async wait_for_completion(ingestionId, options = {}) {
|
|
958
|
-
if (!ingestionId) throw new (0,
|
|
961
|
+
if (!ingestionId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("ingestion_id is required");
|
|
959
962
|
const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
|
|
960
963
|
const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
|
|
961
964
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -976,14 +979,14 @@ function sleep2(ms, signal) {
|
|
|
976
979
|
if (ms <= 0) return Promise.resolve();
|
|
977
980
|
return new Promise((resolve, reject) => {
|
|
978
981
|
const timer = setTimeout(() => {
|
|
979
|
-
_optionalChain([signal, 'optionalAccess',
|
|
982
|
+
_optionalChain([signal, 'optionalAccess', _33 => _33.removeEventListener, 'call', _34 => _34("abort", onAbort)]);
|
|
980
983
|
resolve();
|
|
981
984
|
}, ms);
|
|
982
985
|
function onAbort() {
|
|
983
986
|
clearTimeout(timer);
|
|
984
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
987
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _35 => _35.reason]), () => ( new Error("Aborted"))));
|
|
985
988
|
}
|
|
986
|
-
_optionalChain([signal, 'optionalAccess',
|
|
989
|
+
_optionalChain([signal, 'optionalAccess', _36 => _36.addEventListener, 'call', _37 => _37("abort", onAbort, { once: true })]);
|
|
987
990
|
});
|
|
988
991
|
}
|
|
989
992
|
|
|
@@ -993,13 +996,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
|
|
|
993
996
|
function validateConversationId(conversationId) {
|
|
994
997
|
if (conversationId === void 0 || conversationId === null || conversationId === "") return;
|
|
995
998
|
if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
|
|
996
|
-
throw new (0,
|
|
999
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
|
|
997
1000
|
}
|
|
998
1001
|
}
|
|
999
1002
|
function validateInstanceId(instanceId) {
|
|
1000
1003
|
if (instanceId === void 0 || instanceId === null || instanceId === "") return;
|
|
1001
1004
|
if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
|
|
1002
|
-
throw new (0,
|
|
1005
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
|
|
1003
1006
|
}
|
|
1004
1007
|
}
|
|
1005
1008
|
|
|
@@ -1028,13 +1031,13 @@ function buildRecordMessageBody(options) {
|
|
|
1028
1031
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1029
1032
|
const userId = either2(o2, "user_id", "userId");
|
|
1030
1033
|
const customerId = either2(o2, "customer_id", "customerId");
|
|
1031
|
-
if (!conversationId) throw new (0,
|
|
1034
|
+
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
1032
1035
|
validateConversationId(conversationId);
|
|
1033
|
-
if (!options.role) throw new (0,
|
|
1036
|
+
if (!options.role) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("role is required");
|
|
1034
1037
|
if (options.content === void 0 || options.content === null) {
|
|
1035
|
-
throw new (0,
|
|
1038
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("content is required");
|
|
1036
1039
|
}
|
|
1037
|
-
if (!userId) throw new (0,
|
|
1040
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
1038
1041
|
const body = {
|
|
1039
1042
|
conversation_id: conversationId,
|
|
1040
1043
|
role: options.role,
|
|
@@ -1046,16 +1049,18 @@ function buildRecordMessageBody(options) {
|
|
|
1046
1049
|
};
|
|
1047
1050
|
const sessionId = either2(o2, "session_id", "sessionId");
|
|
1048
1051
|
if (sessionId !== void 0) body["session_id"] = sessionId;
|
|
1052
|
+
const scopePath = either2(o2, "scope_path", "scopePath");
|
|
1053
|
+
if (scopePath !== void 0) body["scope"] = scopePath;
|
|
1049
1054
|
return body;
|
|
1050
1055
|
}
|
|
1051
1056
|
function buildIngestTranscriptBody(options) {
|
|
1052
1057
|
const o2 = options;
|
|
1053
1058
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1054
1059
|
const userId = either2(o2, "user_id", "userId");
|
|
1055
|
-
if (!conversationId) throw new (0,
|
|
1056
|
-
if (!userId) throw new (0,
|
|
1060
|
+
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
1061
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
1057
1062
|
if (options.transcript === void 0 || options.transcript === null) {
|
|
1058
|
-
throw new (0,
|
|
1063
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("transcript is required");
|
|
1059
1064
|
}
|
|
1060
1065
|
const body = {
|
|
1061
1066
|
conversation_id: conversationId,
|
|
@@ -1072,12 +1077,14 @@ function buildIngestTranscriptBody(options) {
|
|
|
1072
1077
|
if (options.metadata !== void 0) body["metadata"] = options.metadata;
|
|
1073
1078
|
if (startedAt !== void 0) body["started_at"] = startedAt;
|
|
1074
1079
|
if (endedAt !== void 0) body["ended_at"] = endedAt;
|
|
1080
|
+
const scopePath = either2(o2, "scope_path", "scopePath");
|
|
1081
|
+
if (scopePath !== void 0) body["scope"] = scopePath;
|
|
1075
1082
|
return body;
|
|
1076
1083
|
}
|
|
1077
1084
|
function buildCompactBody(options) {
|
|
1078
1085
|
const o2 = options;
|
|
1079
1086
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1080
|
-
if (!conversationId) throw new (0,
|
|
1087
|
+
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
1081
1088
|
validateConversationId(conversationId);
|
|
1082
1089
|
const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
|
|
1083
1090
|
const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
|
|
@@ -1133,7 +1140,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1133
1140
|
}, localShortTerm = { prompt: () => null, compacted: () => null }) {
|
|
1134
1141
|
const convId = (v) => {
|
|
1135
1142
|
const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
|
|
1136
|
-
if (!id) throw new (0,
|
|
1143
|
+
if (!id) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
1137
1144
|
validateConversationId(id);
|
|
1138
1145
|
return id;
|
|
1139
1146
|
};
|
|
@@ -1159,7 +1166,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1159
1166
|
},
|
|
1160
1167
|
async record_messages_batch(messages) {
|
|
1161
1168
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
1162
|
-
throw new (0,
|
|
1169
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("messages must be a non-empty array");
|
|
1163
1170
|
}
|
|
1164
1171
|
for (const m of messages) {
|
|
1165
1172
|
const mo = m;
|
|
@@ -1205,7 +1212,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1205
1212
|
onFetched(
|
|
1206
1213
|
response,
|
|
1207
1214
|
id,
|
|
1208
|
-
_nullishCoalesce(options.user_id, () => ( options.userId))
|
|
1215
|
+
_nullishCoalesce(options.user_id, () => ( options.userId)),
|
|
1216
|
+
_nullishCoalesce(options.scope_path, () => ( options.scopePath))
|
|
1209
1217
|
);
|
|
1210
1218
|
return response;
|
|
1211
1219
|
},
|
|
@@ -1217,7 +1225,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1217
1225
|
pathParams: { conversation_id: id },
|
|
1218
1226
|
query: { style: _nullishCoalesce(options.style, () => ( "structured")) }
|
|
1219
1227
|
});
|
|
1220
|
-
return _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
1228
|
+
return _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _38 => _38["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
1221
1229
|
},
|
|
1222
1230
|
async compact(options) {
|
|
1223
1231
|
return transport.request("conversations_compact", { body: buildCompactBody(options) });
|
|
@@ -1256,8 +1264,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
1256
1264
|
* Returns an idempotent unsubscribe thunk, matching Python.
|
|
1257
1265
|
*/
|
|
1258
1266
|
subscribe_to_compaction_updates(conversationId, callback) {
|
|
1259
|
-
if (!conversationId) throw new (0,
|
|
1260
|
-
if (typeof callback !== "function") throw new (0,
|
|
1267
|
+
if (!conversationId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("conversation_id is required");
|
|
1268
|
+
if (typeof callback !== "function") throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("callback is required");
|
|
1261
1269
|
return subscribers.add(conversationId, callback);
|
|
1262
1270
|
},
|
|
1263
1271
|
/** Remove subscribers for one conversation, or all of them. Returns the count removed. */
|
|
@@ -1273,7 +1281,7 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
1273
1281
|
return {
|
|
1274
1282
|
async get_profile(options) {
|
|
1275
1283
|
const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
1276
|
-
if (!userId) throw new (0,
|
|
1284
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
1277
1285
|
const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
1278
1286
|
return transport.request("user_profile", {
|
|
1279
1287
|
pathParams: { user_id: userId },
|
|
@@ -1322,7 +1330,7 @@ function createCreditsNamespace(transport) {
|
|
|
1322
1330
|
});
|
|
1323
1331
|
},
|
|
1324
1332
|
async redeem(code) {
|
|
1325
|
-
if (!code) throw new (0,
|
|
1333
|
+
if (!code) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("code is required");
|
|
1326
1334
|
return transport.request("credits_redeem", { body: { code } });
|
|
1327
1335
|
}
|
|
1328
1336
|
};
|
|
@@ -1333,11 +1341,11 @@ function createCacheNamespace(cache) {
|
|
|
1333
1341
|
return {
|
|
1334
1342
|
clear: () => cache.clear(),
|
|
1335
1343
|
clear_user: (userId) => {
|
|
1336
|
-
if (!userId) throw new (0,
|
|
1344
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
1337
1345
|
cache.dropEntity(userId);
|
|
1338
1346
|
},
|
|
1339
1347
|
clear_customer: (customerId) => {
|
|
1340
|
-
if (!customerId) throw new (0,
|
|
1348
|
+
if (!customerId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("customer_id is required");
|
|
1341
1349
|
cache.dropEntity(customerId);
|
|
1342
1350
|
},
|
|
1343
1351
|
stats: () => ({ bundles: cache.size, items: cache.itemCount })
|
|
@@ -1370,23 +1378,39 @@ function thinkingMetadata(options) {
|
|
|
1370
1378
|
}
|
|
1371
1379
|
return md;
|
|
1372
1380
|
}
|
|
1381
|
+
var KNOWN_EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
1382
|
+
"user_message",
|
|
1383
|
+
"assistant_message",
|
|
1384
|
+
"tool_call",
|
|
1385
|
+
"tool_result",
|
|
1386
|
+
"agent_thinking",
|
|
1387
|
+
"context_request",
|
|
1388
|
+
"context_fetch",
|
|
1389
|
+
"session_start",
|
|
1390
|
+
"session_end"
|
|
1391
|
+
]);
|
|
1392
|
+
function toolResultJson(result) {
|
|
1393
|
+
if (result === void 0 || result === null) return "";
|
|
1394
|
+
return typeof result === "string" ? result : JSON.stringify(result);
|
|
1395
|
+
}
|
|
1373
1396
|
function createInstanceNamespace(credentials, cache, onTurn) {
|
|
1374
1397
|
let client = null;
|
|
1398
|
+
const openSessions = /* @__PURE__ */ new Map();
|
|
1375
1399
|
let dispatchCompaction = null;
|
|
1376
1400
|
let applyCompaction = null;
|
|
1377
1401
|
const internals = {
|
|
1378
1402
|
onCompactionUpdate(conversationId, bundle) {
|
|
1379
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
1380
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
1403
|
+
_optionalChain([applyCompaction, 'optionalCall', _39 => _39(bundle)]);
|
|
1404
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _40 => _40(conversationId, bundle)]);
|
|
1381
1405
|
},
|
|
1382
1406
|
setCompactionApplier(apply) {
|
|
1383
1407
|
applyCompaction = apply;
|
|
1384
1408
|
},
|
|
1385
1409
|
sendContextUsed(event) {
|
|
1386
|
-
_optionalChain([client, 'optionalAccess',
|
|
1410
|
+
_optionalChain([client, 'optionalAccess', _41 => _41.sendContextUsed, 'call', _42 => _42(event)]);
|
|
1387
1411
|
},
|
|
1388
1412
|
sendContextAssembled(event) {
|
|
1389
|
-
_optionalChain([client, 'optionalAccess',
|
|
1413
|
+
_optionalChain([client, 'optionalAccess', _43 => _43.sendContextAssembled, 'call', _44 => _44(event)]);
|
|
1390
1414
|
},
|
|
1391
1415
|
setCompactionDispatcher(dispatch) {
|
|
1392
1416
|
dispatchCompaction = dispatch;
|
|
@@ -1395,16 +1419,33 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1395
1419
|
return client !== null && client.isConnected;
|
|
1396
1420
|
}
|
|
1397
1421
|
};
|
|
1422
|
+
function ensureSession(conversationId, userId, customerId) {
|
|
1423
|
+
if (!conversationId || !userId || client === null) return;
|
|
1424
|
+
if (openSessions.has(conversationId)) return;
|
|
1425
|
+
const sessionId = _chunkT372OL3Qcjs.newCorrelationId.call(void 0, );
|
|
1426
|
+
try {
|
|
1427
|
+
client.sendSessionControl({
|
|
1428
|
+
action: "start",
|
|
1429
|
+
session_id: sessionId,
|
|
1430
|
+
conversation_id: conversationId,
|
|
1431
|
+
...userId ? { user_id: userId } : {},
|
|
1432
|
+
...customerId ? { customer_id: customerId } : {}
|
|
1433
|
+
});
|
|
1434
|
+
openSessions.set(conversationId, sessionId);
|
|
1435
|
+
} catch (e5) {
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1398
1438
|
const namespace = {
|
|
1399
1439
|
async listen(options = {}) {
|
|
1400
1440
|
if (client !== null) {
|
|
1401
|
-
throw new (0,
|
|
1441
|
+
throw new (0, _chunkT372OL3Qcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
1402
1442
|
}
|
|
1403
|
-
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-
|
|
1443
|
+
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-Y5JGSF2R.cjs")));
|
|
1404
1444
|
const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
|
|
1405
1445
|
const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
|
|
1406
1446
|
const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
|
|
1407
1447
|
let reconnectAttempts = 0;
|
|
1448
|
+
let stream = null;
|
|
1408
1449
|
const created = new GrpcStreamClient(credentials(), cache, {
|
|
1409
1450
|
host: _nullishCoalesce(_nullishCoalesce(options.host, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_GRPC_HOST"))), () => ( DEFAULT_GRPC_HOST)),
|
|
1410
1451
|
port: _nullishCoalesce(_nullishCoalesce(options.port, () => ( envPort())), () => ( DEFAULT_GRPC_PORT)),
|
|
@@ -1414,20 +1455,24 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1414
1455
|
internals.onCompactionUpdate(conversationId, bundle);
|
|
1415
1456
|
},
|
|
1416
1457
|
onStateChange: (state) => {
|
|
1458
|
+
if (state !== "connected") openSessions.clear();
|
|
1417
1459
|
if (state === "reconnecting") {
|
|
1418
1460
|
reconnectAttempts += 1;
|
|
1419
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
1461
|
+
_optionalChain([onReconnect, 'optionalCall', _45 => _45(reconnectAttempts)]);
|
|
1420
1462
|
} else if (state === "disconnected") {
|
|
1421
|
-
_optionalChain([
|
|
1463
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _46 => _46.lastError]), () => ( null));
|
|
1464
|
+
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
1465
|
+
_optionalChain([onDisconnect, 'optionalCall', _47 => _47(reason)]);
|
|
1422
1466
|
}
|
|
1423
1467
|
}
|
|
1424
1468
|
});
|
|
1469
|
+
stream = created;
|
|
1425
1470
|
try {
|
|
1426
1471
|
await created.connect();
|
|
1427
1472
|
} catch (error) {
|
|
1428
|
-
if (error instanceof
|
|
1429
|
-
throw new (0,
|
|
1430
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1473
|
+
if (error instanceof _chunkT372OL3Qcjs.SynapError) throw error;
|
|
1474
|
+
throw new (0, _chunkT372OL3Qcjs.SynapError)(
|
|
1475
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _48 => _48.message]), () => ( String(error)))}`,
|
|
1431
1476
|
{ cause: error }
|
|
1432
1477
|
);
|
|
1433
1478
|
}
|
|
@@ -1435,29 +1480,58 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1435
1480
|
},
|
|
1436
1481
|
async stop_listening() {
|
|
1437
1482
|
if (client === null) return;
|
|
1483
|
+
for (const conversationId of [...openSessions.keys()]) {
|
|
1484
|
+
await namespace.end_session(conversationId);
|
|
1485
|
+
}
|
|
1438
1486
|
const active = client;
|
|
1439
1487
|
client = null;
|
|
1440
1488
|
await active.disconnect();
|
|
1441
1489
|
},
|
|
1490
|
+
async end_session(conversationId) {
|
|
1491
|
+
const sessionId = openSessions.get(conversationId);
|
|
1492
|
+
if (sessionId === void 0 || client === null) return;
|
|
1493
|
+
openSessions.delete(conversationId);
|
|
1494
|
+
try {
|
|
1495
|
+
client.sendSessionControl({
|
|
1496
|
+
action: "end",
|
|
1497
|
+
session_id: sessionId,
|
|
1498
|
+
conversation_id: conversationId
|
|
1499
|
+
});
|
|
1500
|
+
} catch (e6) {
|
|
1501
|
+
}
|
|
1502
|
+
},
|
|
1442
1503
|
async send_message(options) {
|
|
1443
|
-
if (client === null) throw new (0,
|
|
1504
|
+
if (client === null) throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("Listening is not active");
|
|
1444
1505
|
if (options.content === void 0) {
|
|
1445
|
-
throw new (0,
|
|
1506
|
+
throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("content is required");
|
|
1507
|
+
}
|
|
1508
|
+
const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
|
|
1509
|
+
if (!KNOWN_EVENT_TYPES.has(eventType)) {
|
|
1510
|
+
throw new (0, _chunkT372OL3Qcjs.SynapError)(
|
|
1511
|
+
`unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
|
|
1512
|
+
);
|
|
1446
1513
|
}
|
|
1447
1514
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1448
|
-
|
|
1515
|
+
ensureSession(
|
|
1449
1516
|
conversationId,
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1517
|
+
_nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1518
|
+
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
1519
|
+
);
|
|
1520
|
+
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
1521
|
+
_optionalChain([onTurn, 'optionalCall', _49 => _49({
|
|
1522
|
+
conversationId,
|
|
1523
|
+
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
1524
|
+
content: options.content
|
|
1525
|
+
})]);
|
|
1526
|
+
}
|
|
1453
1527
|
client.sendConversationEvent({
|
|
1454
|
-
event_type:
|
|
1528
|
+
event_type: eventType,
|
|
1455
1529
|
content: options.content,
|
|
1456
1530
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
1457
1531
|
conversation_id: _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( "")),
|
|
1458
1532
|
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1459
1533
|
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
1460
|
-
session_id: _nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( "")),
|
|
1534
|
+
session_id: _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( openSessions.get(conversationId))), () => ( "")),
|
|
1461
1535
|
metadata: _nullishCoalesce(options.metadata, () => ( {})),
|
|
1462
1536
|
timestamp_ms: Date.now(),
|
|
1463
1537
|
tool_name: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")),
|
|
@@ -1466,17 +1540,61 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1466
1540
|
const a = _nullishCoalesce(options.tool_args, () => ( options.toolArgs));
|
|
1467
1541
|
return a === void 0 ? "" : JSON.stringify(a);
|
|
1468
1542
|
})(),
|
|
1543
|
+
tool_result_json: toolResultJson(_nullishCoalesce(options.tool_result, () => ( options.toolResult))),
|
|
1544
|
+
tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
|
|
1469
1545
|
search_queries: _nullishCoalesce(_nullishCoalesce(options.search_queries, () => ( options.searchQueries)), () => ( [])),
|
|
1470
1546
|
context_types: _nullishCoalesce(_nullishCoalesce(options.context_types, () => ( options.contextTypes)), () => ( []))
|
|
1471
1547
|
});
|
|
1472
1548
|
},
|
|
1549
|
+
async record_tool_call(options) {
|
|
1550
|
+
await namespace.send_message({
|
|
1551
|
+
content: "",
|
|
1552
|
+
role: "assistant",
|
|
1553
|
+
event_type: "tool_call",
|
|
1554
|
+
tool_name: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")),
|
|
1555
|
+
..._nullishCoalesce(options.tool_args, () => ( options.toolArgs)) ? { tool_args: _nullishCoalesce(options.tool_args, () => ( options.toolArgs)) } : {},
|
|
1556
|
+
tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
|
|
1557
|
+
conversation_id: _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( "")),
|
|
1558
|
+
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1559
|
+
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
1560
|
+
session_id: _nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( "")),
|
|
1561
|
+
metadata: _nullishCoalesce(options.metadata, () => ( {}))
|
|
1562
|
+
});
|
|
1563
|
+
},
|
|
1564
|
+
async record_tool_result(options) {
|
|
1565
|
+
await namespace.send_message({
|
|
1566
|
+
content: "",
|
|
1567
|
+
role: "tool",
|
|
1568
|
+
event_type: "tool_result",
|
|
1569
|
+
tool_result: options.result,
|
|
1570
|
+
tool_name: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")),
|
|
1571
|
+
tool_call_id: _nullishCoalesce(_nullishCoalesce(options.tool_call_id, () => ( options.toolCallId)), () => ( "")),
|
|
1572
|
+
conversation_id: _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( "")),
|
|
1573
|
+
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1574
|
+
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
1575
|
+
session_id: _nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( "")),
|
|
1576
|
+
metadata: _nullishCoalesce(options.metadata, () => ( {}))
|
|
1577
|
+
});
|
|
1578
|
+
},
|
|
1473
1579
|
async record_thinking(options) {
|
|
1474
|
-
if (client === null) throw new (0,
|
|
1580
|
+
if (client === null) throw new (0, _chunkT372OL3Qcjs.ListeningNotActiveError)("Listening is not active");
|
|
1581
|
+
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
1582
|
+
ensureSession(
|
|
1583
|
+
conversationId,
|
|
1584
|
+
_nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1585
|
+
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
1586
|
+
);
|
|
1475
1587
|
client.sendConversationEvent({
|
|
1476
1588
|
// Python emits reasoning as an `agent_thinking` conversation event.
|
|
1477
1589
|
event_type: "agent_thinking",
|
|
1478
1590
|
content: options.content,
|
|
1479
|
-
role
|
|
1591
|
+
// Deliberately no role. A thought is not the assistant's reply, and
|
|
1592
|
+
// this went out as 'assistant' from the day it shipped: the server
|
|
1593
|
+
// checked role before event_type, so every reasoning step any client
|
|
1594
|
+
// sent was filed as the final answer and the reasoning path never ran.
|
|
1595
|
+
// Sending no role is correct against both the fixed server and one that
|
|
1596
|
+
// has not been updated yet.
|
|
1597
|
+
role: "",
|
|
1480
1598
|
conversation_id: _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( "")),
|
|
1481
1599
|
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
1482
1600
|
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
@@ -1494,7 +1612,7 @@ function createInstanceNamespace(credentials, cache, onTurn) {
|
|
|
1494
1612
|
}
|
|
1495
1613
|
|
|
1496
1614
|
// src/version.ts
|
|
1497
|
-
var SDK_VERSION = "
|
|
1615
|
+
var SDK_VERSION = "0.5.1";
|
|
1498
1616
|
|
|
1499
1617
|
// src/registry.ts
|
|
1500
1618
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -1683,7 +1801,7 @@ function budgetRecentTurns(turns) {
|
|
|
1683
1801
|
return windowed;
|
|
1684
1802
|
}
|
|
1685
1803
|
function overlayLocalRecentTurns(response, store, conversationId, configured) {
|
|
1686
|
-
if (conversationId === void 0 || conversationId === "") return;
|
|
1804
|
+
if (conversationId === void 0 || conversationId === null || conversationId === "") return;
|
|
1687
1805
|
try {
|
|
1688
1806
|
const entry = store.get(conversationId);
|
|
1689
1807
|
if (entry === null) return;
|
|
@@ -1706,7 +1824,7 @@ function overlayLocalRecentTurns(response, store, conversationId, configured) {
|
|
|
1706
1824
|
compacted_at: orLocal("compacted_at", entry.compactedAt),
|
|
1707
1825
|
conversation_id: conversationId
|
|
1708
1826
|
};
|
|
1709
|
-
} catch (
|
|
1827
|
+
} catch (e7) {
|
|
1710
1828
|
}
|
|
1711
1829
|
}
|
|
1712
1830
|
|
|
@@ -1719,7 +1837,7 @@ function stringify(value) {
|
|
|
1719
1837
|
if (t === "string" || t === "number" || t === "boolean") return String(value);
|
|
1720
1838
|
try {
|
|
1721
1839
|
return _nullishCoalesce(JSON.stringify(value), () => ( ""));
|
|
1722
|
-
} catch (
|
|
1840
|
+
} catch (e8) {
|
|
1723
1841
|
return String(value);
|
|
1724
1842
|
}
|
|
1725
1843
|
}
|
|
@@ -1944,16 +2062,16 @@ function mergeUserSummary(response, bundle) {
|
|
|
1944
2062
|
|
|
1945
2063
|
// src/context/anticipated.ts
|
|
1946
2064
|
function scopeLookupParams(scope, params) {
|
|
1947
|
-
const { searchQuery, entityId, customerId, clientId, conversationId } = params;
|
|
2065
|
+
const { searchQuery, entityId, customerId, clientId, conversationId, scopeRung } = params;
|
|
1948
2066
|
switch (scope) {
|
|
1949
2067
|
case "conversation":
|
|
1950
|
-
return { searchQuery, entityId, customerId, clientId, conversationId };
|
|
2068
|
+
return { searchQuery, entityId, customerId, clientId, conversationId, scopeRung };
|
|
1951
2069
|
case "user":
|
|
1952
|
-
return { searchQuery, entityId, customerId, clientId };
|
|
2070
|
+
return { searchQuery, entityId, customerId, clientId, scopeRung };
|
|
1953
2071
|
case "customer":
|
|
1954
|
-
return { searchQuery, entityId: null, customerId, clientId };
|
|
2072
|
+
return { searchQuery, entityId: null, customerId, clientId, scopeRung };
|
|
1955
2073
|
case "client":
|
|
1956
|
-
return { searchQuery, entityId: null, customerId: null, clientId };
|
|
2074
|
+
return { searchQuery, entityId: null, customerId: null, clientId, scopeRung };
|
|
1957
2075
|
}
|
|
1958
2076
|
}
|
|
1959
2077
|
function buildAnticipationResponse(hit) {
|
|
@@ -1988,11 +2106,12 @@ function tryServeFromCache(cache, scope, params, maxItems) {
|
|
|
1988
2106
|
customerId: _nullishCoalesce(scoped.customerId, () => ( null)),
|
|
1989
2107
|
clientId: _nullishCoalesce(scoped.clientId, () => ( null)),
|
|
1990
2108
|
conversationId: _nullishCoalesce(scoped.conversationId, () => ( null)),
|
|
2109
|
+
scopeRung: _nullishCoalesce(scoped.scopeRung, () => ( null)),
|
|
1991
2110
|
maxItems
|
|
1992
2111
|
});
|
|
1993
2112
|
if (hit === null) return { response: null, hit: null };
|
|
1994
2113
|
return { response: buildAnticipationResponse(hit), hit };
|
|
1995
|
-
} catch (
|
|
2114
|
+
} catch (e9) {
|
|
1996
2115
|
return { response: null, hit: null };
|
|
1997
2116
|
}
|
|
1998
2117
|
}
|
|
@@ -2387,7 +2506,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2387
2506
|
const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
|
|
2388
2507
|
if (!VALID_SCOPES.includes(scope)) {
|
|
2389
2508
|
const sorted = [...VALID_SCOPES].sort();
|
|
2390
|
-
throw new (0,
|
|
2509
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
2391
2510
|
`scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
|
|
2392
2511
|
);
|
|
2393
2512
|
}
|
|
@@ -2395,10 +2514,10 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2395
2514
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
2396
2515
|
const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
|
|
2397
2516
|
if (scope === "user" && (userId === void 0 || userId === "")) {
|
|
2398
|
-
throw new (0,
|
|
2517
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("scope='user' requires user_id");
|
|
2399
2518
|
}
|
|
2400
2519
|
if (scope === "customer" && (customerId === void 0 || customerId === "")) {
|
|
2401
|
-
throw new (0,
|
|
2520
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("scope='customer' requires customer_id");
|
|
2402
2521
|
}
|
|
2403
2522
|
if (scope === "conversation" && (userId === void 0 || userId === "")) {
|
|
2404
2523
|
onWarning(
|
|
@@ -2407,7 +2526,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
2407
2526
|
}
|
|
2408
2527
|
const style = String(_nullishCoalesce(options.style, () => ( "openai")));
|
|
2409
2528
|
if (style !== "openai" && style !== "anthropic") {
|
|
2410
|
-
throw new (0,
|
|
2529
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
|
|
2411
2530
|
}
|
|
2412
2531
|
const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
|
|
2413
2532
|
const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
|
|
@@ -2488,7 +2607,7 @@ var SynapClient = class {
|
|
|
2488
2607
|
userAgent: `@maximem/synap-js-sdk/${SDK_VERSION}`
|
|
2489
2608
|
});
|
|
2490
2609
|
if (options.heartbeat) this.#transport.startHeartbeat();
|
|
2491
|
-
this.#anticipationCache = new (0,
|
|
2610
|
+
this.#anticipationCache = new (0, _chunkT6U5PVADcjs.AnticipationCache)();
|
|
2492
2611
|
this.#fetchHooks = {
|
|
2493
2612
|
beforeFetch: (scope, options2) => {
|
|
2494
2613
|
const o2 = options2;
|
|
@@ -2500,7 +2619,15 @@ var SynapClient = class {
|
|
|
2500
2619
|
entityId: _nullishCoalesce(o2["user_id"], () => ( o2["userId"])),
|
|
2501
2620
|
customerId: _nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])),
|
|
2502
2621
|
clientId: this.#transport.currentCredentials().clientId || null,
|
|
2503
|
-
conversationId: _nullishCoalesce(o2["conversation_id"], () => ( o2["conversationId"]))
|
|
2622
|
+
conversationId: _nullishCoalesce(o2["conversation_id"], () => ( o2["conversationId"])),
|
|
2623
|
+
// The rung this read is addressed to, in the same words the server
|
|
2624
|
+
// stamped on the bundles it pushed. Without it the cache matched
|
|
2625
|
+
// on entity and conversation alone, so a bundle prefetched for one
|
|
2626
|
+
// rung answered a caller standing at another, entirely inside this
|
|
2627
|
+
// process and invisible to every server log.
|
|
2628
|
+
scopeRung: _chunkT6U5PVADcjs.rungKey.call(void 0,
|
|
2629
|
+
_nullishCoalesce(o2["scope_path"], () => ( o2["scopePath"]))
|
|
2630
|
+
)
|
|
2504
2631
|
},
|
|
2505
2632
|
Number(_nullishCoalesce(_nullishCoalesce(o2["max_results"], () => ( o2["maxResults"])), () => ( 10)))
|
|
2506
2633
|
);
|
|
@@ -2545,9 +2672,9 @@ var SynapClient = class {
|
|
|
2545
2672
|
({ conversationId, role, content, timestamp }) => {
|
|
2546
2673
|
this.#shortTerm.appendTurn(conversationId, role, content, timestamp);
|
|
2547
2674
|
},
|
|
2548
|
-
(response, conversationId, userId) => {
|
|
2675
|
+
(response, conversationId, userId, scopePath) => {
|
|
2549
2676
|
overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
|
|
2550
|
-
this.#injectUserSummary(response, conversationId, userId);
|
|
2677
|
+
this.#injectUserSummary(response, conversationId, userId, _chunkT6U5PVADcjs.rungKey.call(void 0, scopePath));
|
|
2551
2678
|
},
|
|
2552
2679
|
{
|
|
2553
2680
|
prompt: (conversationId, style) => this.#localPrompt(conversationId, style),
|
|
@@ -2602,9 +2729,9 @@ var SynapClient = class {
|
|
|
2602
2729
|
*/
|
|
2603
2730
|
async searchMemory(options) {
|
|
2604
2731
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
2605
|
-
if (!userId) throw new (0,
|
|
2732
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
2606
2733
|
if (options.query === void 0 || options.query === null) {
|
|
2607
|
-
throw new (0,
|
|
2734
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("query is required");
|
|
2608
2735
|
}
|
|
2609
2736
|
const context = await fetchContext(this.#transport, "user", {
|
|
2610
2737
|
user_id: userId,
|
|
@@ -2625,7 +2752,7 @@ var SynapClient = class {
|
|
|
2625
2752
|
*/
|
|
2626
2753
|
async getMemories(options) {
|
|
2627
2754
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
2628
|
-
if (!userId) throw new (0,
|
|
2755
|
+
if (!userId) throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("user_id is required");
|
|
2629
2756
|
const context = await fetchContext(this.#transport, "user", {
|
|
2630
2757
|
user_id: userId,
|
|
2631
2758
|
...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
|
|
@@ -2684,7 +2811,7 @@ var SynapClient = class {
|
|
|
2684
2811
|
this.#registryKeys.push(resolvedInstanceId);
|
|
2685
2812
|
}
|
|
2686
2813
|
}
|
|
2687
|
-
} catch (
|
|
2814
|
+
} catch (e10) {
|
|
2688
2815
|
}
|
|
2689
2816
|
}
|
|
2690
2817
|
/**
|
|
@@ -2719,7 +2846,7 @@ var SynapClient = class {
|
|
|
2719
2846
|
*/
|
|
2720
2847
|
configure(options = {}) {
|
|
2721
2848
|
if (this.#initialized) {
|
|
2722
|
-
throw new (0,
|
|
2849
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)("Cannot reconfigure after initialization");
|
|
2723
2850
|
}
|
|
2724
2851
|
if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
|
|
2725
2852
|
if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
|
|
@@ -2770,7 +2897,8 @@ var SynapClient = class {
|
|
|
2770
2897
|
};
|
|
2771
2898
|
const labels = [];
|
|
2772
2899
|
const tasks = [];
|
|
2773
|
-
|
|
2900
|
+
const present = (v) => v !== void 0 && v !== null && v !== "";
|
|
2901
|
+
if (present(conversationId) && wants("conversation")) {
|
|
2774
2902
|
labels.push("conversation");
|
|
2775
2903
|
tasks.push(this.conversation.context.fetch({
|
|
2776
2904
|
conversation_id: conversationId,
|
|
@@ -2779,7 +2907,7 @@ var SynapClient = class {
|
|
|
2779
2907
|
customer_id: customerId
|
|
2780
2908
|
}));
|
|
2781
2909
|
}
|
|
2782
|
-
if (userId
|
|
2910
|
+
if (present(userId) && wants("user")) {
|
|
2783
2911
|
labels.push("user");
|
|
2784
2912
|
tasks.push(this.user.context.fetch({
|
|
2785
2913
|
user_id: userId,
|
|
@@ -2791,7 +2919,7 @@ var SynapClient = class {
|
|
|
2791
2919
|
last_n_conversations: lastNConversations
|
|
2792
2920
|
}));
|
|
2793
2921
|
}
|
|
2794
|
-
if (customerId
|
|
2922
|
+
if (present(customerId) && wants("customer")) {
|
|
2795
2923
|
labels.push("customer");
|
|
2796
2924
|
tasks.push(this.customer.context.fetch({
|
|
2797
2925
|
customer_id: customerId,
|
|
@@ -2818,19 +2946,19 @@ var SynapClient = class {
|
|
|
2818
2946
|
successful.push([label, result.value]);
|
|
2819
2947
|
continue;
|
|
2820
2948
|
}
|
|
2821
|
-
if (result.reason instanceof
|
|
2949
|
+
if (result.reason instanceof _chunkT372OL3Qcjs.InvalidInputError) throw result.reason;
|
|
2822
2950
|
this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
|
|
2823
2951
|
}
|
|
2824
2952
|
const merged = mergeScopeResults(successful);
|
|
2825
2953
|
for (const [, response] of successful) {
|
|
2826
2954
|
overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
|
|
2827
2955
|
}
|
|
2828
|
-
if (includeConversationContext && conversationId
|
|
2956
|
+
if (includeConversationContext && present(conversationId)) {
|
|
2829
2957
|
try {
|
|
2830
2958
|
merged.conversation_context = await this.conversation.context.get_context_for_prompt({
|
|
2831
2959
|
conversation_id: conversationId
|
|
2832
2960
|
});
|
|
2833
|
-
} catch (
|
|
2961
|
+
} catch (e11) {
|
|
2834
2962
|
}
|
|
2835
2963
|
}
|
|
2836
2964
|
merged.formatted_context = formatForPrompt(merged, {
|
|
@@ -2877,7 +3005,7 @@ var SynapClient = class {
|
|
|
2877
3005
|
source_bundle_ids: served.bundleId ? [served.bundleId] : [],
|
|
2878
3006
|
timestamp_ms: Date.now()
|
|
2879
3007
|
});
|
|
2880
|
-
} catch (
|
|
3008
|
+
} catch (e12) {
|
|
2881
3009
|
}
|
|
2882
3010
|
}
|
|
2883
3011
|
/**
|
|
@@ -2892,7 +3020,7 @@ var SynapClient = class {
|
|
|
2892
3020
|
if (!this.instance.is_listening) return;
|
|
2893
3021
|
this.instance._internal.sendContextAssembled({
|
|
2894
3022
|
...buildAssembledEvent({
|
|
2895
|
-
correlationId: newCorrelationId(),
|
|
3023
|
+
correlationId: _chunkT372OL3Qcjs.newCorrelationId.call(void 0, ),
|
|
2896
3024
|
response,
|
|
2897
3025
|
conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
|
|
2898
3026
|
userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
|
|
@@ -2902,7 +3030,7 @@ var SynapClient = class {
|
|
|
2902
3030
|
}),
|
|
2903
3031
|
scope
|
|
2904
3032
|
});
|
|
2905
|
-
} catch (
|
|
3033
|
+
} catch (e13) {
|
|
2906
3034
|
}
|
|
2907
3035
|
}
|
|
2908
3036
|
/**
|
|
@@ -2912,11 +3040,11 @@ var SynapClient = class {
|
|
|
2912
3040
|
* cannot be scoped, and an unscoped lookup is how user A's summary ends up in
|
|
2913
3041
|
* user B's response.
|
|
2914
3042
|
*/
|
|
2915
|
-
#injectUserSummary(response, conversationId, userId) {
|
|
3043
|
+
#injectUserSummary(response, conversationId, userId, scopeRung) {
|
|
2916
3044
|
this.#turns.increment(conversationId);
|
|
2917
3045
|
if (userId === void 0 || userId === "") return;
|
|
2918
3046
|
if (!this.#turns.shouldInject(conversationId)) return;
|
|
2919
|
-
const summary = this.#anticipationCache.lookupUserSummary(userId);
|
|
3047
|
+
const summary = this.#anticipationCache.lookupUserSummary(userId, scopeRung);
|
|
2920
3048
|
if (summary === null) return;
|
|
2921
3049
|
mergeUserSummary(response, summary);
|
|
2922
3050
|
}
|
|
@@ -2980,13 +3108,13 @@ function pick3(o2, snake, camel) {
|
|
|
2980
3108
|
function resolveBaseUrl(options) {
|
|
2981
3109
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
2982
3110
|
if (explicit !== void 0) return explicit;
|
|
2983
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
3111
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _50 => _50.trim, 'call', _51 => _51()]);
|
|
2984
3112
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
2985
3113
|
}
|
|
2986
3114
|
function resolveCredentials(options) {
|
|
2987
3115
|
const apiKey = _nullishCoalesce(options.apiKey, () => ( _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY")));
|
|
2988
3116
|
if (!apiKey) {
|
|
2989
|
-
throw new (0,
|
|
3117
|
+
throw new (0, _chunkT372OL3Qcjs.InvalidInputError)(
|
|
2990
3118
|
"No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
|
|
2991
3119
|
);
|
|
2992
3120
|
}
|
|
@@ -3047,5 +3175,5 @@ function resolveCredentials(options) {
|
|
|
3047
3175
|
|
|
3048
3176
|
|
|
3049
3177
|
|
|
3050
|
-
exports.ANY_SCOPE =
|
|
3178
|
+
exports.ANY_SCOPE = _chunkT6U5PVADcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkT372OL3Qcjs.AgentUnavailableError; exports.AnticipationCache = _chunkT6U5PVADcjs.AnticipationCache; exports.AuthenticationError = _chunkT372OL3Qcjs.AuthenticationError; exports.BM25 = _chunkT6U5PVADcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkT6U5PVADcjs.CONTRACT; exports.ConflictError = _chunkT372OL3Qcjs.ConflictError; exports.ConnectionError = _chunkT372OL3Qcjs.ConnectionError; exports.ContextNotFoundError = _chunkT372OL3Qcjs.ContextNotFoundError; exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL; exports.DEFAULT_DOCUMENT_TYPE = DEFAULT_DOCUMENT_TYPE; exports.DEFAULT_INGEST_MODE = DEFAULT_INGEST_MODE; exports.DEFAULT_RETRY_POLICY = DEFAULT_RETRY_POLICY; exports.DEFAULT_TIMEOUTS = DEFAULT_TIMEOUTS; exports.DOCUMENT_TYPES = DOCUMENT_TYPES; exports.ENDPOINTS = ENDPOINTS; exports.HttpTransport = HttpTransport; exports.INGEST_MODES = INGEST_MODES; exports.ITEM_COLLECTIONS = ITEM_COLLECTIONS; exports.InsufficientCreditsError = _chunkT372OL3Qcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkT372OL3Qcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkT372OL3Qcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkT372OL3Qcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkT372OL3Qcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkT372OL3Qcjs.ListeningNotActiveError; exports.NetworkTimeoutError = _chunkT372OL3Qcjs.NetworkTimeoutError; exports.PermanentError = _chunkT372OL3Qcjs.PermanentError; exports.RateLimitError = _chunkT372OL3Qcjs.RateLimitError; exports.SDKError = _chunkT372OL3Qcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ServiceUnavailableError = _chunkT372OL3Qcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkT372OL3Qcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkT372OL3Qcjs.SynapError; exports.SynapPermanentError = _chunkT372OL3Qcjs.SynapPermanentError; exports.SynapTransientError = _chunkT372OL3Qcjs.SynapTransientError; exports.THRESHOLDS = _chunkT6U5PVADcjs.THRESHOLDS; exports.TranscriptConflictError = _chunkT372OL3Qcjs.TranscriptConflictError; exports.TransientError = _chunkT372OL3Qcjs.TransientError; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isRecallQuery = _chunkT6U5PVADcjs.isRecallQuery; exports.isSynapError = _chunkT372OL3Qcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkT6U5PVADcjs.stem; exports.tokenize = _chunkT6U5PVADcjs.tokenize;
|
|
3051
3179
|
//# sourceMappingURL=index.cjs.map
|