@maximem/synap-js-sdk 0.7.1 → 0.8.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-VL5WHTJB.js → anticipation-cache-B5OY43LX.js} +2 -2
- package/dist/anticipation-cache-JDX2VTFE.cjs +26 -0
- package/dist/anticipation-cache-JDX2VTFE.cjs.map +1 -0
- package/dist/{chunk-BYUGILQI.cjs → chunk-6GHXJD7L.cjs} +92 -3
- package/dist/chunk-6GHXJD7L.cjs.map +1 -0
- package/dist/chunk-JPDEKN5M.cjs.map +1 -1
- package/dist/chunk-SAKMZI7G.cjs.map +1 -1
- package/dist/{chunk-CSG3N5E3.js → chunk-W6AH4CPC.js} +91 -2
- package/dist/chunk-W6AH4CPC.js.map +1 -0
- package/dist/chunk-ZKOJDUN4.cjs.map +1 -1
- package/dist/env-55ULHNJZ.cjs.map +1 -1
- package/dist/grpc/index.cjs +1 -1
- package/dist/grpc/index.cjs.map +1 -1
- package/dist/grpc/index.js +1 -1
- package/dist/index.cjs +186 -69
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +103 -7
- package/dist/index.d.ts +103 -7
- package/dist/index.js +136 -19
- package/dist/index.js.map +1 -1
- package/dist/onnx-encoder-4RSL6ID4.cjs.map +1 -1
- package/dist/stream-client-H2ES74FF.cjs.map +1 -1
- package/package.json +1 -1
- package/dist/anticipation-cache-Q7IYC3ID.cjs +0 -26
- package/dist/anticipation-cache-Q7IYC3ID.cjs.map +0 -1
- package/dist/chunk-BYUGILQI.cjs.map +0 -1
- package/dist/chunk-CSG3N5E3.js.map +0 -1
- /package/dist/{anticipation-cache-VL5WHTJB.js.map → anticipation-cache-B5OY43LX.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
var _chunk6GHXJD7Lcjs = require('./chunk-6GHXJD7L.cjs');
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
var _chunkZKOJDUN4cjs = require('./chunk-ZKOJDUN4.cjs');
|
|
@@ -66,6 +67,7 @@ var ENDPOINTS = {
|
|
|
66
67
|
memories_delete: { method: "DELETE", path: "/api/v1/memories/{memory_id}", idempotent: true },
|
|
67
68
|
memories_forget: { method: "POST", path: "/api/v1/memories/forget", idempotent: false },
|
|
68
69
|
data_delete: { method: "POST", path: "/v1/data/delete", idempotent: true },
|
|
70
|
+
data_restore: { method: "POST", path: "/v1/data/restore", idempotent: true },
|
|
69
71
|
data_delete_status: { method: "GET", path: "/v1/data/delete/{deletion_id}", idempotent: true },
|
|
70
72
|
context_fetch_user: { method: "POST", path: "/v1/context/user/fetch", idempotent: true },
|
|
71
73
|
context_fetch_customer: { method: "POST", path: "/v1/context/customer/fetch", idempotent: true },
|
|
@@ -2129,20 +2131,35 @@ function createMemoriesInterface(transport, onForgotten) {
|
|
|
2129
2131
|
body
|
|
2130
2132
|
});
|
|
2131
2133
|
},
|
|
2132
|
-
async delete(memoryId) {
|
|
2134
|
+
async delete(memoryId, options) {
|
|
2135
|
+
const permanent = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _63 => _63.permanent]), () => ( false));
|
|
2136
|
+
if (typeof permanent !== "boolean") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("permanent must be a boolean");
|
|
2133
2137
|
if (!memoryId) {
|
|
2134
2138
|
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2135
2139
|
"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."
|
|
2136
2140
|
);
|
|
2137
2141
|
}
|
|
2138
|
-
|
|
2142
|
+
const r = await transport.request("memories_delete", {
|
|
2143
|
+
pathParams: { memory_id: memoryId },
|
|
2144
|
+
...permanent ? { query: { permanent: "true" } } : {}
|
|
2145
|
+
});
|
|
2146
|
+
return {
|
|
2147
|
+
memory_id: String(_nullishCoalesce(_optionalChain([r, 'optionalAccess', _64 => _64["memory_id"]]), () => ( memoryId))),
|
|
2148
|
+
deleted_at: String(_nullishCoalesce(_optionalChain([r, 'optionalAccess', _65 => _65["deleted_at"]]), () => ( ""))),
|
|
2149
|
+
fully_removed: _optionalChain([r, 'optionalAccess', _66 => _66["fully_removed"]]) === true,
|
|
2150
|
+
still_present_in: Array.isArray(_optionalChain([r, 'optionalAccess', _67 => _67["still_present_in"]])) ? r["still_present_in"] : [],
|
|
2151
|
+
source_text_kept: _optionalChain([r, 'optionalAccess', _68 => _68["source_text_kept"]]) === true,
|
|
2152
|
+
status: typeof _optionalChain([r, 'optionalAccess', _69 => _69["status"]]) === "string" && r["status"] ? r["status"] : "complete",
|
|
2153
|
+
purge_after: typeof _optionalChain([r, 'optionalAccess', _70 => _70["purge_after"]]) === "string" ? r["purge_after"] : null,
|
|
2154
|
+
permanent: _optionalChain([r, 'optionalAccess', _71 => _71["permanent"]]) === true
|
|
2155
|
+
};
|
|
2139
2156
|
},
|
|
2140
2157
|
async forget(options) {
|
|
2141
2158
|
const o2 = options;
|
|
2142
2159
|
await transport.checkCustomerId(_nullishCoalesce(o2["customer_id"], () => ( o2["customerId"])), "memories.forget");
|
|
2143
2160
|
const body = buildForgetBody(options);
|
|
2144
2161
|
const result = await transport.request("memories_forget", { body });
|
|
2145
|
-
const removed = !!_optionalChain([result, 'optionalAccess',
|
|
2162
|
+
const removed = !!_optionalChain([result, 'optionalAccess', _72 => _72.deleted_ids, 'optionalAccess', _73 => _73.length]) || _optionalChain([result, 'optionalAccess', _74 => _74.status]) === "deleted" || _optionalChain([result, 'optionalAccess', _75 => _75.status]) === "partial";
|
|
2146
2163
|
if (removed && onForgotten) {
|
|
2147
2164
|
try {
|
|
2148
2165
|
onForgotten({
|
|
@@ -2182,14 +2199,14 @@ function sleep2(ms, signal) {
|
|
|
2182
2199
|
if (ms <= 0) return Promise.resolve();
|
|
2183
2200
|
return new Promise((resolve, reject) => {
|
|
2184
2201
|
const timer = setTimeout(() => {
|
|
2185
|
-
_optionalChain([signal, 'optionalAccess',
|
|
2202
|
+
_optionalChain([signal, 'optionalAccess', _76 => _76.removeEventListener, 'call', _77 => _77("abort", onAbort)]);
|
|
2186
2203
|
resolve();
|
|
2187
2204
|
}, ms);
|
|
2188
2205
|
function onAbort() {
|
|
2189
2206
|
clearTimeout(timer);
|
|
2190
|
-
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess',
|
|
2207
|
+
reject(_nullishCoalesce(_optionalChain([signal, 'optionalAccess', _78 => _78.reason]), () => ( new Error("Aborted"))));
|
|
2191
2208
|
}
|
|
2192
|
-
_optionalChain([signal, 'optionalAccess',
|
|
2209
|
+
_optionalChain([signal, 'optionalAccess', _79 => _79.addEventListener, 'call', _80 => _80("abort", onAbort, { once: true })]);
|
|
2193
2210
|
});
|
|
2194
2211
|
}
|
|
2195
2212
|
|
|
@@ -2270,7 +2287,7 @@ function buildRecordMessageBody(options, resolvedContent, field = "content") {
|
|
|
2270
2287
|
content = resolvedContent;
|
|
2271
2288
|
} else {
|
|
2272
2289
|
const n2 = normaliseContent(options.content, field);
|
|
2273
|
-
if (_optionalChain([n2, 'optionalAccess',
|
|
2290
|
+
if (_optionalChain([n2, 'optionalAccess', _81 => _81.kind]) === "parts") {
|
|
2274
2291
|
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(
|
|
2275
2292
|
"content holds a FilePart, whose bytes have to be read first. Send it with conversation.record_message."
|
|
2276
2293
|
);
|
|
@@ -2339,6 +2356,7 @@ function buildCompactBody(options) {
|
|
|
2339
2356
|
var CompactionSubscribers = class {
|
|
2340
2357
|
#byConversation = /* @__PURE__ */ new Map();
|
|
2341
2358
|
add(conversationId, callback) {
|
|
2359
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
2342
2360
|
const list = this.#byConversation.get(conversationId);
|
|
2343
2361
|
if (list === void 0) this.#byConversation.set(conversationId, [callback]);
|
|
2344
2362
|
else list.push(callback);
|
|
@@ -2354,6 +2372,7 @@ var CompactionSubscribers = class {
|
|
|
2354
2372
|
};
|
|
2355
2373
|
}
|
|
2356
2374
|
removeAll(conversationId) {
|
|
2375
|
+
if (conversationId !== void 0) conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
2357
2376
|
if (conversationId === void 0) {
|
|
2358
2377
|
let count = 0;
|
|
2359
2378
|
for (const list2 of this.#byConversation.values()) count += list2.length;
|
|
@@ -2367,6 +2386,7 @@ var CompactionSubscribers = class {
|
|
|
2367
2386
|
}
|
|
2368
2387
|
/** Fires subscribers in registration order. A throwing listener must not break the stream reader. */
|
|
2369
2388
|
dispatch(conversationId, bundle, onError) {
|
|
2389
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
2370
2390
|
for (const callback of [..._nullishCoalesce(this.#byConversation.get(conversationId), () => ( []))]) {
|
|
2371
2391
|
try {
|
|
2372
2392
|
const result = callback(bundle);
|
|
@@ -2381,7 +2401,7 @@ function storedBatchRows(bodies, result) {
|
|
|
2381
2401
|
const r = _nullishCoalesce(result, () => ( {}));
|
|
2382
2402
|
const results = Array.isArray(r["results"]) ? r["results"] : [];
|
|
2383
2403
|
const errors = Array.isArray(r["errors"]) ? r["errors"] : [];
|
|
2384
|
-
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess',
|
|
2404
|
+
const failed = new Set(errors.map((e) => _optionalChain([e, 'optionalAccess', _82 => _82["index"]])));
|
|
2385
2405
|
const stored = bodies.filter((_, index) => !failed.has(index));
|
|
2386
2406
|
if (stored.length !== results.length) return [];
|
|
2387
2407
|
const pairs = [];
|
|
@@ -2425,7 +2445,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2425
2445
|
};
|
|
2426
2446
|
const fetchImpl = ((url, init) => transport.fetchExternal(url, init));
|
|
2427
2447
|
const validateMessage = (options, field = "content") => {
|
|
2428
|
-
if (_optionalChain([normaliseContent, 'call',
|
|
2448
|
+
if (_optionalChain([normaliseContent, 'call', _83 => _83(options.content, field), 'optionalAccess', _84 => _84.kind]) === "parts") {
|
|
2429
2449
|
buildRecordMessageBody(options, "", field);
|
|
2430
2450
|
} else {
|
|
2431
2451
|
buildRecordMessageBody(options, void 0, field);
|
|
@@ -2433,7 +2453,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2433
2453
|
};
|
|
2434
2454
|
const prepareMessage = async (options, field = "content") => {
|
|
2435
2455
|
const n2 = normaliseContent(options.content, field);
|
|
2436
|
-
if (_optionalChain([n2, 'optionalAccess',
|
|
2456
|
+
if (_optionalChain([n2, 'optionalAccess', _85 => _85.kind]) !== "parts") {
|
|
2437
2457
|
const body = buildRecordMessageBody(options, void 0, field);
|
|
2438
2458
|
return { body, mirror: String(_nullishCoalesce(body["content"], () => ( ""))) };
|
|
2439
2459
|
}
|
|
@@ -2524,7 +2544,7 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2524
2544
|
const raw = await transport.request("conversations_ingest", { body });
|
|
2525
2545
|
const result = {
|
|
2526
2546
|
...raw,
|
|
2527
|
-
warnings: Array.isArray(_optionalChain([raw, 'optionalAccess',
|
|
2547
|
+
warnings: Array.isArray(_optionalChain([raw, 'optionalAccess', _86 => _86.warnings])) ? raw.warnings.map(String) : []
|
|
2528
2548
|
};
|
|
2529
2549
|
onWrite({
|
|
2530
2550
|
userId: body["user_id"],
|
|
@@ -2568,8 +2588,8 @@ function createConversationNamespace(transport, subscribers = new CompactionSubs
|
|
|
2568
2588
|
pathParams: { conversation_id: id },
|
|
2569
2589
|
query: { style }
|
|
2570
2590
|
});
|
|
2571
|
-
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess',
|
|
2572
|
-
_optionalChain([localShortTerm, 'access',
|
|
2591
|
+
const response = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _87 => _87["context_for_prompt"]]), () => ( result)), () => ( {}));
|
|
2592
|
+
_optionalChain([localShortTerm, 'access', _88 => _88.reseed, 'optionalCall', _89 => _89(id, response)]);
|
|
2573
2593
|
return withHistory(response);
|
|
2574
2594
|
},
|
|
2575
2595
|
async compact(options) {
|
|
@@ -2629,6 +2649,7 @@ var ID_FIELD = {
|
|
|
2629
2649
|
customer: "customer_id",
|
|
2630
2650
|
conversation: "conversation_id"
|
|
2631
2651
|
};
|
|
2652
|
+
var MAX_RESTORE_IDS = 200;
|
|
2632
2653
|
function either3(o2, snake, camel) {
|
|
2633
2654
|
const a = o2[snake];
|
|
2634
2655
|
if (a !== void 0) return a;
|
|
@@ -2676,15 +2697,39 @@ function buildDeleteBody(options, instanceId) {
|
|
|
2676
2697
|
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)(`confirm must equal the ${field} being deleted`);
|
|
2677
2698
|
}
|
|
2678
2699
|
}
|
|
2679
|
-
|
|
2700
|
+
const instances2 = options.instances === void 0 || options.instances === null ? null : checkInstances(options.instances);
|
|
2701
|
+
const permanent = _nullishCoalesce(options.permanent, () => ( false));
|
|
2702
|
+
if (typeof permanent !== "boolean") throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("permanent must be a boolean");
|
|
2703
|
+
const body = {
|
|
2680
2704
|
scope,
|
|
2681
|
-
|
|
2705
|
+
// Without `instances` the body is byte-identical to earlier versions.
|
|
2706
|
+
instance_id: instances2 === null ? instanceId : null,
|
|
2682
2707
|
user_id: _nullishCoalesce(ids["user_id"], () => ( null)),
|
|
2683
2708
|
customer_id: _nullishCoalesce(ids["customer_id"], () => ( null)),
|
|
2684
2709
|
conversation_id: _nullishCoalesce(ids["conversation_id"], () => ( null)),
|
|
2685
2710
|
dry_run: dryRun,
|
|
2686
2711
|
confirm
|
|
2687
2712
|
};
|
|
2713
|
+
if (instances2 !== null) body["instance_ids"] = instances2;
|
|
2714
|
+
if (permanent) body["permanent"] = true;
|
|
2715
|
+
return body;
|
|
2716
|
+
}
|
|
2717
|
+
function checkInstances(instances2) {
|
|
2718
|
+
if (instances2 === "all") return "all";
|
|
2719
|
+
if (!Array.isArray(instances2)) {
|
|
2720
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)('instances must be "all" or a list of instance ids');
|
|
2721
|
+
}
|
|
2722
|
+
const out = [];
|
|
2723
|
+
for (const i of instances2) {
|
|
2724
|
+
if (typeof i !== "string" || i.trim() === "") {
|
|
2725
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("instances must not contain an empty instance id");
|
|
2726
|
+
}
|
|
2727
|
+
if (!out.includes(i.trim())) out.push(i.trim());
|
|
2728
|
+
}
|
|
2729
|
+
if (out.length === 0) {
|
|
2730
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)('instances is empty: name at least one instance, or "all"');
|
|
2731
|
+
}
|
|
2732
|
+
return out;
|
|
2688
2733
|
}
|
|
2689
2734
|
function normalise(raw) {
|
|
2690
2735
|
return {
|
|
@@ -2700,13 +2745,43 @@ function normalise(raw) {
|
|
|
2700
2745
|
fully_removed: false,
|
|
2701
2746
|
continue: false,
|
|
2702
2747
|
kept: [],
|
|
2748
|
+
not_covered: [],
|
|
2703
2749
|
note: null,
|
|
2704
2750
|
memories_kept: false,
|
|
2705
2751
|
audit: null,
|
|
2706
2752
|
local_cleared: [],
|
|
2753
|
+
instances: [],
|
|
2754
|
+
not_started: [],
|
|
2755
|
+
deletion_ids: [],
|
|
2756
|
+
purge_after: null,
|
|
2707
2757
|
...raw
|
|
2708
2758
|
};
|
|
2709
2759
|
}
|
|
2760
|
+
function buildRestoreBody(memoryIds, instanceId, deletionId = null) {
|
|
2761
|
+
const noIds = memoryIds === null || memoryIds === void 0;
|
|
2762
|
+
const noDeletion = deletionId === null || deletionId === void 0;
|
|
2763
|
+
if (noIds === noDeletion) {
|
|
2764
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("send exactly one of memory_ids or deletion_id");
|
|
2765
|
+
}
|
|
2766
|
+
if (!noDeletion) {
|
|
2767
|
+
if (typeof deletionId !== "string" || deletionId.trim() === "") {
|
|
2768
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("deletion_id must not be empty");
|
|
2769
|
+
}
|
|
2770
|
+
return { deletion_id: deletionId.trim(), instance_id: instanceId };
|
|
2771
|
+
}
|
|
2772
|
+
if (typeof memoryIds === "string" || !Array.isArray(memoryIds)) {
|
|
2773
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must be a list of memory ids");
|
|
2774
|
+
}
|
|
2775
|
+
const ids = memoryIds.map((i) => String(i));
|
|
2776
|
+
if (ids.length === 0) throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must not be empty");
|
|
2777
|
+
if (ids.length > MAX_RESTORE_IDS) {
|
|
2778
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("at most " + String(MAX_RESTORE_IDS) + " memory_ids per call");
|
|
2779
|
+
}
|
|
2780
|
+
if (ids.some((i) => i.trim() === "")) {
|
|
2781
|
+
throw new (0, _chunkJPDEKN5Mcjs.InvalidInputError)("memory_ids must not contain empty ids");
|
|
2782
|
+
}
|
|
2783
|
+
return { memory_ids: ids, instance_id: instanceId };
|
|
2784
|
+
}
|
|
2710
2785
|
function createDataInterface(transport, onDeleted) {
|
|
2711
2786
|
return {
|
|
2712
2787
|
async delete(options) {
|
|
@@ -2726,7 +2801,7 @@ function createDataInterface(transport, onDeleted) {
|
|
|
2726
2801
|
if (dryRun || !result.continue) break;
|
|
2727
2802
|
}
|
|
2728
2803
|
const final = result;
|
|
2729
|
-
if (!dryRun && ["complete", "partial", "in_progress"].includes(final.status) && onDeleted) {
|
|
2804
|
+
if (!dryRun && ["complete", "pending_purge", "partial", "in_progress"].includes(final.status) && onDeleted) {
|
|
2730
2805
|
try {
|
|
2731
2806
|
final.local_cleared = onDeleted({
|
|
2732
2807
|
scope: body["scope"],
|
|
@@ -2749,6 +2824,29 @@ function createDataInterface(transport, onDeleted) {
|
|
|
2749
2824
|
query: { instance_id: transport.currentCredentials().instanceId }
|
|
2750
2825
|
})
|
|
2751
2826
|
);
|
|
2827
|
+
},
|
|
2828
|
+
async restore(target) {
|
|
2829
|
+
const instanceId = transport.currentCredentials().instanceId;
|
|
2830
|
+
let body;
|
|
2831
|
+
if (Array.isArray(target) || typeof target === "string" || target === null || target === void 0) {
|
|
2832
|
+
body = buildRestoreBody(target, instanceId);
|
|
2833
|
+
} else {
|
|
2834
|
+
const o2 = target;
|
|
2835
|
+
body = buildRestoreBody(
|
|
2836
|
+
_nullishCoalesce(either3(o2, "memory_ids", "memoryIds"), () => ( null)),
|
|
2837
|
+
instanceId,
|
|
2838
|
+
_nullishCoalesce(either3(o2, "deletion_id", "deletionId"), () => ( null))
|
|
2839
|
+
);
|
|
2840
|
+
}
|
|
2841
|
+
const raw = await transport.request("data_restore", { body });
|
|
2842
|
+
return {
|
|
2843
|
+
restored_ids: [],
|
|
2844
|
+
not_restorable_ids: [],
|
|
2845
|
+
still_missing_in: [],
|
|
2846
|
+
reindexed_ids: [],
|
|
2847
|
+
fully_restored: false,
|
|
2848
|
+
...raw
|
|
2849
|
+
};
|
|
2752
2850
|
}
|
|
2753
2851
|
};
|
|
2754
2852
|
}
|
|
@@ -2966,8 +3064,8 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2966
3064
|
let onConversationState = null;
|
|
2967
3065
|
const internals = {
|
|
2968
3066
|
onCompactionUpdate(conversationId, bundle) {
|
|
2969
|
-
_optionalChain([applyCompaction, 'optionalCall',
|
|
2970
|
-
_optionalChain([dispatchCompaction, 'optionalCall',
|
|
3067
|
+
_optionalChain([applyCompaction, 'optionalCall', _90 => _90(bundle)]);
|
|
3068
|
+
_optionalChain([dispatchCompaction, 'optionalCall', _91 => _91(conversationId, bundle)]);
|
|
2971
3069
|
},
|
|
2972
3070
|
setCompactionApplier(apply) {
|
|
2973
3071
|
applyCompaction = apply;
|
|
@@ -2982,10 +3080,10 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2982
3080
|
onConversationState = handle;
|
|
2983
3081
|
},
|
|
2984
3082
|
sendContextUsed(event) {
|
|
2985
|
-
_optionalChain([client, 'optionalAccess',
|
|
3083
|
+
_optionalChain([client, 'optionalAccess', _92 => _92.sendContextUsed, 'call', _93 => _93(event)]);
|
|
2986
3084
|
},
|
|
2987
3085
|
sendContextAssembled(event) {
|
|
2988
|
-
_optionalChain([client, 'optionalAccess',
|
|
3086
|
+
_optionalChain([client, 'optionalAccess', _94 => _94.sendContextAssembled, 'call', _95 => _95(event)]);
|
|
2989
3087
|
},
|
|
2990
3088
|
setCompactionDispatcher(dispatch) {
|
|
2991
3089
|
dispatchCompaction = dispatch;
|
|
@@ -2994,9 +3092,18 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
2994
3092
|
return client !== null && client.isConnected;
|
|
2995
3093
|
}
|
|
2996
3094
|
};
|
|
3095
|
+
function openSessionKey(conversationId) {
|
|
3096
|
+
if (!conversationId) return void 0;
|
|
3097
|
+
if (openSessions.has(conversationId)) return conversationId;
|
|
3098
|
+
const wanted = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
3099
|
+
for (const key of openSessions.keys()) {
|
|
3100
|
+
if (_chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, key) === wanted) return key;
|
|
3101
|
+
}
|
|
3102
|
+
return void 0;
|
|
3103
|
+
}
|
|
2997
3104
|
function ensureSession(conversationId, userId, customerId) {
|
|
2998
3105
|
if (!conversationId || !userId || client === null) return;
|
|
2999
|
-
if (
|
|
3106
|
+
if (openSessionKey(conversationId) !== void 0) return;
|
|
3000
3107
|
const sessionId = _chunkJPDEKN5Mcjs.newCorrelationId.call(void 0, );
|
|
3001
3108
|
try {
|
|
3002
3109
|
client.sendSessionControl({
|
|
@@ -3017,7 +3124,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3017
3124
|
send(sync);
|
|
3018
3125
|
return Promise.resolve();
|
|
3019
3126
|
}
|
|
3020
|
-
_optionalChain([prepared, 'optionalAccess',
|
|
3127
|
+
_optionalChain([prepared, 'optionalAccess', _96 => _96.catch, 'call', _97 => _97(() => {
|
|
3021
3128
|
})]);
|
|
3022
3129
|
queued += 1;
|
|
3023
3130
|
const run = tail.then(async () => {
|
|
@@ -3036,7 +3143,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3036
3143
|
throw new (0, _chunkJPDEKN5Mcjs.ListeningAlreadyActiveError)("Listening is already active on this instance");
|
|
3037
3144
|
}
|
|
3038
3145
|
try {
|
|
3039
|
-
_optionalChain([onListen, 'optionalCall',
|
|
3146
|
+
_optionalChain([onListen, 'optionalCall', _98 => _98()]);
|
|
3040
3147
|
} catch (e17) {
|
|
3041
3148
|
}
|
|
3042
3149
|
const { GrpcStreamClient } = await Promise.resolve().then(() => _interopRequireWildcard(require("./stream-client-H2ES74FF.cjs")));
|
|
@@ -3054,17 +3161,17 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3054
3161
|
internals.onCompactionUpdate(conversationId, bundle);
|
|
3055
3162
|
},
|
|
3056
3163
|
onConversationState: (conversationId, messageCount) => {
|
|
3057
|
-
_optionalChain([onConversationState, 'optionalCall',
|
|
3164
|
+
_optionalChain([onConversationState, 'optionalCall', _99 => _99(conversationId, messageCount)]);
|
|
3058
3165
|
},
|
|
3059
3166
|
onStateChange: (state) => {
|
|
3060
3167
|
if (state !== "connected") openSessions.clear();
|
|
3061
3168
|
if (state === "reconnecting") {
|
|
3062
3169
|
reconnectAttempts += 1;
|
|
3063
|
-
_optionalChain([onReconnect, 'optionalCall',
|
|
3170
|
+
_optionalChain([onReconnect, 'optionalCall', _100 => _100(reconnectAttempts)]);
|
|
3064
3171
|
} else if (state === "disconnected") {
|
|
3065
|
-
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess',
|
|
3172
|
+
const stopped = _nullishCoalesce(_optionalChain([stream, 'optionalAccess', _101 => _101.lastError]), () => ( null));
|
|
3066
3173
|
const reason = stopped === null ? "stream disconnected" : `credit_stop:${_nullishCoalesce(stopped.reason, () => ( "unknown"))}`;
|
|
3067
|
-
_optionalChain([onDisconnect, 'optionalCall',
|
|
3174
|
+
_optionalChain([onDisconnect, 'optionalCall', _102 => _102(reason)]);
|
|
3068
3175
|
}
|
|
3069
3176
|
}
|
|
3070
3177
|
});
|
|
@@ -3074,7 +3181,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3074
3181
|
} catch (error) {
|
|
3075
3182
|
if (error instanceof _chunkJPDEKN5Mcjs.SynapError) throw error;
|
|
3076
3183
|
throw new (0, _chunkJPDEKN5Mcjs.SynapError)(
|
|
3077
|
-
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess',
|
|
3184
|
+
`Could not open the Synap anticipation stream: ${_nullishCoalesce(_optionalChain([error, 'optionalAccess', _103 => _103.message]), () => ( String(error)))}`,
|
|
3078
3185
|
{ cause: error }
|
|
3079
3186
|
);
|
|
3080
3187
|
}
|
|
@@ -3090,9 +3197,10 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3090
3197
|
await active.disconnect();
|
|
3091
3198
|
},
|
|
3092
3199
|
async end_session(conversationId) {
|
|
3093
|
-
const
|
|
3094
|
-
|
|
3095
|
-
|
|
3200
|
+
const openedAs = openSessionKey(conversationId);
|
|
3201
|
+
const sessionId = openedAs === void 0 ? void 0 : openSessions.get(openedAs);
|
|
3202
|
+
if (openedAs === void 0 || sessionId === void 0 || client === null) return;
|
|
3203
|
+
openSessions.delete(openedAs);
|
|
3096
3204
|
try {
|
|
3097
3205
|
client.sendSessionControl({
|
|
3098
3206
|
action: "end",
|
|
@@ -3129,7 +3237,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3129
3237
|
_nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( ""))
|
|
3130
3238
|
);
|
|
3131
3239
|
if (eventType === "user_message" || eventType === "assistant_message") {
|
|
3132
|
-
_optionalChain([onTurn, 'optionalCall',
|
|
3240
|
+
_optionalChain([onTurn, 'optionalCall', _104 => _104({
|
|
3133
3241
|
conversationId,
|
|
3134
3242
|
role: _nullishCoalesce(options.role, () => ( "user")),
|
|
3135
3243
|
content
|
|
@@ -3142,7 +3250,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3142
3250
|
conversation_id: _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( "")),
|
|
3143
3251
|
user_id: _nullishCoalesce(_nullishCoalesce(options.user_id, () => ( options.userId)), () => ( "")),
|
|
3144
3252
|
customer_id: _nullishCoalesce(_nullishCoalesce(options.customer_id, () => ( options.customerId)), () => ( "")),
|
|
3145
|
-
session_id: _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( openSessions.get(conversationId))), () => ( "")),
|
|
3253
|
+
session_id: _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(options.session_id, () => ( options.sessionId)), () => ( openSessions.get(_nullishCoalesce(openSessionKey(conversationId), () => ( ""))))), () => ( "")),
|
|
3146
3254
|
metadata: _nullishCoalesce(withAgentModel(metadata, agentModelOf(options), agentModel(), true), () => ( {})),
|
|
3147
3255
|
timestamp_ms: Date.now(),
|
|
3148
3256
|
tool_name: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")),
|
|
@@ -3161,8 +3269,8 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3161
3269
|
})()
|
|
3162
3270
|
});
|
|
3163
3271
|
};
|
|
3164
|
-
if (_optionalChain([parts, 'optionalAccess',
|
|
3165
|
-
const content = _optionalChain([parts, 'optionalAccess',
|
|
3272
|
+
if (_optionalChain([parts, 'optionalAccess', _105 => _105.kind]) !== "parts") {
|
|
3273
|
+
const content = _optionalChain([parts, 'optionalAccess', _106 => _106.kind]) === "text" ? parts.text : options.content;
|
|
3166
3274
|
return inOrder(null, emit, { content, metadata: _nullishCoalesce(options.metadata, () => ( {})) });
|
|
3167
3275
|
}
|
|
3168
3276
|
const prepared = (async () => {
|
|
@@ -3200,7 +3308,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3200
3308
|
async record_tool_result(options) {
|
|
3201
3309
|
const conversationId = _nullishCoalesce(_nullishCoalesce(options.conversation_id, () => ( options.conversationId)), () => ( ""));
|
|
3202
3310
|
if (conversationId) {
|
|
3203
|
-
_optionalChain([onToolResult, 'optionalCall',
|
|
3311
|
+
_optionalChain([onToolResult, 'optionalCall', _107 => _107({ conversationId, result: options.result, toolName: _nullishCoalesce(_nullishCoalesce(options.tool_name, () => ( options.toolName)), () => ( "")) })]);
|
|
3204
3312
|
}
|
|
3205
3313
|
await namespace.send_message({
|
|
3206
3314
|
content: "",
|
|
@@ -3255,7 +3363,7 @@ function createInstanceNamespace(credentials, cache, onTurn, fetchOrAgentModel,
|
|
|
3255
3363
|
}
|
|
3256
3364
|
|
|
3257
3365
|
// src/version.ts
|
|
3258
|
-
var SDK_VERSION = "0.
|
|
3366
|
+
var SDK_VERSION = "0.8.0";
|
|
3259
3367
|
|
|
3260
3368
|
// src/registry.ts
|
|
3261
3369
|
var instances = /* @__PURE__ */ new Map();
|
|
@@ -3363,6 +3471,7 @@ var ShortTermStore = class {
|
|
|
3363
3471
|
/** The entry, or null. Age-evicts on read, as Python does. */
|
|
3364
3472
|
get(conversationId) {
|
|
3365
3473
|
if (!conversationId) return null;
|
|
3474
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
3366
3475
|
const entry = this.#entries.get(conversationId);
|
|
3367
3476
|
if (entry === void 0) return null;
|
|
3368
3477
|
if (this.#now() - entry.lastActivityAt > this.#maxAgeMs) {
|
|
@@ -3391,6 +3500,7 @@ var ShortTermStore = class {
|
|
|
3391
3500
|
*/
|
|
3392
3501
|
appendTurn(conversationId, role, content, timestamp, confirmation = {}) {
|
|
3393
3502
|
if (!conversationId) return;
|
|
3503
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
3394
3504
|
const stamp = _nullishCoalesce(timestamp, () => ( new Date(this.#now()).toISOString()));
|
|
3395
3505
|
if (this.#archive !== null) {
|
|
3396
3506
|
try {
|
|
@@ -3424,6 +3534,7 @@ var ShortTermStore = class {
|
|
|
3424
3534
|
*/
|
|
3425
3535
|
noteServerCount(conversationId, count) {
|
|
3426
3536
|
if (!conversationId) return;
|
|
3537
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
3427
3538
|
const entry = this.#entries.get(conversationId);
|
|
3428
3539
|
if (entry !== void 0) this.#noteCount(entry, Number(count), 0);
|
|
3429
3540
|
}
|
|
@@ -3471,10 +3582,11 @@ var ShortTermStore = class {
|
|
|
3471
3582
|
applyCompaction(bundle) {
|
|
3472
3583
|
if (typeof bundle !== "object" || bundle === null) return;
|
|
3473
3584
|
const cc = _nullishCoalesce(bundle["conversation_context"], () => ( {}));
|
|
3474
|
-
const
|
|
3585
|
+
const rawConversationId = String(
|
|
3475
3586
|
_nullishCoalesce(_nullishCoalesce(_nullishCoalesce(cc["conversation_id"], () => ( bundle["anticipation_conversation_id"])), () => ( bundle["conversation_id"])), () => ( ""))
|
|
3476
3587
|
);
|
|
3477
|
-
if (!
|
|
3588
|
+
if (!rawConversationId) return;
|
|
3589
|
+
const conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, rawConversationId);
|
|
3478
3590
|
const endTs = parseIso(_nullishCoalesce(cc["end_timestamp"], () => ( cc["compacted_at"])));
|
|
3479
3591
|
const compactedAt = parseIso(cc["compacted_at"]);
|
|
3480
3592
|
const compactedCount = Number(_nullishCoalesce(cc["compacted_message_count"], () => ( 0))) || 0;
|
|
@@ -3539,6 +3651,7 @@ var ShortTermStore = class {
|
|
|
3539
3651
|
*/
|
|
3540
3652
|
reseed(conversationId, state) {
|
|
3541
3653
|
if (!conversationId) return;
|
|
3654
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
3542
3655
|
const entry = this.#entries.get(conversationId);
|
|
3543
3656
|
if (entry === void 0 || entry.shared) return;
|
|
3544
3657
|
entry.serverMessageCount = Math.max(
|
|
@@ -3555,7 +3668,7 @@ var ShortTermStore = class {
|
|
|
3555
3668
|
entry.synced = true;
|
|
3556
3669
|
}
|
|
3557
3670
|
invalidate(conversationId) {
|
|
3558
|
-
this.#entries.delete(conversationId);
|
|
3671
|
+
this.#entries.delete(_chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId));
|
|
3559
3672
|
}
|
|
3560
3673
|
clear() {
|
|
3561
3674
|
this.#entries.clear();
|
|
@@ -3609,7 +3722,7 @@ var TurnStore = (_class3 = class {
|
|
|
3609
3722
|
#conversations = /* @__PURE__ */ new Map();
|
|
3610
3723
|
#vectors = /* @__PURE__ */ new Map();
|
|
3611
3724
|
constructor(options = {}) {;_class3.prototype.__init7.call(this);
|
|
3612
|
-
this.limits = _nullishCoalesce(options.limits, () => ( { ...
|
|
3725
|
+
this.limits = _nullishCoalesce(options.limits, () => ( { ..._chunk6GHXJD7Lcjs.HISTORY_SEARCH.store_limits }));
|
|
3613
3726
|
this.#now = _nullishCoalesce(options.now, () => ( (() => Date.now() / 1e3)));
|
|
3614
3727
|
}
|
|
3615
3728
|
add(conversationId, role, content, timestamp, options = {}) {
|
|
@@ -3723,7 +3836,7 @@ var TurnStore = (_class3 = class {
|
|
|
3723
3836
|
}
|
|
3724
3837
|
/** Turns the server also holds: archived tool results are local only. Python: `count`. */
|
|
3725
3838
|
count(conversationId) {
|
|
3726
|
-
return (_nullishCoalesce(_optionalChain([this, 'access',
|
|
3839
|
+
return (_nullishCoalesce(_optionalChain([this, 'access', _108 => _108.#conversations, 'access', _109 => _109.get, 'call', _110 => _110(conversationId), 'optionalAccess', _111 => _111.turns]), () => ( []))).filter((t) => t.role !== "tool").length;
|
|
3727
3840
|
}
|
|
3728
3841
|
sizeBytes() {
|
|
3729
3842
|
let n2 = 0;
|
|
@@ -3753,11 +3866,11 @@ var TurnStore = (_class3 = class {
|
|
|
3753
3866
|
|
|
3754
3867
|
// src/cache/history-search.ts
|
|
3755
3868
|
var WORD_RE = /[\p{L}\p{N}\p{M}]+/gu;
|
|
3756
|
-
var FORMS = _nullishCoalesce(
|
|
3869
|
+
var FORMS = _nullishCoalesce(_chunk6GHXJD7Lcjs.HISTORY_SEARCH.irregular_forms, () => ( {}));
|
|
3757
3870
|
function tokenize2(text) {
|
|
3758
3871
|
const out = [];
|
|
3759
3872
|
for (const word of _nullishCoalesce((text || "").toLowerCase().match(WORD_RE), () => ( []))) {
|
|
3760
|
-
if (/^[\x00-\x7f]+$/.test(word)) out.push(...
|
|
3873
|
+
if (/^[\x00-\x7f]+$/.test(word)) out.push(..._chunk6GHXJD7Lcjs.tokenize.call(void 0, _nullishCoalesce(FORMS[word], () => ( word))));
|
|
3761
3874
|
else out.push(word);
|
|
3762
3875
|
}
|
|
3763
3876
|
return out;
|
|
@@ -3894,19 +4007,19 @@ function windowsOf(pieces, maxWords) {
|
|
|
3894
4007
|
}
|
|
3895
4008
|
function askedKinds(query) {
|
|
3896
4009
|
const out = [];
|
|
3897
|
-
for (const [name, spec] of Object.entries(_nullishCoalesce(
|
|
4010
|
+
for (const [name, spec] of Object.entries(_nullishCoalesce(_chunk6GHXJD7Lcjs.HISTORY_SEARCH.asked_kinds, () => ( {})))) {
|
|
3898
4011
|
if (name.startsWith("$") || typeof spec !== "object") continue;
|
|
3899
4012
|
if (new RegExp(spec.query, "i").test(_nullishCoalesce(query, () => ( "")))) out.push(new RegExp(spec.value));
|
|
3900
4013
|
}
|
|
3901
4014
|
return out;
|
|
3902
4015
|
}
|
|
3903
4016
|
function asksHowItStarted(query) {
|
|
3904
|
-
const spec =
|
|
3905
|
-
if (!_optionalChain([spec, 'optionalAccess',
|
|
4017
|
+
const spec = _chunk6GHXJD7Lcjs.HISTORY_SEARCH.early_query;
|
|
4018
|
+
if (!_optionalChain([spec, 'optionalAccess', _112 => _112.pattern])) return false;
|
|
3906
4019
|
return new RegExp(spec.pattern, (_nullishCoalesce(spec.flags, () => ( ""))).includes("i") ? "i" : "").test(_nullishCoalesce(query, () => ( "")));
|
|
3907
4020
|
}
|
|
3908
4021
|
async function searchTurns(turns, query, options = {}) {
|
|
3909
|
-
const params =
|
|
4022
|
+
const params = _chunk6GHXJD7Lcjs.HISTORY_SEARCH;
|
|
3910
4023
|
const k = params.max_excerpts;
|
|
3911
4024
|
const skip = new Set(_nullishCoalesce(options.exclude, () => ( [])));
|
|
3912
4025
|
const pool = turns.filter((t) => t.content && !skip.has(t.content) && !skip.has(_nullishCoalesce(t.message_id, () => ( ""))));
|
|
@@ -3933,7 +4046,7 @@ async function searchTurns(turns, query, options = {}) {
|
|
|
3933
4046
|
});
|
|
3934
4047
|
});
|
|
3935
4048
|
const docs = units.map((u) => tokenize2(u.content));
|
|
3936
|
-
const bm = new (0,
|
|
4049
|
+
const bm = new (0, _chunk6GHXJD7Lcjs.BM25)(docs);
|
|
3937
4050
|
const termList = [...terms];
|
|
3938
4051
|
const rows = units.map((turn, i) => {
|
|
3939
4052
|
const held = new Set(docs[i]);
|
|
@@ -4071,13 +4184,13 @@ async function embeddingRanks(pool, query, encoder, store, minCosine) {
|
|
|
4071
4184
|
}
|
|
4072
4185
|
function toolResultText(result, toolName) {
|
|
4073
4186
|
let text = typeof result === "string" ? result : _nullishCoalesce(JSON.stringify(result), () => ( String(result)));
|
|
4074
|
-
const limit = _nullishCoalesce(
|
|
4187
|
+
const limit = _nullishCoalesce(_chunk6GHXJD7Lcjs.HISTORY_SEARCH.tool_result_max_chars, () => ( 16e3));
|
|
4075
4188
|
if (text.length > limit) text = text.slice(0, limit) + " ...[cut]";
|
|
4076
4189
|
return `[tool result: ${toolName || "tool"}] ${text}`;
|
|
4077
4190
|
}
|
|
4078
4191
|
function renderExcerpts(excerpts, latest = "") {
|
|
4079
4192
|
if (excerpts.length === 0) return "";
|
|
4080
|
-
const lines = [
|
|
4193
|
+
const lines = [_chunk6GHXJD7Lcjs.HISTORY_SEARCH.heading];
|
|
4081
4194
|
for (const e of excerpts) {
|
|
4082
4195
|
let where = e.position ? `turn ${e.position}, ${e.role}` : `${e.role}, earlier`;
|
|
4083
4196
|
if (e.timestamp) {
|
|
@@ -4356,7 +4469,7 @@ var TurnCounter = class {
|
|
|
4356
4469
|
#counts = /* @__PURE__ */ new Map();
|
|
4357
4470
|
/** Increment and return the new count. Python buckets a missing id under `_global`. */
|
|
4358
4471
|
increment(conversationId) {
|
|
4359
|
-
const key = conversationId !== void 0 && conversationId !== "" ? conversationId : "_global";
|
|
4472
|
+
const key = conversationId !== void 0 && conversationId !== "" ? _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId) : "_global";
|
|
4360
4473
|
const next = (_nullishCoalesce(this.#counts.get(key), () => ( 0))) + 1;
|
|
4361
4474
|
this.#counts.set(key, next);
|
|
4362
4475
|
return next;
|
|
@@ -4369,7 +4482,7 @@ var TurnCounter = class {
|
|
|
4369
4482
|
* triggered a fresh retrieval anyway.
|
|
4370
4483
|
*/
|
|
4371
4484
|
shouldInject(conversationId) {
|
|
4372
|
-
const key = conversationId !== void 0 && conversationId !== "" ? conversationId : "_global";
|
|
4485
|
+
const key = conversationId !== void 0 && conversationId !== "" ? _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId) : "_global";
|
|
4373
4486
|
const count = _nullishCoalesce(this.#counts.get(key), () => ( 0));
|
|
4374
4487
|
return count > 0 && count % USER_SUMMARY_INTERVAL === 0;
|
|
4375
4488
|
}
|
|
@@ -5059,7 +5172,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5059
5172
|
this.#transport.onInvalidInput = (_error, carriedScopePath) => {
|
|
5060
5173
|
if (carriedScopePath) this.#transport.invalidateScopeLadder();
|
|
5061
5174
|
};
|
|
5062
|
-
this.#anticipationCache = new (0,
|
|
5175
|
+
this.#anticipationCache = new (0, _chunk6GHXJD7Lcjs.AnticipationCache)();
|
|
5063
5176
|
this.#fetchHooks = {
|
|
5064
5177
|
beforeFetch: async (scope, options2) => {
|
|
5065
5178
|
const o2 = options2;
|
|
@@ -5078,7 +5191,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5078
5191
|
// on entity and conversation alone, so a bundle prefetched for one
|
|
5079
5192
|
// rung answered a caller standing at another, entirely inside this
|
|
5080
5193
|
// process and invisible to every server log.
|
|
5081
|
-
scopeRung:
|
|
5194
|
+
scopeRung: _chunk6GHXJD7Lcjs.rungKey.call(void 0,
|
|
5082
5195
|
_nullishCoalesce(o2["scope_path"], () => ( o2["scopePath"]))
|
|
5083
5196
|
),
|
|
5084
5197
|
maxResultsPerQuery: _nullishCoalesce(_nullishCoalesce(o2["max_results_per_query"], () => ( o2["maxResultsPerQuery"])), () => ( null))
|
|
@@ -5091,7 +5204,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5091
5204
|
servedItemIds: servedItemIds(attempt.hit),
|
|
5092
5205
|
bundleId: _nullishCoalesce(attempt.hit.bundleIds[0], () => ( "")),
|
|
5093
5206
|
borderline: attempt.hit.band === "borderline",
|
|
5094
|
-
raceDeadlineMs:
|
|
5207
|
+
raceDeadlineMs: _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.race_deadline_ms
|
|
5095
5208
|
};
|
|
5096
5209
|
},
|
|
5097
5210
|
onAssembled: (scope, options2, response, startedAt) => {
|
|
@@ -5144,7 +5257,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5144
5257
|
response,
|
|
5145
5258
|
_nullishCoalesce(o2["conversation_id"], () => ( o2["conversationId"])),
|
|
5146
5259
|
owner,
|
|
5147
|
-
|
|
5260
|
+
_chunk6GHXJD7Lcjs.rungKey.call(void 0, _nullishCoalesce(o2["scope_path"], () => ( o2["scopePath"])))
|
|
5148
5261
|
);
|
|
5149
5262
|
}
|
|
5150
5263
|
};
|
|
@@ -5165,7 +5278,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5165
5278
|
this.#localEncoder = _nullishCoalesce(_nullishCoalesce(options.history_search_encoder, () => ( options.historySearchEncoder)), () => ( null));
|
|
5166
5279
|
const modelOption = options.history_search_model !== void 0 ? options.history_search_model : options.historySearchModel;
|
|
5167
5280
|
this.#localModelName = modelOption === void 0 ? "auto" : modelOption;
|
|
5168
|
-
if (_optionalChain([this, 'access',
|
|
5281
|
+
if (_optionalChain([this, 'access', _113 => _113.#localEncoder, 'optionalAccess', _114 => _114.model]) === _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(this.#localEncoder);
|
|
5169
5282
|
this.#turns = new TurnCounter();
|
|
5170
5283
|
this.conversation = createConversationNamespace(
|
|
5171
5284
|
this.#transport,
|
|
@@ -5191,7 +5304,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5191
5304
|
},
|
|
5192
5305
|
(response, conversationId, userId, scopePath) => {
|
|
5193
5306
|
overlayLocalRecentTurns(response, this.#shortTerm, conversationId, this.#stVerbatimOverlay);
|
|
5194
|
-
this.#injectUserSummary(response, conversationId, userId,
|
|
5307
|
+
this.#injectUserSummary(response, conversationId, userId, _chunk6GHXJD7Lcjs.rungKey.call(void 0, scopePath));
|
|
5195
5308
|
},
|
|
5196
5309
|
{
|
|
5197
5310
|
prompt: (conversationId, style) => this.#localPrompt(conversationId, style),
|
|
@@ -5216,7 +5329,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5216
5329
|
if (scope === "conversation") {
|
|
5217
5330
|
if (conversationId) {
|
|
5218
5331
|
this.#shortTerm.invalidate(conversationId);
|
|
5219
|
-
this.#turnStore.drop(conversationId);
|
|
5332
|
+
this.#turnStore.drop(_chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId));
|
|
5220
5333
|
cleared.push("short_term_context", "turns");
|
|
5221
5334
|
}
|
|
5222
5335
|
} else {
|
|
@@ -5407,7 +5520,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5407
5520
|
} catch (error) {
|
|
5408
5521
|
if (this.#localMode) {
|
|
5409
5522
|
throw new (0, _chunkJPDEKN5Mcjs.AuthenticationError)(
|
|
5410
|
-
`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',
|
|
5523
|
+
`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', _115 => _115.message]), () => ( String(error)))}).`,
|
|
5411
5524
|
{ cause: error }
|
|
5412
5525
|
);
|
|
5413
5526
|
}
|
|
@@ -5735,6 +5848,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5735
5848
|
async #withHistoryExcerpts(conversationId, response, query) {
|
|
5736
5849
|
const r = _nullishCoalesce(response, () => ( {}));
|
|
5737
5850
|
const store = this.#turnStore;
|
|
5851
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
5738
5852
|
const recent = Array.isArray(r["recent_messages"]) ? r["recent_messages"] : [];
|
|
5739
5853
|
store.addMany(
|
|
5740
5854
|
conversationId,
|
|
@@ -5746,14 +5860,14 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5746
5860
|
}))
|
|
5747
5861
|
);
|
|
5748
5862
|
const entry = this.#shortTerm.get(conversationId);
|
|
5749
|
-
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess',
|
|
5863
|
+
const total = Math.max(Number(_nullishCoalesce(r["total_message_count"], () => ( 0))) || 0, Number(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _116 => _116.serverMessageCount]), () => ( 0))) || 0);
|
|
5750
5864
|
this.#maybeBackfillTurns(conversationId, total);
|
|
5751
5865
|
if (!r["context_block"]) return response;
|
|
5752
5866
|
const turns = store.turns(conversationId);
|
|
5753
5867
|
let q = query;
|
|
5754
5868
|
if (!q) {
|
|
5755
5869
|
const latest = [...recent].reverse().find((m) => m["role"] === "user");
|
|
5756
|
-
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access',
|
|
5870
|
+
q = latest ? String(_nullishCoalesce(latest["content"], () => ( ""))) : _nullishCoalesce(_optionalChain([[...turns], 'access', _117 => _117.reverse, 'call', _118 => _118(), 'access', _119 => _119.find, 'call', _120 => _120((t) => t.role === "user"), 'optionalAccess', _121 => _121.content]), () => ( ""));
|
|
5757
5871
|
}
|
|
5758
5872
|
if (!q) return response;
|
|
5759
5873
|
const exclude = /* @__PURE__ */ new Set();
|
|
@@ -5782,7 +5896,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5782
5896
|
if (!conversationId || result === null || result === void 0) return;
|
|
5783
5897
|
try {
|
|
5784
5898
|
this.#turnStore.add(
|
|
5785
|
-
conversationId,
|
|
5899
|
+
_chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId),
|
|
5786
5900
|
"tool",
|
|
5787
5901
|
toolResultText(result, _nullishCoalesce(options.tool_name, () => ( options.toolName))),
|
|
5788
5902
|
_nullishCoalesce(options.timestamp, () => ( (/* @__PURE__ */ new Date()).toISOString()))
|
|
@@ -5801,17 +5915,18 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5801
5915
|
if (this.#localModelStarted) return;
|
|
5802
5916
|
this.#localModelStarted = true;
|
|
5803
5917
|
if (localModelOff()) return;
|
|
5804
|
-
const name = this.#localModelName === "auto" ?
|
|
5918
|
+
const name = this.#localModelName === "auto" ? _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.model : this.#localModelName;
|
|
5805
5919
|
if (!name) return;
|
|
5806
5920
|
const callerEncoder = this.#localEncoder;
|
|
5807
5921
|
void Promise.resolve().then(() => _interopRequireWildcard(require("./onnx-encoder-4RSL6ID4.cjs"))).then(({ canRunLocalModel, loadOnnxEncoder }) => canRunLocalModel() ? loadOnnxEncoder(name) : null).then((encoder) => {
|
|
5808
5922
|
if (encoder === null) return;
|
|
5809
5923
|
if (callerEncoder === null) this.#localEncoder = encoder;
|
|
5810
|
-
if (encoder.model ===
|
|
5924
|
+
if (encoder.model === _chunk6GHXJD7Lcjs.SEMANTIC_MATCH.model) this.#anticipationCache.setEncoder(encoder);
|
|
5811
5925
|
}).catch(() => {
|
|
5812
5926
|
});
|
|
5813
5927
|
}
|
|
5814
5928
|
#maybeBackfillTurns(conversationId, total) {
|
|
5929
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
5815
5930
|
if (total <= this.#turnStore.count(conversationId)) return;
|
|
5816
5931
|
const now = Date.now();
|
|
5817
5932
|
if (now < (_nullishCoalesce(this.#backfillAfter.get(conversationId), () => ( 0)))) return;
|
|
@@ -5819,6 +5934,7 @@ var SynapClient = (_class4 = class _SynapClient {
|
|
|
5819
5934
|
void this.#backfillTurns(conversationId, total);
|
|
5820
5935
|
}
|
|
5821
5936
|
async #backfillTurns(conversationId, total) {
|
|
5937
|
+
conversationId = _chunk6GHXJD7Lcjs.normalizeConversationId.call(void 0, conversationId);
|
|
5822
5938
|
try {
|
|
5823
5939
|
let start = 1;
|
|
5824
5940
|
while (start <= total) {
|
|
@@ -5897,7 +6013,7 @@ function pick3(o2, snake, camel) {
|
|
|
5897
6013
|
function resolveBaseUrl(options) {
|
|
5898
6014
|
const explicit = _nullishCoalesce(options.baseUrl, () => ( options.api_base_url));
|
|
5899
6015
|
if (explicit !== void 0) return explicit;
|
|
5900
|
-
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess',
|
|
6016
|
+
const fromEnv = _optionalChain([_chunkZKOJDUN4cjs.getEnv.call(void 0, "SYNAP_BASE_URL"), 'optionalAccess', _122 => _122.trim, 'call', _123 => _123()]);
|
|
5901
6017
|
return fromEnv !== void 0 && fromEnv !== "" ? fromEnv : void 0;
|
|
5902
6018
|
}
|
|
5903
6019
|
function resolveCredentials(options, localMode) {
|
|
@@ -5981,5 +6097,6 @@ function resolveCredentials(options, localMode) {
|
|
|
5981
6097
|
|
|
5982
6098
|
|
|
5983
6099
|
|
|
5984
|
-
|
|
6100
|
+
|
|
6101
|
+
exports.ANY_SCOPE = _chunk6GHXJD7Lcjs.ANY_SCOPE; exports.AgentUnavailableError = _chunkJPDEKN5Mcjs.AgentUnavailableError; exports.AnticipationCache = _chunk6GHXJD7Lcjs.AnticipationCache; exports.AuthenticationError = _chunkJPDEKN5Mcjs.AuthenticationError; exports.BM25 = _chunk6GHXJD7Lcjs.BM25; exports.COMPACTION_LEVELS = COMPACTION_LEVELS; exports.CONTRACT = _chunk6GHXJD7Lcjs.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.MAX_RESTORE_IDS = MAX_RESTORE_IDS; 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 = _chunk6GHXJD7Lcjs.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 = _chunk6GHXJD7Lcjs.stem; exports.textPart = textPart; exports.tokenize = _chunk6GHXJD7Lcjs.tokenize; exports.wireRankScore = wireRankScore;
|
|
5985
6102
|
//# sourceMappingURL=index.cjs.map
|