@maximem/synap-js-sdk 0.6.7 → 0.7.0
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-Q7IYC3ID.cjs.map +1 -1
- package/dist/{chunk-DEFC7NHQ.js → chunk-BMA3HZEX.js} +6 -1
- package/dist/chunk-BMA3HZEX.js.map +1 -0
- package/dist/chunk-BYUGILQI.cjs.map +1 -1
- package/dist/{chunk-7IZHVYO2.cjs → chunk-JPDEKN5M.cjs} +28 -23
- package/dist/chunk-JPDEKN5M.cjs.map +1 -0
- package/dist/{chunk-YUCHB2YK.js → chunk-RKKTOLXP.js} +2 -2
- package/dist/{chunk-EI4AGILN.cjs → chunk-SAKMZI7G.cjs} +6 -6
- package/dist/chunk-SAKMZI7G.cjs.map +1 -0
- package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
- package/dist/env-55ULHNJZ.cjs.map +1 -1
- package/dist/{errors-x5bpgxmC.d.ts → errors-DEJFTN6v.d.cts} +9 -2
- package/dist/{errors-x5bpgxmC.d.cts → errors-DEJFTN6v.d.ts} +9 -2
- package/dist/grpc/index.cjs +7 -7
- package/dist/grpc/index.cjs.map +1 -1
- 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 +673 -233
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +171 -4
- package/dist/index.d.ts +171 -4
- package/dist/index.js +450 -10
- package/dist/index.js.map +1 -1
- package/dist/onnx-encoder-4RSL6ID4.cjs.map +1 -1
- package/dist/{stream-client-Q2RR5SCS.js → stream-client-7A2DQ3H3.js} +3 -3
- package/dist/stream-client-H2ES74FF.cjs +22 -0
- package/dist/stream-client-H2ES74FF.cjs.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-7IZHVYO2.cjs.map +0 -1
- package/dist/chunk-DEFC7NHQ.js.map +0 -1
- package/dist/chunk-EI4AGILN.cjs.map +0 -1
- package/dist/stream-client-TDHTS7F4.cjs +0 -22
- package/dist/stream-client-TDHTS7F4.cjs.map +0 -1
- /package/dist/{chunk-YUCHB2YK.js.map → chunk-RKKTOLXP.js.map} +0 -0
- /package/dist/{stream-client-Q2RR5SCS.js.map → stream-client-7A2DQ3H3.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -41,7 +41,8 @@ var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
|
|
45
|
+
var _chunkJPDEKN5Mcjs = require('./chunk-JPDEKN5M.cjs');
|
|
45
46
|
|
|
46
47
|
// src/local-mode.ts
|
|
47
48
|
function isLocalMode(apiKey, baseUrl) {
|
|
@@ -83,7 +84,9 @@ var ENDPOINTS = {
|
|
|
83
84
|
credits_ledger: { method: "GET", path: "/v1/credits/ledger", idempotent: true },
|
|
84
85
|
credits_estimate: { method: "POST", path: "/v1/credits/estimate", idempotent: true },
|
|
85
86
|
credits_redeem: { method: "POST", path: "/v1/credits/redeem", idempotent: false },
|
|
86
|
-
telemetry_batch: { method: "POST", path: "/v1/telemetry/batch", idempotent: false }
|
|
87
|
+
telemetry_batch: { method: "POST", path: "/v1/telemetry/batch", idempotent: false },
|
|
88
|
+
maca_generate: { method: "POST", path: "/v1/maca/generate", idempotent: false },
|
|
89
|
+
maca_job: { method: "GET", path: "/v1/maca/jobs/{job_id}", idempotent: true }
|
|
87
90
|
};
|
|
88
91
|
function resolvePath(name, params = {}) {
|
|
89
92
|
return ENDPOINTS[name].path.replace(/\{(\w+)\}/g, (_m, key) => {
|
|
@@ -116,10 +119,10 @@ function shouldRetry(input) {
|
|
|
116
119
|
if (attempt >= policy.maxAttempts) {
|
|
117
120
|
return { retry: false, delaySeconds: 0, reason: "max_attempts_exhausted" };
|
|
118
121
|
}
|
|
119
|
-
if (!
|
|
122
|
+
if (!_chunkJPDEKN5Mcjs.isSynapError.call(void 0, error) || !error.transient) {
|
|
120
123
|
return { retry: false, delaySeconds: 0, reason: "not_transient" };
|
|
121
124
|
}
|
|
122
|
-
if (error instanceof
|
|
125
|
+
if (error instanceof _chunkJPDEKN5Mcjs.RateLimitError && error.reason) {
|
|
123
126
|
return { retry: false, delaySeconds: 0, reason: "credit_stop" };
|
|
124
127
|
}
|
|
125
128
|
const idempotent = _nullishCoalesce(input.idempotent, () => ( IDEMPOTENT_METHODS.has(method.toUpperCase())));
|
|
@@ -137,7 +140,7 @@ function shouldRetry(input) {
|
|
|
137
140
|
};
|
|
138
141
|
}
|
|
139
142
|
function backoffDelay(error, attempt, policy) {
|
|
140
|
-
if (error instanceof
|
|
143
|
+
if (error instanceof _chunkJPDEKN5Mcjs.RateLimitError && error.retryAfterSeconds != null) {
|
|
141
144
|
return Math.min(error.retryAfterSeconds, policy.backoffMax);
|
|
142
145
|
}
|
|
143
146
|
const exponential = policy.backoffBase * 2 ** (attempt - 1);
|
|
@@ -211,7 +214,198 @@ var B2C_ISOLATION = "equals_customer";
|
|
|
211
214
|
function checkCustomerId(isolation, customerId, where, instanceId) {
|
|
212
215
|
if (customerId === void 0 || customerId === null || customerId === "") return;
|
|
213
216
|
if (isolation !== B2C_ISOLATION) return;
|
|
214
|
-
throw new (0,
|
|
217
|
+
throw new (0, _chunkJPDEKN5Mcjs.CustomerIdNotAcceptedError)(where, String(customerId), instanceId);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/scope-ladder.ts
|
|
221
|
+
var ROLE_TENANT = "tenant_of_record";
|
|
222
|
+
var ROLE_IDENTITY = "identity";
|
|
223
|
+
var LADDER_TTL_MS = 3e5;
|
|
224
|
+
var LADDER_RETRY_BACKOFF_MS = 6e4;
|
|
225
|
+
var LADDER_INVALIDATION_MIN_INTERVAL_MS = 5e3;
|
|
226
|
+
var ScopeAddress = class {
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
constructor(init = {}) {
|
|
231
|
+
this.user_id = _nullishCoalesce(init.user_id, () => ( null));
|
|
232
|
+
this.customer_id = _nullishCoalesce(init.customer_id, () => ( null));
|
|
233
|
+
this.scope_path = _nullishCoalesce(init.scope_path, () => ( null));
|
|
234
|
+
}
|
|
235
|
+
/** Options for reads (`fetch`, `*.context.fetch`, `send_message`, ...): the path is `scope_path`. */
|
|
236
|
+
read_kwargs() {
|
|
237
|
+
const out = {};
|
|
238
|
+
if (this.user_id) out.user_id = this.user_id;
|
|
239
|
+
if (this.customer_id) out.customer_id = this.customer_id;
|
|
240
|
+
if (this.scope_path && Object.keys(this.scope_path).length > 0) {
|
|
241
|
+
out.scope_path = { ...this.scope_path };
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
/** Options for `memories.create` / `create_from_file` / `forget`: the path is `scope`. */
|
|
246
|
+
write_kwargs() {
|
|
247
|
+
const out = {};
|
|
248
|
+
if (this.user_id) out.user_id = this.user_id;
|
|
249
|
+
if (this.customer_id) out.customer_id = this.customer_id;
|
|
250
|
+
if (this.scope_path && Object.keys(this.scope_path).length > 0) {
|
|
251
|
+
out.scope = { ...this.scope_path };
|
|
252
|
+
}
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var REFRESH_HINT = "The account's ladder may not be accepted yet, or nested scoping may be off for this instance. If that changed recently, `await sdk.get_scope_ladder({ refresh: true })` re-reads it.";
|
|
257
|
+
var ScopeLadder = class {
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
/** "server" | "inferred" */
|
|
263
|
+
|
|
264
|
+
/** True when the instance is B2C: the tenant and identity level are one node. */
|
|
265
|
+
|
|
266
|
+
constructor(init) {
|
|
267
|
+
this.levels = Object.freeze([...init.levels]);
|
|
268
|
+
this.is_default = init.is_default;
|
|
269
|
+
this.ladder_ratified = init.ladder_ratified;
|
|
270
|
+
this.nested_scoping_enabled = init.nested_scoping_enabled;
|
|
271
|
+
this.source = init.source;
|
|
272
|
+
this.b2c = _nullishCoalesce(init.b2c, () => ( false));
|
|
273
|
+
}
|
|
274
|
+
get keys() {
|
|
275
|
+
return this.levels.map((l) => l.key);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Map `values` (outermost level first) to ids and, on a deeper ladder, the
|
|
279
|
+
* full prefix path. A shorter list addresses a higher level. Throws
|
|
280
|
+
* `ScopeLadderError` before any call when the values cannot be addressed.
|
|
281
|
+
*/
|
|
282
|
+
address(values) {
|
|
283
|
+
if (!Array.isArray(values)) {
|
|
284
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(
|
|
285
|
+
`address() takes a list of values, outermost level first, got ${typeof values}.`
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
const vals = [...values];
|
|
289
|
+
if (vals.length === 0) {
|
|
290
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(
|
|
291
|
+
`address() needs at least one value. The client level is addressed explicitly elsewhere (scope='client'), not through the ladder. Levels, outermost first: ${JSON.stringify(this.keys)}.`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
for (const v of vals) {
|
|
295
|
+
if (typeof v !== "string" || v === "") {
|
|
296
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(`address() values must be non-empty strings, got ${JSON.stringify(v)}.`);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
const levels = this.levels;
|
|
300
|
+
const expected = this.b2c ? levels.filter((l) => l.role !== ROLE_TENANT) : levels;
|
|
301
|
+
if (vals.length > expected.length) {
|
|
302
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(
|
|
303
|
+
`${vals.length} values for ${expected.length} levels (${JSON.stringify(expected.map((l) => l.key))}, outermost first).`
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
if (!this.is_default && (!this.nested_scoping_enabled || !this.ladder_ratified)) {
|
|
307
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(
|
|
308
|
+
`This account has a deeper scope ladder (${JSON.stringify(this.keys)}), but the server would refuse a scope path (nested_scoping_enabled=${this.nested_scoping_enabled}, ladder_ratified=${this.ladder_ratified}). ` + REFRESH_HINT
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
let userId = null;
|
|
312
|
+
let customerId = null;
|
|
313
|
+
const path = {};
|
|
314
|
+
if (this.b2c) {
|
|
315
|
+
const identity = levels.find((l) => l.role === ROLE_IDENTITY);
|
|
316
|
+
if (identity === void 0) {
|
|
317
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)("This ladder has no identity level, so a B2C address cannot be built.");
|
|
318
|
+
}
|
|
319
|
+
if (vals.length < expected.length) {
|
|
320
|
+
throw new (0, _chunkJPDEKN5Mcjs.ScopeLadderError)(
|
|
321
|
+
`On a B2C instance the tenant level takes the identity's value, so give one value for every level after it (${JSON.stringify(expected.map((l) => l.key))}); got ${vals.length}.`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
325
|
+
expected.forEach((l, i) => byKey.set(l.key, vals[i]));
|
|
326
|
+
const identityValue = byKey.get(identity.key);
|
|
327
|
+
userId = identityValue;
|
|
328
|
+
if (!this.is_default) {
|
|
329
|
+
for (const l of levels) {
|
|
330
|
+
path[l.key] = l.role === ROLE_TENANT ? identityValue : byKey.get(l.key);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} else {
|
|
334
|
+
levels.slice(0, vals.length).forEach((l, i) => {
|
|
335
|
+
const v = vals[i];
|
|
336
|
+
if (l.role === ROLE_TENANT) customerId = v;
|
|
337
|
+
else if (l.role === ROLE_IDENTITY) userId = v;
|
|
338
|
+
if (!this.is_default) path[l.key] = v;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
return new ScopeAddress({
|
|
342
|
+
user_id: userId,
|
|
343
|
+
customer_id: customerId,
|
|
344
|
+
scope_path: Object.keys(path).length > 0 ? path : null
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
var STRICT_LEVELS = [
|
|
349
|
+
{ key: "customer", label: "Customer", position: 1, role: ROLE_TENANT, required: true },
|
|
350
|
+
{ key: "user", label: "User", position: 2, role: ROLE_IDENTITY, required: true }
|
|
351
|
+
];
|
|
352
|
+
var B2C_LEVELS = [
|
|
353
|
+
{ key: "user", label: "User", position: 1, role: ROLE_IDENTITY, required: true }
|
|
354
|
+
];
|
|
355
|
+
function parseLevels(raw) {
|
|
356
|
+
if (!Array.isArray(raw) || raw.length === 0) return null;
|
|
357
|
+
const out = [];
|
|
358
|
+
for (const item of raw) {
|
|
359
|
+
if (typeof item !== "object" || item === null || Array.isArray(item)) return null;
|
|
360
|
+
const o2 = item;
|
|
361
|
+
const key = o2["key"];
|
|
362
|
+
if (typeof key !== "string" || key === "") return null;
|
|
363
|
+
const position = Number(o2["position"]);
|
|
364
|
+
if (!Number.isFinite(position) || o2["position"] === null || o2["position"] === "") return null;
|
|
365
|
+
const label = o2["label"];
|
|
366
|
+
const role = o2["role"];
|
|
367
|
+
out.push({
|
|
368
|
+
key,
|
|
369
|
+
label: typeof label === "string" && label !== "" ? label : key,
|
|
370
|
+
position: Math.trunc(position),
|
|
371
|
+
role: typeof role === "string" && role !== "" ? role : null,
|
|
372
|
+
required: o2["required"] === void 0 ? true : Boolean(o2["required"])
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
out.sort((a, b) => a.position - b.position);
|
|
376
|
+
return out;
|
|
377
|
+
}
|
|
378
|
+
function ladderFromWhoami(whoami, fallbackIsolation, warn = () => {
|
|
379
|
+
}) {
|
|
380
|
+
const rawIso = whoami["user_context_isolation"];
|
|
381
|
+
const isolation = _nullishCoalesce((typeof rawIso === "string" && rawIso !== "" ? rawIso : void 0), () => ( fallbackIsolation));
|
|
382
|
+
const b2c = isolation === "equals_customer";
|
|
383
|
+
const block = whoami["scope_ladder"];
|
|
384
|
+
if (block !== void 0 && block !== null) {
|
|
385
|
+
const levels = typeof block === "object" && !Array.isArray(block) ? parseLevels(block["levels"]) : null;
|
|
386
|
+
if (levels === null) {
|
|
387
|
+
warn("whoami returned a malformed scope_ladder block; ignoring it and inferring the default ladder.");
|
|
388
|
+
} else {
|
|
389
|
+
const b = block;
|
|
390
|
+
return new ScopeLadder({
|
|
391
|
+
levels,
|
|
392
|
+
is_default: Boolean(b["is_default"]),
|
|
393
|
+
ladder_ratified: Boolean(b["ladder_ratified"]),
|
|
394
|
+
nested_scoping_enabled: Boolean(b["nested_scoping_enabled"]),
|
|
395
|
+
source: "server",
|
|
396
|
+
b2c
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
if (isolation === void 0) return null;
|
|
401
|
+
return new ScopeLadder({
|
|
402
|
+
levels: b2c ? B2C_LEVELS : STRICT_LEVELS,
|
|
403
|
+
is_default: true,
|
|
404
|
+
ladder_ratified: false,
|
|
405
|
+
nested_scoping_enabled: false,
|
|
406
|
+
source: "inferred",
|
|
407
|
+
b2c
|
|
408
|
+
});
|
|
215
409
|
}
|
|
216
410
|
|
|
217
411
|
// src/transport/http.ts
|
|
@@ -268,7 +462,7 @@ var HttpTransport = (_class2 = class {
|
|
|
268
462
|
// instance id -> when the refusal's wait ends (monotonic ms), and what was said.
|
|
269
463
|
// One JS thread runs every request, so a plain Map needs no lock.
|
|
270
464
|
__init3() {this.notReadyCooldown = /* @__PURE__ */ new Map()}
|
|
271
|
-
constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);
|
|
465
|
+
constructor(options) {;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);
|
|
272
466
|
this.clock = _nullishCoalesce(options.clock, () => ( (() => performance.now())));
|
|
273
467
|
this.#credentials = options.credentials;
|
|
274
468
|
this.baseUrl = (_nullishCoalesce(options.baseUrl, () => ( DEFAULT_BASE_URL))).replace(/\/+$/, "");
|
|
@@ -327,13 +521,111 @@ var HttpTransport = (_class2 = class {
|
|
|
327
521
|
* deployment older than the field, and must mean "enforce nothing".
|
|
328
522
|
*/
|
|
329
523
|
__init4() {this.userContextIsolation = void 0}
|
|
524
|
+
// ── Scope ladder (Python: MaximemSynapSDK.get_scope_ladder) ───────────────
|
|
525
|
+
// Held here, like `userContextIsolation`, so the interface factories that
|
|
526
|
+
// receive the transport can reach it and the client's public surface carries
|
|
527
|
+
// only the method Python has.
|
|
528
|
+
#ladder = null;
|
|
529
|
+
// Loaded is separate from the value: "the server does not say" (null) is an
|
|
530
|
+
// answer too, and is cached for the same 300 s.
|
|
531
|
+
#ladderLoaded = false;
|
|
532
|
+
#ladderExpiresAt = 0;
|
|
533
|
+
#ladderRetryAt = 0;
|
|
534
|
+
// Bumped by every invalidation. A read that started under an older number is
|
|
535
|
+
// not stored when it finishes.
|
|
536
|
+
#ladderGeneration = 0;
|
|
537
|
+
#ladderInvalidated = false;
|
|
538
|
+
#ladderInvalidationReadAt = Number.NEGATIVE_INFINITY;
|
|
539
|
+
// The read in flight, shared by concurrent callers.
|
|
540
|
+
#ladderInflight = void 0;
|
|
541
|
+
/**
|
|
542
|
+
* Called as observer(error, carriedScopePath) for every 400 answer.
|
|
543
|
+
* `carriedScopePath` says whether the refused request named a scope path,
|
|
544
|
+
* which is how the client learns its cached ladder may be stale. Never
|
|
545
|
+
* allowed to throw.
|
|
546
|
+
*/
|
|
547
|
+
__init5() {this.onInvalidInput = void 0}
|
|
548
|
+
/**
|
|
549
|
+
* A 400 answered a call that carried a scope path: the ladder we hold may be
|
|
550
|
+
* stale. The next read is at most one per LADDER_INVALIDATION_MIN_INTERVAL_MS,
|
|
551
|
+
* the last known ladder stays as the answer if it fails, and a read already
|
|
552
|
+
* in flight will not be stored.
|
|
553
|
+
*
|
|
554
|
+
* The server's refusal wording is deliberately not inspected. The gRPC
|
|
555
|
+
* stream does not surface HTTP 400, so a ladder error on the stream is not
|
|
556
|
+
* observed here.
|
|
557
|
+
*/
|
|
558
|
+
invalidateScopeLadder() {
|
|
559
|
+
this.#ladderGeneration += 1;
|
|
560
|
+
this.#ladderInvalidated = true;
|
|
561
|
+
this.#ladderRetryAt = 0;
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* The account's ladder, from whoami, cached for 300 s (`null` included).
|
|
565
|
+
* Concurrent callers share one read. A failed re-read after expiry keeps the
|
|
566
|
+
* last known ladder (with a warning) and waits 60 s before trying again. A
|
|
567
|
+
* failure on the first read, or with `refresh`, is thrown.
|
|
568
|
+
*/
|
|
569
|
+
async getScopeLadder(refresh, warn) {
|
|
570
|
+
const now = this.clock();
|
|
571
|
+
const cached2 = this.#ladder;
|
|
572
|
+
const loaded = this.#ladderLoaded;
|
|
573
|
+
if (!refresh && loaded) {
|
|
574
|
+
if (now < this.#ladderRetryAt) return cached2;
|
|
575
|
+
if (this.#ladderInvalidated) {
|
|
576
|
+
if (now < this.#ladderInvalidationReadAt + LADDER_INVALIDATION_MIN_INTERVAL_MS) return cached2;
|
|
577
|
+
} else if (now < this.#ladderExpiresAt) {
|
|
578
|
+
return cached2;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const keepOnFailure = loaded && !refresh;
|
|
582
|
+
const inflight = this.#ladderInflight;
|
|
583
|
+
if (inflight !== void 0 && inflight.generation === this.#ladderGeneration && inflight.keepOnFailure === keepOnFailure) {
|
|
584
|
+
return inflight.promise;
|
|
585
|
+
}
|
|
586
|
+
const generation = this.#ladderGeneration;
|
|
587
|
+
if (this.#ladderInvalidated && !refresh) this.#ladderInvalidationReadAt = now;
|
|
588
|
+
const promise = this.#readScopeLadder(now, generation, cached2, keepOnFailure, warn);
|
|
589
|
+
const entry = { promise, generation, keepOnFailure };
|
|
590
|
+
this.#ladderInflight = entry;
|
|
591
|
+
const clear = () => {
|
|
592
|
+
if (this.#ladderInflight === entry) this.#ladderInflight = void 0;
|
|
593
|
+
};
|
|
594
|
+
promise.then(clear, clear);
|
|
595
|
+
return promise;
|
|
596
|
+
}
|
|
597
|
+
async #readScopeLadder(now, generation, cached2, keepOnFailure, warn) {
|
|
598
|
+
let whoami;
|
|
599
|
+
try {
|
|
600
|
+
const raw = await this.request("whoami", {});
|
|
601
|
+
whoami = typeof raw === "object" && raw !== null && !Array.isArray(raw) ? raw : {};
|
|
602
|
+
} catch (error) {
|
|
603
|
+
if (keepOnFailure) {
|
|
604
|
+
warn(
|
|
605
|
+
`Could not re-read the scope ladder (${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _11 => _11.message]), () => ( String(error)))}); keeping the last known one and retrying in ${LADDER_RETRY_BACKOFF_MS / 1e3}s.`
|
|
606
|
+
);
|
|
607
|
+
this.#ladderRetryAt = now + LADDER_RETRY_BACKOFF_MS;
|
|
608
|
+
return cached2;
|
|
609
|
+
}
|
|
610
|
+
throw error;
|
|
611
|
+
}
|
|
612
|
+
const ladder = ladderFromWhoami(whoami, this.userContextIsolation, warn);
|
|
613
|
+
if (generation === this.#ladderGeneration) {
|
|
614
|
+
this.#ladder = ladder;
|
|
615
|
+
this.#ladderLoaded = true;
|
|
616
|
+
this.#ladderExpiresAt = now + LADDER_TTL_MS;
|
|
617
|
+
this.#ladderRetryAt = 0;
|
|
618
|
+
this.#ladderInvalidated = false;
|
|
619
|
+
}
|
|
620
|
+
return ladder;
|
|
621
|
+
}
|
|
330
622
|
/**
|
|
331
623
|
* Set by the client to its identity resolution (`initialize()`'s whoami).
|
|
332
624
|
* Python refuses every call before `initialize()`; here the first request
|
|
333
625
|
* runs it instead, so a caller who skips it gets the same identity-dependent
|
|
334
626
|
* behaviour (client-scope cache hits, the B2C check) rather than an error.
|
|
335
627
|
*/
|
|
336
|
-
|
|
628
|
+
__init6() {this.identityResolver = void 0}
|
|
337
629
|
/** Resolve identity once, before the first request. Never throws. */
|
|
338
630
|
async ready() {
|
|
339
631
|
if (this.identityResolver !== void 0) await this.identityResolver();
|
|
@@ -379,7 +671,7 @@ var HttpTransport = (_class2 = class {
|
|
|
379
671
|
this.notReadyCooldown.delete(instanceId);
|
|
380
672
|
return;
|
|
381
673
|
}
|
|
382
|
-
throw new (0,
|
|
674
|
+
throw new (0, _chunkJPDEKN5Mcjs.InstanceNotReadyError)(entry.message, {
|
|
383
675
|
correlationId,
|
|
384
676
|
retryAfterSeconds: Math.max(1, Math.ceil(remainingMs / 1e3)),
|
|
385
677
|
instanceId,
|
|
@@ -400,7 +692,7 @@ var HttpTransport = (_class2 = class {
|
|
|
400
692
|
}
|
|
401
693
|
async request(name, options = {}) {
|
|
402
694
|
const spec = ENDPOINTS[name];
|
|
403
|
-
const correlationId = _nullishCoalesce(options.correlationId, () => (
|
|
695
|
+
const correlationId = _nullishCoalesce(options.correlationId, () => ( _chunkJPDEKN5Mcjs.newCorrelationId.call(void 0, )));
|
|
404
696
|
const idempotent = _nullishCoalesce(options.idempotent, () => ( spec.idempotent));
|
|
405
697
|
if (name !== "whoami") await this.ready();
|
|
406
698
|
const gated = isGatedPath(spec.method, resolvePath(name, options.pathParams));
|
|
@@ -415,7 +707,7 @@ var HttpTransport = (_class2 = class {
|
|
|
415
707
|
if (gated) this.notReadyCooldown.delete(cooldownKey);
|
|
416
708
|
return result;
|
|
417
709
|
} catch (error) {
|
|
418
|
-
if (gated && error instanceof
|
|
710
|
+
if (gated && error instanceof _chunkJPDEKN5Mcjs.InstanceNotReadyError && !error.fromCooldown) {
|
|
419
711
|
this.cooldownStart(cooldownKey, error);
|
|
420
712
|
}
|
|
421
713
|
last = { error, outcomeUnknown: isOutcomeUnknown(error) };
|
|
@@ -431,7 +723,7 @@ var HttpTransport = (_class2 = class {
|
|
|
431
723
|
await sleep(decision.delaySeconds * 1e3, options.signal);
|
|
432
724
|
}
|
|
433
725
|
}
|
|
434
|
-
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess',
|
|
726
|
+
throw _nullishCoalesce(_optionalChain([last, 'optionalAccess', _12 => _12.error]), () => ( new (0, _chunkJPDEKN5Mcjs.SynapError)("Request failed with no recorded error")));
|
|
435
727
|
}
|
|
436
728
|
async attempt(name, options, correlationId) {
|
|
437
729
|
const spec = ENDPOINTS[name];
|
|
@@ -457,15 +749,21 @@ var HttpTransport = (_class2 = class {
|
|
|
457
749
|
}
|
|
458
750
|
if (!response.ok) {
|
|
459
751
|
const error = await toHttpError(response, correlationId);
|
|
460
|
-
|
|
752
|
+
if (response.status === 400 && error instanceof _chunkJPDEKN5Mcjs.InvalidInputError) {
|
|
753
|
+
try {
|
|
754
|
+
_optionalChain([this, 'access', _13 => _13.onInvalidInput, 'optionalCall', _14 => _14(error, carriesScopePath(options.body))]);
|
|
755
|
+
} catch (e3) {
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
throw _nullishCoalesce(_optionalChain([options, 'access', _15 => _15.mapError, 'optionalCall', _16 => _16(response.status, error)]), () => ( error));
|
|
461
759
|
}
|
|
462
760
|
if (response.status === 204) return void 0;
|
|
463
761
|
const text = await response.text();
|
|
464
762
|
if (!text) return void 0;
|
|
465
763
|
try {
|
|
466
764
|
return JSON.parse(text);
|
|
467
|
-
} catch (
|
|
468
|
-
throw new (0,
|
|
765
|
+
} catch (e4) {
|
|
766
|
+
throw new (0, _chunkJPDEKN5Mcjs.SynapError)(`Malformed JSON in response from ${url}`, { correlationId });
|
|
469
767
|
}
|
|
470
768
|
}
|
|
471
769
|
buildUrl(path, query) {
|
|
@@ -500,15 +798,15 @@ var HttpTransport = (_class2 = class {
|
|
|
500
798
|
}
|
|
501
799
|
}, _class2);
|
|
502
800
|
function isOutcomeUnknown(error) {
|
|
503
|
-
if (error instanceof
|
|
504
|
-
if (error instanceof
|
|
505
|
-
if (error instanceof
|
|
506
|
-
if (error instanceof
|
|
507
|
-
if (error instanceof
|
|
508
|
-
if (error instanceof
|
|
509
|
-
if (error instanceof
|
|
801
|
+
if (error instanceof _chunkJPDEKN5Mcjs.RateLimitError) return false;
|
|
802
|
+
if (error instanceof _chunkJPDEKN5Mcjs.ServiceUnavailableError) return false;
|
|
803
|
+
if (error instanceof _chunkJPDEKN5Mcjs.AuthenticationError) return false;
|
|
804
|
+
if (error instanceof _chunkJPDEKN5Mcjs.InvalidInputError) return false;
|
|
805
|
+
if (error instanceof _chunkJPDEKN5Mcjs.ConflictError) return false;
|
|
806
|
+
if (error instanceof _chunkJPDEKN5Mcjs.InsufficientCreditsError) return false;
|
|
807
|
+
if (error instanceof _chunkJPDEKN5Mcjs.ContextNotFoundError) return false;
|
|
510
808
|
if (isConnectionRefusal(error)) return false;
|
|
511
|
-
if (error instanceof
|
|
809
|
+
if (error instanceof _chunkJPDEKN5Mcjs.NetworkTimeoutError) return true;
|
|
512
810
|
return true;
|
|
513
811
|
}
|
|
514
812
|
var CONNECTION_REFUSAL_CODES = /* @__PURE__ */ new Set([
|
|
@@ -528,19 +826,19 @@ function isConnectionRefusal(error) {
|
|
|
528
826
|
return false;
|
|
529
827
|
}
|
|
530
828
|
function toTransportError(error, correlationId) {
|
|
531
|
-
if (error instanceof
|
|
532
|
-
const name = _optionalChain([error, 'optionalAccess',
|
|
829
|
+
if (error instanceof _chunkJPDEKN5Mcjs.SynapError) return error;
|
|
830
|
+
const name = _optionalChain([error, 'optionalAccess', _17 => _17.name]);
|
|
533
831
|
if (name === "AbortError" || name === "TimeoutError") {
|
|
534
|
-
return new (0,
|
|
832
|
+
return new (0, _chunkJPDEKN5Mcjs.NetworkTimeoutError)("Request timed out", { correlationId, cause: error });
|
|
535
833
|
}
|
|
536
834
|
if (isConnectionRefusal(error)) {
|
|
537
|
-
return new (0,
|
|
538
|
-
`Connection failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
835
|
+
return new (0, _chunkJPDEKN5Mcjs.NetworkTimeoutError)(
|
|
836
|
+
`Connection failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _18 => _18.message]), () => ( String(error)))}`,
|
|
539
837
|
{ correlationId, cause: error }
|
|
540
838
|
);
|
|
541
839
|
}
|
|
542
|
-
return new (0,
|
|
543
|
-
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
840
|
+
return new (0, _chunkJPDEKN5Mcjs.ServiceUnavailableError)(
|
|
841
|
+
`Network request failed: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _19 => _19.message]), () => ( String(error)))}`,
|
|
544
842
|
{ correlationId, cause: error }
|
|
545
843
|
);
|
|
546
844
|
}
|
|
@@ -554,12 +852,44 @@ function creditReason(payload) {
|
|
|
554
852
|
const error = stringOrNull(payload["error"]);
|
|
555
853
|
return error !== null && CREDIT_ERRORS.has(error) ? error : null;
|
|
556
854
|
}
|
|
855
|
+
function isScopePath(value) {
|
|
856
|
+
let v = value;
|
|
857
|
+
if (typeof v === "string" && v.trimStart().startsWith("{")) {
|
|
858
|
+
try {
|
|
859
|
+
v = JSON.parse(v);
|
|
860
|
+
} catch (e5) {
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return typeof v === "object" && v !== null && !Array.isArray(v) && Object.keys(v).length > 0;
|
|
865
|
+
}
|
|
866
|
+
function carriesScopePath(body) {
|
|
867
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) {
|
|
868
|
+
if (isScopePath(body.get("scope"))) return true;
|
|
869
|
+
const manifest = body.get("manifest");
|
|
870
|
+
if (typeof manifest === "string") {
|
|
871
|
+
try {
|
|
872
|
+
const parsed = JSON.parse(manifest);
|
|
873
|
+
return typeof parsed === "object" && parsed !== null && isScopePath(parsed["scope"]);
|
|
874
|
+
} catch (e6) {
|
|
875
|
+
return false;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return false;
|
|
881
|
+
const o2 = body;
|
|
882
|
+
if (isScopePath(o2["scope"])) return true;
|
|
883
|
+
return Object.values(o2).some(
|
|
884
|
+
(v) => Array.isArray(v) && v.some((i) => typeof i === "object" && i !== null && isScopePath(i["scope"]))
|
|
885
|
+
);
|
|
886
|
+
}
|
|
557
887
|
async function toHttpError(response, correlationId) {
|
|
558
888
|
const body = await response.text().catch(() => "");
|
|
559
889
|
let parsed = {};
|
|
560
890
|
try {
|
|
561
891
|
parsed = JSON.parse(body);
|
|
562
|
-
} catch (
|
|
892
|
+
} catch (e7) {
|
|
563
893
|
}
|
|
564
894
|
const rawDetail = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(parsed["detail"], () => ( parsed["message"])), () => ( body)), () => ( ""));
|
|
565
895
|
const detailObject = typeof rawDetail === "object" && rawDetail !== null ? rawDetail : null;
|
|
@@ -574,15 +904,15 @@ async function toHttpError(response, correlationId) {
|
|
|
574
904
|
case 405:
|
|
575
905
|
case 413:
|
|
576
906
|
case 415:
|
|
577
|
-
return new (0,
|
|
907
|
+
return new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(message, opts);
|
|
578
908
|
case 401:
|
|
579
909
|
case 403:
|
|
580
|
-
return new (0,
|
|
910
|
+
return new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(message, opts);
|
|
581
911
|
case 404:
|
|
582
|
-
return new (0,
|
|
912
|
+
return new (0, _chunkJPDEKN5Mcjs.ContextNotFoundError)(message, opts);
|
|
583
913
|
case 402: {
|
|
584
914
|
const credit = creditPayload(parsed, detailObject);
|
|
585
|
-
return new (0,
|
|
915
|
+
return new (0, _chunkJPDEKN5Mcjs.InsufficientCreditsError)(message, {
|
|
586
916
|
...opts,
|
|
587
917
|
balanceCredits: numberOrNull(credit["balance_credits"]),
|
|
588
918
|
requiredCredits: _nullishCoalesce(numberOrNull(credit["minimum_required_credits"]), () => ( numberOrNull(credit["required_credits"]))),
|
|
@@ -593,11 +923,11 @@ async function toHttpError(response, correlationId) {
|
|
|
593
923
|
});
|
|
594
924
|
}
|
|
595
925
|
case 409:
|
|
596
|
-
if (parsed["error"] === "instance_build_failed" || _optionalChain([detailObject, 'optionalAccess',
|
|
597
|
-
const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess',
|
|
926
|
+
if (parsed["error"] === "instance_build_failed" || _optionalChain([detailObject, 'optionalAccess', _20 => _20["code"]]) === "instance_build_failed" || _optionalChain([detailObject, 'optionalAccess', _21 => _21["error"]]) === "instance_build_failed") {
|
|
927
|
+
const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess', _22 => _22[key]])));
|
|
598
928
|
const msg = pick4("message");
|
|
599
929
|
const attempts = Number(pick4("attempts"));
|
|
600
|
-
return new (0,
|
|
930
|
+
return new (0, _chunkJPDEKN5Mcjs.InstanceBuildFailedError)(
|
|
601
931
|
typeof msg === "string" && msg !== "" ? msg : "This instance's memory architecture build failed.",
|
|
602
932
|
{
|
|
603
933
|
...opts,
|
|
@@ -607,12 +937,12 @@ async function toHttpError(response, correlationId) {
|
|
|
607
937
|
}
|
|
608
938
|
);
|
|
609
939
|
}
|
|
610
|
-
if (parsed["error"] === "instance_not_ready" || _optionalChain([detailObject, 'optionalAccess',
|
|
611
|
-
const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess',
|
|
940
|
+
if (parsed["error"] === "instance_not_ready" || _optionalChain([detailObject, 'optionalAccess', _23 => _23["code"]]) === "instance_not_ready" || _optionalChain([detailObject, 'optionalAccess', _24 => _24["error"]]) === "instance_not_ready") {
|
|
941
|
+
const pick4 = (key) => _nullishCoalesce(parsed[key], () => ( _optionalChain([detailObject, 'optionalAccess', _25 => _25[key]])));
|
|
612
942
|
const rawWait = _nullishCoalesce(pick4("retry_after_seconds"), () => ( response.headers.get("retry-after")));
|
|
613
943
|
const wait = rawWait !== null && rawWait !== void 0 && String(rawWait).trim() !== "" ? Number(rawWait) : NaN;
|
|
614
944
|
const msg = pick4("message");
|
|
615
|
-
return new (0,
|
|
945
|
+
return new (0, _chunkJPDEKN5Mcjs.InstanceNotReadyError)(
|
|
616
946
|
typeof msg === "string" && msg !== "" ? msg : "This instance's memory architecture is still being built.",
|
|
617
947
|
{
|
|
618
948
|
...opts,
|
|
@@ -623,14 +953,14 @@ async function toHttpError(response, correlationId) {
|
|
|
623
953
|
);
|
|
624
954
|
}
|
|
625
955
|
if (detailObject !== null && detailObject["code"] === "transcript_conflict") {
|
|
626
|
-
return new (0,
|
|
956
|
+
return new (0, _chunkJPDEKN5Mcjs.TranscriptConflictError)(message, opts);
|
|
627
957
|
}
|
|
628
|
-
return new (0,
|
|
958
|
+
return new (0, _chunkJPDEKN5Mcjs.ConflictError)(message, opts);
|
|
629
959
|
case 429: {
|
|
630
960
|
const header = response.headers.get("retry-after");
|
|
631
961
|
const retryAfter = header !== null && header.trim() !== "" ? Number(header) : null;
|
|
632
962
|
const credit = creditPayload(parsed, detailObject);
|
|
633
|
-
return new (0,
|
|
963
|
+
return new (0, _chunkJPDEKN5Mcjs.RateLimitError)(message, {
|
|
634
964
|
...opts,
|
|
635
965
|
retryAfterSeconds: retryAfter !== null && Number.isFinite(retryAfter) ? retryAfter : null,
|
|
636
966
|
reason: creditReason(credit),
|
|
@@ -639,13 +969,13 @@ async function toHttpError(response, correlationId) {
|
|
|
639
969
|
});
|
|
640
970
|
}
|
|
641
971
|
case 503:
|
|
642
|
-
return new (0,
|
|
972
|
+
return new (0, _chunkJPDEKN5Mcjs.ServiceUnavailableError)(message, opts);
|
|
643
973
|
case 504:
|
|
644
|
-
return new (0,
|
|
974
|
+
return new (0, _chunkJPDEKN5Mcjs.AgentUnavailableError)(message, opts);
|
|
645
975
|
default:
|
|
646
|
-
if (response.status >= 500) return new (0,
|
|
647
|
-
if (response.status >= 400) return new (0,
|
|
648
|
-
return new (0,
|
|
976
|
+
if (response.status >= 500) return new (0, _chunkJPDEKN5Mcjs.ServiceUnavailableError)(message, opts);
|
|
977
|
+
if (response.status >= 400) return new (0, _chunkJPDEKN5Mcjs.SynapPermanentError)(message, opts);
|
|
978
|
+
return new (0, _chunkJPDEKN5Mcjs.SynapError)(message, opts);
|
|
649
979
|
}
|
|
650
980
|
}
|
|
651
981
|
function numberOrNull(v) {
|
|
@@ -656,11 +986,11 @@ function stringOrNull(v) {
|
|
|
656
986
|
}
|
|
657
987
|
function withTimeout(ms, external) {
|
|
658
988
|
const controller = new AbortController();
|
|
659
|
-
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess',
|
|
989
|
+
const onExternalAbort = () => controller.abort(_optionalChain([external, 'optionalAccess', _26 => _26.reason]));
|
|
660
990
|
const timer = setTimeout(() => {
|
|
661
|
-
controller.abort(new (0,
|
|
991
|
+
controller.abort(new (0, _chunkJPDEKN5Mcjs.NetworkTimeoutError)(`Timed out after ${ms}ms`));
|
|
662
992
|
}, ms);
|
|
663
|
-
_optionalChain([timer, 'access',
|
|
993
|
+
_optionalChain([timer, 'access', _27 => _27.unref, 'optionalCall', _28 => _28()]);
|
|
664
994
|
if (external) {
|
|
665
995
|
if (external.aborted) onExternalAbort();
|
|
666
996
|
else external.addEventListener("abort", onExternalAbort, { once: true });
|
|
@@ -669,7 +999,7 @@ function withTimeout(ms, external) {
|
|
|
669
999
|
signal: controller.signal,
|
|
670
1000
|
dispose() {
|
|
671
1001
|
clearTimeout(timer);
|
|
672
|
-
_optionalChain([external, 'optionalAccess',
|
|
1002
|
+
_optionalChain([external, 'optionalAccess', _29 => _29.removeEventListener, 'call', _30 => _30("abort", onExternalAbort)]);
|
|
673
1003
|
}
|
|
674
1004
|
};
|
|
675
1005
|
}
|
|
@@ -677,14 +1007,14 @@ function sleep(ms, signal) {
|
|
|
677
1007
|
if (ms <= 0) return Promise.resolve();
|
|
678
1008
|
return new Promise((resolve, reject) => {
|
|
679
1009
|
const timer = setTimeout(() => {
|
|
680
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1010
|
+
_optionalChain([signal, 'optionalAccess', _31 => _31.removeEventListener, 'call', _32 => _32("abort", onAbort)]);
|
|
681
1011
|
resolve();
|
|
682
1012
|
}, ms);
|
|
683
1013
|
function onAbort() {
|
|
684
1014
|
clearTimeout(timer);
|
|
685
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
1015
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _33 => _33.reason]), () => ( new Error("Aborted"))));
|
|
686
1016
|
}
|
|
687
|
-
_optionalChain([signal, 'optionalAccess',
|
|
1017
|
+
_optionalChain([signal, 'optionalAccess', _34 => _34.addEventListener, 'call', _35 => _35("abort", onAbort, { once: true })]);
|
|
688
1018
|
});
|
|
689
1019
|
}
|
|
690
1020
|
|
|
@@ -828,10 +1158,10 @@ function buildFetchRequest(scope, options) {
|
|
|
828
1158
|
const { mode, precisionLevel } = retrievalOptionsOf(options);
|
|
829
1159
|
const { contextMode, lastN } = scopeOptionsOf(scope, options);
|
|
830
1160
|
if (searchQuery !== void 0 && !Array.isArray(searchQuery)) {
|
|
831
|
-
throw new (0,
|
|
1161
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("search_query must be an array when provided");
|
|
832
1162
|
}
|
|
833
1163
|
if (options.types !== void 0 && !Array.isArray(options.types)) {
|
|
834
|
-
throw new (0,
|
|
1164
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("types must be an array when provided");
|
|
835
1165
|
}
|
|
836
1166
|
const body = {
|
|
837
1167
|
conversation_id: _nullishCoalesce(conversationId, () => ( null)),
|
|
@@ -880,7 +1210,7 @@ var VALID_CONTEXT_MODES = ["in-conversation", "conversation-summary"];
|
|
|
880
1210
|
function responseShapeOf(options) {
|
|
881
1211
|
const shape = _nullishCoalesce(opt(options, "response_shape", "responseShape"), () => ( "by_type"));
|
|
882
1212
|
if (!RESPONSE_SHAPES.includes(shape)) {
|
|
883
|
-
throw new (0,
|
|
1213
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
884
1214
|
`Invalid response_shape '${shape}'. Must be one of: ${RESPONSE_SHAPES.join(", ")}`
|
|
885
1215
|
);
|
|
886
1216
|
}
|
|
@@ -895,21 +1225,21 @@ var REQUIRED_ID = {
|
|
|
895
1225
|
function scopeOptionsOf(scope, options) {
|
|
896
1226
|
const required = REQUIRED_ID[scope];
|
|
897
1227
|
if (required !== null && !opt(options, required[0], required[1])) {
|
|
898
|
-
throw new (0,
|
|
1228
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`${required[0]} is required`);
|
|
899
1229
|
}
|
|
900
1230
|
const contextMode = _nullishCoalesce(opt(options, "context_mode", "contextMode"), () => ( "in-conversation"));
|
|
901
1231
|
const lastN = _nullishCoalesce(opt(options, "last_n_conversations", "lastNConversations"), () => ( 1));
|
|
902
1232
|
if (scope !== "user") return { contextMode, lastN };
|
|
903
1233
|
if (!VALID_CONTEXT_MODES.includes(contextMode)) {
|
|
904
|
-
throw new (0,
|
|
1234
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
905
1235
|
`Invalid context_mode '${contextMode}'. Must be one of: ${VALID_CONTEXT_MODES.join(", ")}`
|
|
906
1236
|
);
|
|
907
1237
|
}
|
|
908
1238
|
if (!Number.isInteger(lastN)) {
|
|
909
|
-
throw new (0,
|
|
1239
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("last_n_conversations must be an integer");
|
|
910
1240
|
}
|
|
911
1241
|
if (lastN < 0 || lastN > 20) {
|
|
912
|
-
throw new (0,
|
|
1242
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("last_n_conversations must be between 0 and 20");
|
|
913
1243
|
}
|
|
914
1244
|
return { contextMode, lastN };
|
|
915
1245
|
}
|
|
@@ -918,13 +1248,13 @@ var VALID_PRECISION = ["high", "medium"];
|
|
|
918
1248
|
function retrievalOptionsOf(options) {
|
|
919
1249
|
const mode = _nullishCoalesce(options.mode, () => ( "fast"));
|
|
920
1250
|
if (!VALID_MODES.includes(mode)) {
|
|
921
|
-
throw new (0,
|
|
1251
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
922
1252
|
`Invalid mode '${mode}'. Must be one of: ${VALID_MODES.join(", ")}`
|
|
923
1253
|
);
|
|
924
1254
|
}
|
|
925
1255
|
const precisionLevel = _nullishCoalesce(opt(options, "precision_level", "precisionLevel"), () => ( "high"));
|
|
926
1256
|
if (!VALID_PRECISION.includes(precisionLevel)) {
|
|
927
|
-
throw new (0,
|
|
1257
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
928
1258
|
`Invalid precision_level '${precisionLevel}'. Must be one of: ${VALID_PRECISION.join(", ")}`
|
|
929
1259
|
);
|
|
930
1260
|
}
|
|
@@ -933,12 +1263,12 @@ function retrievalOptionsOf(options) {
|
|
|
933
1263
|
function validateSearchQuery(searchQuery) {
|
|
934
1264
|
if (searchQuery === void 0 || searchQuery === null) return;
|
|
935
1265
|
if (!Array.isArray(searchQuery) || searchQuery.some((query) => typeof query !== "string")) {
|
|
936
|
-
throw new (0,
|
|
1266
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("search_query must be an array of strings when provided");
|
|
937
1267
|
}
|
|
938
1268
|
}
|
|
939
1269
|
async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
940
1270
|
const startedAt = Date.now();
|
|
941
|
-
await _optionalChain([transport, 'access',
|
|
1271
|
+
await _optionalChain([transport, 'access', _36 => _36.ready, 'optionalCall', _37 => _37()]);
|
|
942
1272
|
await transport.checkCustomerId(
|
|
943
1273
|
opt(options, "customer_id", "customerId"),
|
|
944
1274
|
`${scope}.context.fetch`
|
|
@@ -954,20 +1284,20 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
|
954
1284
|
if (answer !== null) return applyResponseShape(answer, responseShape);
|
|
955
1285
|
}
|
|
956
1286
|
const finish = (response2) => {
|
|
957
|
-
_optionalChain([hooks, 'access',
|
|
1287
|
+
_optionalChain([hooks, 'access', _38 => _38.onResponse, 'optionalCall', _39 => _39(scope, options, response2)]);
|
|
958
1288
|
return response2;
|
|
959
1289
|
};
|
|
960
1290
|
const conversationId = opt(options, "conversation_id", "conversationId");
|
|
961
|
-
const skipServerSt = conversationId ? _optionalChain([hooks, 'access',
|
|
1291
|
+
const skipServerSt = conversationId ? _optionalChain([hooks, 'access', _40 => _40.skipServerShortTerm, 'optionalCall', _41 => _41(conversationId)]) === true : false;
|
|
962
1292
|
const network = async () => {
|
|
963
1293
|
const { endpoint, body } = buildFetchRequest(
|
|
964
1294
|
scope,
|
|
965
1295
|
skipServerSt ? { ...options, include_conversation_context: false } : options
|
|
966
1296
|
);
|
|
967
1297
|
const result = await transport.request(endpoint, { body });
|
|
968
|
-
return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
1298
|
+
return applyResponseShape(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _42 => _42["context"]]), () => ( {})), responseShape);
|
|
969
1299
|
};
|
|
970
|
-
const anticipated = summaryMode ? null : await _asyncNullishCoalesce(await _optionalChain([hooks, 'access',
|
|
1300
|
+
const anticipated = summaryMode ? null : await _asyncNullishCoalesce(await _optionalChain([hooks, 'access', _43 => _43.beforeFetch, 'optionalCall', _44 => _44(scope, options)]), async () => ( null));
|
|
971
1301
|
if (anticipated !== null && anticipated.borderline) {
|
|
972
1302
|
const pending = network();
|
|
973
1303
|
pending.catch(() => void 0);
|
|
@@ -978,17 +1308,17 @@ async function fetchContext(transport, scope, options = {}, hooks = {}) {
|
|
|
978
1308
|
const won = await Promise.race([pending.then((r) => r, () => null), late]);
|
|
979
1309
|
if (timer !== void 0) clearTimeout(timer);
|
|
980
1310
|
if (won !== null) {
|
|
981
|
-
_optionalChain([hooks, 'access',
|
|
1311
|
+
_optionalChain([hooks, 'access', _45 => _45.onAssembled, 'optionalCall', _46 => _46(scope, options, won, startedAt)]);
|
|
982
1312
|
return finish(won);
|
|
983
1313
|
}
|
|
984
1314
|
}
|
|
985
1315
|
if (anticipated !== null) {
|
|
986
|
-
_optionalChain([hooks, 'access',
|
|
987
|
-
_optionalChain([hooks, 'access',
|
|
1316
|
+
_optionalChain([hooks, 'access', _47 => _47.onServedFromCache, 'optionalCall', _48 => _48(scope, options, anticipated)]);
|
|
1317
|
+
_optionalChain([hooks, 'access', _49 => _49.onAssembled, 'optionalCall', _50 => _50(scope, options, anticipated.response, startedAt)]);
|
|
988
1318
|
return finish(applyResponseShape(anticipated.response, responseShape));
|
|
989
1319
|
}
|
|
990
1320
|
const response = await network();
|
|
991
|
-
_optionalChain([hooks, 'access',
|
|
1321
|
+
_optionalChain([hooks, 'access', _51 => _51.onAssembled, 'optionalCall', _52 => _52(scope, options, response, startedAt)]);
|
|
992
1322
|
return finish(response);
|
|
993
1323
|
}
|
|
994
1324
|
|
|
@@ -1239,7 +1569,7 @@ function isBranded(value) {
|
|
|
1239
1569
|
return typeof value === "object" && value !== null && PART_BRAND in value;
|
|
1240
1570
|
}
|
|
1241
1571
|
function textPart(text) {
|
|
1242
|
-
if (typeof text !== "string") throw new (0,
|
|
1572
|
+
if (typeof text !== "string") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("TextPart text must be a string");
|
|
1243
1573
|
return brand({ type: "text", text });
|
|
1244
1574
|
}
|
|
1245
1575
|
function filePart(init) {
|
|
@@ -1268,7 +1598,7 @@ function checkOneSource(p) {
|
|
|
1268
1598
|
(k) => p[k] !== void 0 && p[k] !== null
|
|
1269
1599
|
);
|
|
1270
1600
|
if (given.length !== 1) {
|
|
1271
|
-
throw new (0,
|
|
1601
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1272
1602
|
"FilePart takes exactly one of data, path or url" + (given.length > 0 ? ` (got ${given.join(", ")})` : "")
|
|
1273
1603
|
);
|
|
1274
1604
|
}
|
|
@@ -1285,12 +1615,12 @@ function defaultFilename(p, source) {
|
|
|
1285
1615
|
let pathname = "";
|
|
1286
1616
|
try {
|
|
1287
1617
|
pathname = new URL(String(p.url)).pathname;
|
|
1288
|
-
} catch (
|
|
1618
|
+
} catch (e8) {
|
|
1289
1619
|
pathname = _nullishCoalesce(String(p.url).split(/[?#]/)[0], () => ( ""));
|
|
1290
1620
|
}
|
|
1291
1621
|
return lastSegment(pathname) || "file";
|
|
1292
1622
|
}
|
|
1293
|
-
const named = _optionalChain([p, 'access',
|
|
1623
|
+
const named = _optionalChain([p, 'access', _53 => _53.data, 'optionalAccess', _54 => _54.name]);
|
|
1294
1624
|
return typeof named === "string" && named ? named : "file";
|
|
1295
1625
|
}
|
|
1296
1626
|
var MEDIA_TYPES = {
|
|
@@ -1327,7 +1657,7 @@ function guessMediaType(filename) {
|
|
|
1327
1657
|
function defaultMediaType(filename, data) {
|
|
1328
1658
|
const guessed = guessMediaType(filename);
|
|
1329
1659
|
if (guessed !== null) return guessed;
|
|
1330
|
-
const blobType = _optionalChain([data, 'optionalAccess',
|
|
1660
|
+
const blobType = _optionalChain([data, 'optionalAccess', _55 => _55.type]);
|
|
1331
1661
|
return typeof blobType === "string" && blobType ? blobType : DEFAULT_MEDIA_TYPE;
|
|
1332
1662
|
}
|
|
1333
1663
|
function normaliseContent(value, field) {
|
|
@@ -1335,12 +1665,12 @@ function normaliseContent(value, field) {
|
|
|
1335
1665
|
if (isBranded(value) && isFilePart(value)) return { kind: "parts", parts: [value] };
|
|
1336
1666
|
if (!Array.isArray(value)) return null;
|
|
1337
1667
|
if (value.length === 0) {
|
|
1338
|
-
throw new (0,
|
|
1668
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`${field} is an empty list; pass at least one part`);
|
|
1339
1669
|
}
|
|
1340
1670
|
const parts = value.map((item, i) => {
|
|
1341
1671
|
if (typeof item === "string") return { type: "text", text: item };
|
|
1342
1672
|
if (isTextPart(item) || isFilePart(item)) return item;
|
|
1343
|
-
throw new (0,
|
|
1673
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1344
1674
|
`${field}[${i}] is a ${typeName(item)}; expected a string, TextPart or FilePart`
|
|
1345
1675
|
);
|
|
1346
1676
|
});
|
|
@@ -1353,7 +1683,7 @@ function typeName(value) {
|
|
|
1353
1683
|
if (value === null) return "null";
|
|
1354
1684
|
if (Array.isArray(value)) return "array";
|
|
1355
1685
|
if (typeof value === "object") {
|
|
1356
|
-
return _nullishCoalesce(_optionalChain([value, 'access',
|
|
1686
|
+
return _nullishCoalesce(_optionalChain([value, 'access', _56 => _56.constructor, 'optionalAccess', _57 => _57.name]), () => ( "object"));
|
|
1357
1687
|
}
|
|
1358
1688
|
return typeof value;
|
|
1359
1689
|
}
|
|
@@ -1369,8 +1699,8 @@ async function resolveFile(part, fetchImpl) {
|
|
|
1369
1699
|
try {
|
|
1370
1700
|
bytes = new Uint8Array(await readFile(part.path));
|
|
1371
1701
|
} catch (error) {
|
|
1372
|
-
throw new (0,
|
|
1373
|
-
`Could not read FilePart path '${part.path}': ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1702
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1703
|
+
`Could not read FilePart path '${part.path}': ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _58 => _58.message]), () => ( String(error)))}`,
|
|
1374
1704
|
{ cause: error }
|
|
1375
1705
|
);
|
|
1376
1706
|
}
|
|
@@ -1380,7 +1710,7 @@ async function resolveFile(part, fetchImpl) {
|
|
|
1380
1710
|
if (mediaType === DEFAULT_MEDIA_TYPE && fetched.contentType) mediaType = fetched.contentType;
|
|
1381
1711
|
}
|
|
1382
1712
|
if (bytes.byteLength > MAX_FILE_BYTES) {
|
|
1383
|
-
throw new (0,
|
|
1713
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1384
1714
|
`${filename} is ${bytes.byteLength} bytes; the limit is ${MAX_FILE_BYTES} bytes per file`
|
|
1385
1715
|
);
|
|
1386
1716
|
}
|
|
@@ -1400,17 +1730,17 @@ async function toBytes(data) {
|
|
|
1400
1730
|
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
1401
1731
|
return new Uint8Array(await data.arrayBuffer());
|
|
1402
1732
|
}
|
|
1403
|
-
throw new (0,
|
|
1733
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("FilePart data must be a Uint8Array, ArrayBuffer or Blob");
|
|
1404
1734
|
}
|
|
1405
1735
|
async function fetchUrl(url, fetchImpl) {
|
|
1406
1736
|
let scheme = "";
|
|
1407
1737
|
try {
|
|
1408
1738
|
scheme = new URL(url).protocol;
|
|
1409
|
-
} catch (
|
|
1410
|
-
throw new (0,
|
|
1739
|
+
} catch (e9) {
|
|
1740
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`Could not fetch FilePart url '${url}': not a valid URL`);
|
|
1411
1741
|
}
|
|
1412
1742
|
if (scheme !== "http:" && scheme !== "https:") {
|
|
1413
|
-
throw new (0,
|
|
1743
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1414
1744
|
`Could not fetch FilePart url '${url}': only http and https are supported`
|
|
1415
1745
|
);
|
|
1416
1746
|
}
|
|
@@ -1419,28 +1749,28 @@ async function fetchUrl(url, fetchImpl) {
|
|
|
1419
1749
|
try {
|
|
1420
1750
|
const response = await fetchImpl(url, { method: "GET", signal: controller.signal });
|
|
1421
1751
|
if (response.status < 200 || response.status >= 300) {
|
|
1422
|
-
throw new (0,
|
|
1752
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1423
1753
|
`Fetching FilePart url '${url}' returned HTTP ${response.status}`
|
|
1424
1754
|
);
|
|
1425
1755
|
}
|
|
1426
1756
|
const declared = Number(_nullishCoalesce(response.headers.get("content-length"), () => ( "")));
|
|
1427
1757
|
if (Number.isFinite(declared) && declared > MAX_FILE_BYTES) {
|
|
1428
|
-
throw new (0,
|
|
1758
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(urlTooLarge(url));
|
|
1429
1759
|
}
|
|
1430
1760
|
const bytes = await readCapped(response, url);
|
|
1431
1761
|
const rawType = response.headers.get("content-type");
|
|
1432
1762
|
const contentType = rawType ? rawType.split(";", 1)[0].trim().toLowerCase() || null : null;
|
|
1433
1763
|
return { bytes, contentType };
|
|
1434
1764
|
} catch (error) {
|
|
1435
|
-
if (error instanceof
|
|
1765
|
+
if (error instanceof _chunkJPDEKN5Mcjs.InvalidInputError) throw error;
|
|
1436
1766
|
if (controller.signal.aborted) {
|
|
1437
|
-
throw new (0,
|
|
1767
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1438
1768
|
`Could not fetch FilePart url '${url}': timed out after ${URL_FETCH_TIMEOUT_MS / 1e3} s`,
|
|
1439
1769
|
{ cause: error }
|
|
1440
1770
|
);
|
|
1441
1771
|
}
|
|
1442
|
-
throw new (0,
|
|
1443
|
-
`Could not fetch FilePart url '${url}': ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
1772
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1773
|
+
`Could not fetch FilePart url '${url}': ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _59 => _59.message]), () => ( String(error)))}`,
|
|
1444
1774
|
{ cause: error }
|
|
1445
1775
|
);
|
|
1446
1776
|
} finally {
|
|
@@ -1462,7 +1792,7 @@ async function readCapped(response, url) {
|
|
|
1462
1792
|
if (total > MAX_FILE_BYTES) {
|
|
1463
1793
|
await reader.cancel().catch(() => {
|
|
1464
1794
|
});
|
|
1465
|
-
throw new (0,
|
|
1795
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(urlTooLarge(url));
|
|
1466
1796
|
}
|
|
1467
1797
|
chunks.push(value);
|
|
1468
1798
|
}
|
|
@@ -1534,12 +1864,12 @@ function createFields(options, defaultType) {
|
|
|
1534
1864
|
const documentType = _nullishCoalesce(either(o2, "document_type", "documentType"), () => ( defaultType));
|
|
1535
1865
|
const mode = _nullishCoalesce(options.mode, () => ( DEFAULT_INGEST_MODE));
|
|
1536
1866
|
if (documentType !== null && !DOCUMENT_TYPES.includes(documentType)) {
|
|
1537
|
-
throw new (0,
|
|
1867
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1538
1868
|
`Invalid document_type '${documentType}'. Expected one of: ${DOCUMENT_TYPES.join(", ")}`
|
|
1539
1869
|
);
|
|
1540
1870
|
}
|
|
1541
1871
|
if (!INGEST_MODES.includes(mode)) {
|
|
1542
|
-
throw new (0,
|
|
1872
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1543
1873
|
`Invalid mode '${mode}'. Expected one of: ${INGEST_MODES.join(", ")}`
|
|
1544
1874
|
);
|
|
1545
1875
|
}
|
|
@@ -1569,13 +1899,13 @@ function normaliseCreateScope(scope, userId, customerId) {
|
|
|
1569
1899
|
if (scope === void 0 || scope === null) return null;
|
|
1570
1900
|
const entries = Object.entries(scope);
|
|
1571
1901
|
if (entries.length > 1 && entries.some(([, v]) => v === "self")) {
|
|
1572
|
-
throw new (0,
|
|
1902
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1573
1903
|
`"self" can only be used alone, as scope={"client": "self"}; got ${JSON.stringify(scope)}`
|
|
1574
1904
|
);
|
|
1575
1905
|
}
|
|
1576
1906
|
if (entries.length === 1 && entries[0][0] === "client" && entries[0][1] === "self") {
|
|
1577
1907
|
if (userId !== null || customerId !== null) {
|
|
1578
|
-
throw new (0,
|
|
1908
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1579
1909
|
'scope={"client": "self"} names the client level, so it cannot be combined with user_id or customer_id'
|
|
1580
1910
|
);
|
|
1581
1911
|
}
|
|
@@ -1587,7 +1917,7 @@ function jsonDocument(document, where) {
|
|
|
1587
1917
|
const n2 = normaliseContent(document, "document");
|
|
1588
1918
|
if (n2 === null) return document;
|
|
1589
1919
|
if (n2.kind === "parts") {
|
|
1590
|
-
throw new (0,
|
|
1920
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1591
1921
|
`${where} cannot carry a FilePart. memories.create sends files as multipart; call it once per document that has files.`
|
|
1592
1922
|
);
|
|
1593
1923
|
}
|
|
@@ -1595,7 +1925,7 @@ function jsonDocument(document, where) {
|
|
|
1595
1925
|
}
|
|
1596
1926
|
function buildCreateBody(options) {
|
|
1597
1927
|
const document = jsonDocument(options.document, "This request");
|
|
1598
|
-
if (!document) throw new (0,
|
|
1928
|
+
if (!document) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("document is required");
|
|
1599
1929
|
return { document, ...createFields(options, DEFAULT_DOCUMENT_TYPE) };
|
|
1600
1930
|
}
|
|
1601
1931
|
function buildCreateManifest(options, parts, files) {
|
|
@@ -1616,13 +1946,13 @@ function buildForgetBody(options) {
|
|
|
1616
1946
|
if (typeof description !== "string" || // Code points, as Python's len() and the server count; `.length` counts
|
|
1617
1947
|
// UTF-16 units, so 251 emoji (502 units) were refused here only.
|
|
1618
1948
|
[...description].length < FORGET_DESCRIPTION_MIN || [...description].length > FORGET_DESCRIPTION_MAX) {
|
|
1619
|
-
throw new (0,
|
|
1949
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1620
1950
|
`description must be between ${FORGET_DESCRIPTION_MIN} and ${FORGET_DESCRIPTION_MAX} characters`
|
|
1621
1951
|
);
|
|
1622
1952
|
}
|
|
1623
1953
|
const mode = _nullishCoalesce(options.mode, () => ( "preview"));
|
|
1624
1954
|
if (!FORGET_MODES.includes(mode)) {
|
|
1625
|
-
throw new (0,
|
|
1955
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1626
1956
|
`Invalid mode '${mode}'. Expected one of: ${FORGET_MODES.join(", ")}`
|
|
1627
1957
|
);
|
|
1628
1958
|
}
|
|
@@ -1637,7 +1967,7 @@ function buildForgetBody(options) {
|
|
|
1637
1967
|
const conversationId = either(o2, "conversation_id", "conversationId");
|
|
1638
1968
|
if (conversationId !== void 0 && conversationId !== null) {
|
|
1639
1969
|
if (typeof conversationId !== "string" || [...conversationId].length < 1 || [...conversationId].length > 200) {
|
|
1640
|
-
throw new (0,
|
|
1970
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id must be a string of 1 to 200 characters");
|
|
1641
1971
|
}
|
|
1642
1972
|
body["conversation_id"] = conversationId;
|
|
1643
1973
|
}
|
|
@@ -1679,7 +2009,7 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1679
2009
|
// /api/v1/memories/{memory_id} exists with other methods. Either would
|
|
1680
2010
|
// otherwise read as "context not found" or a bare HTTP error.
|
|
1681
2011
|
// InvalidInputError, with Python's message.
|
|
1682
|
-
mapError: (status, error) => status === 404 || status === 405 ? new (0,
|
|
2012
|
+
mapError: (status, error) => status === 404 || status === 405 ? new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1683
2013
|
"This Synap server does not support file parts in memories.create. Upgrade the Synap server, or send text only.",
|
|
1684
2014
|
{ correlationId: error.correlationId, cause: error }
|
|
1685
2015
|
) : void 0
|
|
@@ -1688,7 +2018,7 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1688
2018
|
async batch_create(options) {
|
|
1689
2019
|
const docs = options.documents;
|
|
1690
2020
|
if (!Array.isArray(docs) || docs.length === 0) {
|
|
1691
|
-
throw new (0,
|
|
2021
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("documents must be a non-empty array");
|
|
1692
2022
|
}
|
|
1693
2023
|
const failFast = _nullishCoalesce(_nullishCoalesce(options.fail_fast, () => ( options.failFast)), () => ( false));
|
|
1694
2024
|
return transport.request("memories_batch", {
|
|
@@ -1706,17 +2036,17 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1706
2036
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
1707
2037
|
const scope = options.scope;
|
|
1708
2038
|
if (scope !== void 0 && scope !== null && (typeof scope !== "object" || Array.isArray(scope) || !Object.values(scope).every((v) => typeof v === "string"))) {
|
|
1709
|
-
throw new (0,
|
|
2039
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("scope must be a flat dict of level key to id, both strings.");
|
|
1710
2040
|
}
|
|
1711
|
-
if (!userId) throw new (0,
|
|
2041
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
1712
2042
|
await transport.checkCustomerId(customerId, "memories.create_from_file");
|
|
1713
2043
|
const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
|
|
1714
2044
|
const sources = [filePath, options.file, options.text].filter((v) => v !== void 0);
|
|
1715
2045
|
if (sources.length === 0) {
|
|
1716
|
-
throw new (0,
|
|
2046
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("One of file_path, file, or text must be provided.");
|
|
1717
2047
|
}
|
|
1718
2048
|
if (sources.length > 1) {
|
|
1719
|
-
throw new (0,
|
|
2049
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1720
2050
|
"Provide exactly one of file_path, file, or text, not several."
|
|
1721
2051
|
);
|
|
1722
2052
|
}
|
|
@@ -1752,13 +2082,13 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1752
2082
|
});
|
|
1753
2083
|
},
|
|
1754
2084
|
async get(memoryId) {
|
|
1755
|
-
if (!memoryId) throw new (0,
|
|
2085
|
+
if (!memoryId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_id is required");
|
|
1756
2086
|
return transport.request("memories_get", { pathParams: { memory_id: memoryId } });
|
|
1757
2087
|
},
|
|
1758
2088
|
async update(options) {
|
|
1759
2089
|
const memoryId = _nullishCoalesce(options.memory_id, () => ( options.memoryId));
|
|
1760
|
-
if (!memoryId) throw new (0,
|
|
1761
|
-
if (!options.document) throw new (0,
|
|
2090
|
+
if (!memoryId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_id is required");
|
|
2091
|
+
if (!options.document) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("document is required");
|
|
1762
2092
|
const body = {
|
|
1763
2093
|
document: options.document,
|
|
1764
2094
|
merge_strategy: _nullishCoalesce(_nullishCoalesce(options.merge_strategy, () => ( options.mergeStrategy)), () => ( "smart-merge"))
|
|
@@ -1773,7 +2103,7 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1773
2103
|
},
|
|
1774
2104
|
async delete(memoryId) {
|
|
1775
2105
|
if (!memoryId) {
|
|
1776
|
-
throw new (0,
|
|
2106
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1777
2107
|
"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."
|
|
1778
2108
|
);
|
|
1779
2109
|
}
|
|
@@ -1784,26 +2114,26 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
1784
2114
|
await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
|
|
1785
2115
|
const body = buildForgetBody(options);
|
|
1786
2116
|
const result = await transport.request("memories_forget", { body });
|
|
1787
|
-
const removed = !!_optionalChain([result, 'optionalAccess',
|
|
2117
|
+
const removed = !!_optionalChain([result, 'optionalAccess', _60 => _60.deleted_ids, 'optionalAccess', _61 => _61.length]) || _optionalChain([result, 'optionalAccess', _62 => _62.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _63 => _63.status]) === "partial";
|
|
1788
2118
|
if (removed && onForgotten) {
|
|
1789
2119
|
try {
|
|
1790
2120
|
onForgotten({
|
|
1791
2121
|
userId: _nullishCoalesce(body["user_id"], () => ( null)),
|
|
1792
2122
|
customerId: _nullishCoalesce(body["customer_id"], () => ( null))
|
|
1793
2123
|
});
|
|
1794
|
-
} catch (
|
|
2124
|
+
} catch (e10) {
|
|
1795
2125
|
}
|
|
1796
2126
|
}
|
|
1797
2127
|
return result;
|
|
1798
2128
|
},
|
|
1799
2129
|
async status(ingestionId) {
|
|
1800
|
-
if (!ingestionId) throw new (0,
|
|
2130
|
+
if (!ingestionId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("ingestion_id is required");
|
|
1801
2131
|
return transport.request("memories_status", {
|
|
1802
2132
|
pathParams: { ingestion_id: ingestionId }
|
|
1803
2133
|
});
|
|
1804
2134
|
},
|
|
1805
2135
|
async wait_for_completion(ingestionId, options = {}) {
|
|
1806
|
-
if (!ingestionId) throw new (0,
|
|
2136
|
+
if (!ingestionId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("ingestion_id is required");
|
|
1807
2137
|
const timeoutMs = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 300))) * 1e3;
|
|
1808
2138
|
const pollMs = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 2))) * 1e3;
|
|
1809
2139
|
const deadline = Date.now() + timeoutMs;
|
|
@@ -1824,14 +2154,14 @@ function sleep2(ms, signal) {
|
|
|
1824
2154
|
if (ms <= 0) return Promise.resolve();
|
|
1825
2155
|
return new Promise((resolve, reject) => {
|
|
1826
2156
|
const timer = setTimeout(() => {
|
|
1827
|
-
_optionalChain([signal, 'optionalAccess',
|
|
2157
|
+
_optionalChain([signal, 'optionalAccess', _64 => _64.removeEventListener, 'call', _65 => _65("abort", onAbort)]);
|
|
1828
2158
|
resolve();
|
|
1829
2159
|
}, ms);
|
|
1830
2160
|
function onAbort() {
|
|
1831
2161
|
clearTimeout(timer);
|
|
1832
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
2162
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _66 => _66.reason]), () => ( new Error("Aborted"))));
|
|
1833
2163
|
}
|
|
1834
|
-
_optionalChain([signal, 'optionalAccess',
|
|
2164
|
+
_optionalChain([signal, 'optionalAccess', _67 => _67.addEventListener, 'call', _68 => _68("abort", onAbort, { once: true })]);
|
|
1835
2165
|
});
|
|
1836
2166
|
}
|
|
1837
2167
|
|
|
@@ -1841,13 +2171,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
|
|
|
1841
2171
|
function validateConversationId(conversationId) {
|
|
1842
2172
|
if (conversationId === void 0 || conversationId === null || conversationId === "") return;
|
|
1843
2173
|
if (typeof conversationId !== "string" || !UUID_RE.test(conversationId)) {
|
|
1844
|
-
throw new (0,
|
|
2174
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidConversationIdError)(`Invalid conversation ID: ${String(conversationId)}`);
|
|
1845
2175
|
}
|
|
1846
2176
|
}
|
|
1847
2177
|
function validateInstanceId(instanceId) {
|
|
1848
2178
|
if (instanceId === void 0 || instanceId === null || instanceId === "") return;
|
|
1849
2179
|
if (typeof instanceId !== "string" || !INSTANCE_ID_RE.test(instanceId)) {
|
|
1850
|
-
throw new (0,
|
|
2180
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInstanceIdError)(`Invalid instance ID: ${String(instanceId)}`);
|
|
1851
2181
|
}
|
|
1852
2182
|
}
|
|
1853
2183
|
|
|
@@ -1897,23 +2227,23 @@ function buildRecordMessageBody(options, resolvedContent, field = "content") {
|
|
|
1897
2227
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1898
2228
|
const userId = either2(o2, "user_id", "userId");
|
|
1899
2229
|
const customerId = either2(o2, "customer_id", "customerId");
|
|
1900
|
-
if (!conversationId) throw new (0,
|
|
2230
|
+
if (!conversationId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id is required");
|
|
1901
2231
|
validateConversationId(conversationId);
|
|
1902
|
-
if (!options.role) throw new (0,
|
|
2232
|
+
if (!options.role) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("role is required");
|
|
1903
2233
|
if (!MESSAGE_ROLES.includes(options.role)) {
|
|
1904
|
-
throw new (0,
|
|
2234
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`Invalid role '${options.role}'. Must be 'user' or 'assistant'.`);
|
|
1905
2235
|
}
|
|
1906
2236
|
if (options.content === void 0 || options.content === null) {
|
|
1907
|
-
throw new (0,
|
|
2237
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("content is required");
|
|
1908
2238
|
}
|
|
1909
|
-
if (!userId) throw new (0,
|
|
2239
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
1910
2240
|
let content = options.content;
|
|
1911
2241
|
if (resolvedContent !== void 0) {
|
|
1912
2242
|
content = resolvedContent;
|
|
1913
2243
|
} else {
|
|
1914
2244
|
const n2 = normaliseContent(options.content, field);
|
|
1915
|
-
if (_optionalChain([n2, 'optionalAccess',
|
|
1916
|
-
throw new (0,
|
|
2245
|
+
if (_optionalChain([n2, 'optionalAccess', _69 => _69.kind]) === "parts") {
|
|
2246
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
1917
2247
|
"content holds a FilePart, whose bytes have to be read first. Send it with conversation.record_message."
|
|
1918
2248
|
);
|
|
1919
2249
|
}
|
|
@@ -1940,10 +2270,10 @@ function buildIngestTranscriptBody(options) {
|
|
|
1940
2270
|
const o2 = options;
|
|
1941
2271
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1942
2272
|
const userId = either2(o2, "user_id", "userId");
|
|
1943
|
-
if (!conversationId) throw new (0,
|
|
1944
|
-
if (!userId) throw new (0,
|
|
2273
|
+
if (!conversationId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id is required");
|
|
2274
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
1945
2275
|
if (options.transcript === void 0 || options.transcript === null) {
|
|
1946
|
-
throw new (0,
|
|
2276
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("transcript is required");
|
|
1947
2277
|
}
|
|
1948
2278
|
const body = {
|
|
1949
2279
|
conversation_id: conversationId,
|
|
@@ -1969,7 +2299,7 @@ function buildIngestTranscriptBody(options) {
|
|
|
1969
2299
|
function buildCompactBody(options) {
|
|
1970
2300
|
const o2 = options;
|
|
1971
2301
|
const conversationId = either2(o2, "conversation_id", "conversationId");
|
|
1972
|
-
if (!conversationId) throw new (0,
|
|
2302
|
+
if (!conversationId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id is required");
|
|
1973
2303
|
validateConversationId(conversationId);
|
|
1974
2304
|
const body = { conversation_id: conversationId, force: _nullishCoalesce(options.force, () => ( false)) };
|
|
1975
2305
|
const strategy = _nullishCoalesce(options.strategy, () => ( either2(o2, "compaction_level", "compactionLevel")));
|
|
@@ -2023,7 +2353,7 @@ function storedBatchRows(bodies, result) {
|
|
|
2023
2353
|
const r = _nullishCoalesce(result, () => ( {}));
|
|
2024
2354
|
const results = Array.isArray(r["results"]) ? r["results"] : [];
|
|
2025
2355
|
const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
|
|
2026
|
-
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess',
|
|
2356
|
+
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _70 => _70["index"]])));
|
|
2027
2357
|
const stored = bodies.filter((_, index) => !failed.has(index));
|
|
2028
2358
|
if (stored.length !== results.length) return [];
|
|
2029
2359
|
const pairs = [];
|
|
@@ -2067,7 +2397,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2067
2397
|
};
|
|
2068
2398
|
const fetchImpl = ((url, init) => transport.fetchExternal(url, init));
|
|
2069
2399
|
const validateMessage = (options, field = "content") => {
|
|
2070
|
-
if (_optionalChain([normaliseContent, 'call',
|
|
2400
|
+
if (_optionalChain([normaliseContent, 'call', _71 => _71(options.content, field), 'optionalAccess', _72 => _72.kind]) === "parts") {
|
|
2071
2401
|
buildRecordMessageBody(options, "", field);
|
|
2072
2402
|
} else {
|
|
2073
2403
|
buildRecordMessageBody(options, void 0, field);
|
|
@@ -2075,7 +2405,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2075
2405
|
};
|
|
2076
2406
|
const prepareMessage = async (options, field = "content") => {
|
|
2077
2407
|
const n2 = normaliseContent(options.content, field);
|
|
2078
|
-
if (_optionalChain([n2, 'optionalAccess',
|
|
2408
|
+
if (_optionalChain([n2, 'optionalAccess', _73 => _73.kind]) !== "parts") {
|
|
2079
2409
|
const body = buildRecordMessageBody(options, void 0, field);
|
|
2080
2410
|
return { body, mirror: String(_nullishCoalesce(body["content"], () => ( ""))) };
|
|
2081
2411
|
}
|
|
@@ -2085,7 +2415,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2085
2415
|
};
|
|
2086
2416
|
const convId = (v) => {
|
|
2087
2417
|
const id = typeof v === "string" ? v : _nullishCoalesce(v.conversation_id, () => ( v.conversationId));
|
|
2088
|
-
if (!id) throw new (0,
|
|
2418
|
+
if (!id) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id is required");
|
|
2089
2419
|
validateConversationId(id);
|
|
2090
2420
|
return id;
|
|
2091
2421
|
};
|
|
@@ -2121,7 +2451,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2121
2451
|
},
|
|
2122
2452
|
async record_messages_batch(messages) {
|
|
2123
2453
|
if (!Array.isArray(messages) || messages.length === 0) {
|
|
2124
|
-
throw new (0,
|
|
2454
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("messages must be a non-empty array");
|
|
2125
2455
|
}
|
|
2126
2456
|
for (const m of messages) {
|
|
2127
2457
|
const mo = m;
|
|
@@ -2166,7 +2496,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2166
2496
|
const raw = await transport.request("conversations_ingest", { body });
|
|
2167
2497
|
const result = {
|
|
2168
2498
|
...raw,
|
|
2169
|
-
warnings: Array.isArray(_optionalChain([raw, 'optionalAccess',
|
|
2499
|
+
warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _74 => _74.warnings])) ? raw.warnings.map(String) : []
|
|
2170
2500
|
};
|
|
2171
2501
|
onWrite({
|
|
2172
2502
|
userId: body["user_id"],
|
|
@@ -2191,7 +2521,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2191
2521
|
const id = convId(options);
|
|
2192
2522
|
const style = _nullishCoalesce(options.style, () => ( "structured"));
|
|
2193
2523
|
if (!PROMPT_STYLES.includes(style)) {
|
|
2194
|
-
throw new (0,
|
|
2524
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2195
2525
|
`Invalid style '${style}'. Must be one of: ${PROMPT_STYLES.join(", ")}`
|
|
2196
2526
|
);
|
|
2197
2527
|
}
|
|
@@ -2200,7 +2530,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2200
2530
|
if (!search) return response2;
|
|
2201
2531
|
try {
|
|
2202
2532
|
return await localShortTerm.historyExcerpts(id, response2, options.query);
|
|
2203
|
-
} catch (
|
|
2533
|
+
} catch (e11) {
|
|
2204
2534
|
return response2;
|
|
2205
2535
|
}
|
|
2206
2536
|
};
|
|
@@ -2210,8 +2540,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2210
2540
|
pathParams: { conversation_id: id },
|
|
2211
2541
|
query: { style }
|
|
2212
2542
|
});
|
|
2213
|
-
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
2214
|
-
_optionalChain([localShortTerm, 'access',
|
|
2543
|
+
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _75 => _75["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
2544
|
+
_optionalChain([localShortTerm, 'access', _76 => _76.reseed, 'optionalCall', _77 => _77(id, response)]);
|
|
2215
2545
|
return withHistory(response);
|
|
2216
2546
|
},
|
|
2217
2547
|
async compact(options) {
|
|
@@ -2251,8 +2581,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2251
2581
|
* Returns an idempotent unsubscribe thunk, matching Python.
|
|
2252
2582
|
*/
|
|
2253
2583
|
subscribe_to_compaction_updates(conversationId, callback) {
|
|
2254
|
-
if (!conversationId) throw new (0,
|
|
2255
|
-
if (typeof callback !== "function") throw new (0,
|
|
2584
|
+
if (!conversationId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("conversation_id is required");
|
|
2585
|
+
if (typeof callback !== "function") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("callback is required");
|
|
2256
2586
|
return subscribers.add(conversationId, callback);
|
|
2257
2587
|
},
|
|
2258
2588
|
/** Remove subscribers for one conversation, or all of them. Returns the count removed. */
|
|
@@ -2281,17 +2611,17 @@ function buildDeleteBody(options, instanceId) {
|
|
|
2281
2611
|
const o2 = options;
|
|
2282
2612
|
const scope = options.scope;
|
|
2283
2613
|
if (scope !== null && typeof scope === "object") {
|
|
2284
|
-
throw new (0,
|
|
2614
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2285
2615
|
"scope must be one of: user, conversation, customer. A dict is not accepted here (the rung-path dict used by memories.create and fetch is a different parameter)."
|
|
2286
2616
|
);
|
|
2287
2617
|
}
|
|
2288
2618
|
if (typeof scope !== "string" || !DATA_SCOPES.includes(scope)) {
|
|
2289
|
-
throw new (0,
|
|
2619
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2290
2620
|
`Invalid scope '${String(scope)}'. Expected one of: ${DATA_SCOPES.join(", ")}`
|
|
2291
2621
|
);
|
|
2292
2622
|
}
|
|
2293
2623
|
const dryRun = _nullishCoalesce(either3(o2, "dry_run", "dryRun"), () => ( false));
|
|
2294
|
-
if (typeof dryRun !== "boolean") throw new (0,
|
|
2624
|
+
if (typeof dryRun !== "boolean") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("dry_run must be a boolean");
|
|
2295
2625
|
const ids = {
|
|
2296
2626
|
user_id: either3(o2, "user_id", "userId"),
|
|
2297
2627
|
customer_id: either3(o2, "customer_id", "customerId"),
|
|
@@ -2299,23 +2629,23 @@ function buildDeleteBody(options, instanceId) {
|
|
|
2299
2629
|
};
|
|
2300
2630
|
for (const [name, value] of Object.entries(ids)) {
|
|
2301
2631
|
if (value !== void 0 && value !== null && (typeof value !== "string" || value.trim() === "")) {
|
|
2302
|
-
throw new (0,
|
|
2632
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`${name} must not be empty`);
|
|
2303
2633
|
}
|
|
2304
2634
|
}
|
|
2305
2635
|
const field = ID_FIELD[scope];
|
|
2306
2636
|
const target = ids[field];
|
|
2307
2637
|
if (target === void 0 || target === null) {
|
|
2308
|
-
throw new (0,
|
|
2638
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`${field} is required for scope='${scope}'`);
|
|
2309
2639
|
}
|
|
2310
2640
|
const confirm = _nullishCoalesce(options.confirm, () => ( null));
|
|
2311
2641
|
if (!dryRun) {
|
|
2312
2642
|
if (confirm === null || confirm === "") {
|
|
2313
|
-
throw new (0,
|
|
2643
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2314
2644
|
`confirm is required unless dry_run=True: pass the ${field} being deleted as confirm`
|
|
2315
2645
|
);
|
|
2316
2646
|
}
|
|
2317
2647
|
if (confirm !== target) {
|
|
2318
|
-
throw new (0,
|
|
2648
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`confirm must equal the ${field} being deleted`);
|
|
2319
2649
|
}
|
|
2320
2650
|
}
|
|
2321
2651
|
return {
|
|
@@ -2376,14 +2706,14 @@ function createDataInterface(transport, onDeleted) {
|
|
|
2376
2706
|
customerId: _nullishCoalesce(body["customer_id"], () => ( null)),
|
|
2377
2707
|
conversationId: _nullishCoalesce(body["conversation_id"], () => ( null))
|
|
2378
2708
|
});
|
|
2379
|
-
} catch (
|
|
2709
|
+
} catch (e12) {
|
|
2380
2710
|
}
|
|
2381
2711
|
}
|
|
2382
2712
|
return final;
|
|
2383
2713
|
},
|
|
2384
2714
|
async status(deletionId) {
|
|
2385
2715
|
if (typeof deletionId !== "string" || deletionId.trim() === "") {
|
|
2386
|
-
throw new (0,
|
|
2716
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("deletion_id is required");
|
|
2387
2717
|
}
|
|
2388
2718
|
return normalise(
|
|
2389
2719
|
await transport.request("data_delete_status", {
|
|
@@ -2400,7 +2730,7 @@ function createUserNamespace(transport, hooks = {}) {
|
|
|
2400
2730
|
return {
|
|
2401
2731
|
async get_profile(options) {
|
|
2402
2732
|
const userId = typeof options === "string" ? options : _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
2403
|
-
if (!userId) throw new (0,
|
|
2733
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
2404
2734
|
const customerId = typeof options === "string" ? void 0 : _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
2405
2735
|
return transport.request("user_profile", {
|
|
2406
2736
|
pathParams: { user_id: userId },
|
|
@@ -2449,22 +2779,84 @@ function createCreditsNamespace(transport) {
|
|
|
2449
2779
|
});
|
|
2450
2780
|
},
|
|
2451
2781
|
async redeem(code) {
|
|
2452
|
-
if (!code) throw new (0,
|
|
2782
|
+
if (!code) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("code is required");
|
|
2453
2783
|
return transport.request("credits_redeem", { body: { code } });
|
|
2454
2784
|
}
|
|
2455
2785
|
};
|
|
2456
2786
|
}
|
|
2457
2787
|
|
|
2788
|
+
// src/maca/interface.ts
|
|
2789
|
+
var MACA_FINAL_STATUSES = ["succeeded", "invalid", "failed"];
|
|
2790
|
+
var MACA_MAX_FILE_BYTES = 256 * 1024;
|
|
2791
|
+
function toJob(raw) {
|
|
2792
|
+
return {
|
|
2793
|
+
job_id: String(raw["job_id"]),
|
|
2794
|
+
status: String(raw["status"]),
|
|
2795
|
+
message: typeof raw["message"] === "string" ? raw["message"] : "",
|
|
2796
|
+
created_at: typeof raw["created_at"] === "string" ? raw["created_at"] : null,
|
|
2797
|
+
updated_at: typeof raw["updated_at"] === "string" ? raw["updated_at"] : null,
|
|
2798
|
+
removed_fields: Array.isArray(raw["removed_fields"]) ? raw["removed_fields"] : [],
|
|
2799
|
+
problems: Array.isArray(raw["problems"]) ? raw["problems"] : [],
|
|
2800
|
+
config_file: typeof raw["config_file"] === "string" ? raw["config_file"] : null,
|
|
2801
|
+
yaml: typeof raw["yaml"] === "string" ? raw["yaml"] : null
|
|
2802
|
+
};
|
|
2803
|
+
}
|
|
2804
|
+
function createMacaNamespace(transport) {
|
|
2805
|
+
const namespace = {
|
|
2806
|
+
async generate(options) {
|
|
2807
|
+
const filePath = _nullishCoalesce(options.file_path, () => ( options.filePath));
|
|
2808
|
+
const relationship = _nullishCoalesce(options.user_relationship, () => ( options.userRelationship));
|
|
2809
|
+
if (relationship !== "b2c" && relationship !== "b2b") {
|
|
2810
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_relationship must be 'b2c' or 'b2b'");
|
|
2811
|
+
}
|
|
2812
|
+
if (typeof filePath !== "string" || !filePath) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("file_path is required");
|
|
2813
|
+
const { readFile, stat } = await Promise.resolve().then(() => _interopRequireWildcard(require("fs/promises")));
|
|
2814
|
+
const { basename } = await Promise.resolve().then(() => _interopRequireWildcard(require("path")));
|
|
2815
|
+
let size;
|
|
2816
|
+
try {
|
|
2817
|
+
size = (await stat(filePath)).size;
|
|
2818
|
+
} catch (e13) {
|
|
2819
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`file_path does not point to a readable file: ${filePath}`);
|
|
2820
|
+
}
|
|
2821
|
+
if (size === 0) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("The use-case file is empty");
|
|
2822
|
+
if (size > MACA_MAX_FILE_BYTES) {
|
|
2823
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`The use-case file is larger than ${MACA_MAX_FILE_BYTES / 1024} KB`);
|
|
2824
|
+
}
|
|
2825
|
+
const bytes = await readFile(filePath);
|
|
2826
|
+
const form = new FormData();
|
|
2827
|
+
form.set("user_relationship", relationship);
|
|
2828
|
+
form.set("file", new Blob([bytes]), basename(filePath));
|
|
2829
|
+
return toJob(await transport.request("maca_generate", { body: form, rawBody: true }));
|
|
2830
|
+
},
|
|
2831
|
+
async get_job(jobId) {
|
|
2832
|
+
if (!jobId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("job_id is required");
|
|
2833
|
+
return toJob(await transport.request("maca_job", { pathParams: { job_id: jobId } }));
|
|
2834
|
+
},
|
|
2835
|
+
async wait_for_completion(jobId, options = {}) {
|
|
2836
|
+
const timeout = (_nullishCoalesce(_nullishCoalesce(options.timeout_seconds, () => ( options.timeoutSeconds)), () => ( 3e3))) * 1e3;
|
|
2837
|
+
const interval = (_nullishCoalesce(_nullishCoalesce(options.poll_interval_seconds, () => ( options.pollIntervalSeconds)), () => ( 15))) * 1e3;
|
|
2838
|
+
const start = Date.now();
|
|
2839
|
+
while (Date.now() - start < timeout) {
|
|
2840
|
+
const job = await namespace.get_job(jobId);
|
|
2841
|
+
if (MACA_FINAL_STATUSES.includes(job.status)) return job;
|
|
2842
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
2843
|
+
}
|
|
2844
|
+
throw new Error(`MACA job ${jobId} did not finish within ${timeout / 1e3}s`);
|
|
2845
|
+
}
|
|
2846
|
+
};
|
|
2847
|
+
return namespace;
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2458
2850
|
// src/cache/interface.ts
|
|
2459
2851
|
function createCacheNamespace(cache) {
|
|
2460
2852
|
return {
|
|
2461
2853
|
clear: () => cache.clear(),
|
|
2462
2854
|
clear_user: (userId) => {
|
|
2463
|
-
if (!userId) throw new (0,
|
|
2855
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
2464
2856
|
cache.dropEntity(userId);
|
|
2465
2857
|
},
|
|
2466
2858
|
clear_customer: (customerId) => {
|
|
2467
|
-
if (!customerId) throw new (0,
|
|
2859
|
+
if (!customerId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("customer_id is required");
|
|
2468
2860
|
cache.dropEntity(customerId);
|
|
2469
2861
|
},
|
|
2470
2862
|
stats: () => ({ bundles: cache.size, items: cache.itemCount })
|
|
@@ -2520,10 +2912,10 @@ function jsonOrText(value) {
|
|
|
2520
2912
|
(_k, v) => typeof v === "bigint" ? String(v) : v
|
|
2521
2913
|
);
|
|
2522
2914
|
return out === void 0 ? String(value) : out;
|
|
2523
|
-
} catch (
|
|
2915
|
+
} catch (e14) {
|
|
2524
2916
|
try {
|
|
2525
2917
|
return String(value);
|
|
2526
|
-
} catch (
|
|
2918
|
+
} catch (e15) {
|
|
2527
2919
|
return "";
|
|
2528
2920
|
}
|
|
2529
2921
|
}
|
|
@@ -2546,8 +2938,8 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2546
2938
|
let onConversationState = null;
|
|
2547
2939
|
const internals = {
|
|
2548
2940
|
onCompactionUpdate(conversationId, bundle) {
|
|
2549
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
2550
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
2941
|
+
_optionalChain([applyCompaction, 'optionalCall', _78 => _78(bundle)]);
|
|
2942
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _79 => _79(conversationId, bundle)]);
|
|
2551
2943
|
},
|
|
2552
2944
|
setCompactionApplier(apply) {
|
|
2553
2945
|
applyCompaction = apply;
|
|
@@ -2562,10 +2954,10 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2562
2954
|
onConversationState = handle;
|
|
2563
2955
|
},
|
|
2564
2956
|
sendContextUsed(event) {
|
|
2565
|
-
_optionalChain([client, 'optionalAccess',
|
|
2957
|
+
_optionalChain([client, 'optionalAccess', _80 => _80.sendContextUsed, 'call', _81 => _81(event)]);
|
|
2566
2958
|
},
|
|
2567
2959
|
sendContextAssembled(event) {
|
|
2568
|
-
_optionalChain([client, 'optionalAccess',
|
|
2960
|
+
_optionalChain([client, 'optionalAccess', _82 => _82.sendContextAssembled, 'call', _83 => _83(event)]);
|
|
2569
2961
|
},
|
|
2570
2962
|
setCompactionDispatcher(dispatch) {
|
|
2571
2963
|
dispatchCompaction = dispatch;
|
|
@@ -2577,7 +2969,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2577
2969
|
function ensureSession(conversationId, userId, customerId) {
|
|
2578
2970
|
if (!conversationId || !userId || client === null) return;
|
|
2579
2971
|
if (openSessions.has(conversationId)) return;
|
|
2580
|
-
const sessionId =
|
|
2972
|
+
const sessionId = _chunkJPDEKN5Mcjs.newCorrelationId.call(void 0, );
|
|
2581
2973
|
try {
|
|
2582
2974
|
client.sendSessionControl({
|
|
2583
2975
|
action: "start",
|
|
@@ -2587,7 +2979,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2587
2979
|
...customerId ? { customer_id: customerId } : {}
|
|
2588
2980
|
});
|
|
2589
2981
|
openSessions.set(conversationId, sessionId);
|
|
2590
|
-
} catch (
|
|
2982
|
+
} catch (e16) {
|
|
2591
2983
|
}
|
|
2592
2984
|
}
|
|
2593
2985
|
let tail = Promise.resolve();
|
|
@@ -2597,7 +2989,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2597
2989
|
send(sync);
|
|
2598
2990
|
return Promise.resolve();
|
|
2599
2991
|
}
|
|
2600
|
-
_optionalChain([prepared, 'optionalAccess',
|
|
2992
|
+
_optionalChain([prepared, 'optionalAccess', _84 => _84.catch, 'call', _85 => _85(() => {
|
|
2601
2993
|
})]);
|
|
2602
2994
|
queued += 1;
|
|
2603
2995
|
const run = tail.then(async () => {
|
|
@@ -2611,15 +3003,15 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2611
3003
|
}
|
|
2612
3004
|
const namespace = {
|
|
2613
3005
|
async listen(options = {}) {
|
|
2614
|
-
if (listenBlockedBy !== null) throw new (0,
|
|
3006
|
+
if (listenBlockedBy !== null) throw new (0, _chunkJPDEKN5Mcjs.SynapPermanentError)(listenBlockedBy);
|
|
2615
3007
|
if (client !== null) {
|
|
2616
|
-
throw new (0,
|
|
3008
|
+
throw new (0, _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
2617
3009
|
}
|
|
2618
3010
|
try {
|
|
2619
|
-
_optionalChain([onListen, 'optionalCall',
|
|
2620
|
-
} catch (
|
|
3011
|
+
_optionalChain([onListen, 'optionalCall', _86 => _86()]);
|
|
3012
|
+
} catch (e17) {
|
|
2621
3013
|
}
|
|
2622
|
-
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-
|
|
3014
|
+
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-H2ES74FF.cjs")));
|
|
2623
3015
|
const onContext = _nullishCoalesce(options.on_context, () => ( options.onContext));
|
|
2624
3016
|
const onDisconnect = _nullishCoalesce(options.on_disconnect, () => ( options.onDisconnect));
|
|
2625
3017
|
const onReconnect = _nullishCoalesce(options.on_reconnect, () => ( options.onReconnect));
|
|
@@ -2634,17 +3026,17 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2634
3026
|
internals.onCompactionUpdate(conversationId, bundle);
|
|
2635
3027
|
},
|
|
2636
3028
|
onConversationState: (conversationId, messageCount) => {
|
|
2637
|
-
_optionalChain([onConversationState, 'optionalCall',
|
|
3029
|
+
_optionalChain([onConversationState, 'optionalCall', _87 => _87(conversationId, messageCount)]);
|
|
2638
3030
|
},
|
|
2639
3031
|
onStateChange: (state) => {
|
|
2640
3032
|
if (state !== "connected") openSessions.clear();
|
|
2641
3033
|
if (state === "reconnecting") {
|
|
2642
3034
|
reconnectAttempts += 1;
|
|
2643
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
3035
|
+
_optionalChain([onReconnect, 'optionalCall', _88 => _88(reconnectAttempts)]);
|
|
2644
3036
|
} else if (state === "disconnected") {
|
|
2645
|
-
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
3037
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _89 => _89.lastError]), () => ( null));
|
|
2646
3038
|
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
2647
|
-
_optionalChain([onDisconnect, 'optionalCall',
|
|
3039
|
+
_optionalChain([onDisconnect, 'optionalCall', _90 => _90(reason)]);
|
|
2648
3040
|
}
|
|
2649
3041
|
}
|
|
2650
3042
|
});
|
|
@@ -2652,9 +3044,9 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2652
3044
|
try {
|
|
2653
3045
|
await created.connect();
|
|
2654
3046
|
} catch (error) {
|
|
2655
|
-
if (error instanceof
|
|
2656
|
-
throw new (0,
|
|
2657
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
3047
|
+
if (error instanceof _chunkJPDEKN5Mcjs.SynapError) throw error;
|
|
3048
|
+
throw new (0, _chunkJPDEKN5Mcjs.SynapError)(
|
|
3049
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _91 => _91.message]), () => ( String(error)))}`,
|
|
2658
3050
|
{ cause: error }
|
|
2659
3051
|
);
|
|
2660
3052
|
}
|
|
@@ -2679,7 +3071,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2679
3071
|
session_id: sessionId,
|
|
2680
3072
|
conversation_id: conversationId
|
|
2681
3073
|
});
|
|
2682
|
-
} catch (
|
|
3074
|
+
} catch (e18) {
|
|
2683
3075
|
}
|
|
2684
3076
|
},
|
|
2685
3077
|
async send_message(options) {
|
|
@@ -2689,19 +3081,19 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2689
3081
|
"instance.send_message"
|
|
2690
3082
|
);
|
|
2691
3083
|
}
|
|
2692
|
-
if (client === null) throw new (0,
|
|
3084
|
+
if (client === null) throw new (0, _chunkJPDEKN5Mcjs.ListeningNotActiveError)("Listening is not active");
|
|
2693
3085
|
const eventType = _nullishCoalesce(_nullishCoalesce(options.event_type, () => ( options.eventType)), () => ( "user_message"));
|
|
2694
3086
|
if (!KNOWN_EVENT_TYPES.has(eventType)) {
|
|
2695
|
-
throw new (0,
|
|
3087
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2696
3088
|
`unknown event_type '${eventType}'. Expected one of: ` + [...KNOWN_EVENT_TYPES].sort().join(", ")
|
|
2697
3089
|
);
|
|
2698
3090
|
}
|
|
2699
3091
|
if (options.content === void 0 || options.content === null) {
|
|
2700
|
-
throw new (0,
|
|
3092
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("content is required");
|
|
2701
3093
|
}
|
|
2702
3094
|
const parts = normaliseContent(options.content, "content");
|
|
2703
3095
|
const emit = ({ content, metadata }) => {
|
|
2704
|
-
if (client === null) throw new (0,
|
|
3096
|
+
if (client === null) throw new (0, _chunkJPDEKN5Mcjs.ListeningNotActiveError)("Listening is not active");
|
|
2705
3097
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
2706
3098
|
ensureSession(
|
|
2707
3099
|
conversationId,
|
|
@@ -2709,7 +3101,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2709
3101
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
2710
3102
|
);
|
|
2711
3103
|
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
2712
|
-
_optionalChain([onTurn, 'optionalCall',
|
|
3104
|
+
_optionalChain([onTurn, 'optionalCall', _92 => _92({
|
|
2713
3105
|
conversationId,
|
|
2714
3106
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
2715
3107
|
content
|
|
@@ -2741,14 +3133,14 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2741
3133
|
})()
|
|
2742
3134
|
});
|
|
2743
3135
|
};
|
|
2744
|
-
if (_optionalChain([parts, 'optionalAccess',
|
|
2745
|
-
const content = _optionalChain([parts, 'optionalAccess',
|
|
3136
|
+
if (_optionalChain([parts, 'optionalAccess', _93 => _93.kind]) !== "parts") {
|
|
3137
|
+
const content = _optionalChain([parts, 'optionalAccess', _94 => _94.kind]) === "text" ? parts.text : options.content;
|
|
2746
3138
|
return inOrder(null, emit, { content, metadata: _nullishCoalesce(options.metadata, () => ( {})) });
|
|
2747
3139
|
}
|
|
2748
3140
|
const prepared = (async () => {
|
|
2749
3141
|
const inline = await toInlineParts(parts.parts, fetchUrl2);
|
|
2750
3142
|
if (inline.rawBytes > MAX_STREAM_IMAGE_BYTES) {
|
|
2751
|
-
throw new (0,
|
|
3143
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2752
3144
|
`The images in this event come to more than ${MAX_STREAM_IMAGE_BYTES} bytes, which is over what one streamed event can carry. Send them with memories.create or conversation.record_message instead.`
|
|
2753
3145
|
);
|
|
2754
3146
|
}
|
|
@@ -2780,7 +3172,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2780
3172
|
async record_tool_result(options) {
|
|
2781
3173
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
2782
3174
|
if (conversationId) {
|
|
2783
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
3175
|
+
_optionalChain([onToolResult, 'optionalCall', _95 => _95({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
|
|
2784
3176
|
}
|
|
2785
3177
|
await namespace.send_message({
|
|
2786
3178
|
content: "",
|
|
@@ -2797,7 +3189,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2797
3189
|
});
|
|
2798
3190
|
},
|
|
2799
3191
|
async record_thinking(options) {
|
|
2800
|
-
if (client === null) throw new (0,
|
|
3192
|
+
if (client === null) throw new (0, _chunkJPDEKN5Mcjs.ListeningNotActiveError)("Listening is not active");
|
|
2801
3193
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
2802
3194
|
ensureSession(
|
|
2803
3195
|
conversationId,
|
|
@@ -2805,7 +3197,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2805
3197
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
2806
3198
|
);
|
|
2807
3199
|
return inOrder(null, () => {
|
|
2808
|
-
if (client === null) throw new (0,
|
|
3200
|
+
if (client === null) throw new (0, _chunkJPDEKN5Mcjs.ListeningNotActiveError)("Listening is not active");
|
|
2809
3201
|
client.sendConversationEvent({
|
|
2810
3202
|
// Python emits reasoning as an `agent_thinking` conversation event.
|
|
2811
3203
|
event_type: "agent_thinking",
|
|
@@ -2835,7 +3227,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2835
3227
|
}
|
|
2836
3228
|
|
|
2837
3229
|
// src/version.ts
|
|
2838
|
-
var SDK_VERSION = "0.
|
|
3230
|
+
var SDK_VERSION = "0.7.0";
|
|
2839
3231
|
|
|
2840
3232
|
// src/registry.ts
|
|
2841
3233
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -2975,7 +3367,7 @@ var ShortTermStore = class {
|
|
|
2975
3367
|
if (this.#archive !== null) {
|
|
2976
3368
|
try {
|
|
2977
3369
|
this.#archive.add(conversationId, role, content, stamp, { messageId: _nullishCoalesce(confirmation.messageId, () => ( null)) });
|
|
2978
|
-
} catch (
|
|
3370
|
+
} catch (e19) {
|
|
2979
3371
|
}
|
|
2980
3372
|
}
|
|
2981
3373
|
const entry = _nullishCoalesce(this.#entries.get(conversationId), () => ( this.#blank(conversationId)));
|
|
@@ -3182,13 +3574,13 @@ function bytesOf(text) {
|
|
|
3182
3574
|
}
|
|
3183
3575
|
var TurnStore = (_class3 = class {
|
|
3184
3576
|
|
|
3185
|
-
|
|
3577
|
+
__init7() {this.onDisk = false}
|
|
3186
3578
|
#now;
|
|
3187
3579
|
#seq = 0;
|
|
3188
3580
|
#writes = 0;
|
|
3189
3581
|
#conversations = /* @__PURE__ */ new Map();
|
|
3190
3582
|
#vectors = /* @__PURE__ */ new Map();
|
|
3191
|
-
constructor(options = {}) {;_class3.prototype.
|
|
3583
|
+
constructor(options = {}) {;_class3.prototype.__init7.call(this);
|
|
3192
3584
|
this.limits = _nullishCoalesce(options.limits, () => ( { ..._chunkBYUGILQIcjs.HISTORY_SEARCH.store_limits }));
|
|
3193
3585
|
this.#now = _nullishCoalesce(options.now, () => ( (() => Date.now() / 1e3)));
|
|
3194
3586
|
}
|
|
@@ -3303,7 +3695,7 @@ var TurnStore = (_class3 = class {
|
|
|
3303
3695
|
}
|
|
3304
3696
|
/** Turns the server also holds: archived tool results are local only. Python: `count`. */
|
|
3305
3697
|
count(conversationId) {
|
|
3306
|
-
return (_nullishCoalesce(_optionalChain([this, 'access',
|
|
3698
|
+
return (_nullishCoalesce(_optionalChain([this, 'access', _96 => _96.#conversations, 'access', _97 => _97.get, 'call', _98 => _98(conversationId), 'optionalAccess', _99 => _99.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
|
|
3307
3699
|
}
|
|
3308
3700
|
sizeBytes() {
|
|
3309
3701
|
let n2 = 0;
|
|
@@ -3482,7 +3874,7 @@ function askedKinds(query) {
|
|
|
3482
3874
|
}
|
|
3483
3875
|
function asksHowItStarted(query) {
|
|
3484
3876
|
const spec = _chunkBYUGILQIcjs.HISTORY_SEARCH.early_query;
|
|
3485
|
-
if (!_optionalChain([spec, 'optionalAccess',
|
|
3877
|
+
if (!_optionalChain([spec, 'optionalAccess', _100 => _100.pattern])) return false;
|
|
3486
3878
|
return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
|
|
3487
3879
|
}
|
|
3488
3880
|
async function searchTurns(turns, query, options = {}) {
|
|
@@ -3750,7 +4142,7 @@ function overlayLocalRecentTurns(response, store, conversationId, configured) {
|
|
|
3750
4142
|
compacted_at: orLocal("compacted_at", entry.compactedAt),
|
|
3751
4143
|
conversation_id: conversationId
|
|
3752
4144
|
};
|
|
3753
|
-
} catch (
|
|
4145
|
+
} catch (e20) {
|
|
3754
4146
|
}
|
|
3755
4147
|
}
|
|
3756
4148
|
|
|
@@ -3763,7 +4155,7 @@ function stringify(value) {
|
|
|
3763
4155
|
if (t === "string" || t === "number" || t === "boolean") return String(value);
|
|
3764
4156
|
try {
|
|
3765
4157
|
return _nullishCoalesce(JSON.stringify(value), () => ( ""));
|
|
3766
|
-
} catch (
|
|
4158
|
+
} catch (e21) {
|
|
3767
4159
|
return String(value);
|
|
3768
4160
|
}
|
|
3769
4161
|
}
|
|
@@ -4023,10 +4415,16 @@ function scopeLookupParams(scope, params) {
|
|
|
4023
4415
|
return { searchQuery, entityId: null, customerId: null, clientId, scopeRung, maxResultsPerQuery };
|
|
4024
4416
|
}
|
|
4025
4417
|
}
|
|
4418
|
+
function wireMetadata(item) {
|
|
4419
|
+
const md = item["metadata"];
|
|
4420
|
+
const out = md !== null && typeof md === "object" && !Array.isArray(md) ? { ...md } : {};
|
|
4421
|
+
if (!out["scope"] && item["scope"]) out["scope"] = item["scope"];
|
|
4422
|
+
return out;
|
|
4423
|
+
}
|
|
4026
4424
|
function buildAnticipationResponse(hit) {
|
|
4027
4425
|
const response = {};
|
|
4028
4426
|
for (const [type, items] of Object.entries(hit.itemsByType)) {
|
|
4029
|
-
response[type] = items;
|
|
4427
|
+
response[type] = items.map((item) => ({ ...item, metadata: wireMetadata(item) }));
|
|
4030
4428
|
}
|
|
4031
4429
|
response.metadata = {
|
|
4032
4430
|
source: "anticipation",
|
|
@@ -4061,7 +4459,7 @@ async function tryServeFromCache(cache, scope, params, maxItems) {
|
|
|
4061
4459
|
});
|
|
4062
4460
|
if (hit === null) return { response: null, hit: null };
|
|
4063
4461
|
return { response: buildAnticipationResponse(hit), hit };
|
|
4064
|
-
} catch (
|
|
4462
|
+
} catch (e22) {
|
|
4065
4463
|
return { response: null, hit: null };
|
|
4066
4464
|
}
|
|
4067
4465
|
}
|
|
@@ -4431,7 +4829,8 @@ function toolInputSchema(scope, options) {
|
|
|
4431
4829
|
}
|
|
4432
4830
|
var RESULT_COLLECTIONS = ["facts", "preferences", "episodes", "emotions", "temporal_events"];
|
|
4433
4831
|
async function invokeScopeFetch(params) {
|
|
4434
|
-
const { target, scope, userId, customerId, conversationId, callArgs } = params;
|
|
4832
|
+
const { target, scope, userId, customerId, conversationId, callArgs, scopePath } = params;
|
|
4833
|
+
const pathOpt = scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0 ? { scope_path: scopePath } : {};
|
|
4435
4834
|
const searchQuery = callArgs["search_query"];
|
|
4436
4835
|
const rawMax = callArgs["max_results"];
|
|
4437
4836
|
const maxResults = typeof rawMax === "number" && rawMax !== 0 ? Math.trunc(rawMax) : 10;
|
|
@@ -4444,7 +4843,8 @@ async function invokeScopeFetch(params) {
|
|
|
4444
4843
|
max_results: maxResults,
|
|
4445
4844
|
types,
|
|
4446
4845
|
mode,
|
|
4447
|
-
precision_level: precisionLevel
|
|
4846
|
+
precision_level: precisionLevel,
|
|
4847
|
+
...pathOpt
|
|
4448
4848
|
};
|
|
4449
4849
|
if (scope === "unified") {
|
|
4450
4850
|
const response2 = await target.fetch({
|
|
@@ -4499,7 +4899,7 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
4499
4899
|
const scope = String(_nullishCoalesce(options.scope, () => ( "user"))).toLowerCase();
|
|
4500
4900
|
if (!VALID_SCOPES.includes(scope)) {
|
|
4501
4901
|
const sorted = [...VALID_SCOPES].sort();
|
|
4502
|
-
throw new (0,
|
|
4902
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
4503
4903
|
`scope must be one of ['${sorted.join("', '")}'], got '${String(options.scope)}'`
|
|
4504
4904
|
);
|
|
4505
4905
|
}
|
|
@@ -4507,10 +4907,10 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
4507
4907
|
const customerId = _nullishCoalesce(options.customer_id, () => ( options.customerId));
|
|
4508
4908
|
const conversationId = _nullishCoalesce(options.conversation_id, () => ( options.conversationId));
|
|
4509
4909
|
if (scope === "user" && (userId === void 0 || userId === "")) {
|
|
4510
|
-
throw new (0,
|
|
4910
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("scope='user' requires user_id");
|
|
4511
4911
|
}
|
|
4512
4912
|
if (scope === "customer" && (customerId === void 0 || customerId === "")) {
|
|
4513
|
-
throw new (0,
|
|
4913
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("scope='customer' requires customer_id");
|
|
4514
4914
|
}
|
|
4515
4915
|
if (scope === "conversation" && (userId === void 0 || userId === "")) {
|
|
4516
4916
|
onWarning(
|
|
@@ -4519,12 +4919,20 @@ function buildTool(target, options = {}, onWarning = () => {
|
|
|
4519
4919
|
}
|
|
4520
4920
|
const style = String(_nullishCoalesce(options.style, () => ( "openai")));
|
|
4521
4921
|
if (style !== "openai" && style !== "anthropic") {
|
|
4522
|
-
throw new (0,
|
|
4922
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`style must be 'openai' or 'anthropic', got '${style}'`);
|
|
4523
4923
|
}
|
|
4524
4924
|
const toolName = _nullishCoalesce(options.name, () => ( `synap_fetch_${scope}_context`));
|
|
4525
4925
|
const toolDesc = _nullishCoalesce(options.description, () => ( defaultToolDescription(scope)));
|
|
4526
4926
|
const schema = toolInputSchema(scope, { hasConversationId: conversationId !== void 0 });
|
|
4527
|
-
const handler = (callArgs = {}) => invokeScopeFetch({
|
|
4927
|
+
const handler = (callArgs = {}) => invokeScopeFetch({
|
|
4928
|
+
target,
|
|
4929
|
+
scope,
|
|
4930
|
+
userId,
|
|
4931
|
+
customerId,
|
|
4932
|
+
conversationId,
|
|
4933
|
+
callArgs,
|
|
4934
|
+
scopePath: options.scope_path
|
|
4935
|
+
});
|
|
4528
4936
|
if (style === "openai") {
|
|
4529
4937
|
return {
|
|
4530
4938
|
type: "function",
|
|
@@ -4561,6 +4969,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4561
4969
|
|
|
4562
4970
|
|
|
4563
4971
|
|
|
4972
|
+
|
|
4564
4973
|
#closed = false;
|
|
4565
4974
|
#initialized = false;
|
|
4566
4975
|
#identity;
|
|
@@ -4614,10 +5023,14 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4614
5023
|
...options.retryPolicy !== void 0 ? { retryPolicy: options.retryPolicy } : {},
|
|
4615
5024
|
...options.keepAlive !== void 0 ? { keepAlive: options.keepAlive } : {},
|
|
4616
5025
|
...options.fetchImpl !== void 0 ? { fetchImpl: options.fetchImpl } : {},
|
|
5026
|
+
...options._clock !== void 0 ? { clock: options._clock } : {},
|
|
4617
5027
|
userAgent: `@maximem/synap-js-sdk/${SDK_VERSION}`
|
|
4618
5028
|
});
|
|
4619
5029
|
if (options.heartbeat) this.#transport.startHeartbeat();
|
|
4620
5030
|
this.#transport.identityResolver = () => this.#resolveIdentity();
|
|
5031
|
+
this.#transport.onInvalidInput = (_error, carriedScopePath) => {
|
|
5032
|
+
if (carriedScopePath) this.#transport.invalidateScopeLadder();
|
|
5033
|
+
};
|
|
4621
5034
|
this.#anticipationCache = new (0, _chunkBYUGILQIcjs.AnticipationCache)();
|
|
4622
5035
|
this.#fetchHooks = {
|
|
4623
5036
|
beforeFetch: async (scope, options2) => {
|
|
@@ -4684,7 +5097,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4684
5097
|
...customerId !== void 0 ? { customer_id: customerId } : {}
|
|
4685
5098
|
});
|
|
4686
5099
|
return profileContext(profile);
|
|
4687
|
-
} catch (
|
|
5100
|
+
} catch (e23) {
|
|
4688
5101
|
return null;
|
|
4689
5102
|
}
|
|
4690
5103
|
}
|
|
@@ -4724,7 +5137,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4724
5137
|
this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
|
|
4725
5138
|
const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
|
|
4726
5139
|
this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
|
|
4727
|
-
if (_optionalChain([this, 'access',
|
|
5140
|
+
if (_optionalChain([this, 'access', _101 => _101.#localEncoder, 'optionalAccess', _102 => _102.model]) === _chunkBYUGILQIcjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
|
|
4728
5141
|
this.#turns = new TurnCounter();
|
|
4729
5142
|
this.conversation = createConversationNamespace(
|
|
4730
5143
|
this.#transport,
|
|
@@ -4787,6 +5200,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4787
5200
|
return cleared;
|
|
4788
5201
|
});
|
|
4789
5202
|
this.credits = createCreditsNamespace(this.#transport);
|
|
5203
|
+
this.maca = createMacaNamespace(this.#transport);
|
|
4790
5204
|
this.cache = createCacheNamespace(this.#anticipationCache);
|
|
4791
5205
|
this.instance = createInstanceNamespace(
|
|
4792
5206
|
() => this.#transport.currentCredentials(),
|
|
@@ -4847,9 +5261,9 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4847
5261
|
*/
|
|
4848
5262
|
async searchMemory(options) {
|
|
4849
5263
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
4850
|
-
if (!userId) throw new (0,
|
|
5264
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
4851
5265
|
if (options.query === void 0 || options.query === null) {
|
|
4852
|
-
throw new (0,
|
|
5266
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("query is required");
|
|
4853
5267
|
}
|
|
4854
5268
|
const context = await fetchContext(this.#transport, "user", {
|
|
4855
5269
|
user_id: userId,
|
|
@@ -4870,7 +5284,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4870
5284
|
*/
|
|
4871
5285
|
async getMemories(options) {
|
|
4872
5286
|
const userId = _nullishCoalesce(options.user_id, () => ( options.userId));
|
|
4873
|
-
if (!userId) throw new (0,
|
|
5287
|
+
if (!userId) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("user_id is required");
|
|
4874
5288
|
const context = await fetchContext(this.#transport, "user", {
|
|
4875
5289
|
user_id: userId,
|
|
4876
5290
|
...pick3(options, "customer_id", "customerId") !== void 0 ? { customer_id: pick3(options, "customer_id", "customerId") } : {},
|
|
@@ -4917,6 +5331,25 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4917
5331
|
this.#initialized = true;
|
|
4918
5332
|
await this.#resolveIdentity();
|
|
4919
5333
|
}
|
|
5334
|
+
/**
|
|
5335
|
+
* The account's scope ladder, or `null` when it cannot be known.
|
|
5336
|
+
*
|
|
5337
|
+
* Mirrors Python's `get_scope_ladder()`. Read lazily from
|
|
5338
|
+
* `GET /api/v1/auth/whoami` (even when the client and instance ids are
|
|
5339
|
+
* already known), cached for 300 s (`null` included), re-read on `refresh: true`. Concurrent
|
|
5340
|
+
* callers share one read. If a re-read
|
|
5341
|
+
* after expiry fails, the last known ladder is returned with a warning and
|
|
5342
|
+
* the next try waits 60 s. A failure on the very first read, or with
|
|
5343
|
+
* `refresh`, is thrown. With no `scope_ladder` block the default ladder is
|
|
5344
|
+
* inferred from `user_context_isolation` (`source: "inferred"`).
|
|
5345
|
+
*
|
|
5346
|
+
* const ladder = await client.get_scope_ladder();
|
|
5347
|
+
* const addr = ladder!.address(['acme', 'payments', 'dana']);
|
|
5348
|
+
* await client.fetch({ search_query: ['...'], ...addr.read_kwargs() });
|
|
5349
|
+
*/
|
|
5350
|
+
async get_scope_ladder(options = {}) {
|
|
5351
|
+
return this.#transport.getScopeLadder(options.refresh === true, (m) => this.#warn(m));
|
|
5352
|
+
}
|
|
4920
5353
|
/** Runs whoami at most once, however many calls arrive together. */
|
|
4921
5354
|
#resolveIdentity() {
|
|
4922
5355
|
this.#identity ??= this.#whoami().catch((error) => {
|
|
@@ -4945,8 +5378,8 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4945
5378
|
}
|
|
4946
5379
|
} catch (error) {
|
|
4947
5380
|
if (this.#localMode) {
|
|
4948
|
-
throw new (0,
|
|
4949
|
-
`Could not reach the Synap server at ${this.#transport.baseUrl}, or it did not identify itself: GET /api/v1/auth/whoami failed (${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
5381
|
+
throw new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(
|
|
5382
|
+
`Could not reach the Synap server at ${this.#transport.baseUrl}, or it did not identify itself: GET /api/v1/auth/whoami failed (${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _103 => _103.message]), () => ( String(error)))}).`,
|
|
4950
5383
|
{ cause: error }
|
|
4951
5384
|
);
|
|
4952
5385
|
}
|
|
@@ -4954,7 +5387,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4954
5387
|
if (this.#localMode) {
|
|
4955
5388
|
const known = this.#transport.currentCredentials();
|
|
4956
5389
|
if (known.clientId === "" || known.instanceId === "") {
|
|
4957
|
-
throw new (0,
|
|
5390
|
+
throw new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(
|
|
4958
5391
|
`The Synap server at ${this.#transport.baseUrl} did not identify itself: GET /api/v1/auth/whoami returned no client_id or instance_id.`
|
|
4959
5392
|
);
|
|
4960
5393
|
}
|
|
@@ -4992,7 +5425,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
4992
5425
|
*/
|
|
4993
5426
|
configure(options = {}) {
|
|
4994
5427
|
if (this.#initialized) {
|
|
4995
|
-
throw new (0,
|
|
5428
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("Cannot reconfigure after initialization");
|
|
4996
5429
|
}
|
|
4997
5430
|
if (options.timeouts !== void 0) this.#transport.setTimeouts(options.timeouts);
|
|
4998
5431
|
if (options.retryPolicy !== void 0 || options.retry_policy !== void 0) {
|
|
@@ -5043,7 +5476,8 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5043
5476
|
context_mode: contextMode = "in-conversation",
|
|
5044
5477
|
include_profile: includeProfile = true,
|
|
5045
5478
|
last_n_conversations: lastNConversations = 1,
|
|
5046
|
-
response_shape: responseShape = "by_type"
|
|
5479
|
+
response_shape: responseShape = "by_type",
|
|
5480
|
+
scope_path: scopePath
|
|
5047
5481
|
} = options;
|
|
5048
5482
|
await this.#transport.checkCustomerId(customerId, "sdk.fetch");
|
|
5049
5483
|
validateConversationId(conversationId);
|
|
@@ -5060,7 +5494,10 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5060
5494
|
// sits one indent deeper; spreading removes that whole class of miss.
|
|
5061
5495
|
query_date: queryDate,
|
|
5062
5496
|
max_results_per_query: maxResultsPerQuery,
|
|
5063
|
-
response_shape: responseShape
|
|
5497
|
+
response_shape: responseShape,
|
|
5498
|
+
// Forwarded only when set (Python: `if scope_path`), so a call without
|
|
5499
|
+
// one hands every scope fetch exactly the options it always got.
|
|
5500
|
+
...scopePath !== void 0 && scopePath !== null && Object.keys(scopePath).length > 0 ? { scope_path: scopePath } : {}
|
|
5064
5501
|
};
|
|
5065
5502
|
const labels = [];
|
|
5066
5503
|
const tasks = [];
|
|
@@ -5115,7 +5552,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5115
5552
|
successful.push([label, result.value]);
|
|
5116
5553
|
continue;
|
|
5117
5554
|
}
|
|
5118
|
-
if (result.reason instanceof
|
|
5555
|
+
if (result.reason instanceof _chunkJPDEKN5Mcjs.InvalidInputError) throw result.reason;
|
|
5119
5556
|
this.#warn(`Scope '${label}' fetch failed in unified fetch (non-fatal): ${String(result.reason)}`);
|
|
5120
5557
|
}
|
|
5121
5558
|
const merged = mergeScopeResults(successful);
|
|
@@ -5130,7 +5567,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5130
5567
|
if (conversationState && !merged.scopes_queried.includes("conversation")) {
|
|
5131
5568
|
merged.scopes_queried.unshift("conversation");
|
|
5132
5569
|
}
|
|
5133
|
-
} catch (
|
|
5570
|
+
} catch (e24) {
|
|
5134
5571
|
}
|
|
5135
5572
|
}
|
|
5136
5573
|
merged.formatted_context = formatForPrompt(merged, {
|
|
@@ -5182,7 +5619,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5182
5619
|
// not carry the caller's words.
|
|
5183
5620
|
query_count: distinctQueryCount(_nullishCoalesce(options["search_query"], () => ( options["searchQuery"])))
|
|
5184
5621
|
});
|
|
5185
|
-
} catch (
|
|
5622
|
+
} catch (e25) {
|
|
5186
5623
|
}
|
|
5187
5624
|
}
|
|
5188
5625
|
/**
|
|
@@ -5197,7 +5634,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5197
5634
|
if (!this.instance.is_listening) return;
|
|
5198
5635
|
this.instance._internal.sendContextAssembled({
|
|
5199
5636
|
...buildAssembledEvent({
|
|
5200
|
-
correlationId:
|
|
5637
|
+
correlationId: _chunkJPDEKN5Mcjs.newCorrelationId.call(void 0, ),
|
|
5201
5638
|
response,
|
|
5202
5639
|
conversationId: _nullishCoalesce(options["conversation_id"], () => ( options["conversationId"])),
|
|
5203
5640
|
userId: _nullishCoalesce(options["user_id"], () => ( options["userId"])),
|
|
@@ -5207,7 +5644,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5207
5644
|
}),
|
|
5208
5645
|
scope
|
|
5209
5646
|
});
|
|
5210
|
-
} catch (
|
|
5647
|
+
} catch (e26) {
|
|
5211
5648
|
}
|
|
5212
5649
|
}
|
|
5213
5650
|
/**
|
|
@@ -5268,14 +5705,14 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5268
5705
|
}))
|
|
5269
5706
|
);
|
|
5270
5707
|
const entry = this.#shortTerm.get(conversationId);
|
|
5271
|
-
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess',
|
|
5708
|
+
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _104 => _104.serverMessageCount]), () => ( 0))) || 0);
|
|
5272
5709
|
this.#maybeBackfillTurns(conversationId, total);
|
|
5273
5710
|
if (!r["context_block"]) return response;
|
|
5274
5711
|
const turns = store.turns(conversationId);
|
|
5275
5712
|
let q = query;
|
|
5276
5713
|
if (!q) {
|
|
5277
5714
|
const latest = [...recent].reverse().find((m) => m["role"] === "user");
|
|
5278
|
-
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access',
|
|
5715
|
+
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _105 => _105.reverse, 'call', _106 => _106(), 'access', _107 => _107.find, 'call', _108 => _108((t) => t.role === "user"), 'optionalAccess', _109 => _109.content]), () => ( ""));
|
|
5279
5716
|
}
|
|
5280
5717
|
if (!q) return response;
|
|
5281
5718
|
const exclude = /* @__PURE__ */ new Set();
|
|
@@ -5309,7 +5746,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5309
5746
|
toolResultText(result, _nullishCoalesce(options.tool_name, () => ( options.toolName))),
|
|
5310
5747
|
_nullishCoalesce(options.timestamp, () => ( (/* @__PURE__ */ new Date()).toISOString()))
|
|
5311
5748
|
);
|
|
5312
|
-
} catch (
|
|
5749
|
+
} catch (e27) {
|
|
5313
5750
|
}
|
|
5314
5751
|
}
|
|
5315
5752
|
static __initStatic() {this.BACKFILL_COOLDOWN_MS = 6e4}
|
|
@@ -5419,13 +5856,13 @@ function pick3(o2, snake, camel) {
|
|
|
5419
5856
|
function resolveBaseUrl(options) {
|
|
5420
5857
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
5421
5858
|
if (explicit !== void 0) return explicit;
|
|
5422
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
5859
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _110 => _110.trim, 'call', _111 => _111()]);
|
|
5423
5860
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
5424
5861
|
}
|
|
5425
5862
|
function resolveCredentials(options, localMode) {
|
|
5426
5863
|
const apiKey = options.apiKey || _chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_API_KEY");
|
|
5427
5864
|
if (!apiKey && !localMode) {
|
|
5428
|
-
throw new (0,
|
|
5865
|
+
throw new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(
|
|
5429
5866
|
"No Synap API key found. Set SYNAP_API_KEY in your environment, or pass apiKey to the SynapClient constructor."
|
|
5430
5867
|
);
|
|
5431
5868
|
}
|
|
@@ -5500,5 +5937,8 @@ function resolveCredentials(options, localMode) {
|
|
|
5500
5937
|
|
|
5501
5938
|
|
|
5502
5939
|
|
|
5503
|
-
|
|
5940
|
+
|
|
5941
|
+
|
|
5942
|
+
|
|
5943
|
+
exports.ANY_SCOPE = _chunkBYUGILQIcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkJPDEKN5Mcjs.AgentUnavailableError; exports.AnticipationCache = _chunkBYUGILQIcjs.AnticipationCache; exports.AuthenticationError = _chunkJPDEKN5Mcjs.AuthenticationError; exports.BM25 = _chunkBYUGILQIcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunkBYUGILQIcjs.CONTRACT; exports.ConflictError = _chunkJPDEKN5Mcjs.ConflictError; exports.ConnectionError = _chunkJPDEKN5Mcjs.ConnectionError; exports.ContextNotFoundError = _chunkJPDEKN5Mcjs.ContextNotFoundError; exports.CustomerIdNotAcceptedError = _chunkJPDEKN5Mcjs.CustomerIdNotAcceptedError; exports.DATA_SCOPES = DATA_SCOPES; 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.InstanceBuildFailedError = _chunkJPDEKN5Mcjs.InstanceBuildFailedError; exports.InstanceNotReadyError = _chunkJPDEKN5Mcjs.InstanceNotReadyError; exports.InsufficientCreditsError = _chunkJPDEKN5Mcjs.InsufficientCreditsError; exports.InvalidConversationIdError = _chunkJPDEKN5Mcjs.InvalidConversationIdError; exports.InvalidInputError = _chunkJPDEKN5Mcjs.InvalidInputError; exports.InvalidInstanceIdError = _chunkJPDEKN5Mcjs.InvalidInstanceIdError; exports.ListeningAlreadyActiveError = _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError; exports.ListeningNotActiveError = _chunkJPDEKN5Mcjs.ListeningNotActiveError; exports.MEMORY_TYPES = MEMORY_TYPES; exports.NetworkTimeoutError = _chunkJPDEKN5Mcjs.NetworkTimeoutError; exports.OBJECTIVES = OBJECTIVES; exports.PermanentError = _chunkJPDEKN5Mcjs.PermanentError; exports.RESPONSE_SHAPES = RESPONSE_SHAPES; exports.RateLimitError = _chunkJPDEKN5Mcjs.RateLimitError; exports.SDKError = _chunkJPDEKN5Mcjs.SDKError; exports.SDK_VERSION = SDK_VERSION; exports.ScopeAddress = ScopeAddress; exports.ScopeLadder = ScopeLadder; exports.ScopeLadderError = _chunkJPDEKN5Mcjs.ScopeLadderError; exports.ServiceUnavailableError = _chunkJPDEKN5Mcjs.ServiceUnavailableError; exports.SessionExpiredError = _chunkJPDEKN5Mcjs.SessionExpiredError; exports.SynapClient = SynapClient; exports.SynapError = _chunkJPDEKN5Mcjs.SynapError; exports.SynapPermanentError = _chunkJPDEKN5Mcjs.SynapPermanentError; exports.SynapTransientError = _chunkJPDEKN5Mcjs.SynapTransientError; exports.THRESHOLDS = _chunkBYUGILQIcjs.THRESHOLDS; exports.TranscriptConflictError = _chunkJPDEKN5Mcjs.TranscriptConflictError; exports.TransientError = _chunkJPDEKN5Mcjs.TransientError; exports.applyResponseShape = applyResponseShape; exports.filePart = filePart; exports.flattenContextItems = flattenContextItems; exports.formatForPrompt = formatForPrompt; exports.isOutcomeUnknown = isOutcomeUnknown; exports.isSynapError = _chunkJPDEKN5Mcjs.isSynapError; exports.mergeScopeResults = mergeScopeResults; exports.rankItems = rankItems; exports.resolvePath = resolvePath; exports.shouldRetry = shouldRetry; exports.stem = _chunkBYUGILQIcjs.stem; exports.textPart = textPart; exports.tokenize = _chunkBYUGILQIcjs.tokenize; exports.wireRankScore = wireRankScore;
|
|
5504
5944
|
//# sourceMappingURL=index.cjs.map
|