@anuma/sdk 9.1.2 → 9.1.3
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/index.cjs +19 -3
- package/dist/expo/index.mjs +19 -3
- package/dist/index.cjs +9 -4
- package/dist/index.mjs +9 -4
- package/dist/react/index.cjs +19 -3
- package/dist/react/index.mjs +19 -3
- package/dist/server/index.cjs +19 -3
- package/dist/server/index.mjs +19 -3
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -2326,6 +2326,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
2326
2326
|
if (cachedKey) {
|
|
2327
2327
|
return cachedKey;
|
|
2328
2328
|
}
|
|
2329
|
+
const startEpoch = sessionEpoch;
|
|
2329
2330
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
2330
2331
|
if (!keyHex) {
|
|
2331
2332
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -2338,6 +2339,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
2338
2339
|
false,
|
|
2339
2340
|
["encrypt", "decrypt"]
|
|
2340
2341
|
);
|
|
2342
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
2343
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
2344
|
+
}
|
|
2341
2345
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
2342
2346
|
return cryptoKey;
|
|
2343
2347
|
}
|
|
@@ -25015,6 +25019,18 @@ async function assembleMemoryContext(options) {
|
|
|
25015
25019
|
|
|
25016
25020
|
// src/lib/memory/durableExtraction.ts
|
|
25017
25021
|
var import_watermelondb25 = require("@nozbe/watermelondb");
|
|
25022
|
+
async function messagePositions(storage, ids) {
|
|
25023
|
+
try {
|
|
25024
|
+
return await storage.messagesCollection.query(
|
|
25025
|
+
import_watermelondb25.Q.unsafeSqlQuery(
|
|
25026
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
25027
|
+
ids
|
|
25028
|
+
)
|
|
25029
|
+
).unsafeFetchRaw();
|
|
25030
|
+
} catch {
|
|
25031
|
+
return await storage.messagesCollection.query(import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(ids))).unsafeFetchRaw();
|
|
25032
|
+
}
|
|
25033
|
+
}
|
|
25018
25034
|
var MAX_JOBS_PER_PASS = 3;
|
|
25019
25035
|
var MAX_ATTEMPTS = 3;
|
|
25020
25036
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -25583,9 +25599,9 @@ function createDurableAutoExtractor(options) {
|
|
|
25583
25599
|
r._setRaw("watermark_seq", null);
|
|
25584
25600
|
});
|
|
25585
25601
|
}
|
|
25586
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
25602
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
25587
25603
|
const foreignRows = new Set(
|
|
25588
|
-
rows.filter((row) => row.
|
|
25604
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
25589
25605
|
);
|
|
25590
25606
|
const sequences = /* @__PURE__ */ new Map();
|
|
25591
25607
|
if (fromSourceConversation) {
|
|
@@ -25595,7 +25611,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25595
25611
|
}
|
|
25596
25612
|
for (const row of rows) {
|
|
25597
25613
|
if (foreignRows.has(row.id)) continue;
|
|
25598
|
-
const sequence = Number(row.
|
|
25614
|
+
const sequence = Number(row.message_id);
|
|
25599
25615
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
25600
25616
|
}
|
|
25601
25617
|
let boundary = -1;
|
package/dist/expo/index.mjs
CHANGED
|
@@ -729,6 +729,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
729
729
|
if (cachedKey) {
|
|
730
730
|
return cachedKey;
|
|
731
731
|
}
|
|
732
|
+
const startEpoch = sessionEpoch;
|
|
732
733
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
733
734
|
if (!keyHex) {
|
|
734
735
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -741,6 +742,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
741
742
|
false,
|
|
742
743
|
["encrypt", "decrypt"]
|
|
743
744
|
);
|
|
745
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
746
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
747
|
+
}
|
|
744
748
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
745
749
|
return cryptoKey;
|
|
746
750
|
}
|
|
@@ -23337,6 +23341,18 @@ async function assembleMemoryContext(options) {
|
|
|
23337
23341
|
|
|
23338
23342
|
// src/lib/memory/durableExtraction.ts
|
|
23339
23343
|
import { Q as Q10 } from "@nozbe/watermelondb";
|
|
23344
|
+
async function messagePositions(storage, ids) {
|
|
23345
|
+
try {
|
|
23346
|
+
return await storage.messagesCollection.query(
|
|
23347
|
+
Q10.unsafeSqlQuery(
|
|
23348
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
23349
|
+
ids
|
|
23350
|
+
)
|
|
23351
|
+
).unsafeFetchRaw();
|
|
23352
|
+
} catch {
|
|
23353
|
+
return await storage.messagesCollection.query(Q10.where("id", Q10.oneOf(ids))).unsafeFetchRaw();
|
|
23354
|
+
}
|
|
23355
|
+
}
|
|
23340
23356
|
var MAX_JOBS_PER_PASS = 3;
|
|
23341
23357
|
var MAX_ATTEMPTS = 3;
|
|
23342
23358
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -23905,9 +23921,9 @@ function createDurableAutoExtractor(options) {
|
|
|
23905
23921
|
r._setRaw("watermark_seq", null);
|
|
23906
23922
|
});
|
|
23907
23923
|
}
|
|
23908
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
23924
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
23909
23925
|
const foreignRows = new Set(
|
|
23910
|
-
rows.filter((row) => row.
|
|
23926
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
23911
23927
|
);
|
|
23912
23928
|
const sequences = /* @__PURE__ */ new Map();
|
|
23913
23929
|
if (fromSourceConversation) {
|
|
@@ -23917,7 +23933,7 @@ function createDurableAutoExtractor(options) {
|
|
|
23917
23933
|
}
|
|
23918
23934
|
for (const row of rows) {
|
|
23919
23935
|
if (foreignRows.has(row.id)) continue;
|
|
23920
|
-
const sequence = Number(row.
|
|
23936
|
+
const sequence = Number(row.message_id);
|
|
23921
23937
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
23922
23938
|
}
|
|
23923
23939
|
let boundary = -1;
|
package/dist/index.cjs
CHANGED
|
@@ -1404,6 +1404,7 @@ var EncryptionKeyMissingError = class extends Error {
|
|
|
1404
1404
|
}
|
|
1405
1405
|
};
|
|
1406
1406
|
var encryptionKeyStore = /* @__PURE__ */ new Map();
|
|
1407
|
+
var sessionEpoch = 0;
|
|
1407
1408
|
var cryptoKeyCache = /* @__PURE__ */ new Map();
|
|
1408
1409
|
var clearAllEncryptionStateCallbacks = /* @__PURE__ */ new Set();
|
|
1409
1410
|
function onClearAllEncryptionState(callback) {
|
|
@@ -1455,6 +1456,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
1455
1456
|
if (cachedKey) {
|
|
1456
1457
|
return cachedKey;
|
|
1457
1458
|
}
|
|
1459
|
+
const startEpoch = sessionEpoch;
|
|
1458
1460
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
1459
1461
|
if (!keyHex) {
|
|
1460
1462
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -1467,6 +1469,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
1467
1469
|
false,
|
|
1468
1470
|
["encrypt", "decrypt"]
|
|
1469
1471
|
);
|
|
1472
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
1473
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
1474
|
+
}
|
|
1470
1475
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
1471
1476
|
return cryptoKey;
|
|
1472
1477
|
}
|
|
@@ -2159,7 +2164,7 @@ async function createRemoteChatStore(options) {
|
|
|
2159
2164
|
var LRU_CAPACITY = 256;
|
|
2160
2165
|
var titleCache = /* @__PURE__ */ new Map();
|
|
2161
2166
|
var pendingDecrypts = /* @__PURE__ */ new Map();
|
|
2162
|
-
var
|
|
2167
|
+
var sessionEpoch2 = 0;
|
|
2163
2168
|
function buildCacheKey(address, encryptedTitle) {
|
|
2164
2169
|
return `${address}:${encryptedTitle}`;
|
|
2165
2170
|
}
|
|
@@ -2178,7 +2183,7 @@ function insertWithEviction(key, value) {
|
|
|
2178
2183
|
function clearLazyTitleCache() {
|
|
2179
2184
|
titleCache.clear();
|
|
2180
2185
|
pendingDecrypts.clear();
|
|
2181
|
-
|
|
2186
|
+
sessionEpoch2 += 1;
|
|
2182
2187
|
}
|
|
2183
2188
|
onClearAllEncryptionState(clearLazyTitleCache);
|
|
2184
2189
|
async function decryptConversationTitle(encryptedTitle, address) {
|
|
@@ -2200,13 +2205,13 @@ async function decryptConversationTitle(encryptedTitle, address) {
|
|
|
2200
2205
|
}
|
|
2201
2206
|
const inFlight = pendingDecrypts.get(cacheKey);
|
|
2202
2207
|
if (inFlight) return inFlight;
|
|
2203
|
-
const epochAtStart =
|
|
2208
|
+
const epochAtStart = sessionEpoch2;
|
|
2204
2209
|
const promise = (async () => {
|
|
2205
2210
|
const plaintext = await decryptField(encryptedTitle, address);
|
|
2206
2211
|
if (isEncrypted(plaintext)) {
|
|
2207
2212
|
throw new Error("decryptConversationTitle: decryption failed (returned ciphertext)");
|
|
2208
2213
|
}
|
|
2209
|
-
if (
|
|
2214
|
+
if (sessionEpoch2 === epochAtStart) {
|
|
2210
2215
|
insertWithEviction(cacheKey, plaintext);
|
|
2211
2216
|
}
|
|
2212
2217
|
return plaintext;
|
package/dist/index.mjs
CHANGED
|
@@ -1201,6 +1201,7 @@ var EncryptionKeyMissingError = class extends Error {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
};
|
|
1203
1203
|
var encryptionKeyStore = /* @__PURE__ */ new Map();
|
|
1204
|
+
var sessionEpoch = 0;
|
|
1204
1205
|
var cryptoKeyCache = /* @__PURE__ */ new Map();
|
|
1205
1206
|
var clearAllEncryptionStateCallbacks = /* @__PURE__ */ new Set();
|
|
1206
1207
|
function onClearAllEncryptionState(callback) {
|
|
@@ -1252,6 +1253,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
1252
1253
|
if (cachedKey) {
|
|
1253
1254
|
return cachedKey;
|
|
1254
1255
|
}
|
|
1256
|
+
const startEpoch = sessionEpoch;
|
|
1255
1257
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
1256
1258
|
if (!keyHex) {
|
|
1257
1259
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -1264,6 +1266,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
1264
1266
|
false,
|
|
1265
1267
|
["encrypt", "decrypt"]
|
|
1266
1268
|
);
|
|
1269
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
1270
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
1271
|
+
}
|
|
1267
1272
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
1268
1273
|
return cryptoKey;
|
|
1269
1274
|
}
|
|
@@ -1956,7 +1961,7 @@ async function createRemoteChatStore(options) {
|
|
|
1956
1961
|
var LRU_CAPACITY = 256;
|
|
1957
1962
|
var titleCache = /* @__PURE__ */ new Map();
|
|
1958
1963
|
var pendingDecrypts = /* @__PURE__ */ new Map();
|
|
1959
|
-
var
|
|
1964
|
+
var sessionEpoch2 = 0;
|
|
1960
1965
|
function buildCacheKey(address, encryptedTitle) {
|
|
1961
1966
|
return `${address}:${encryptedTitle}`;
|
|
1962
1967
|
}
|
|
@@ -1975,7 +1980,7 @@ function insertWithEviction(key, value) {
|
|
|
1975
1980
|
function clearLazyTitleCache() {
|
|
1976
1981
|
titleCache.clear();
|
|
1977
1982
|
pendingDecrypts.clear();
|
|
1978
|
-
|
|
1983
|
+
sessionEpoch2 += 1;
|
|
1979
1984
|
}
|
|
1980
1985
|
onClearAllEncryptionState(clearLazyTitleCache);
|
|
1981
1986
|
async function decryptConversationTitle(encryptedTitle, address) {
|
|
@@ -1997,13 +2002,13 @@ async function decryptConversationTitle(encryptedTitle, address) {
|
|
|
1997
2002
|
}
|
|
1998
2003
|
const inFlight = pendingDecrypts.get(cacheKey);
|
|
1999
2004
|
if (inFlight) return inFlight;
|
|
2000
|
-
const epochAtStart =
|
|
2005
|
+
const epochAtStart = sessionEpoch2;
|
|
2001
2006
|
const promise = (async () => {
|
|
2002
2007
|
const plaintext = await decryptField(encryptedTitle, address);
|
|
2003
2008
|
if (isEncrypted(plaintext)) {
|
|
2004
2009
|
throw new Error("decryptConversationTitle: decryption failed (returned ciphertext)");
|
|
2005
2010
|
}
|
|
2006
|
-
if (
|
|
2011
|
+
if (sessionEpoch2 === epochAtStart) {
|
|
2007
2012
|
insertWithEviction(cacheKey, plaintext);
|
|
2008
2013
|
}
|
|
2009
2014
|
return plaintext;
|
package/dist/react/index.cjs
CHANGED
|
@@ -2093,6 +2093,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
2093
2093
|
if (cachedKey) {
|
|
2094
2094
|
return cachedKey;
|
|
2095
2095
|
}
|
|
2096
|
+
const startEpoch = sessionEpoch;
|
|
2096
2097
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
2097
2098
|
if (!keyHex) {
|
|
2098
2099
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -2105,6 +2106,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
2105
2106
|
false,
|
|
2106
2107
|
["encrypt", "decrypt"]
|
|
2107
2108
|
);
|
|
2109
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
2110
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
2111
|
+
}
|
|
2108
2112
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
2109
2113
|
return cryptoKey;
|
|
2110
2114
|
}
|
|
@@ -27328,6 +27332,18 @@ async function assembleMemoryContext(options) {
|
|
|
27328
27332
|
|
|
27329
27333
|
// src/lib/memory/durableExtraction.ts
|
|
27330
27334
|
var import_watermelondb34 = require("@nozbe/watermelondb");
|
|
27335
|
+
async function messagePositions(storage, ids) {
|
|
27336
|
+
try {
|
|
27337
|
+
return await storage.messagesCollection.query(
|
|
27338
|
+
import_watermelondb34.Q.unsafeSqlQuery(
|
|
27339
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
27340
|
+
ids
|
|
27341
|
+
)
|
|
27342
|
+
).unsafeFetchRaw();
|
|
27343
|
+
} catch {
|
|
27344
|
+
return await storage.messagesCollection.query(import_watermelondb34.Q.where("id", import_watermelondb34.Q.oneOf(ids))).unsafeFetchRaw();
|
|
27345
|
+
}
|
|
27346
|
+
}
|
|
27331
27347
|
var MAX_JOBS_PER_PASS = 3;
|
|
27332
27348
|
var MAX_ATTEMPTS = 3;
|
|
27333
27349
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -27896,9 +27912,9 @@ function createDurableAutoExtractor(options) {
|
|
|
27896
27912
|
r._setRaw("watermark_seq", null);
|
|
27897
27913
|
});
|
|
27898
27914
|
}
|
|
27899
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
27915
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
27900
27916
|
const foreignRows = new Set(
|
|
27901
|
-
rows.filter((row) => row.
|
|
27917
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
27902
27918
|
);
|
|
27903
27919
|
const sequences = /* @__PURE__ */ new Map();
|
|
27904
27920
|
if (fromSourceConversation) {
|
|
@@ -27908,7 +27924,7 @@ function createDurableAutoExtractor(options) {
|
|
|
27908
27924
|
}
|
|
27909
27925
|
for (const row of rows) {
|
|
27910
27926
|
if (foreignRows.has(row.id)) continue;
|
|
27911
|
-
const sequence = Number(row.
|
|
27927
|
+
const sequence = Number(row.message_id);
|
|
27912
27928
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
27913
27929
|
}
|
|
27914
27930
|
let boundary = -1;
|
package/dist/react/index.mjs
CHANGED
|
@@ -295,6 +295,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
295
295
|
if (cachedKey) {
|
|
296
296
|
return cachedKey;
|
|
297
297
|
}
|
|
298
|
+
const startEpoch = sessionEpoch;
|
|
298
299
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
299
300
|
if (!keyHex) {
|
|
300
301
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -307,6 +308,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
307
308
|
false,
|
|
308
309
|
["encrypt", "decrypt"]
|
|
309
310
|
);
|
|
311
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
312
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
313
|
+
}
|
|
310
314
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
311
315
|
return cryptoKey;
|
|
312
316
|
}
|
|
@@ -25442,6 +25446,18 @@ async function assembleMemoryContext(options) {
|
|
|
25442
25446
|
|
|
25443
25447
|
// src/lib/memory/durableExtraction.ts
|
|
25444
25448
|
import { Q as Q17 } from "@nozbe/watermelondb";
|
|
25449
|
+
async function messagePositions(storage, ids) {
|
|
25450
|
+
try {
|
|
25451
|
+
return await storage.messagesCollection.query(
|
|
25452
|
+
Q17.unsafeSqlQuery(
|
|
25453
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
25454
|
+
ids
|
|
25455
|
+
)
|
|
25456
|
+
).unsafeFetchRaw();
|
|
25457
|
+
} catch {
|
|
25458
|
+
return await storage.messagesCollection.query(Q17.where("id", Q17.oneOf(ids))).unsafeFetchRaw();
|
|
25459
|
+
}
|
|
25460
|
+
}
|
|
25445
25461
|
var MAX_JOBS_PER_PASS = 3;
|
|
25446
25462
|
var MAX_ATTEMPTS = 3;
|
|
25447
25463
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -26010,9 +26026,9 @@ function createDurableAutoExtractor(options) {
|
|
|
26010
26026
|
r._setRaw("watermark_seq", null);
|
|
26011
26027
|
});
|
|
26012
26028
|
}
|
|
26013
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
26029
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
26014
26030
|
const foreignRows = new Set(
|
|
26015
|
-
rows.filter((row) => row.
|
|
26031
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
26016
26032
|
);
|
|
26017
26033
|
const sequences = /* @__PURE__ */ new Map();
|
|
26018
26034
|
if (fromSourceConversation) {
|
|
@@ -26022,7 +26038,7 @@ function createDurableAutoExtractor(options) {
|
|
|
26022
26038
|
}
|
|
26023
26039
|
for (const row of rows) {
|
|
26024
26040
|
if (foreignRows.has(row.id)) continue;
|
|
26025
|
-
const sequence = Number(row.
|
|
26041
|
+
const sequence = Number(row.message_id);
|
|
26026
26042
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
26027
26043
|
}
|
|
26028
26044
|
let boundary = -1;
|
package/dist/server/index.cjs
CHANGED
|
@@ -17078,6 +17078,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
17078
17078
|
if (cachedKey) {
|
|
17079
17079
|
return cachedKey;
|
|
17080
17080
|
}
|
|
17081
|
+
const startEpoch = sessionEpoch;
|
|
17081
17082
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
17082
17083
|
if (!keyHex) {
|
|
17083
17084
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -17090,6 +17091,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
17090
17091
|
false,
|
|
17091
17092
|
["encrypt", "decrypt"]
|
|
17092
17093
|
);
|
|
17094
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
17095
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
17096
|
+
}
|
|
17093
17097
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
17094
17098
|
return cryptoKey;
|
|
17095
17099
|
}
|
|
@@ -37141,6 +37145,18 @@ async function assembleMemoryContext(options) {
|
|
|
37141
37145
|
|
|
37142
37146
|
// src/lib/memory/durableExtraction.ts
|
|
37143
37147
|
var import_watermelondb25 = __toESM(require_watermelondb());
|
|
37148
|
+
async function messagePositions(storage, ids) {
|
|
37149
|
+
try {
|
|
37150
|
+
return await storage.messagesCollection.query(
|
|
37151
|
+
import_watermelondb25.Q.unsafeSqlQuery(
|
|
37152
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
37153
|
+
ids
|
|
37154
|
+
)
|
|
37155
|
+
).unsafeFetchRaw();
|
|
37156
|
+
} catch {
|
|
37157
|
+
return await storage.messagesCollection.query(import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(ids))).unsafeFetchRaw();
|
|
37158
|
+
}
|
|
37159
|
+
}
|
|
37144
37160
|
var MAX_JOBS_PER_PASS = 3;
|
|
37145
37161
|
var MAX_ATTEMPTS = 3;
|
|
37146
37162
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -37709,9 +37725,9 @@ function createDurableAutoExtractor(options) {
|
|
|
37709
37725
|
r._setRaw("watermark_seq", null);
|
|
37710
37726
|
});
|
|
37711
37727
|
}
|
|
37712
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
37728
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
37713
37729
|
const foreignRows = new Set(
|
|
37714
|
-
rows.filter((row) => row.
|
|
37730
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
37715
37731
|
);
|
|
37716
37732
|
const sequences = /* @__PURE__ */ new Map();
|
|
37717
37733
|
if (fromSourceConversation) {
|
|
@@ -37721,7 +37737,7 @@ function createDurableAutoExtractor(options) {
|
|
|
37721
37737
|
}
|
|
37722
37738
|
for (const row of rows) {
|
|
37723
37739
|
if (foreignRows.has(row.id)) continue;
|
|
37724
|
-
const sequence = Number(row.
|
|
37740
|
+
const sequence = Number(row.message_id);
|
|
37725
37741
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
37726
37742
|
}
|
|
37727
37743
|
let boundary = -1;
|
package/dist/server/index.mjs
CHANGED
|
@@ -15407,6 +15407,7 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
15407
15407
|
if (cachedKey) {
|
|
15408
15408
|
return cachedKey;
|
|
15409
15409
|
}
|
|
15410
|
+
const startEpoch = sessionEpoch;
|
|
15410
15411
|
const keyHex = getStoredKeyByVersion(address, version);
|
|
15411
15412
|
if (!keyHex) {
|
|
15412
15413
|
throw new EncryptionKeyMissingError(address, version);
|
|
@@ -15419,6 +15420,9 @@ async function getEncryptionKey(address, version = "v3") {
|
|
|
15419
15420
|
false,
|
|
15420
15421
|
["encrypt", "decrypt"]
|
|
15421
15422
|
);
|
|
15423
|
+
if (sessionEpoch !== startEpoch || getStoredKeyByVersion(address, version) !== keyHex) {
|
|
15424
|
+
throw new EncryptionKeyMissingError(address, version);
|
|
15425
|
+
}
|
|
15422
15426
|
cryptoKeyCache.set(cacheKey, cryptoKey);
|
|
15423
15427
|
return cryptoKey;
|
|
15424
15428
|
}
|
|
@@ -35388,6 +35392,18 @@ async function assembleMemoryContext(options) {
|
|
|
35388
35392
|
|
|
35389
35393
|
// src/lib/memory/durableExtraction.ts
|
|
35390
35394
|
var import_watermelondb25 = __toESM(require_watermelondb());
|
|
35395
|
+
async function messagePositions(storage, ids) {
|
|
35396
|
+
try {
|
|
35397
|
+
return await storage.messagesCollection.query(
|
|
35398
|
+
import_watermelondb25.Q.unsafeSqlQuery(
|
|
35399
|
+
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
35400
|
+
ids
|
|
35401
|
+
)
|
|
35402
|
+
).unsafeFetchRaw();
|
|
35403
|
+
} catch {
|
|
35404
|
+
return await storage.messagesCollection.query(import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf(ids))).unsafeFetchRaw();
|
|
35405
|
+
}
|
|
35406
|
+
}
|
|
35391
35407
|
var MAX_JOBS_PER_PASS = 3;
|
|
35392
35408
|
var MAX_ATTEMPTS = 3;
|
|
35393
35409
|
var MAX_FAILED_SESSIONS = 3;
|
|
@@ -35956,9 +35972,9 @@ function createDurableAutoExtractor(options) {
|
|
|
35956
35972
|
r._setRaw("watermark_seq", null);
|
|
35957
35973
|
});
|
|
35958
35974
|
}
|
|
35959
|
-
const rows = fromSourceConversation ? [] : await storage
|
|
35975
|
+
const rows = fromSourceConversation ? [] : await messagePositions(storage, ids);
|
|
35960
35976
|
const foreignRows = new Set(
|
|
35961
|
-
rows.filter((row) => row.
|
|
35977
|
+
rows.filter((row) => row.conversation_id !== conversationId).map((row) => row.id)
|
|
35962
35978
|
);
|
|
35963
35979
|
const sequences = /* @__PURE__ */ new Map();
|
|
35964
35980
|
if (fromSourceConversation) {
|
|
@@ -35968,7 +35984,7 @@ function createDurableAutoExtractor(options) {
|
|
|
35968
35984
|
}
|
|
35969
35985
|
for (const row of rows) {
|
|
35970
35986
|
if (foreignRows.has(row.id)) continue;
|
|
35971
|
-
const sequence = Number(row.
|
|
35987
|
+
const sequence = Number(row.message_id);
|
|
35972
35988
|
if (Number.isFinite(sequence) && sequence > 0) sequences.set(row.id, sequence);
|
|
35973
35989
|
}
|
|
35974
35990
|
let boundary = -1;
|