@anuma/sdk 6.4.2 → 6.5.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/expo/{chunk-WYARTNEN.mjs → chunk-NCP3VGRX.mjs} +232 -7
- package/dist/expo/index.cjs +268 -153
- package/dist/expo/index.d.mts +163 -7
- package/dist/expo/index.d.ts +163 -7
- package/dist/expo/index.mjs +12 -148
- package/dist/expo/{recall-7FOWWX5T.mjs → recall-ISSI7RMD.mjs} +1 -1
- package/dist/index.cjs +71 -0
- package/dist/index.d.mts +121 -1
- package/dist/index.d.ts +121 -1
- package/dist/index.mjs +67 -0
- package/dist/react/{chunk-IO4ZCPK2.mjs → chunk-OB5HFCLB.mjs} +253 -7
- package/dist/react/index.cjs +293 -203
- package/dist/react/index.d.mts +163 -7
- package/dist/react/index.d.ts +163 -7
- package/dist/react/index.mjs +15 -196
- package/dist/react/{recall-2J2755WC.mjs → recall-DQJINKEY.mjs} +1 -1
- package/dist/server/{chunk-EKYGWD5N.mjs → chunk-BZEAYCBV.mjs} +97 -7
- package/dist/server/index.cjs +120 -45
- package/dist/server/index.d.mts +54 -6
- package/dist/server/index.d.ts +54 -6
- package/dist/server/index.mjs +3 -37
- package/dist/server/{recall-IVV6EILK.mjs → recall-CZFWWOVF.mjs} +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CHUNKS_DISCARDED_ORIGIN,
|
|
2
3
|
DEFAULT_API_EMBEDDING_MODEL,
|
|
3
4
|
DEFAULT_CHUNK_OVERLAP,
|
|
4
5
|
DEFAULT_CHUNK_SIZE,
|
|
5
6
|
DEFAULT_MIN_CHUNK_SIZE,
|
|
6
7
|
DEFAULT_MIN_CONTENT_LENGTH,
|
|
7
8
|
DEFAULT_VAULT_CACHE_SIZE,
|
|
9
|
+
DISPLAY_CARD_PLACEHOLDER,
|
|
8
10
|
EMBEDDINGS_DEGRADED_EMPTY,
|
|
9
11
|
ENTITY_FANOUT,
|
|
10
12
|
ENTITY_KINDS,
|
|
@@ -15,6 +17,7 @@ import {
|
|
|
15
17
|
RECALL_MAX_LIMIT,
|
|
16
18
|
RECALL_TOOL_NAME,
|
|
17
19
|
RerankerUnavailableError,
|
|
20
|
+
TOOL_RESULT_ORIGIN,
|
|
18
21
|
TOPICS_EXTRACTION_VERSION,
|
|
19
22
|
TREND_RECENT_WINDOW_DAYS,
|
|
20
23
|
TREND_STALE_WINDOW_DAYS,
|
|
@@ -23,6 +26,8 @@ import {
|
|
|
23
26
|
assertVaultScopeForSweep,
|
|
24
27
|
backfillMemoryEntityUserIdsOp,
|
|
25
28
|
backfillMemoryTopicsOp,
|
|
29
|
+
base64ToUint8Array,
|
|
30
|
+
buildToolResultContent,
|
|
26
31
|
capHopsForDensity,
|
|
27
32
|
chunkAndEmbedAllMessages,
|
|
28
33
|
chunkAndEmbedMessage,
|
|
@@ -47,6 +52,8 @@ import {
|
|
|
47
52
|
createVaultEmbeddingCache,
|
|
48
53
|
createVaultMemoriesBatchOp,
|
|
49
54
|
createVaultMemoryOp,
|
|
55
|
+
dataUrlToArrayBuffer,
|
|
56
|
+
decodeChunkVector,
|
|
50
57
|
decomposeQuery,
|
|
51
58
|
decryptData,
|
|
52
59
|
decryptDataBatch,
|
|
@@ -62,6 +69,7 @@ import {
|
|
|
62
69
|
eagerEmbedContent,
|
|
63
70
|
embedAllMessages,
|
|
64
71
|
embedMessage,
|
|
72
|
+
encodeChunkVector,
|
|
65
73
|
encryptData,
|
|
66
74
|
encryptDataBatch,
|
|
67
75
|
encryptDataBytes,
|
|
@@ -134,6 +142,7 @@ import {
|
|
|
134
142
|
postAuthOauthByProviderRefresh,
|
|
135
143
|
postAuthOauthByProviderRevoke,
|
|
136
144
|
preEmbedVaultMemories,
|
|
145
|
+
prepareToolResultsForReplay,
|
|
137
146
|
prepareVaultCandidates,
|
|
138
147
|
rankPreparedVaultCandidates,
|
|
139
148
|
recall,
|
|
@@ -156,6 +165,7 @@ import {
|
|
|
156
165
|
summarizeObservationTrends,
|
|
157
166
|
supersedeVaultMemoryOp,
|
|
158
167
|
traverseGraphLane,
|
|
168
|
+
uint8ArrayToBase64,
|
|
159
169
|
updateConversationPinnedOp,
|
|
160
170
|
updateConversationProjectOp,
|
|
161
171
|
updateConversationTitleOp,
|
|
@@ -168,7 +178,7 @@ import {
|
|
|
168
178
|
updateVaultMemoryOp,
|
|
169
179
|
useEncryption,
|
|
170
180
|
vaultMemoryToStored
|
|
171
|
-
} from "./chunk-
|
|
181
|
+
} from "./chunk-OB5HFCLB.mjs";
|
|
172
182
|
import {
|
|
173
183
|
PiiRedactor,
|
|
174
184
|
createStreamingDeAnonymizer,
|
|
@@ -5346,153 +5356,6 @@ async function cleanupConversationSummary(database, conversationId) {
|
|
|
5346
5356
|
}
|
|
5347
5357
|
}
|
|
5348
5358
|
|
|
5349
|
-
// src/lib/chat/toolResultMessage.ts
|
|
5350
|
-
var HEADER = "[Tool Execution Results]\n\n";
|
|
5351
|
-
var FOOTER = "\n\nBased on these results, continue with the task.";
|
|
5352
|
-
var ENTRY_SEPARATOR = "\n\n";
|
|
5353
|
-
var TOOL_RESULT_FOOTER_LINE = FOOTER.trim();
|
|
5354
|
-
var MAX_PERSISTED_TOOL_RESULT_CHARS = 1e5;
|
|
5355
|
-
function buildToolResultContent(results) {
|
|
5356
|
-
const entries = results.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`);
|
|
5357
|
-
const framing = HEADER.length + FOOTER.length + ENTRY_SEPARATOR.length * Math.max(0, entries.length - 1);
|
|
5358
|
-
const summary = capEntries(entries, MAX_PERSISTED_TOOL_RESULT_CHARS - framing).join(
|
|
5359
|
-
ENTRY_SEPARATOR
|
|
5360
|
-
);
|
|
5361
|
-
return `${HEADER}${summary}${FOOTER}`;
|
|
5362
|
-
}
|
|
5363
|
-
function capToolResultEntries(entries, budget) {
|
|
5364
|
-
return capEntries(entries, budget);
|
|
5365
|
-
}
|
|
5366
|
-
function capEntries(entries, budget) {
|
|
5367
|
-
const smallestFirst = entries.map((_, index) => index).sort((a, b) => entries[a].length - entries[b].length);
|
|
5368
|
-
const capped = [...entries];
|
|
5369
|
-
let remaining = budget;
|
|
5370
|
-
let unassigned = entries.length;
|
|
5371
|
-
for (const index of smallestFirst) {
|
|
5372
|
-
capped[index] = truncateEntry(entries[index], Math.floor(remaining / unassigned));
|
|
5373
|
-
remaining -= capped[index].length;
|
|
5374
|
-
unassigned--;
|
|
5375
|
-
}
|
|
5376
|
-
return capped;
|
|
5377
|
-
}
|
|
5378
|
-
function truncateEntry(entry, allowance) {
|
|
5379
|
-
if (entry.length <= allowance) return entry;
|
|
5380
|
-
const keep = allowance - truncationMarker(entry.length).length;
|
|
5381
|
-
if (keep <= 0) return entry.slice(0, Math.max(0, allowance));
|
|
5382
|
-
return `${entry.slice(0, keep)}${truncationMarker(entry.length - keep)}`;
|
|
5383
|
-
}
|
|
5384
|
-
function truncationMarker(omitted) {
|
|
5385
|
-
return `
|
|
5386
|
-
|
|
5387
|
-
... (tool output truncated, ${omitted} characters omitted)`;
|
|
5388
|
-
}
|
|
5389
|
-
|
|
5390
|
-
// src/lib/chat/toolResults.ts
|
|
5391
|
-
var TOOL_RESULTS_PREFIX = "[Tool Execution Results]";
|
|
5392
|
-
var DISPLAY_CARD_PLACEHOLDER = "[displayed a card to the user with the tool result]";
|
|
5393
|
-
var TOOL_LINE = /^Tool "([^"]+)" returned: (.*)$/;
|
|
5394
|
-
var TOOL_RESULT_ORIGIN = "tool_result";
|
|
5395
|
-
function isToolResultsRow(row) {
|
|
5396
|
-
if (row.origin === TOOL_RESULT_ORIGIN) return true;
|
|
5397
|
-
if (typeof row.origin === "string") return false;
|
|
5398
|
-
if (row.role !== "user" || !row.content.startsWith(TOOL_RESULTS_PREFIX)) return false;
|
|
5399
|
-
return parseToolResultSegments(row.content).length > 0;
|
|
5400
|
-
}
|
|
5401
|
-
function parseToolResultSegments(content) {
|
|
5402
|
-
const segments = [];
|
|
5403
|
-
for (const raw of content.split("\n")) {
|
|
5404
|
-
const line = raw.trim();
|
|
5405
|
-
const match = TOOL_LINE.exec(line);
|
|
5406
|
-
if (match) {
|
|
5407
|
-
segments.push({ name: match[1], line });
|
|
5408
|
-
continue;
|
|
5409
|
-
}
|
|
5410
|
-
const current = segments[segments.length - 1];
|
|
5411
|
-
if (!current || line === "" || line === TOOL_RESULT_FOOTER_LINE) continue;
|
|
5412
|
-
if (line === TOOL_RESULTS_PREFIX) continue;
|
|
5413
|
-
current.line = `${current.line}
|
|
5414
|
-
${line}`;
|
|
5415
|
-
}
|
|
5416
|
-
return segments;
|
|
5417
|
-
}
|
|
5418
|
-
function prepareToolResultsForReplay(rows, options) {
|
|
5419
|
-
if (options.fold) {
|
|
5420
|
-
return foldToolResultsRows(rows, {
|
|
5421
|
-
exclude: options.exclude,
|
|
5422
|
-
placeholder: options.placeholder
|
|
5423
|
-
});
|
|
5424
|
-
}
|
|
5425
|
-
return rows.filter((row) => !isToolResultsRow(row));
|
|
5426
|
-
}
|
|
5427
|
-
function foldToolResultsRows(rows, options) {
|
|
5428
|
-
const exclude = new Set(options?.exclude ?? []);
|
|
5429
|
-
const out = [];
|
|
5430
|
-
const pending = [];
|
|
5431
|
-
const assistantIndexById = /* @__PURE__ */ new Map();
|
|
5432
|
-
for (const row of rows) {
|
|
5433
|
-
if (isToolResultsRow(row)) {
|
|
5434
|
-
pending.push({ row, insertionPoint: out.length });
|
|
5435
|
-
continue;
|
|
5436
|
-
}
|
|
5437
|
-
out.push(row);
|
|
5438
|
-
if (row.role === "assistant" && row.uniqueId) {
|
|
5439
|
-
assistantIndexById.set(row.uniqueId, out.length - 1);
|
|
5440
|
-
}
|
|
5441
|
-
}
|
|
5442
|
-
const byTarget = /* @__PURE__ */ new Map();
|
|
5443
|
-
for (const { row, insertionPoint } of pending) {
|
|
5444
|
-
const target = resolveFoldTarget(out, row, insertionPoint, assistantIndexById);
|
|
5445
|
-
if (target === void 0) continue;
|
|
5446
|
-
const group = byTarget.get(target);
|
|
5447
|
-
if (group) group.push(row);
|
|
5448
|
-
else byTarget.set(target, [row]);
|
|
5449
|
-
}
|
|
5450
|
-
for (const [target, groupedRows] of byTarget) {
|
|
5451
|
-
const assistant = out[target];
|
|
5452
|
-
const kept = groupedRows.flatMap((row) => parseToolResultSegments(row.content)).filter((segment) => !exclude.has(segment.name));
|
|
5453
|
-
if (kept.length > 0) {
|
|
5454
|
-
out[target] = { ...assistant, content: appendToolResults(assistant.content, kept) };
|
|
5455
|
-
} else if (!assistant.content.trim() && options?.placeholder) {
|
|
5456
|
-
out[target] = { ...assistant, content: options.placeholder };
|
|
5457
|
-
}
|
|
5458
|
-
}
|
|
5459
|
-
return out;
|
|
5460
|
-
}
|
|
5461
|
-
function resolveFoldTarget(out, row, insertionPoint, assistantIndexById) {
|
|
5462
|
-
const linked = row.parentMessageId ? assistantIndexById.get(row.parentMessageId) : void 0;
|
|
5463
|
-
if (linked !== void 0) return linked;
|
|
5464
|
-
let previous;
|
|
5465
|
-
for (let i = insertionPoint - 1; i >= 0; i--) {
|
|
5466
|
-
if (out[i].role === "assistant") {
|
|
5467
|
-
previous = i;
|
|
5468
|
-
break;
|
|
5469
|
-
}
|
|
5470
|
-
}
|
|
5471
|
-
let next;
|
|
5472
|
-
for (let i = insertionPoint; i < out.length; i++) {
|
|
5473
|
-
if (out[i].role === "assistant") {
|
|
5474
|
-
next = i;
|
|
5475
|
-
break;
|
|
5476
|
-
}
|
|
5477
|
-
}
|
|
5478
|
-
if (previous === void 0) return next;
|
|
5479
|
-
if (next === void 0) return previous;
|
|
5480
|
-
return next - insertionPoint < insertionPoint - previous ? next : previous;
|
|
5481
|
-
}
|
|
5482
|
-
var MAX_FOLDED_APPENDIX_CHARS = 2e4;
|
|
5483
|
-
function appendToolResults(assistantContent, kept) {
|
|
5484
|
-
const framing = TOOL_RESULTS_PREFIX.length + 1 + (kept.length - 1);
|
|
5485
|
-
const capped = capToolResultEntries(
|
|
5486
|
-
kept.map((segment) => segment.line),
|
|
5487
|
-
MAX_FOLDED_APPENDIX_CHARS - framing
|
|
5488
|
-
);
|
|
5489
|
-
const appendix = `${TOOL_RESULTS_PREFIX}
|
|
5490
|
-
${capped.join("\n")}`;
|
|
5491
|
-
return assistantContent.trim() ? `${assistantContent}
|
|
5492
|
-
|
|
5493
|
-
${appendix}` : appendix;
|
|
5494
|
-
}
|
|
5495
|
-
|
|
5496
5359
|
// src/lib/db/chat/lazyDecrypt.ts
|
|
5497
5360
|
var LRU_CAPACITY = 256;
|
|
5498
5361
|
var titleCache = /* @__PURE__ */ new Map();
|
|
@@ -10456,54 +10319,6 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
|
|
|
10456
10319
|
};
|
|
10457
10320
|
}
|
|
10458
10321
|
|
|
10459
|
-
// src/lib/processors/encoding.ts
|
|
10460
|
-
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
10461
|
-
async function dataUrlToArrayBuffer(dataUrl) {
|
|
10462
|
-
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
10463
|
-
const response = await fetch(dataUrl);
|
|
10464
|
-
return response.arrayBuffer();
|
|
10465
|
-
}
|
|
10466
|
-
const base64 = dataUrl.split(",")[1];
|
|
10467
|
-
if (typeof Buffer !== "undefined") {
|
|
10468
|
-
const buf = Buffer.from(base64, "base64");
|
|
10469
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
10470
|
-
}
|
|
10471
|
-
const binary = atob(base64);
|
|
10472
|
-
const buffer = new ArrayBuffer(binary.length);
|
|
10473
|
-
const view = new Uint8Array(buffer);
|
|
10474
|
-
for (let i = 0; i < binary.length; i++) {
|
|
10475
|
-
view[i] = binary.charCodeAt(i);
|
|
10476
|
-
}
|
|
10477
|
-
return buffer;
|
|
10478
|
-
}
|
|
10479
|
-
function uint8ArrayToBase64(data) {
|
|
10480
|
-
if (typeof Buffer !== "undefined") {
|
|
10481
|
-
return Buffer.from(data).toString("base64");
|
|
10482
|
-
}
|
|
10483
|
-
let base64 = "";
|
|
10484
|
-
for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
|
|
10485
|
-
const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
|
|
10486
|
-
let binary = "";
|
|
10487
|
-
for (let j = 0; j < slice.length; j++) {
|
|
10488
|
-
binary += String.fromCharCode(slice[j]);
|
|
10489
|
-
}
|
|
10490
|
-
base64 += btoa(binary);
|
|
10491
|
-
}
|
|
10492
|
-
return base64;
|
|
10493
|
-
}
|
|
10494
|
-
function base64ToUint8Array(base64) {
|
|
10495
|
-
if (typeof Buffer !== "undefined") {
|
|
10496
|
-
const buf = Buffer.from(base64, "base64");
|
|
10497
|
-
return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
10498
|
-
}
|
|
10499
|
-
const binary = atob(base64);
|
|
10500
|
-
const bytes = new Uint8Array(binary.length);
|
|
10501
|
-
for (let i = 0; i < binary.length; i++) {
|
|
10502
|
-
bytes[i] = binary.charCodeAt(i);
|
|
10503
|
-
}
|
|
10504
|
-
return bytes;
|
|
10505
|
-
}
|
|
10506
|
-
|
|
10507
10322
|
// src/lib/processors/ExcelProcessor.ts
|
|
10508
10323
|
if (typeof process !== "undefined" && typeof process.umask !== "function") {
|
|
10509
10324
|
process.umask = (_mask) => 18;
|
|
@@ -25156,6 +24971,7 @@ export {
|
|
|
25156
24971
|
BUILT_IN_TOOL_SETS,
|
|
25157
24972
|
BackupAuthProvider,
|
|
25158
24973
|
BlobUrlManager,
|
|
24974
|
+
CHUNKS_DISCARDED_ORIGIN,
|
|
25159
24975
|
ChartCard,
|
|
25160
24976
|
ChartContainer,
|
|
25161
24977
|
ChartLegend,
|
|
@@ -25232,6 +25048,7 @@ export {
|
|
|
25232
25048
|
VaultMemory as StoredVaultMemoryModel,
|
|
25233
25049
|
StreamExpiredError,
|
|
25234
25050
|
THEME_ATTRS,
|
|
25051
|
+
TOOL_RESULT_ORIGIN,
|
|
25235
25052
|
TOPICS_EXTRACTION_VERSION,
|
|
25236
25053
|
TOPIC_EXTRACTION_BATCH_SIZE,
|
|
25237
25054
|
TREND_RECENT_WINDOW_DAYS,
|
|
@@ -25309,6 +25126,7 @@ export {
|
|
|
25309
25126
|
createVaultMemoryOp,
|
|
25310
25127
|
createWeatherPreProcessor,
|
|
25311
25128
|
createWebSearchPreProcessor,
|
|
25129
|
+
decodeChunkVector,
|
|
25312
25130
|
decryptConversationTitle,
|
|
25313
25131
|
decryptData,
|
|
25314
25132
|
decryptDataBatch,
|
|
@@ -25331,6 +25149,7 @@ export {
|
|
|
25331
25149
|
eagerEmbedContent,
|
|
25332
25150
|
embedAllMessages,
|
|
25333
25151
|
embedMessage,
|
|
25152
|
+
encodeChunkVector,
|
|
25334
25153
|
encryptData,
|
|
25335
25154
|
encryptDataBatch,
|
|
25336
25155
|
encryptDataBytes,
|
|
@@ -15115,6 +15115,77 @@ function cosineSimilarity(a, b) {
|
|
|
15115
15115
|
return denom === 0 ? 0 : dot / denom;
|
|
15116
15116
|
}
|
|
15117
15117
|
|
|
15118
|
+
// src/lib/processors/encoding.ts
|
|
15119
|
+
var B64_ENCODE_CHUNK = 32768 * 3;
|
|
15120
|
+
async function dataUrlToArrayBuffer(dataUrl) {
|
|
15121
|
+
if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
|
|
15122
|
+
const response = await fetch(dataUrl);
|
|
15123
|
+
return response.arrayBuffer();
|
|
15124
|
+
}
|
|
15125
|
+
const base64 = dataUrl.split(",")[1];
|
|
15126
|
+
if (typeof Buffer !== "undefined") {
|
|
15127
|
+
const buf = Buffer.from(base64, "base64");
|
|
15128
|
+
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
15129
|
+
}
|
|
15130
|
+
const binary = atob(base64);
|
|
15131
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
15132
|
+
const view = new Uint8Array(buffer);
|
|
15133
|
+
for (let i = 0; i < binary.length; i++) {
|
|
15134
|
+
view[i] = binary.charCodeAt(i);
|
|
15135
|
+
}
|
|
15136
|
+
return buffer;
|
|
15137
|
+
}
|
|
15138
|
+
function uint8ArrayToBase64(data) {
|
|
15139
|
+
if (typeof Buffer !== "undefined") {
|
|
15140
|
+
return Buffer.from(data).toString("base64");
|
|
15141
|
+
}
|
|
15142
|
+
let base64 = "";
|
|
15143
|
+
for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
|
|
15144
|
+
const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
|
|
15145
|
+
let binary = "";
|
|
15146
|
+
for (let j = 0; j < slice.length; j++) {
|
|
15147
|
+
binary += String.fromCharCode(slice[j]);
|
|
15148
|
+
}
|
|
15149
|
+
base64 += btoa(binary);
|
|
15150
|
+
}
|
|
15151
|
+
return base64;
|
|
15152
|
+
}
|
|
15153
|
+
function base64ToUint8Array(base64) {
|
|
15154
|
+
if (typeof Buffer !== "undefined") {
|
|
15155
|
+
const buf = Buffer.from(base64, "base64");
|
|
15156
|
+
return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
|
|
15157
|
+
}
|
|
15158
|
+
const binary = atob(base64);
|
|
15159
|
+
const bytes = new Uint8Array(binary.length);
|
|
15160
|
+
for (let i = 0; i < binary.length; i++) {
|
|
15161
|
+
bytes[i] = binary.charCodeAt(i);
|
|
15162
|
+
}
|
|
15163
|
+
return bytes;
|
|
15164
|
+
}
|
|
15165
|
+
|
|
15166
|
+
// src/lib/memoryEngine/vectorEncoding.ts
|
|
15167
|
+
var BYTES_PER_FLOAT32 = 4;
|
|
15168
|
+
var CANONICAL_BASE64 = /^[A-Za-z0-9+/]+={0,2}$/;
|
|
15169
|
+
function decodeChunkVector(vector, onMalformed) {
|
|
15170
|
+
if (!vector || vector.length === 0) return new Float32Array(0);
|
|
15171
|
+
if (typeof vector !== "string") return Float32Array.from(vector);
|
|
15172
|
+
if (vector.length % 4 !== 0 || !CANONICAL_BASE64.test(vector)) {
|
|
15173
|
+
onMalformed?.();
|
|
15174
|
+
return new Float32Array(0);
|
|
15175
|
+
}
|
|
15176
|
+
try {
|
|
15177
|
+
const bytes = base64ToUint8Array(vector);
|
|
15178
|
+
if (bytes.byteLength === 0 || bytes.byteLength % BYTES_PER_FLOAT32 !== 0) {
|
|
15179
|
+
onMalformed?.();
|
|
15180
|
+
return new Float32Array(0);
|
|
15181
|
+
}
|
|
15182
|
+
return new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / BYTES_PER_FLOAT32);
|
|
15183
|
+
} catch {
|
|
15184
|
+
onMalformed?.();
|
|
15185
|
+
return new Float32Array(0);
|
|
15186
|
+
}
|
|
15187
|
+
}
|
|
15188
|
+
|
|
15118
15189
|
// src/lib/db/encryption-utils.ts
|
|
15119
15190
|
var ENCRYPTION_PREFIX = "enc:v3:";
|
|
15120
15191
|
function isEncrypted(value) {
|
|
@@ -16052,6 +16123,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16052
16123
|
const messages = await ctx.messagesCollection.query(...queryConditions).fetch();
|
|
16053
16124
|
const candidates = [];
|
|
16054
16125
|
let staleSkipped = 0;
|
|
16126
|
+
let unreadableVectors = 0;
|
|
16055
16127
|
for (const message of messages) {
|
|
16056
16128
|
const msgConvId = String(message._getRaw("conversation_id"));
|
|
16057
16129
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
@@ -16089,7 +16161,9 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16089
16161
|
const chunks = await readJsonField(message, "chunks", ctx.walletAddress);
|
|
16090
16162
|
if (chunks && chunks.length > 0) {
|
|
16091
16163
|
const vectors = chunks.map(
|
|
16092
|
-
(chunk) => chunk.vector
|
|
16164
|
+
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
16165
|
+
unreadableVectors++;
|
|
16166
|
+
})
|
|
16093
16167
|
);
|
|
16094
16168
|
chunkCache?.set(message.id, { version, chunks: vectors });
|
|
16095
16169
|
for (let ci = 0; ci < chunks.length; ci++) {
|
|
@@ -16120,6 +16194,11 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16120
16194
|
`searchChunksOp: skipped ${staleSkipped} messages whose embedding model differs from the current model (${embeddingModel}) \u2014 re-embed via chunkAndEmbedAllMessages`
|
|
16121
16195
|
);
|
|
16122
16196
|
}
|
|
16197
|
+
if (unreadableVectors > 0) {
|
|
16198
|
+
getLogger().warn(
|
|
16199
|
+
`searchChunksOp: could not read ${unreadableVectors} chunk vectors and left them out of ranking \u2014 the stored value is corrupt, so those chunks stay unsearchable until the message is re-embedded via chunkAndEmbedAllMessages`
|
|
16200
|
+
);
|
|
16201
|
+
}
|
|
16123
16202
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
16124
16203
|
const uniqueMessages = /* @__PURE__ */ new Map();
|
|
16125
16204
|
for (const c of topK) uniqueMessages.set(c.message.id, c.message);
|
|
@@ -17695,6 +17774,9 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
|
|
|
17695
17774
|
// src/lib/memoryEngine/constants.ts
|
|
17696
17775
|
var DEFAULT_API_EMBEDDING_MODEL = "qwen/qwen3-embedding-8b";
|
|
17697
17776
|
|
|
17777
|
+
// src/lib/chat/toolResults.ts
|
|
17778
|
+
var TOOL_RESULT_ORIGIN = "tool_result";
|
|
17779
|
+
|
|
17698
17780
|
// src/lib/memoryEngine/chunking.ts
|
|
17699
17781
|
var DEFAULT_CHUNK_SIZE = 400;
|
|
17700
17782
|
var DEFAULT_CHUNK_OVERLAP = 50;
|
|
@@ -18820,7 +18902,13 @@ async function generateEmbeddings(texts, options) {
|
|
|
18820
18902
|
|
|
18821
18903
|
// src/lib/memoryEngine/embeddings.ts
|
|
18822
18904
|
var DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
18823
|
-
var
|
|
18905
|
+
var CHUNKS_DISCARDED_ORIGIN = "chunks_discarded";
|
|
18906
|
+
var NON_EMBEDDABLE_ORIGINS = /* @__PURE__ */ new Set([TOOL_RESULT_ORIGIN, CHUNKS_DISCARDED_ORIGIN]);
|
|
18907
|
+
function isNonEmbeddableOrigin(origin, reembedDiscarded = false) {
|
|
18908
|
+
if (typeof origin !== "string") return false;
|
|
18909
|
+
if (reembedDiscarded && origin === CHUNKS_DISCARDED_ORIGIN) return false;
|
|
18910
|
+
return NON_EMBEDDABLE_ORIGINS.has(origin);
|
|
18911
|
+
}
|
|
18824
18912
|
async function embedMessage(ctx, messageId, options) {
|
|
18825
18913
|
const message = await getMessageOp(ctx, messageId);
|
|
18826
18914
|
if (!message) {
|
|
@@ -18829,7 +18917,7 @@ async function embedMessage(ctx, messageId, options) {
|
|
|
18829
18917
|
if (message.vector && message.vector.length > 0) {
|
|
18830
18918
|
return message;
|
|
18831
18919
|
}
|
|
18832
|
-
if (message.origin
|
|
18920
|
+
if (isNonEmbeddableOrigin(message.origin)) {
|
|
18833
18921
|
return message;
|
|
18834
18922
|
}
|
|
18835
18923
|
if (isEncrypted(message.content)) {
|
|
@@ -18865,7 +18953,7 @@ async function embedAllMessages(ctx, options, filter) {
|
|
|
18865
18953
|
if (message.role === "system") {
|
|
18866
18954
|
continue;
|
|
18867
18955
|
}
|
|
18868
|
-
if (message.origin
|
|
18956
|
+
if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) {
|
|
18869
18957
|
continue;
|
|
18870
18958
|
}
|
|
18871
18959
|
considered++;
|
|
@@ -18905,7 +18993,7 @@ async function chunkAndEmbedMessage(ctx, messageId, options) {
|
|
|
18905
18993
|
if (message.chunks && message.chunks.length > 0) {
|
|
18906
18994
|
return message;
|
|
18907
18995
|
}
|
|
18908
|
-
if (message.origin
|
|
18996
|
+
if (isNonEmbeddableOrigin(message.origin)) {
|
|
18909
18997
|
return message;
|
|
18910
18998
|
}
|
|
18911
18999
|
if (isEncrypted(message.content)) {
|
|
@@ -18953,7 +19041,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
18953
19041
|
if (hasVector && !filter?.rechunkExisting && !isStale) continue;
|
|
18954
19042
|
if (filter?.roles && !filter.roles.includes(message.role)) continue;
|
|
18955
19043
|
if (message.role === "system") continue;
|
|
18956
|
-
if (message.origin
|
|
19044
|
+
if (isNonEmbeddableOrigin(message.origin, filter?.reembedDiscarded)) continue;
|
|
18957
19045
|
considered++;
|
|
18958
19046
|
if (isEncrypted(message.content)) {
|
|
18959
19047
|
stillEncrypted++;
|
|
@@ -20757,7 +20845,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
20757
20845
|
subQueries = decomp.subQueries;
|
|
20758
20846
|
}
|
|
20759
20847
|
}
|
|
20760
|
-
const { recall: recall2 } = await import("./recall-
|
|
20848
|
+
const { recall: recall2 } = await import("./recall-CZFWWOVF.mjs");
|
|
20761
20849
|
let recallDegraded = [];
|
|
20762
20850
|
const result = await recall2(
|
|
20763
20851
|
query,
|
|
@@ -21746,6 +21834,8 @@ export {
|
|
|
21746
21834
|
encryptJsonField,
|
|
21747
21835
|
decryptJsonField,
|
|
21748
21836
|
cosineSimilarity,
|
|
21837
|
+
dataUrlToArrayBuffer,
|
|
21838
|
+
uint8ArrayToBase64,
|
|
21749
21839
|
stripToolCalls,
|
|
21750
21840
|
generateConversationId,
|
|
21751
21841
|
conversationToStoredRaw,
|