@anuma/sdk 6.15.1 → 6.15.2
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/package.json +1 -1
|
@@ -1680,6 +1680,29 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
1680
1680
|
}
|
|
1681
1681
|
return skeletons;
|
|
1682
1682
|
}
|
|
1683
|
+
async function getToolCallEventIdsOp(ctx, convId) {
|
|
1684
|
+
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
1685
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1686
|
+
for (const raw of results) {
|
|
1687
|
+
const value = raw.tool_call_events;
|
|
1688
|
+
if (!value) continue;
|
|
1689
|
+
let events;
|
|
1690
|
+
if (typeof value === "string") {
|
|
1691
|
+
try {
|
|
1692
|
+
events = JSON.parse(value);
|
|
1693
|
+
} catch {
|
|
1694
|
+
continue;
|
|
1695
|
+
}
|
|
1696
|
+
} else if (Array.isArray(value)) {
|
|
1697
|
+
events = value;
|
|
1698
|
+
}
|
|
1699
|
+
if (!Array.isArray(events)) continue;
|
|
1700
|
+
for (const evt of events) {
|
|
1701
|
+
if (evt && evt.id) ids.add(evt.id);
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
return ids;
|
|
1705
|
+
}
|
|
1683
1706
|
async function clearMessagesOp(ctx, convId) {
|
|
1684
1707
|
const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
|
|
1685
1708
|
await ctx.database.write(async () => {
|
|
@@ -1918,14 +1941,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
1918
1941
|
if (covered !== content.length) return content;
|
|
1919
1942
|
return content.slice(start, end);
|
|
1920
1943
|
}
|
|
1921
|
-
async function
|
|
1922
|
-
const
|
|
1923
|
-
if (!
|
|
1924
|
-
if (walletAddress && isEncrypted(
|
|
1925
|
-
return await decryptJsonField(
|
|
1944
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
1945
|
+
const value = raw[column];
|
|
1946
|
+
if (!value) return void 0;
|
|
1947
|
+
if (walletAddress && isEncrypted(value)) {
|
|
1948
|
+
return await decryptJsonField(value, walletAddress);
|
|
1926
1949
|
}
|
|
1927
1950
|
try {
|
|
1928
|
-
return JSON.parse(
|
|
1951
|
+
return JSON.parse(value);
|
|
1929
1952
|
} catch {
|
|
1930
1953
|
return void 0;
|
|
1931
1954
|
}
|
|
@@ -1944,21 +1967,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
1944
1967
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
1945
1968
|
);
|
|
1946
1969
|
const queryConditions = conversationId ? [Q.where("conversation_id", conversationId)] : [];
|
|
1947
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
1970
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
1948
1971
|
const candidates = [];
|
|
1949
1972
|
let staleSkipped = 0;
|
|
1950
1973
|
let unreadableVectors = 0;
|
|
1951
1974
|
for (const message of messages) {
|
|
1952
|
-
const msgConvId = String(message.
|
|
1975
|
+
const msgConvId = String(message.conversation_id);
|
|
1953
1976
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
1954
1977
|
if (embeddingModel) {
|
|
1955
|
-
const storedModel = message.
|
|
1978
|
+
const storedModel = message.embedding_model;
|
|
1956
1979
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
1957
1980
|
staleSkipped++;
|
|
1958
1981
|
continue;
|
|
1959
1982
|
}
|
|
1960
1983
|
}
|
|
1961
|
-
const version = Number(message.
|
|
1984
|
+
const version = Number(message.updated_at) || 0;
|
|
1962
1985
|
const cached = chunkCache?.get(message.id);
|
|
1963
1986
|
if (cached && cached.version === version) {
|
|
1964
1987
|
if (cached.chunks.length > 0) {
|
|
@@ -1982,7 +2005,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
1982
2005
|
}
|
|
1983
2006
|
continue;
|
|
1984
2007
|
}
|
|
1985
|
-
const chunks = await
|
|
2008
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
1986
2009
|
if (chunks && chunks.length > 0) {
|
|
1987
2010
|
const vectors = chunks.map(
|
|
1988
2011
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -2003,7 +2026,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2003
2026
|
}
|
|
2004
2027
|
}
|
|
2005
2028
|
} else {
|
|
2006
|
-
const messageVector = await
|
|
2029
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2007
2030
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2008
2031
|
const fallback = Float32Array.from(messageVector);
|
|
2009
2032
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -2029,7 +2052,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2029
2052
|
const storedById = new Map(
|
|
2030
2053
|
await Promise.all(
|
|
2031
2054
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
2032
|
-
const stored = await
|
|
2055
|
+
const stored = await messageRawToStored(
|
|
2033
2056
|
m,
|
|
2034
2057
|
ctx.walletAddress,
|
|
2035
2058
|
ctx.signMessage,
|
|
@@ -2047,8 +2070,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2047
2070
|
await Promise.all(
|
|
2048
2071
|
Array.from(needsChunkText, async (id) => {
|
|
2049
2072
|
const m = uniqueMessages.get(id);
|
|
2050
|
-
const parsed = await
|
|
2051
|
-
const version = Number(m.
|
|
2073
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
2074
|
+
const version = Number(m.updated_at) || 0;
|
|
2052
2075
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
2053
2076
|
})
|
|
2054
2077
|
);
|
|
@@ -6885,7 +6908,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
6885
6908
|
subQueries = decomp.subQueries;
|
|
6886
6909
|
}
|
|
6887
6910
|
}
|
|
6888
|
-
const { recall: recall2 } = await import("./recall-
|
|
6911
|
+
const { recall: recall2 } = await import("./recall-TGRI5MN4.mjs");
|
|
6889
6912
|
let recallDegraded = [];
|
|
6890
6913
|
const result = await recall2(
|
|
6891
6914
|
query,
|
|
@@ -7889,6 +7912,7 @@ export {
|
|
|
7889
7912
|
getMessageCountOp,
|
|
7890
7913
|
getMessagesPageOp,
|
|
7891
7914
|
getMessageSkeletonsOp,
|
|
7915
|
+
getToolCallEventIdsOp,
|
|
7892
7916
|
clearMessagesOp,
|
|
7893
7917
|
createMessageOp,
|
|
7894
7918
|
upsertMessageOp,
|
package/dist/expo/index.cjs
CHANGED
|
@@ -1963,6 +1963,29 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
1963
1963
|
}
|
|
1964
1964
|
return skeletons;
|
|
1965
1965
|
}
|
|
1966
|
+
async function getToolCallEventIdsOp(ctx, convId) {
|
|
1967
|
+
const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
1968
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1969
|
+
for (const raw of results) {
|
|
1970
|
+
const value = raw.tool_call_events;
|
|
1971
|
+
if (!value) continue;
|
|
1972
|
+
let events;
|
|
1973
|
+
if (typeof value === "string") {
|
|
1974
|
+
try {
|
|
1975
|
+
events = JSON.parse(value);
|
|
1976
|
+
} catch {
|
|
1977
|
+
continue;
|
|
1978
|
+
}
|
|
1979
|
+
} else if (Array.isArray(value)) {
|
|
1980
|
+
events = value;
|
|
1981
|
+
}
|
|
1982
|
+
if (!Array.isArray(events)) continue;
|
|
1983
|
+
for (const evt of events) {
|
|
1984
|
+
if (evt && evt.id) ids.add(evt.id);
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return ids;
|
|
1988
|
+
}
|
|
1966
1989
|
async function clearMessagesOp(ctx, convId) {
|
|
1967
1990
|
const messages = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId)).fetch();
|
|
1968
1991
|
await ctx.database.write(async () => {
|
|
@@ -2201,14 +2224,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
2201
2224
|
if (covered !== content.length) return content;
|
|
2202
2225
|
return content.slice(start, end);
|
|
2203
2226
|
}
|
|
2204
|
-
async function
|
|
2205
|
-
const
|
|
2206
|
-
if (!
|
|
2207
|
-
if (walletAddress && isEncrypted(
|
|
2208
|
-
return await decryptJsonField(
|
|
2227
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
2228
|
+
const value = raw[column];
|
|
2229
|
+
if (!value) return void 0;
|
|
2230
|
+
if (walletAddress && isEncrypted(value)) {
|
|
2231
|
+
return await decryptJsonField(value, walletAddress);
|
|
2209
2232
|
}
|
|
2210
2233
|
try {
|
|
2211
|
-
return JSON.parse(
|
|
2234
|
+
return JSON.parse(value);
|
|
2212
2235
|
} catch {
|
|
2213
2236
|
return void 0;
|
|
2214
2237
|
}
|
|
@@ -2227,21 +2250,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2227
2250
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2228
2251
|
);
|
|
2229
2252
|
const queryConditions = conversationId ? [import_watermelondb.Q.where("conversation_id", conversationId)] : [];
|
|
2230
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2253
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2231
2254
|
const candidates = [];
|
|
2232
2255
|
let staleSkipped = 0;
|
|
2233
2256
|
let unreadableVectors = 0;
|
|
2234
2257
|
for (const message of messages) {
|
|
2235
|
-
const msgConvId = String(message.
|
|
2258
|
+
const msgConvId = String(message.conversation_id);
|
|
2236
2259
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2237
2260
|
if (embeddingModel) {
|
|
2238
|
-
const storedModel = message.
|
|
2261
|
+
const storedModel = message.embedding_model;
|
|
2239
2262
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
2240
2263
|
staleSkipped++;
|
|
2241
2264
|
continue;
|
|
2242
2265
|
}
|
|
2243
2266
|
}
|
|
2244
|
-
const version = Number(message.
|
|
2267
|
+
const version = Number(message.updated_at) || 0;
|
|
2245
2268
|
const cached = chunkCache?.get(message.id);
|
|
2246
2269
|
if (cached && cached.version === version) {
|
|
2247
2270
|
if (cached.chunks.length > 0) {
|
|
@@ -2265,7 +2288,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2265
2288
|
}
|
|
2266
2289
|
continue;
|
|
2267
2290
|
}
|
|
2268
|
-
const chunks = await
|
|
2291
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
2269
2292
|
if (chunks && chunks.length > 0) {
|
|
2270
2293
|
const vectors = chunks.map(
|
|
2271
2294
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -2286,7 +2309,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2286
2309
|
}
|
|
2287
2310
|
}
|
|
2288
2311
|
} else {
|
|
2289
|
-
const messageVector = await
|
|
2312
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2290
2313
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2291
2314
|
const fallback = Float32Array.from(messageVector);
|
|
2292
2315
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -2312,7 +2335,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2312
2335
|
const storedById = new Map(
|
|
2313
2336
|
await Promise.all(
|
|
2314
2337
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
2315
|
-
const stored = await
|
|
2338
|
+
const stored = await messageRawToStored(
|
|
2316
2339
|
m,
|
|
2317
2340
|
ctx.walletAddress,
|
|
2318
2341
|
ctx.signMessage,
|
|
@@ -2330,8 +2353,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2330
2353
|
await Promise.all(
|
|
2331
2354
|
Array.from(needsChunkText, async (id) => {
|
|
2332
2355
|
const m = uniqueMessages.get(id);
|
|
2333
|
-
const parsed = await
|
|
2334
|
-
const version = Number(m.
|
|
2356
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
2357
|
+
const version = Number(m.updated_at) || 0;
|
|
2335
2358
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
2336
2359
|
})
|
|
2337
2360
|
);
|
|
@@ -21328,22 +21351,31 @@ function useChatStorage(options) {
|
|
|
21328
21351
|
const serverToolsPromise = getTokenRef.current && !(Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) ? fetchServerToolsSettled(getTokenRef.current) : null;
|
|
21329
21352
|
const userMessageEmbeddingPromise = getTokenRef.current && contentForStorage.length >= MIN_CONTENT_LENGTH_FOR_TOOLS && (isServerToolsFunction && !(serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") || !!clientTools?.length) ? embedForToolsSettled(getTokenRef.current) : null;
|
|
21330
21353
|
let messagesToSend;
|
|
21331
|
-
const
|
|
21332
|
-
const knownToolCallEventIds = /* @__PURE__ */ new Set();
|
|
21333
|
-
for (const msg of storedMessages) {
|
|
21334
|
-
if (msg.toolCallEvents) {
|
|
21335
|
-
for (const evt of msg.toolCallEvents) {
|
|
21336
|
-
if (evt.id) knownToolCallEventIds.add(evt.id);
|
|
21337
|
-
}
|
|
21338
|
-
}
|
|
21339
|
-
}
|
|
21354
|
+
const knownToolCallEventIds = await getToolCallEventIdsOp(storageCtx, convId);
|
|
21340
21355
|
if (includeHistory) {
|
|
21341
|
-
|
|
21342
|
-
|
|
21343
|
-
|
|
21344
|
-
|
|
21345
|
-
|
|
21346
|
-
|
|
21356
|
+
let tail = [];
|
|
21357
|
+
let replayableMessages = [];
|
|
21358
|
+
let beforeMessageId;
|
|
21359
|
+
let boundaryExcludeUniqueIds;
|
|
21360
|
+
for (; ; ) {
|
|
21361
|
+
const page = await getMessagesPageOp(storageCtx, convId, {
|
|
21362
|
+
limit: maxHistoryMessages,
|
|
21363
|
+
beforeMessageId,
|
|
21364
|
+
boundaryExcludeUniqueIds
|
|
21365
|
+
});
|
|
21366
|
+
if (page.length === 0) break;
|
|
21367
|
+
tail = [...page, ...tail];
|
|
21368
|
+
const validMessages = tail.filter((msg) => !msg.error);
|
|
21369
|
+
replayableMessages = prepareToolResultsForReplay(validMessages, {
|
|
21370
|
+
fold: foldToolResultsInHistoryRef.current === true,
|
|
21371
|
+
exclude: toolResultsHistoryExcludeRef.current,
|
|
21372
|
+
placeholder: DISPLAY_CARD_PLACEHOLDER
|
|
21373
|
+
});
|
|
21374
|
+
if (replayableMessages.length >= maxHistoryMessages) break;
|
|
21375
|
+
if (page.length < maxHistoryMessages) break;
|
|
21376
|
+
beforeMessageId = page[0].messageId;
|
|
21377
|
+
boundaryExcludeUniqueIds = tail.filter((msg) => msg.messageId === beforeMessageId).map((msg) => msg.uniqueId);
|
|
21378
|
+
}
|
|
21347
21379
|
const limitedMessages = replayableMessages.slice(-maxHistoryMessages);
|
|
21348
21380
|
const foldedHistory = limitedMessages;
|
|
21349
21381
|
if (summarizeHistory && !getTokenRef.current) {
|
package/dist/expo/index.mjs
CHANGED
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
getMessageSkeletonsOp,
|
|
85
85
|
getMessagesOp,
|
|
86
86
|
getMessagesPageOp,
|
|
87
|
+
getToolCallEventIdsOp,
|
|
87
88
|
getToolCallEvents,
|
|
88
89
|
getToolsChecksum,
|
|
89
90
|
getUnfiledVaultMemoriesOp,
|
|
@@ -132,7 +133,7 @@ import {
|
|
|
132
133
|
upsertMessageOp,
|
|
133
134
|
useEncryption,
|
|
134
135
|
vaultMemoryToStored
|
|
135
|
-
} from "./chunk-
|
|
136
|
+
} from "./chunk-JXN7LD6B.mjs";
|
|
136
137
|
import {
|
|
137
138
|
PII_PATTERNS,
|
|
138
139
|
PiiRedactor,
|
|
@@ -11550,22 +11551,31 @@ function useChatStorage(options) {
|
|
|
11550
11551
|
const serverToolsPromise = getTokenRef.current && !(Array.isArray(serverToolsFilter) && serverToolsFilter.length === 0) ? fetchServerToolsSettled(getTokenRef.current) : null;
|
|
11551
11552
|
const userMessageEmbeddingPromise = getTokenRef.current && contentForStorage.length >= MIN_CONTENT_LENGTH_FOR_TOOLS && (isServerToolsFunction && !(serverToolsConfig?.deferLoading?.enabled && effectiveApiType === "responses") || !!clientTools?.length) ? embedForToolsSettled(getTokenRef.current) : null;
|
|
11552
11553
|
let messagesToSend;
|
|
11553
|
-
const
|
|
11554
|
-
const knownToolCallEventIds = /* @__PURE__ */ new Set();
|
|
11555
|
-
for (const msg of storedMessages) {
|
|
11556
|
-
if (msg.toolCallEvents) {
|
|
11557
|
-
for (const evt of msg.toolCallEvents) {
|
|
11558
|
-
if (evt.id) knownToolCallEventIds.add(evt.id);
|
|
11559
|
-
}
|
|
11560
|
-
}
|
|
11561
|
-
}
|
|
11554
|
+
const knownToolCallEventIds = await getToolCallEventIdsOp(storageCtx, convId);
|
|
11562
11555
|
if (includeHistory) {
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11556
|
+
let tail = [];
|
|
11557
|
+
let replayableMessages = [];
|
|
11558
|
+
let beforeMessageId;
|
|
11559
|
+
let boundaryExcludeUniqueIds;
|
|
11560
|
+
for (; ; ) {
|
|
11561
|
+
const page = await getMessagesPageOp(storageCtx, convId, {
|
|
11562
|
+
limit: maxHistoryMessages,
|
|
11563
|
+
beforeMessageId,
|
|
11564
|
+
boundaryExcludeUniqueIds
|
|
11565
|
+
});
|
|
11566
|
+
if (page.length === 0) break;
|
|
11567
|
+
tail = [...page, ...tail];
|
|
11568
|
+
const validMessages = tail.filter((msg) => !msg.error);
|
|
11569
|
+
replayableMessages = prepareToolResultsForReplay(validMessages, {
|
|
11570
|
+
fold: foldToolResultsInHistoryRef.current === true,
|
|
11571
|
+
exclude: toolResultsHistoryExcludeRef.current,
|
|
11572
|
+
placeholder: DISPLAY_CARD_PLACEHOLDER
|
|
11573
|
+
});
|
|
11574
|
+
if (replayableMessages.length >= maxHistoryMessages) break;
|
|
11575
|
+
if (page.length < maxHistoryMessages) break;
|
|
11576
|
+
beforeMessageId = page[0].messageId;
|
|
11577
|
+
boundaryExcludeUniqueIds = tail.filter((msg) => msg.messageId === beforeMessageId).map((msg) => msg.uniqueId);
|
|
11578
|
+
}
|
|
11569
11579
|
const limitedMessages = replayableMessages.slice(-maxHistoryMessages);
|
|
11570
11580
|
const foldedHistory = limitedMessages;
|
|
11571
11581
|
if (summarizeHistory && !getTokenRef.current) {
|
|
@@ -1773,6 +1773,29 @@ async function getMessageSkeletonsOp(ctx, convId) {
|
|
|
1773
1773
|
}
|
|
1774
1774
|
return skeletons;
|
|
1775
1775
|
}
|
|
1776
|
+
async function getToolCallEventIdsOp(ctx, convId) {
|
|
1777
|
+
const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).unsafeFetchRaw();
|
|
1778
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1779
|
+
for (const raw of results) {
|
|
1780
|
+
const value = raw.tool_call_events;
|
|
1781
|
+
if (!value) continue;
|
|
1782
|
+
let events;
|
|
1783
|
+
if (typeof value === "string") {
|
|
1784
|
+
try {
|
|
1785
|
+
events = JSON.parse(value);
|
|
1786
|
+
} catch {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
} else if (Array.isArray(value)) {
|
|
1790
|
+
events = value;
|
|
1791
|
+
}
|
|
1792
|
+
if (!Array.isArray(events)) continue;
|
|
1793
|
+
for (const evt of events) {
|
|
1794
|
+
if (evt && evt.id) ids.add(evt.id);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
return ids;
|
|
1798
|
+
}
|
|
1776
1799
|
async function clearMessagesOp(ctx, convId) {
|
|
1777
1800
|
const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
|
|
1778
1801
|
await ctx.database.write(async () => {
|
|
@@ -2002,14 +2025,14 @@ function resolveChunkText(content, chunk, chunksInRow) {
|
|
|
2002
2025
|
if (covered !== content.length) return content;
|
|
2003
2026
|
return content.slice(start, end);
|
|
2004
2027
|
}
|
|
2005
|
-
async function
|
|
2006
|
-
const
|
|
2007
|
-
if (!
|
|
2008
|
-
if (walletAddress && isEncrypted(
|
|
2009
|
-
return await decryptJsonField(
|
|
2028
|
+
async function readRawJsonField(raw, column, walletAddress) {
|
|
2029
|
+
const value = raw[column];
|
|
2030
|
+
if (!value) return void 0;
|
|
2031
|
+
if (walletAddress && isEncrypted(value)) {
|
|
2032
|
+
return await decryptJsonField(value, walletAddress);
|
|
2010
2033
|
}
|
|
2011
2034
|
try {
|
|
2012
|
-
return JSON.parse(
|
|
2035
|
+
return JSON.parse(value);
|
|
2013
2036
|
} catch {
|
|
2014
2037
|
return void 0;
|
|
2015
2038
|
}
|
|
@@ -2022,12 +2045,12 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2022
2045
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2023
2046
|
);
|
|
2024
2047
|
const queryConditions = conversationId ? [Q.where("conversation_id", conversationId)] : [];
|
|
2025
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2048
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2026
2049
|
const candidates = [];
|
|
2027
2050
|
for (const message of messages) {
|
|
2028
|
-
const msgConvId = String(message.
|
|
2051
|
+
const msgConvId = String(message.conversation_id);
|
|
2029
2052
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2030
|
-
const messageVector = await
|
|
2053
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2031
2054
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2032
2055
|
const similarity = cosineSimilarity(queryVector, messageVector);
|
|
2033
2056
|
if (similarity >= minSimilarity) {
|
|
@@ -2037,7 +2060,7 @@ async function searchMessagesOp(ctx, queryVector, options) {
|
|
|
2037
2060
|
const topK = candidates.sort((a, b) => b.similarity - a.similarity).slice(0, limit);
|
|
2038
2061
|
return Promise.all(
|
|
2039
2062
|
topK.map(async ({ message, similarity }) => {
|
|
2040
|
-
const stored = await
|
|
2063
|
+
const stored = await messageRawToStored(
|
|
2041
2064
|
message,
|
|
2042
2065
|
ctx.walletAddress,
|
|
2043
2066
|
ctx.signMessage,
|
|
@@ -2061,21 +2084,21 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2061
2084
|
activeConversations.map((c) => String(c._getRaw("conversation_id")))
|
|
2062
2085
|
);
|
|
2063
2086
|
const queryConditions = conversationId ? [Q.where("conversation_id", conversationId)] : [];
|
|
2064
|
-
const messages = await ctx.messagesCollection.query(...queryConditions).
|
|
2087
|
+
const messages = await ctx.messagesCollection.query(...queryConditions).unsafeFetchRaw();
|
|
2065
2088
|
const candidates = [];
|
|
2066
2089
|
let staleSkipped = 0;
|
|
2067
2090
|
let unreadableVectors = 0;
|
|
2068
2091
|
for (const message of messages) {
|
|
2069
|
-
const msgConvId = String(message.
|
|
2092
|
+
const msgConvId = String(message.conversation_id);
|
|
2070
2093
|
if (!activeConversationIds.has(msgConvId)) continue;
|
|
2071
2094
|
if (embeddingModel) {
|
|
2072
|
-
const storedModel = message.
|
|
2095
|
+
const storedModel = message.embedding_model;
|
|
2073
2096
|
if (storedModel !== null && storedModel !== void 0 && storedModel !== embeddingModel) {
|
|
2074
2097
|
staleSkipped++;
|
|
2075
2098
|
continue;
|
|
2076
2099
|
}
|
|
2077
2100
|
}
|
|
2078
|
-
const version = Number(message.
|
|
2101
|
+
const version = Number(message.updated_at) || 0;
|
|
2079
2102
|
const cached = chunkCache?.get(message.id);
|
|
2080
2103
|
if (cached && cached.version === version) {
|
|
2081
2104
|
if (cached.chunks.length > 0) {
|
|
@@ -2099,7 +2122,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2099
2122
|
}
|
|
2100
2123
|
continue;
|
|
2101
2124
|
}
|
|
2102
|
-
const chunks = await
|
|
2125
|
+
const chunks = await readRawJsonField(message, "chunks", ctx.walletAddress);
|
|
2103
2126
|
if (chunks && chunks.length > 0) {
|
|
2104
2127
|
const vectors = chunks.map(
|
|
2105
2128
|
(chunk) => decodeChunkVector(chunk.vector, () => {
|
|
@@ -2120,7 +2143,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2120
2143
|
}
|
|
2121
2144
|
}
|
|
2122
2145
|
} else {
|
|
2123
|
-
const messageVector = await
|
|
2146
|
+
const messageVector = await readRawJsonField(message, "vector", ctx.walletAddress);
|
|
2124
2147
|
if (!messageVector || messageVector.length === 0) continue;
|
|
2125
2148
|
const fallback = Float32Array.from(messageVector);
|
|
2126
2149
|
chunkCache?.set(message.id, { version, chunks: [], fallback });
|
|
@@ -2146,7 +2169,7 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2146
2169
|
const storedById = new Map(
|
|
2147
2170
|
await Promise.all(
|
|
2148
2171
|
Array.from(uniqueMessages, async ([id, m]) => {
|
|
2149
|
-
const stored = await
|
|
2172
|
+
const stored = await messageRawToStored(
|
|
2150
2173
|
m,
|
|
2151
2174
|
ctx.walletAddress,
|
|
2152
2175
|
ctx.signMessage,
|
|
@@ -2164,8 +2187,8 @@ async function searchChunksOp(ctx, queryVector, options) {
|
|
|
2164
2187
|
await Promise.all(
|
|
2165
2188
|
Array.from(needsChunkText, async (id) => {
|
|
2166
2189
|
const m = uniqueMessages.get(id);
|
|
2167
|
-
const parsed = await
|
|
2168
|
-
const version = Number(m.
|
|
2190
|
+
const parsed = await readRawJsonField(m, "chunks", ctx.walletAddress);
|
|
2191
|
+
const version = Number(m.updated_at) || 0;
|
|
2169
2192
|
if (parsed) chunkStateByMsgId.set(id, { version, chunks: parsed });
|
|
2170
2193
|
})
|
|
2171
2194
|
);
|
|
@@ -7169,7 +7192,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
7169
7192
|
subQueries = decomp.subQueries;
|
|
7170
7193
|
}
|
|
7171
7194
|
}
|
|
7172
|
-
const { recall: recall2 } = await import("./recall-
|
|
7195
|
+
const { recall: recall2 } = await import("./recall-OKNLU335.mjs");
|
|
7173
7196
|
let recallDegraded = [];
|
|
7174
7197
|
const result = await recall2(
|
|
7175
7198
|
query,
|
|
@@ -8195,6 +8218,7 @@ export {
|
|
|
8195
8218
|
getMessageCountOp,
|
|
8196
8219
|
getMessagesPageOp,
|
|
8197
8220
|
getMessageSkeletonsOp,
|
|
8221
|
+
getToolCallEventIdsOp,
|
|
8198
8222
|
clearMessagesOp,
|
|
8199
8223
|
createMessageOp,
|
|
8200
8224
|
getMessageOp,
|
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