@anuma/sdk 9.1.7 → 9.1.9
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 +120 -66
- package/dist/expo/index.mjs +121 -67
- package/dist/react/index.cjs +157 -103
- package/dist/react/index.mjs +152 -98
- package/dist/server/index.cjs +107 -59
- package/dist/server/index.mjs +107 -59
- package/package.json +1 -1
package/dist/expo/index.cjs
CHANGED
|
@@ -14863,10 +14863,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
14863
14863
|
function baseVaultSql(ctx, options) {
|
|
14864
14864
|
const clauses = [
|
|
14865
14865
|
`"_status" is not 'deleted'`,
|
|
14866
|
-
'"is_deleted" = 0',
|
|
14866
|
+
...options?.includeDeleted ? [] : ['"is_deleted" = 0'],
|
|
14867
14867
|
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
14868
14868
|
...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
|
|
14869
|
-
'"superseded_by" is null'
|
|
14869
|
+
...options?.includeSuperseded ? [] : ['"superseded_by" is null']
|
|
14870
14870
|
];
|
|
14871
14871
|
const args = [];
|
|
14872
14872
|
if (ctx.userId !== void 0) {
|
|
@@ -14875,6 +14875,38 @@ function baseVaultSql(ctx, options) {
|
|
|
14875
14875
|
}
|
|
14876
14876
|
return { sql: clauses.join(" and "), args };
|
|
14877
14877
|
}
|
|
14878
|
+
async function getVaultProfileMetadataOp(ctx, options) {
|
|
14879
|
+
const mapRaw = (raw) => ({
|
|
14880
|
+
uniqueId: raw.id,
|
|
14881
|
+
scope: raw.scope ?? "",
|
|
14882
|
+
createdAt: new Date(raw.created_at),
|
|
14883
|
+
updatedAt: new Date(raw.updated_at),
|
|
14884
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
14885
|
+
supersededAt: raw.superseded_at ?? null,
|
|
14886
|
+
supersededBy: raw.superseded_by ?? null,
|
|
14887
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
14888
|
+
proofCount: raw.proof_count ?? null
|
|
14889
|
+
});
|
|
14890
|
+
const listOptions = { ...options, includeDeleted: true, includeSuperseded: true };
|
|
14891
|
+
let rows;
|
|
14892
|
+
try {
|
|
14893
|
+
const base = baseVaultSql(ctx, listOptions);
|
|
14894
|
+
const clauses = [base.sql, `"_status" != 'deleted'`];
|
|
14895
|
+
const args = [...base.args];
|
|
14896
|
+
if (options?.scopes?.length) {
|
|
14897
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
14898
|
+
args.push(...options.scopes);
|
|
14899
|
+
}
|
|
14900
|
+
const sql = `select "id", "scope", "created_at", "updated_at", "last_observed_at", "superseded_at", "superseded_by", "is_deleted", "proof_count" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
14901
|
+
rows = await ctx.vaultMemoryCollection.query(import_watermelondb21.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
14902
|
+
} catch (err) {
|
|
14903
|
+
getLogger().debug(
|
|
14904
|
+
"memoryVault: getVaultProfileMetadataOp uses the query fallback: " + (err instanceof Error ? err.message : String(err))
|
|
14905
|
+
);
|
|
14906
|
+
rows = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, listOptions)).unsafeFetchRaw();
|
|
14907
|
+
}
|
|
14908
|
+
return rows.map(mapRaw);
|
|
14909
|
+
}
|
|
14878
14910
|
async function getVaultCandidateKeysOp(ctx, options) {
|
|
14879
14911
|
const mapRaw = (raw) => ({
|
|
14880
14912
|
uniqueId: raw.id,
|
|
@@ -15758,6 +15790,9 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
15758
15790
|
return null;
|
|
15759
15791
|
}
|
|
15760
15792
|
|
|
15793
|
+
// src/lib/db/memoryVault/photoIngest.ts
|
|
15794
|
+
var import_watermelondb22 = require("@nozbe/watermelondb");
|
|
15795
|
+
|
|
15761
15796
|
// src/lib/memory/decay.ts
|
|
15762
15797
|
init_logger();
|
|
15763
15798
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
@@ -15831,6 +15866,16 @@ function classifyDecay(m, now, policy) {
|
|
|
15831
15866
|
|
|
15832
15867
|
// src/lib/db/memoryVault/photoIngest.ts
|
|
15833
15868
|
var PHOTO_MEMORY_ID_PREFIX = "photo:";
|
|
15869
|
+
var PHOTO_ID_QUERY_CHUNK_SIZE = 500;
|
|
15870
|
+
async function getExistingPhotoMemoryIds(ctx, rows) {
|
|
15871
|
+
const existing = /* @__PURE__ */ new Set();
|
|
15872
|
+
for (let i = 0; i < rows.length; i += PHOTO_ID_QUERY_CHUNK_SIZE) {
|
|
15873
|
+
const ids = rows.slice(i, i + PHOTO_ID_QUERY_CHUNK_SIZE).map((row) => row.memoryId);
|
|
15874
|
+
const found = await ctx.vaultMemoryCollection.query(import_watermelondb22.Q.where("id", import_watermelondb22.Q.oneOf(ids))).fetchIds();
|
|
15875
|
+
for (const id2 of found) existing.add(id2);
|
|
15876
|
+
}
|
|
15877
|
+
return existing;
|
|
15878
|
+
}
|
|
15834
15879
|
async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
15835
15880
|
const byId = /* @__PURE__ */ new Map();
|
|
15836
15881
|
for (const r of rows) {
|
|
@@ -15839,7 +15884,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
15839
15884
|
}
|
|
15840
15885
|
const photoRows = [...byId.values()];
|
|
15841
15886
|
if (photoRows.length === 0) return { inserted: 0, skipped: 0 };
|
|
15842
|
-
const known = await ctx
|
|
15887
|
+
const known = await getExistingPhotoMemoryIds(ctx, photoRows);
|
|
15843
15888
|
const candidates = photoRows.filter((r) => !known.has(r.memoryId));
|
|
15844
15889
|
if (candidates.length === 0) return { inserted: 0, skipped: photoRows.length };
|
|
15845
15890
|
const fresh = candidates;
|
|
@@ -15859,7 +15904,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
15859
15904
|
const now = Date.now();
|
|
15860
15905
|
let inserted = 0;
|
|
15861
15906
|
await ctx.database.write(async () => {
|
|
15862
|
-
const present =
|
|
15907
|
+
const present = await getExistingPhotoMemoryIds(ctx, fresh);
|
|
15863
15908
|
const writable = fresh.map((row, i) => ({ row, content: contents[i] })).filter(({ row }) => !present.has(row.memoryId));
|
|
15864
15909
|
inserted = writable.length;
|
|
15865
15910
|
if (writable.length === 0) return;
|
|
@@ -16233,7 +16278,7 @@ var WalletPoller = class {
|
|
|
16233
16278
|
};
|
|
16234
16279
|
|
|
16235
16280
|
// src/lib/db/vaultFolders/operations.ts
|
|
16236
|
-
var
|
|
16281
|
+
var import_watermelondb23 = require("@nozbe/watermelondb");
|
|
16237
16282
|
function folderToStored(folder) {
|
|
16238
16283
|
return {
|
|
16239
16284
|
uniqueId: folder.id,
|
|
@@ -16258,7 +16303,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
16258
16303
|
return folderToStored(created);
|
|
16259
16304
|
}
|
|
16260
16305
|
async function getAllVaultFoldersOp(ctx) {
|
|
16261
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
16306
|
+
const results = await ctx.vaultFolderCollection.query(import_watermelondb23.Q.where("is_deleted", false), import_watermelondb23.Q.sortBy("created_at", import_watermelondb23.Q.desc)).fetch();
|
|
16262
16307
|
return results.map(folderToStored);
|
|
16263
16308
|
}
|
|
16264
16309
|
async function updateVaultFolderOp(ctx, id2, opts) {
|
|
@@ -16267,7 +16312,7 @@ async function updateVaultFolderOp(ctx, id2, opts) {
|
|
|
16267
16312
|
if (record2.isDeleted) return null;
|
|
16268
16313
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
16269
16314
|
const updated = await ctx.database.write(async () => {
|
|
16270
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
16315
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb23.Q.where("folder_id", id2), import_watermelondb23.Q.where("is_deleted", false)).fetch() : [];
|
|
16271
16316
|
const updates = [];
|
|
16272
16317
|
updates.push(
|
|
16273
16318
|
record2.prepareUpdate((r) => {
|
|
@@ -16296,7 +16341,7 @@ async function deleteVaultFolderOp(ctx, id2) {
|
|
|
16296
16341
|
const record2 = await ctx.vaultFolderCollection.find(id2);
|
|
16297
16342
|
if (record2.isDeleted) return false;
|
|
16298
16343
|
await ctx.database.write(async () => {
|
|
16299
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
16344
|
+
const memories = await ctx.vaultMemoryCollection.query(import_watermelondb23.Q.where("folder_id", id2), import_watermelondb23.Q.where("is_deleted", false)).fetch();
|
|
16300
16345
|
const preparedMemories = memories.map(
|
|
16301
16346
|
(memory) => memory.prepareUpdate((r) => {
|
|
16302
16347
|
r._setRaw("folder_id", null);
|
|
@@ -16367,7 +16412,7 @@ async function updateVaultFolderContextOp(ctx, id2, context) {
|
|
|
16367
16412
|
}
|
|
16368
16413
|
}
|
|
16369
16414
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
16370
|
-
return await ctx.vaultMemoryCollection.query(
|
|
16415
|
+
return await ctx.vaultMemoryCollection.query(import_watermelondb23.Q.where("folder_id", folderId), import_watermelondb23.Q.where("is_deleted", false)).fetchCount();
|
|
16371
16416
|
}
|
|
16372
16417
|
|
|
16373
16418
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -16413,7 +16458,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
16413
16458
|
init_logger();
|
|
16414
16459
|
|
|
16415
16460
|
// src/lib/memory/autoExtract.ts
|
|
16416
|
-
var
|
|
16461
|
+
var import_watermelondb24 = require("@nozbe/watermelondb");
|
|
16417
16462
|
init_logger();
|
|
16418
16463
|
init_redactor();
|
|
16419
16464
|
|
|
@@ -19226,7 +19271,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId, expectedContent) {
|
|
|
19226
19271
|
// src/lib/memory/autoExtract.ts
|
|
19227
19272
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
19228
19273
|
try {
|
|
19229
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
19274
|
+
const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb24.Q.where("id", memoryId)).fetch();
|
|
19230
19275
|
return rows[0]?.topicsUserManaged === true;
|
|
19231
19276
|
} catch {
|
|
19232
19277
|
return true;
|
|
@@ -21799,7 +21844,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
21799
21844
|
}
|
|
21800
21845
|
|
|
21801
21846
|
// src/lib/memory/store/local.ts
|
|
21802
|
-
var
|
|
21847
|
+
var import_watermelondb25 = require("@nozbe/watermelondb");
|
|
21803
21848
|
init_logger();
|
|
21804
21849
|
|
|
21805
21850
|
// src/lib/memory/topicExtract.ts
|
|
@@ -22085,8 +22130,8 @@ function createLocalMemoryStore(options) {
|
|
|
22085
22130
|
writeOptions?.signal?.throwIfAborted();
|
|
22086
22131
|
};
|
|
22087
22132
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
22088
|
-
const ownedBy = userId !== void 0 ? [
|
|
22089
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
22133
|
+
const ownedBy = userId !== void 0 ? [import_watermelondb25.Q.where("user_id", userId)] : [];
|
|
22134
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb25.Q.or(import_watermelondb25.Q.where("user_id", userId), import_watermelondb25.Q.where("user_id", null))] : [import_watermelondb25.Q.where("user_id", userId)];
|
|
22090
22135
|
const watchedColumns = [
|
|
22091
22136
|
"content",
|
|
22092
22137
|
"scope",
|
|
@@ -22132,7 +22177,7 @@ function createLocalMemoryStore(options) {
|
|
|
22132
22177
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
22133
22178
|
get: (id2) => getVaultMemoryOp(vaultCtx, id2),
|
|
22134
22179
|
listArchived: async () => {
|
|
22135
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
22180
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(import_watermelondb25.Q.where("is_deleted", false), import_watermelondb25.Q.where("archived_at", import_watermelondb25.Q.notEq(null)), ...ownedBy).fetchIds();
|
|
22136
22181
|
if (ids.length === 0) return [];
|
|
22137
22182
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
22138
22183
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -22148,7 +22193,7 @@ function createLocalMemoryStore(options) {
|
|
|
22148
22193
|
set.add(String(link.memory_id));
|
|
22149
22194
|
members.set(entityId, set);
|
|
22150
22195
|
}
|
|
22151
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
22196
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb25.Q.where("id", import_watermelondb25.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
22152
22197
|
const byName = /* @__PURE__ */ new Map();
|
|
22153
22198
|
for (const entity of entities) {
|
|
22154
22199
|
const name = String(entity.canonical_name);
|
|
@@ -22198,7 +22243,7 @@ function createLocalMemoryStore(options) {
|
|
|
22198
22243
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
22199
22244
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
22200
22245
|
await assertWrite(writeOptions);
|
|
22201
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
22246
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb25.Q.where("id", memoryId), import_watermelondb25.Q.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
22202
22247
|
return owned > 0 ? writer.callWriter(
|
|
22203
22248
|
() => linkMemoryEntitiesOp(
|
|
22204
22249
|
{
|
|
@@ -22270,7 +22315,7 @@ function createLocalMemoryStore(options) {
|
|
|
22270
22315
|
else onChange();
|
|
22271
22316
|
};
|
|
22272
22317
|
};
|
|
22273
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
22318
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb25.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
22274
22319
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
22275
22320
|
);
|
|
22276
22321
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -23265,32 +23310,38 @@ function stateFilters(options) {
|
|
|
23265
23310
|
include_superseded: options.includeSuperseded
|
|
23266
23311
|
};
|
|
23267
23312
|
}
|
|
23268
|
-
function
|
|
23269
|
-
|
|
23270
|
-
|
|
23271
|
-
return
|
|
23272
|
-
|
|
23273
|
-
|
|
23274
|
-
|
|
23275
|
-
|
|
23276
|
-
|
|
23277
|
-
|
|
23278
|
-
|
|
23279
|
-
|
|
23280
|
-
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23284
|
-
|
|
23285
|
-
|
|
23286
|
-
|
|
23287
|
-
|
|
23288
|
-
|
|
23289
|
-
|
|
23290
|
-
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
|
|
23313
|
+
function subscriptionState({ memory, version }) {
|
|
23314
|
+
const membership = memory.trust_tier === "quarantined" ? void 0 : String(!!memory.is_deleted);
|
|
23315
|
+
const hidden = membership === void 0 || memory.is_deleted || memory.archived_at !== void 0 && memory.archived_at !== null || !!memory.superseded_by;
|
|
23316
|
+
return {
|
|
23317
|
+
version,
|
|
23318
|
+
membership,
|
|
23319
|
+
fingerprint: hidden ? void 0 : (0, import_uuid5.v5)(
|
|
23320
|
+
JSON.stringify([
|
|
23321
|
+
memory.content,
|
|
23322
|
+
memory.scope,
|
|
23323
|
+
memory.updated_at,
|
|
23324
|
+
memory.fact_type,
|
|
23325
|
+
memory.event_time_start,
|
|
23326
|
+
memory.event_time_end,
|
|
23327
|
+
memory.event_time_kind,
|
|
23328
|
+
memory.trust_tier,
|
|
23329
|
+
memory.visibility,
|
|
23330
|
+
memory.published_at,
|
|
23331
|
+
memory.geohash,
|
|
23332
|
+
memory.topics,
|
|
23333
|
+
memory.topics_user_managed,
|
|
23334
|
+
memory.media,
|
|
23335
|
+
memory.source
|
|
23336
|
+
]),
|
|
23337
|
+
import_uuid5.v5.URL
|
|
23338
|
+
)
|
|
23339
|
+
};
|
|
23340
|
+
}
|
|
23341
|
+
function subscriptionKey(state, options) {
|
|
23342
|
+
if (options.includeDeleted) return state.membership;
|
|
23343
|
+
if (state.fingerprint === void 0) return void 0;
|
|
23344
|
+
return options.embeddings ? `${state.version}:${state.fingerprint}` : state.fingerprint;
|
|
23294
23345
|
}
|
|
23295
23346
|
function topicInputs(topics, source) {
|
|
23296
23347
|
return topics.flatMap((topic2) => {
|
|
@@ -23368,7 +23419,7 @@ function createRemoteMemoryStore(options) {
|
|
|
23368
23419
|
for (const record2 of records) {
|
|
23369
23420
|
const previous = seen.get(record2.memory.memory_id);
|
|
23370
23421
|
if ((previous?.version ?? 0) + 1 === record2.version)
|
|
23371
|
-
seen.set(record2.memory.memory_id, record2);
|
|
23422
|
+
seen.set(record2.memory.memory_id, subscriptionState(record2));
|
|
23372
23423
|
}
|
|
23373
23424
|
for (const subscriber of [...subscribers])
|
|
23374
23425
|
if (relevant(change, subscriber.options)) safely(subscriber.onChange);
|
|
@@ -23875,7 +23926,8 @@ function createRemoteMemoryStore(options) {
|
|
|
23875
23926
|
const failed = /* @__PURE__ */ new Map();
|
|
23876
23927
|
const collect = (page) => {
|
|
23877
23928
|
warnFailed(page.failed);
|
|
23878
|
-
|
|
23929
|
+
for (const record2 of page.items)
|
|
23930
|
+
records.push({ id: record2.memory.memory_id, state: subscriptionState(record2) });
|
|
23879
23931
|
for (const failure of page.failed) failed.set(failure.memory_id, failure.version);
|
|
23880
23932
|
};
|
|
23881
23933
|
let resume = cursor2;
|
|
@@ -23980,14 +24032,13 @@ function createRemoteMemoryStore(options) {
|
|
|
23980
24032
|
if (subscriber.options.topics) changed.add(subscriber);
|
|
23981
24033
|
}
|
|
23982
24034
|
if (topicState !== void 0) topicFingerprint = topicState;
|
|
23983
|
-
for (const
|
|
23984
|
-
const id2 = record2.memory.memory_id;
|
|
24035
|
+
for (const { id: id2, state } of records) {
|
|
23985
24036
|
const previous = seen.get(id2);
|
|
23986
|
-
seen.set(id2,
|
|
24037
|
+
seen.set(id2, state);
|
|
23987
24038
|
if (!ready) continue;
|
|
23988
24039
|
for (const subscriber of subscribers) {
|
|
23989
24040
|
const before = previous && subscriptionKey(previous, subscriber.options);
|
|
23990
|
-
if (before !== subscriptionKey(
|
|
24041
|
+
if (before !== subscriptionKey(state, subscriber.options)) changed.add(subscriber);
|
|
23991
24042
|
}
|
|
23992
24043
|
}
|
|
23993
24044
|
ready = true;
|
|
@@ -24591,7 +24642,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
24591
24642
|
};
|
|
24592
24643
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
24593
24644
|
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
24594
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await
|
|
24645
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
24595
24646
|
const watermark = computeVaultWatermark(memories);
|
|
24596
24647
|
const observationTrends = summarizeObservationTrends(
|
|
24597
24648
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -24627,7 +24678,8 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
24627
24678
|
previous,
|
|
24628
24679
|
watermark,
|
|
24629
24680
|
options.reviewedMemoryIds,
|
|
24630
|
-
previousUnreadable
|
|
24681
|
+
previousUnreadable,
|
|
24682
|
+
store ? void 0 : (ids) => getVaultEmbeddingsByIdsOp(vaultCtx, ids)
|
|
24631
24683
|
);
|
|
24632
24684
|
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
24633
24685
|
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
@@ -24714,7 +24766,7 @@ function computeVaultWatermark(memories) {
|
|
|
24714
24766
|
}
|
|
24715
24767
|
return max;
|
|
24716
24768
|
}
|
|
24717
|
-
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable) {
|
|
24769
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable, loadEmbeddings) {
|
|
24718
24770
|
const allKeys = new Set(facets.map((f) => f.key));
|
|
24719
24771
|
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
24720
24772
|
if (!previous) return allKeys;
|
|
@@ -24747,7 +24799,9 @@ async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark,
|
|
|
24747
24799
|
toAttribute = toAttribute.filter((m) => allowed.has(m.uniqueId));
|
|
24748
24800
|
}
|
|
24749
24801
|
if (toAttribute.length > 0) {
|
|
24750
|
-
const
|
|
24802
|
+
const candidates = loadEmbeddings ? await loadEmbeddings(toAttribute.map((m) => m.uniqueId)) : toAttribute;
|
|
24803
|
+
if (candidates.length !== toAttribute.length) return allKeys;
|
|
24804
|
+
const attributed = await attributeFacts(ctx, candidates, facets);
|
|
24751
24805
|
if (attributed === null) return allKeys;
|
|
24752
24806
|
for (const k of attributed) stale.add(k);
|
|
24753
24807
|
}
|
|
@@ -25171,17 +25225,17 @@ async function assembleMemoryContext(options) {
|
|
|
25171
25225
|
}
|
|
25172
25226
|
|
|
25173
25227
|
// src/lib/memory/durableExtraction.ts
|
|
25174
|
-
var
|
|
25228
|
+
var import_watermelondb26 = require("@nozbe/watermelondb");
|
|
25175
25229
|
async function messagePositions(storage, ids) {
|
|
25176
25230
|
try {
|
|
25177
25231
|
return await storage.messagesCollection.query(
|
|
25178
|
-
|
|
25232
|
+
import_watermelondb26.Q.unsafeSqlQuery(
|
|
25179
25233
|
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
25180
25234
|
ids
|
|
25181
25235
|
)
|
|
25182
25236
|
).unsafeFetchRaw();
|
|
25183
25237
|
} catch {
|
|
25184
|
-
return await storage.messagesCollection.query(
|
|
25238
|
+
return await storage.messagesCollection.query(import_watermelondb26.Q.where("id", import_watermelondb26.Q.oneOf(ids))).unsafeFetchRaw();
|
|
25185
25239
|
}
|
|
25186
25240
|
}
|
|
25187
25241
|
var MAX_JOBS_PER_PASS = 3;
|
|
@@ -25354,7 +25408,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25354
25408
|
const source = options.messageSource?.(conversationId);
|
|
25355
25409
|
if (source)
|
|
25356
25410
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
25357
|
-
return await storage.conversationsCollection.query(
|
|
25411
|
+
return await storage.conversationsCollection.query(import_watermelondb26.Q.where("conversation_id", conversationId), import_watermelondb26.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb26.Q.where("conversation_id", conversationId), import_watermelondb26.Q.where("id", import_watermelondb26.Q.oneOf(ids))).fetchCount() === ids.length;
|
|
25358
25412
|
}
|
|
25359
25413
|
function schedule(delay) {
|
|
25360
25414
|
if (disposed) return;
|
|
@@ -25528,7 +25582,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25528
25582
|
let sourceWaiting = false;
|
|
25529
25583
|
try {
|
|
25530
25584
|
await writes;
|
|
25531
|
-
const pending = await jobs.query(
|
|
25585
|
+
const pending = await jobs.query(import_watermelondb26.Q.where("owner_key", owner), import_watermelondb26.Q.where("message_ids", import_watermelondb26.Q.notEq("[]"))).fetch();
|
|
25532
25586
|
storeFailures = 0;
|
|
25533
25587
|
let processed = 0;
|
|
25534
25588
|
for (const job of pending) {
|
|
@@ -25560,7 +25614,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25560
25614
|
let ids = [];
|
|
25561
25615
|
let loaded = [];
|
|
25562
25616
|
try {
|
|
25563
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
25617
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(import_watermelondb26.Q.where("conversation_id", conversationId), import_watermelondb26.Q.where("is_deleted", false)).fetchCount() > 0;
|
|
25564
25618
|
if (!present) {
|
|
25565
25619
|
await database.write(() => job.destroyPermanently());
|
|
25566
25620
|
continue;
|
|
@@ -25728,7 +25782,7 @@ function createDurableAutoExtractor(options) {
|
|
|
25728
25782
|
const scope = currentScope();
|
|
25729
25783
|
writes = writes.then(
|
|
25730
25784
|
() => database.write(async () => {
|
|
25731
|
-
const existing = await jobs.query(
|
|
25785
|
+
const existing = await jobs.query(import_watermelondb26.Q.where("owner_key", owner), import_watermelondb26.Q.where("conversation_id", conversationId)).fetch();
|
|
25732
25786
|
const job = existing.find(
|
|
25733
25787
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
25734
25788
|
);
|
|
@@ -25741,8 +25795,8 @@ function createDurableAutoExtractor(options) {
|
|
|
25741
25795
|
if (watermarks.length) {
|
|
25742
25796
|
const misplaced = new Set(
|
|
25743
25797
|
await storage.messagesCollection.query(
|
|
25744
|
-
|
|
25745
|
-
|
|
25798
|
+
import_watermelondb26.Q.where("id", import_watermelondb26.Q.oneOf(watermarks)),
|
|
25799
|
+
import_watermelondb26.Q.where("conversation_id", import_watermelondb26.Q.notEq(conversationId))
|
|
25746
25800
|
).fetchIds()
|
|
25747
25801
|
);
|
|
25748
25802
|
for (const prior of existing)
|
|
@@ -28986,7 +29040,7 @@ async function cleanupConversationSummary(database, conversationId) {
|
|
|
28986
29040
|
}
|
|
28987
29041
|
|
|
28988
29042
|
// src/lib/db/media/operations.ts
|
|
28989
|
-
var
|
|
29043
|
+
var import_watermelondb27 = require("@nozbe/watermelondb");
|
|
28990
29044
|
|
|
28991
29045
|
// src/lib/storage/opfs.ts
|
|
28992
29046
|
function isOPFSSupported() {
|
|
@@ -29178,7 +29232,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
29178
29232
|
})
|
|
29179
29233
|
);
|
|
29180
29234
|
});
|
|
29181
|
-
const results = await mediaCollection.query(
|
|
29235
|
+
const results = await mediaCollection.query(import_watermelondb27.Q.where("media_id", import_watermelondb27.Q.oneOf(mediaIds))).fetch();
|
|
29182
29236
|
return Promise.all(
|
|
29183
29237
|
results.map(
|
|
29184
29238
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -29188,7 +29242,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
29188
29242
|
var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
29189
29243
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
29190
29244
|
const mediaCollection = ctx.database.get("media");
|
|
29191
|
-
const results = await mediaCollection.query(
|
|
29245
|
+
const results = await mediaCollection.query(import_watermelondb27.Q.where("conversation_id", conversationId), import_watermelondb27.Q.where("is_deleted", false)).fetch();
|
|
29192
29246
|
if (results.length === 0) {
|
|
29193
29247
|
return 0;
|
|
29194
29248
|
}
|