@anuma/sdk 6.15.1 → 6.16.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-TNMPAE3V.mjs → chunk-JXN7LD6B.mjs} +40 -16
- package/dist/expo/index.cjs +62 -30
- package/dist/expo/index.mjs +26 -16
- package/dist/expo/{recall-FJQTIMYT.mjs → recall-TGRI5MN4.mjs} +1 -1
- package/dist/react/{chunk-YSL3J4K4.mjs → chunk-TVPCH7ZZ.mjs} +44 -20
- package/dist/react/index.cjs +66 -34
- package/dist/react/index.mjs +26 -16
- package/dist/react/{recall-UVVZGRVF.mjs → recall-OKNLU335.mjs} +1 -1
- package/dist/server/{chunk-ARYSRI4Z.mjs → chunk-K7H7ICPK.mjs} +20 -20
- package/dist/server/index.cjs +19 -19
- package/dist/server/index.mjs +1 -1
- package/dist/server/{recall-OVSSDRYU.mjs → recall-YXJATOSD.mjs} +1 -1
- package/dist/telemetry/index.cjs +255 -0
- package/dist/telemetry/index.d.mts +578 -0
- package/dist/telemetry/index.d.ts +578 -0
- package/dist/telemetry/index.mjs +226 -0
- package/package.json +7 -1
package/dist/react/index.cjs
CHANGED
|
@@ -2220,6 +2220,29 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
2220
2220
|
}
|
|
2221
2221
|
return skeletons;
|
|
2222
2222
|
}
|
|
2223
|
+
async function getToolCallEventIdsOp(ctx, convId) {
|
|
2224
|
+
const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
2225
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2226
|
+
for (const raw of results) {
|
|
2227
|
+
const value = raw.tool_call_events;
|
|
2228
|
+
if (!value) continue;
|
|
2229
|
+
let events;
|
|
2230
|
+
if (typeof value === "string") {
|
|
2231
|
+
try {
|
|
2232
|
+
events = JSON.parse(value);
|
|
2233
|
+
} catch {
|
|
2234
|
+
continue;
|
|
2235
|
+
}
|
|
2236
|
+
} else if (Array.isArray(value)) {
|
|
2237
|
+
events = value;
|
|
2238
|
+
}
|
|
2239
|
+
if (!Array.isArray(events)) continue;
|
|
2240
|
+
for (const evt of events) {
|
|
2241
|
+
if (evt && evt.id) ids.add(evt.id);
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
return ids;
|
|
2245
|
+
}
|
|
2223
2246
|
async function clearMessagesOp(ctx, convId) {
|
|
2224
2247
|
const messages = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId)).fetch();
|
|
2225
2248
|
await ctx.database.write(async () => {
|
|
@@ -2449,14 +2472,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
2449
2472
|
if (covered !== content.length) return content;
|
|
2450
2473
|
return content.slice(start, end);
|
|
2451
2474
|
}
|
|
2452
|
-
async function
|
|
2453
|
-
const
|
|
2454
|
-
if (!
|
|
2455
|
-
if (walletAddress && isEncrypted(
|
|
2456
|
-
return await decryptJsonField(
|
|
2475
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
2476
|
+
const value = raw[column];
|
|
2477
|
+
if (!value) return void 0;
|
|
2478
|
+
if (walletAddress && isEncrypted(value)) {
|
|
2479
|
+
return await decryptJsonField(value, walletAddress);
|
|
2457
2480
|
}
|
|
2458
2481
|
try {
|
|
2459
|
-
return JSON.parse(
|
|
2482
|
+
return JSON.parse(value);
|
|
2460
2483
|
} catch {
|
|
2461
2484
|
return void 0;
|
|
2462
2485
|
}
|
|
@@ -2469,12 +2492,12 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2469
2492
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2470
2493
|
);
|
|
2471
2494
|
const queryConditions = conversationId ? [import_watermelondb.Q.where("conversation_id", conversationId)] : [];
|
|
2472
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2495
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2473
2496
|
const candidates = [];
|
|
2474
2497
|
for (const message of messages) {
|
|
2475
|
-
const msgConvId = String(message.
|
|
2498
|
+
const msgConvId = String(message.conversation_id);
|
|
2476
2499
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2477
|
-
const messageVector = await
|
|
2500
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2478
2501
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2479
2502
|
const similarity = cosineSimilarity(queryVector, messageVector);
|
|
2480
2503
|
if (similarity >= minSimilarity) {
|
|
@@ -2484,7 +2507,7 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2484
2507
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
2485
2508
|
return Promise.all(
|
|
2486
2509
|
topK.map(async ({ message, similarity }) => {
|
|
2487
|
-
const stored = await
|
|
2510
|
+
const stored = await messageRawToStored(
|
|
2488
2511
|
message,
|
|
2489
2512
|
ctx.walletAddress,
|
|
2490
2513
|
ctx.signMessage,
|
|
@@ -2508,21 +2531,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2508
2531
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2509
2532
|
);
|
|
2510
2533
|
const queryConditions = conversationId ? [import_watermelondb.Q.where("conversation_id", conversationId)] : [];
|
|
2511
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2534
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2512
2535
|
const candidates = [];
|
|
2513
2536
|
let staleSkipped = 0;
|
|
2514
2537
|
let unreadableVectors = 0;
|
|
2515
2538
|
for (const message of messages) {
|
|
2516
|
-
const msgConvId = String(message.
|
|
2539
|
+
const msgConvId = String(message.conversation_id);
|
|
2517
2540
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2518
2541
|
if (embeddingModel) {
|
|
2519
|
-
const storedModel = message.
|
|
2542
|
+
const storedModel = message.embedding_model;
|
|
2520
2543
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
2521
2544
|
staleSkipped++;
|
|
2522
2545
|
continue;
|
|
2523
2546
|
}
|
|
2524
2547
|
}
|
|
2525
|
-
const version = Number(message.
|
|
2548
|
+
const version = Number(message.updated_at) || 0;
|
|
2526
2549
|
const cached = chunkCache?.get(message.id);
|
|
2527
2550
|
if (cached && cached.version === version) {
|
|
2528
2551
|
if (cached.chunks.length > 0) {
|
|
@@ -2546,7 +2569,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2546
2569
|
}
|
|
2547
2570
|
continue;
|
|
2548
2571
|
}
|
|
2549
|
-
const chunks = await
|
|
2572
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
2550
2573
|
if (chunks && chunks.length > 0) {
|
|
2551
2574
|
const vectors = chunks.map(
|
|
2552
2575
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -2567,7 +2590,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2567
2590
|
}
|
|
2568
2591
|
}
|
|
2569
2592
|
} else {
|
|
2570
|
-
const messageVector = await
|
|
2593
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2571
2594
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2572
2595
|
const fallback = Float32Array.from(messageVector);
|
|
2573
2596
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -2593,7 +2616,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2593
2616
|
const storedById = new Map(
|
|
2594
2617
|
await Promise.all(
|
|
2595
2618
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
2596
|
-
const stored = await
|
|
2619
|
+
const stored = await messageRawToStored(
|
|
2597
2620
|
m,
|
|
2598
2621
|
ctx.walletAddress,
|
|
2599
2622
|
ctx.signMessage,
|
|
@@ -2611,8 +2634,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2611
2634
|
await Promise.all(
|
|
2612
2635
|
Array.from(needsChunkText, async (id) => {
|
|
2613
2636
|
const m = uniqueMessages.get(id);
|
|
2614
|
-
const parsed = await
|
|
2615
|
-
const version = Number(m.
|
|
2637
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
2638
|
+
const version = Number(m.updated_at) || 0;
|
|
2616
2639
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
2617
2640
|
})
|
|
2618
2641
|
);
|
|
@@ -23965,22 +23988,31 @@ function useChatStorage(options) {
|
|
|
23965
23988
|
}
|
|
23966
23989
|
})() : null;
|
|
23967
23990
|
let messagesToSend;
|
|
23968
|
-
const
|
|
23969
|
-
const knownToolCallEventIds = /* @__PURE__ */ new Set();
|
|
23970
|
-
for (const msg of storedMessages) {
|
|
23971
|
-
if (msg.toolCallEvents) {
|
|
23972
|
-
for (const evt of msg.toolCallEvents) {
|
|
23973
|
-
if (evt.id) knownToolCallEventIds.add(evt.id);
|
|
23974
|
-
}
|
|
23975
|
-
}
|
|
23976
|
-
}
|
|
23991
|
+
const knownToolCallEventIds = await getToolCallEventIdsOp(storageCtx, convId);
|
|
23977
23992
|
if (includeHistory) {
|
|
23978
|
-
|
|
23979
|
-
|
|
23980
|
-
|
|
23981
|
-
|
|
23982
|
-
|
|
23983
|
-
|
|
23993
|
+
let tail = [];
|
|
23994
|
+
let replayableMessages = [];
|
|
23995
|
+
let beforeMessageId;
|
|
23996
|
+
let boundaryExcludeUniqueIds;
|
|
23997
|
+
for (; ; ) {
|
|
23998
|
+
const page = await getMessagesPageOp(storageCtx, convId, {
|
|
23999
|
+
limit: maxHistoryMessages,
|
|
24000
|
+
beforeMessageId,
|
|
24001
|
+
boundaryExcludeUniqueIds
|
|
24002
|
+
});
|
|
24003
|
+
if (page.length === 0) break;
|
|
24004
|
+
tail = [...page, ...tail];
|
|
24005
|
+
const validMessages = tail.filter((msg) => !msg.error);
|
|
24006
|
+
replayableMessages = prepareToolResultsForReplay(validMessages, {
|
|
24007
|
+
fold: foldToolResultsInHistoryRef.current === true,
|
|
24008
|
+
exclude: toolResultsHistoryExcludeRef.current,
|
|
24009
|
+
placeholder: DISPLAY_CARD_PLACEHOLDER
|
|
24010
|
+
});
|
|
24011
|
+
if (replayableMessages.length >= maxHistoryMessages) break;
|
|
24012
|
+
if (page.length < maxHistoryMessages) break;
|
|
24013
|
+
beforeMessageId = page[0].messageId;
|
|
24014
|
+
boundaryExcludeUniqueIds = tail.filter((msg) => msg.messageId === beforeMessageId).map((msg) => msg.uniqueId);
|
|
24015
|
+
}
|
|
23984
24016
|
const limitedMessages = replayableMessages.slice(-maxHistoryMessages);
|
|
23985
24017
|
if (!fileContextForRequest) {
|
|
23986
24018
|
for (let i = limitedMessages.length - 1; i >= 0; i--) {
|
package/dist/react/index.mjs
CHANGED
|
@@ -111,6 +111,7 @@ import {
|
|
|
111
111
|
getMessageSkeletonsOp,
|
|
112
112
|
getMessagesOp,
|
|
113
113
|
getMessagesPageOp,
|
|
114
|
+
getToolCallEventIdsOp,
|
|
114
115
|
getToolCallEvents,
|
|
115
116
|
getToolsChecksum,
|
|
116
117
|
getUnfiledVaultMemoriesOp,
|
|
@@ -178,7 +179,7 @@ import {
|
|
|
178
179
|
updateVaultMemoryOp,
|
|
179
180
|
useEncryption,
|
|
180
181
|
vaultMemoryToStored
|
|
181
|
-
} from "./chunk-
|
|
182
|
+
} from "./chunk-TVPCH7ZZ.mjs";
|
|
182
183
|
import {
|
|
183
184
|
PiiRedactor,
|
|
184
185
|
createStreamingDeAnonymizer,
|
|
@@ -13691,22 +13692,31 @@ function useChatStorage(options) {
|
|
|
13691
13692
|
}
|
|
13692
13693
|
})() : null;
|
|
13693
13694
|
let messagesToSend;
|
|
13694
|
-
const
|
|
13695
|
-
const knownToolCallEventIds = /* @__PURE__ */ new Set();
|
|
13696
|
-
for (const msg of storedMessages) {
|
|
13697
|
-
if (msg.toolCallEvents) {
|
|
13698
|
-
for (const evt of msg.toolCallEvents) {
|
|
13699
|
-
if (evt.id) knownToolCallEventIds.add(evt.id);
|
|
13700
|
-
}
|
|
13701
|
-
}
|
|
13702
|
-
}
|
|
13695
|
+
const knownToolCallEventIds = await getToolCallEventIdsOp(storageCtx, convId);
|
|
13703
13696
|
if (includeHistory) {
|
|
13704
|
-
|
|
13705
|
-
|
|
13706
|
-
|
|
13707
|
-
|
|
13708
|
-
|
|
13709
|
-
|
|
13697
|
+
let tail = [];
|
|
13698
|
+
let replayableMessages = [];
|
|
13699
|
+
let beforeMessageId;
|
|
13700
|
+
let boundaryExcludeUniqueIds;
|
|
13701
|
+
for (; ; ) {
|
|
13702
|
+
const page = await getMessagesPageOp(storageCtx, convId, {
|
|
13703
|
+
limit: maxHistoryMessages,
|
|
13704
|
+
beforeMessageId,
|
|
13705
|
+
boundaryExcludeUniqueIds
|
|
13706
|
+
});
|
|
13707
|
+
if (page.length === 0) break;
|
|
13708
|
+
tail = [...page, ...tail];
|
|
13709
|
+
const validMessages = tail.filter((msg) => !msg.error);
|
|
13710
|
+
replayableMessages = prepareToolResultsForReplay(validMessages, {
|
|
13711
|
+
fold: foldToolResultsInHistoryRef.current === true,
|
|
13712
|
+
exclude: toolResultsHistoryExcludeRef.current,
|
|
13713
|
+
placeholder: DISPLAY_CARD_PLACEHOLDER
|
|
13714
|
+
});
|
|
13715
|
+
if (replayableMessages.length >= maxHistoryMessages) break;
|
|
13716
|
+
if (page.length < maxHistoryMessages) break;
|
|
13717
|
+
beforeMessageId = page[0].messageId;
|
|
13718
|
+
boundaryExcludeUniqueIds = tail.filter((msg) => msg.messageId === beforeMessageId).map((msg) => msg.uniqueId);
|
|
13719
|
+
}
|
|
13710
13720
|
const limitedMessages = replayableMessages.slice(-maxHistoryMessages);
|
|
13711
13721
|
if (!fileContextForRequest) {
|
|
13712
13722
|
for (let i = limitedMessages.length - 1; i >= 0; i--) {
|
|
@@ -16072,14 +16072,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
16072
16072
|
if (covered !== content.length) return content;
|
|
16073
16073
|
return content.slice(start, end);
|
|
16074
16074
|
}
|
|
16075
|
-
async function
|
|
16076
|
-
const
|
|
16077
|
-
if (!
|
|
16078
|
-
if (walletAddress && isEncrypted(
|
|
16079
|
-
return await decryptJsonField(
|
|
16075
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
16076
|
+
const value = raw[column];
|
|
16077
|
+
if (!value) return void 0;
|
|
16078
|
+
if (walletAddress && isEncrypted(value)) {
|
|
16079
|
+
return await decryptJsonField(value, walletAddress);
|
|
16080
16080
|
}
|
|
16081
16081
|
try {
|
|
16082
|
-
return JSON.parse(
|
|
16082
|
+
return JSON.parse(value);
|
|
16083
16083
|
} catch {
|
|
16084
16084
|
return void 0;
|
|
16085
16085
|
}
|
|
@@ -16092,12 +16092,12 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
16092
16092
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
16093
16093
|
);
|
|
16094
16094
|
const queryConditions = conversationId ? [import_watermelondb.Q.where("conversation_id", conversationId)] : [];
|
|
16095
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
16095
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
16096
16096
|
const candidates = [];
|
|
16097
16097
|
for (const message of messages) {
|
|
16098
|
-
const msgConvId = String(message.
|
|
16098
|
+
const msgConvId = String(message.conversation_id);
|
|
16099
16099
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
16100
|
-
const messageVector = await
|
|
16100
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
16101
16101
|
if (!messageVector || messageVector.length === 0) continue;
|
|
16102
16102
|
const similarity = cosineSimilarity(queryVector, messageVector);
|
|
16103
16103
|
if (similarity >= minSimilarity) {
|
|
@@ -16107,7 +16107,7 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
16107
16107
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
16108
16108
|
return Promise.all(
|
|
16109
16109
|
topK.map(async ({ message, similarity }) => {
|
|
16110
|
-
const stored = await
|
|
16110
|
+
const stored = await messageRawToStored(
|
|
16111
16111
|
message,
|
|
16112
16112
|
ctx.walletAddress,
|
|
16113
16113
|
ctx.signMessage,
|
|
@@ -16131,21 +16131,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16131
16131
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
16132
16132
|
);
|
|
16133
16133
|
const queryConditions = conversationId ? [import_watermelondb.Q.where("conversation_id", conversationId)] : [];
|
|
16134
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
16134
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
16135
16135
|
const candidates = [];
|
|
16136
16136
|
let staleSkipped = 0;
|
|
16137
16137
|
let unreadableVectors = 0;
|
|
16138
16138
|
for (const message of messages) {
|
|
16139
|
-
const msgConvId = String(message.
|
|
16139
|
+
const msgConvId = String(message.conversation_id);
|
|
16140
16140
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
16141
16141
|
if (embeddingModel) {
|
|
16142
|
-
const storedModel = message.
|
|
16142
|
+
const storedModel = message.embedding_model;
|
|
16143
16143
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
16144
16144
|
staleSkipped++;
|
|
16145
16145
|
continue;
|
|
16146
16146
|
}
|
|
16147
16147
|
}
|
|
16148
|
-
const version = Number(message.
|
|
16148
|
+
const version = Number(message.updated_at) || 0;
|
|
16149
16149
|
const cached = chunkCache?.get(message.id);
|
|
16150
16150
|
if (cached && cached.version === version) {
|
|
16151
16151
|
if (cached.chunks.length > 0) {
|
|
@@ -16169,7 +16169,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16169
16169
|
}
|
|
16170
16170
|
continue;
|
|
16171
16171
|
}
|
|
16172
|
-
const chunks = await
|
|
16172
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
16173
16173
|
if (chunks && chunks.length > 0) {
|
|
16174
16174
|
const vectors = chunks.map(
|
|
16175
16175
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -16190,7 +16190,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16190
16190
|
}
|
|
16191
16191
|
}
|
|
16192
16192
|
} else {
|
|
16193
|
-
const messageVector = await
|
|
16193
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
16194
16194
|
if (!messageVector || messageVector.length === 0) continue;
|
|
16195
16195
|
const fallback = Float32Array.from(messageVector);
|
|
16196
16196
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -16216,7 +16216,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16216
16216
|
const storedById = new Map(
|
|
16217
16217
|
await Promise.all(
|
|
16218
16218
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
16219
|
-
const stored = await
|
|
16219
|
+
const stored = await messageRawToStored(
|
|
16220
16220
|
m,
|
|
16221
16221
|
ctx.walletAddress,
|
|
16222
16222
|
ctx.signMessage,
|
|
@@ -16234,8 +16234,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16234
16234
|
await Promise.all(
|
|
16235
16235
|
Array.from(needsChunkText, async (id) => {
|
|
16236
16236
|
const m = uniqueMessages.get(id);
|
|
16237
|
-
const parsed = await
|
|
16238
|
-
const version = Number(m.
|
|
16237
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
16238
|
+
const version = Number(m.updated_at) || 0;
|
|
16239
16239
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
16240
16240
|
})
|
|
16241
16241
|
);
|
|
@@ -20923,7 +20923,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
20923
20923
|
subQueries = decomp.subQueries;
|
|
20924
20924
|
}
|
|
20925
20925
|
}
|
|
20926
|
-
const { recall: recall2 } = await import("./recall-
|
|
20926
|
+
const { recall: recall2 } = await import("./recall-YXJATOSD.mjs");
|
|
20927
20927
|
let recallDegraded = [];
|
|
20928
20928
|
const result = await recall2(
|
|
20929
20929
|
query,
|
package/dist/server/index.cjs
CHANGED
|
@@ -16830,14 +16830,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
16830
16830
|
if (covered !== content.length) return content;
|
|
16831
16831
|
return content.slice(start, end);
|
|
16832
16832
|
}
|
|
16833
|
-
async function
|
|
16834
|
-
const
|
|
16835
|
-
if (!
|
|
16836
|
-
if (walletAddress && isEncrypted(
|
|
16837
|
-
return await decryptJsonField(
|
|
16833
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
16834
|
+
const value = raw[column];
|
|
16835
|
+
if (!value) return void 0;
|
|
16836
|
+
if (walletAddress && isEncrypted(value)) {
|
|
16837
|
+
return await decryptJsonField(value, walletAddress);
|
|
16838
16838
|
}
|
|
16839
16839
|
try {
|
|
16840
|
-
return JSON.parse(
|
|
16840
|
+
return JSON.parse(value);
|
|
16841
16841
|
} catch {
|
|
16842
16842
|
return void 0;
|
|
16843
16843
|
}
|
|
@@ -16850,12 +16850,12 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
16850
16850
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
16851
16851
|
);
|
|
16852
16852
|
const queryConditions = conversationId ? [import_watermelondb14.Q.where("conversation_id", conversationId)] : [];
|
|
16853
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
16853
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
16854
16854
|
const candidates = [];
|
|
16855
16855
|
for (const message of messages) {
|
|
16856
|
-
const msgConvId = String(message.
|
|
16856
|
+
const msgConvId = String(message.conversation_id);
|
|
16857
16857
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
16858
|
-
const messageVector = await
|
|
16858
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
16859
16859
|
if (!messageVector || messageVector.length === 0) continue;
|
|
16860
16860
|
const similarity = cosineSimilarity(queryVector, messageVector);
|
|
16861
16861
|
if (similarity >= minSimilarity) {
|
|
@@ -16865,7 +16865,7 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
16865
16865
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
16866
16866
|
return Promise.all(
|
|
16867
16867
|
topK.map(async ({ message, similarity }) => {
|
|
16868
|
-
const stored = await
|
|
16868
|
+
const stored = await messageRawToStored(
|
|
16869
16869
|
message,
|
|
16870
16870
|
ctx.walletAddress,
|
|
16871
16871
|
ctx.signMessage,
|
|
@@ -16889,21 +16889,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16889
16889
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
16890
16890
|
);
|
|
16891
16891
|
const queryConditions = conversationId ? [import_watermelondb14.Q.where("conversation_id", conversationId)] : [];
|
|
16892
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
16892
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
16893
16893
|
const candidates = [];
|
|
16894
16894
|
let staleSkipped = 0;
|
|
16895
16895
|
let unreadableVectors = 0;
|
|
16896
16896
|
for (const message of messages) {
|
|
16897
|
-
const msgConvId = String(message.
|
|
16897
|
+
const msgConvId = String(message.conversation_id);
|
|
16898
16898
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
16899
16899
|
if (embeddingModel) {
|
|
16900
|
-
const storedModel = message.
|
|
16900
|
+
const storedModel = message.embedding_model;
|
|
16901
16901
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
16902
16902
|
staleSkipped++;
|
|
16903
16903
|
continue;
|
|
16904
16904
|
}
|
|
16905
16905
|
}
|
|
16906
|
-
const version = Number(message.
|
|
16906
|
+
const version = Number(message.updated_at) || 0;
|
|
16907
16907
|
const cached = chunkCache?.get(message.id);
|
|
16908
16908
|
if (cached && cached.version === version) {
|
|
16909
16909
|
if (cached.chunks.length > 0) {
|
|
@@ -16927,7 +16927,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16927
16927
|
}
|
|
16928
16928
|
continue;
|
|
16929
16929
|
}
|
|
16930
|
-
const chunks = await
|
|
16930
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
16931
16931
|
if (chunks && chunks.length > 0) {
|
|
16932
16932
|
const vectors = chunks.map(
|
|
16933
16933
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -16948,7 +16948,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16948
16948
|
}
|
|
16949
16949
|
}
|
|
16950
16950
|
} else {
|
|
16951
|
-
const messageVector = await
|
|
16951
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
16952
16952
|
if (!messageVector || messageVector.length === 0) continue;
|
|
16953
16953
|
const fallback = Float32Array.from(messageVector);
|
|
16954
16954
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -16974,7 +16974,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16974
16974
|
const storedById = new Map(
|
|
16975
16975
|
await Promise.all(
|
|
16976
16976
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
16977
|
-
const stored = await
|
|
16977
|
+
const stored = await messageRawToStored(
|
|
16978
16978
|
m,
|
|
16979
16979
|
ctx.walletAddress,
|
|
16980
16980
|
ctx.signMessage,
|
|
@@ -16992,8 +16992,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
16992
16992
|
await Promise.all(
|
|
16993
16993
|
Array.from(needsChunkText, async (id) => {
|
|
16994
16994
|
const m = uniqueMessages.get(id);
|
|
16995
|
-
const parsed = await
|
|
16996
|
-
const version = Number(m.
|
|
16995
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
16996
|
+
const version = Number(m.updated_at) || 0;
|
|
16997
16997
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
16998
16998
|
})
|
|
16999
16999
|
);
|
package/dist/server/index.mjs
CHANGED