@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
|
@@ -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,
|