@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.mjs
CHANGED
|
@@ -13212,10 +13212,10 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
13212
13212
|
function baseVaultSql(ctx, options) {
|
|
13213
13213
|
const clauses = [
|
|
13214
13214
|
`"_status" is not 'deleted'`,
|
|
13215
|
-
'"is_deleted" = 0',
|
|
13215
|
+
...options?.includeDeleted ? [] : ['"is_deleted" = 0'],
|
|
13216
13216
|
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
13217
13217
|
...options?.includeQuarantined ? [] : [`"trust_tier" is not 'quarantined'`],
|
|
13218
|
-
'"superseded_by" is null'
|
|
13218
|
+
...options?.includeSuperseded ? [] : ['"superseded_by" is null']
|
|
13219
13219
|
];
|
|
13220
13220
|
const args = [];
|
|
13221
13221
|
if (ctx.userId !== void 0) {
|
|
@@ -13224,6 +13224,38 @@ function baseVaultSql(ctx, options) {
|
|
|
13224
13224
|
}
|
|
13225
13225
|
return { sql: clauses.join(" and "), args };
|
|
13226
13226
|
}
|
|
13227
|
+
async function getVaultProfileMetadataOp(ctx, options) {
|
|
13228
|
+
const mapRaw = (raw) => ({
|
|
13229
|
+
uniqueId: raw.id,
|
|
13230
|
+
scope: raw.scope ?? "",
|
|
13231
|
+
createdAt: new Date(raw.created_at),
|
|
13232
|
+
updatedAt: new Date(raw.updated_at),
|
|
13233
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
13234
|
+
supersededAt: raw.superseded_at ?? null,
|
|
13235
|
+
supersededBy: raw.superseded_by ?? null,
|
|
13236
|
+
isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
|
|
13237
|
+
proofCount: raw.proof_count ?? null
|
|
13238
|
+
});
|
|
13239
|
+
const listOptions = { ...options, includeDeleted: true, includeSuperseded: true };
|
|
13240
|
+
let rows;
|
|
13241
|
+
try {
|
|
13242
|
+
const base = baseVaultSql(ctx, listOptions);
|
|
13243
|
+
const clauses = [base.sql, `"_status" != 'deleted'`];
|
|
13244
|
+
const args = [...base.args];
|
|
13245
|
+
if (options?.scopes?.length) {
|
|
13246
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
13247
|
+
args.push(...options.scopes);
|
|
13248
|
+
}
|
|
13249
|
+
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 ")}`;
|
|
13250
|
+
rows = await ctx.vaultMemoryCollection.query(Q6.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
13251
|
+
} catch (err) {
|
|
13252
|
+
getLogger().debug(
|
|
13253
|
+
"memoryVault: getVaultProfileMetadataOp uses the query fallback: " + (err instanceof Error ? err.message : String(err))
|
|
13254
|
+
);
|
|
13255
|
+
rows = await ctx.vaultMemoryCollection.query(...vaultListConditions(ctx, listOptions)).unsafeFetchRaw();
|
|
13256
|
+
}
|
|
13257
|
+
return rows.map(mapRaw);
|
|
13258
|
+
}
|
|
13227
13259
|
async function getVaultCandidateKeysOp(ctx, options) {
|
|
13228
13260
|
const mapRaw = (raw) => ({
|
|
13229
13261
|
uniqueId: raw.id,
|
|
@@ -14107,6 +14139,9 @@ async function findQuarantinedDuplicateOp(ctx, content, sourceIds2, where) {
|
|
|
14107
14139
|
return null;
|
|
14108
14140
|
}
|
|
14109
14141
|
|
|
14142
|
+
// src/lib/db/memoryVault/photoIngest.ts
|
|
14143
|
+
import { Q as Q7 } from "@nozbe/watermelondb";
|
|
14144
|
+
|
|
14110
14145
|
// src/lib/memory/decay.ts
|
|
14111
14146
|
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
14112
14147
|
var SHORT_TTL_MS = 30 * DAY_MS;
|
|
@@ -14179,6 +14214,16 @@ function classifyDecay(m, now, policy) {
|
|
|
14179
14214
|
|
|
14180
14215
|
// src/lib/db/memoryVault/photoIngest.ts
|
|
14181
14216
|
var PHOTO_MEMORY_ID_PREFIX = "photo:";
|
|
14217
|
+
var PHOTO_ID_QUERY_CHUNK_SIZE = 500;
|
|
14218
|
+
async function getExistingPhotoMemoryIds(ctx, rows) {
|
|
14219
|
+
const existing = /* @__PURE__ */ new Set();
|
|
14220
|
+
for (let i = 0; i < rows.length; i += PHOTO_ID_QUERY_CHUNK_SIZE) {
|
|
14221
|
+
const ids = rows.slice(i, i + PHOTO_ID_QUERY_CHUNK_SIZE).map((row) => row.memoryId);
|
|
14222
|
+
const found = await ctx.vaultMemoryCollection.query(Q7.where("id", Q7.oneOf(ids))).fetchIds();
|
|
14223
|
+
for (const id2 of found) existing.add(id2);
|
|
14224
|
+
}
|
|
14225
|
+
return existing;
|
|
14226
|
+
}
|
|
14182
14227
|
async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
14183
14228
|
const byId = /* @__PURE__ */ new Map();
|
|
14184
14229
|
for (const r of rows) {
|
|
@@ -14187,7 +14232,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
14187
14232
|
}
|
|
14188
14233
|
const photoRows = [...byId.values()];
|
|
14189
14234
|
if (photoRows.length === 0) return { inserted: 0, skipped: 0 };
|
|
14190
|
-
const known = await ctx
|
|
14235
|
+
const known = await getExistingPhotoMemoryIds(ctx, photoRows);
|
|
14191
14236
|
const candidates = photoRows.filter((r) => !known.has(r.memoryId));
|
|
14192
14237
|
if (candidates.length === 0) return { inserted: 0, skipped: photoRows.length };
|
|
14193
14238
|
const fresh = candidates;
|
|
@@ -14207,7 +14252,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
14207
14252
|
const now = Date.now();
|
|
14208
14253
|
let inserted = 0;
|
|
14209
14254
|
await ctx.database.write(async () => {
|
|
14210
|
-
const present =
|
|
14255
|
+
const present = await getExistingPhotoMemoryIds(ctx, fresh);
|
|
14211
14256
|
const writable = fresh.map((row, i) => ({ row, content: contents[i] })).filter(({ row }) => !present.has(row.memoryId));
|
|
14212
14257
|
inserted = writable.length;
|
|
14213
14258
|
if (writable.length === 0) return;
|
|
@@ -14580,7 +14625,7 @@ var WalletPoller = class {
|
|
|
14580
14625
|
};
|
|
14581
14626
|
|
|
14582
14627
|
// src/lib/db/vaultFolders/operations.ts
|
|
14583
|
-
import { Q as
|
|
14628
|
+
import { Q as Q8 } from "@nozbe/watermelondb";
|
|
14584
14629
|
function folderToStored(folder) {
|
|
14585
14630
|
return {
|
|
14586
14631
|
uniqueId: folder.id,
|
|
@@ -14605,7 +14650,7 @@ async function createVaultFolderOp(ctx, opts) {
|
|
|
14605
14650
|
return folderToStored(created);
|
|
14606
14651
|
}
|
|
14607
14652
|
async function getAllVaultFoldersOp(ctx) {
|
|
14608
|
-
const results = await ctx.vaultFolderCollection.query(
|
|
14653
|
+
const results = await ctx.vaultFolderCollection.query(Q8.where("is_deleted", false), Q8.sortBy("created_at", Q8.desc)).fetch();
|
|
14609
14654
|
return results.map(folderToStored);
|
|
14610
14655
|
}
|
|
14611
14656
|
async function updateVaultFolderOp(ctx, id2, opts) {
|
|
@@ -14614,7 +14659,7 @@ async function updateVaultFolderOp(ctx, id2, opts) {
|
|
|
14614
14659
|
if (record2.isDeleted) return null;
|
|
14615
14660
|
const scopeChanged = opts.scope !== void 0 && opts.scope !== record2.scope;
|
|
14616
14661
|
const updated = await ctx.database.write(async () => {
|
|
14617
|
-
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(
|
|
14662
|
+
const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(Q8.where("folder_id", id2), Q8.where("is_deleted", false)).fetch() : [];
|
|
14618
14663
|
const updates = [];
|
|
14619
14664
|
updates.push(
|
|
14620
14665
|
record2.prepareUpdate((r) => {
|
|
@@ -14643,7 +14688,7 @@ async function deleteVaultFolderOp(ctx, id2) {
|
|
|
14643
14688
|
const record2 = await ctx.vaultFolderCollection.find(id2);
|
|
14644
14689
|
if (record2.isDeleted) return false;
|
|
14645
14690
|
await ctx.database.write(async () => {
|
|
14646
|
-
const memories = await ctx.vaultMemoryCollection.query(
|
|
14691
|
+
const memories = await ctx.vaultMemoryCollection.query(Q8.where("folder_id", id2), Q8.where("is_deleted", false)).fetch();
|
|
14647
14692
|
const preparedMemories = memories.map(
|
|
14648
14693
|
(memory) => memory.prepareUpdate((r) => {
|
|
14649
14694
|
r._setRaw("folder_id", null);
|
|
@@ -14714,7 +14759,7 @@ async function updateVaultFolderContextOp(ctx, id2, context) {
|
|
|
14714
14759
|
}
|
|
14715
14760
|
}
|
|
14716
14761
|
async function getVaultFolderMemoryCountOp(ctx, folderId) {
|
|
14717
|
-
return await ctx.vaultMemoryCollection.query(
|
|
14762
|
+
return await ctx.vaultMemoryCollection.query(Q8.where("folder_id", folderId), Q8.where("is_deleted", false)).fetchCount();
|
|
14718
14763
|
}
|
|
14719
14764
|
|
|
14720
14765
|
// src/lib/db/vaultFolders/defaults.ts
|
|
@@ -14757,7 +14802,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
|
|
|
14757
14802
|
}
|
|
14758
14803
|
|
|
14759
14804
|
// src/lib/memory/autoExtract.ts
|
|
14760
|
-
import { Q as
|
|
14805
|
+
import { Q as Q9 } from "@nozbe/watermelondb";
|
|
14761
14806
|
|
|
14762
14807
|
// src/lib/memory/entitySalience.ts
|
|
14763
14808
|
var GENERIC_ENTITY_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -17551,7 +17596,7 @@ async function assertMergeTargetGoneOrThrow(ctx, targetId, expectedContent) {
|
|
|
17551
17596
|
// src/lib/memory/autoExtract.ts
|
|
17552
17597
|
async function isMemoryTopicsUserManaged(ctx, memoryId) {
|
|
17553
17598
|
try {
|
|
17554
|
-
const rows = await ctx.database.get(VaultMemory.table).query(
|
|
17599
|
+
const rows = await ctx.database.get(VaultMemory.table).query(Q9.where("id", memoryId)).fetch();
|
|
17555
17600
|
return rows[0]?.topicsUserManaged === true;
|
|
17556
17601
|
} catch {
|
|
17557
17602
|
return true;
|
|
@@ -20107,7 +20152,7 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
20107
20152
|
}
|
|
20108
20153
|
|
|
20109
20154
|
// src/lib/memory/store/local.ts
|
|
20110
|
-
import { Q as
|
|
20155
|
+
import { Q as Q10 } from "@nozbe/watermelondb";
|
|
20111
20156
|
|
|
20112
20157
|
// src/lib/memory/topicExtract.ts
|
|
20113
20158
|
var TOPIC_EXTRACTION_BATCH_SIZE = 10;
|
|
@@ -20389,8 +20434,8 @@ function createLocalMemoryStore(options) {
|
|
|
20389
20434
|
writeOptions?.signal?.throwIfAborted();
|
|
20390
20435
|
};
|
|
20391
20436
|
const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
|
|
20392
|
-
const ownedBy = userId !== void 0 ? [
|
|
20393
|
-
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [
|
|
20437
|
+
const ownedBy = userId !== void 0 ? [Q10.where("user_id", userId)] : [];
|
|
20438
|
+
const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [Q10.or(Q10.where("user_id", userId), Q10.where("user_id", null))] : [Q10.where("user_id", userId)];
|
|
20394
20439
|
const watchedColumns = [
|
|
20395
20440
|
"content",
|
|
20396
20441
|
"scope",
|
|
@@ -20436,7 +20481,7 @@ function createLocalMemoryStore(options) {
|
|
|
20436
20481
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
20437
20482
|
get: (id2) => getVaultMemoryOp(vaultCtx, id2),
|
|
20438
20483
|
listArchived: async () => {
|
|
20439
|
-
const ids = await vaultCtx.vaultMemoryCollection.query(
|
|
20484
|
+
const ids = await vaultCtx.vaultMemoryCollection.query(Q10.where("is_deleted", false), Q10.where("archived_at", Q10.notEq(null)), ...ownedBy).fetchIds();
|
|
20440
20485
|
if (ids.length === 0) return [];
|
|
20441
20486
|
const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
|
|
20442
20487
|
return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
|
|
@@ -20452,7 +20497,7 @@ function createLocalMemoryStore(options) {
|
|
|
20452
20497
|
set.add(String(link.memory_id));
|
|
20453
20498
|
members.set(entityId, set);
|
|
20454
20499
|
}
|
|
20455
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(
|
|
20500
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(Q10.where("id", Q10.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
20456
20501
|
const byName = /* @__PURE__ */ new Map();
|
|
20457
20502
|
for (const entity of entities) {
|
|
20458
20503
|
const name = String(entity.canonical_name);
|
|
@@ -20502,7 +20547,7 @@ function createLocalMemoryStore(options) {
|
|
|
20502
20547
|
setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
|
|
20503
20548
|
addTopics: (memoryId, topics, writeOptions) => database.write(async (writer) => {
|
|
20504
20549
|
await assertWrite(writeOptions);
|
|
20505
|
-
const owned = await vaultCtx.vaultMemoryCollection.query(
|
|
20550
|
+
const owned = await vaultCtx.vaultMemoryCollection.query(Q10.where("id", memoryId), Q10.where("is_deleted", false), ...ownedBy).fetchCount();
|
|
20506
20551
|
return owned > 0 ? writer.callWriter(
|
|
20507
20552
|
() => linkMemoryEntitiesOp(
|
|
20508
20553
|
{
|
|
@@ -20574,7 +20619,7 @@ function createLocalMemoryStore(options) {
|
|
|
20574
20619
|
else onChange();
|
|
20575
20620
|
};
|
|
20576
20621
|
};
|
|
20577
|
-
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(
|
|
20622
|
+
const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(Q10.where("is_deleted", false), ...ownedBy).observeWithColumns(
|
|
20578
20623
|
subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
|
|
20579
20624
|
);
|
|
20580
20625
|
const subscriptions = [memories.subscribe(afterFirst())];
|
|
@@ -21489,7 +21534,7 @@ async function migrateMemoriesToRemote(options) {
|
|
|
21489
21534
|
}
|
|
21490
21535
|
|
|
21491
21536
|
// src/lib/memory/store/remoteStore.ts
|
|
21492
|
-
import { v7 as uuidv75 } from "uuid";
|
|
21537
|
+
import { v5 as uuidv5, v7 as uuidv75 } from "uuid";
|
|
21493
21538
|
function projection({ memory }) {
|
|
21494
21539
|
return {
|
|
21495
21540
|
uniqueId: memory.memory_id,
|
|
@@ -21564,32 +21609,38 @@ function stateFilters(options) {
|
|
|
21564
21609
|
include_superseded: options.includeSuperseded
|
|
21565
21610
|
};
|
|
21566
21611
|
}
|
|
21567
|
-
function
|
|
21568
|
-
|
|
21569
|
-
|
|
21570
|
-
return
|
|
21571
|
-
|
|
21572
|
-
|
|
21573
|
-
|
|
21574
|
-
|
|
21575
|
-
|
|
21576
|
-
|
|
21577
|
-
|
|
21578
|
-
|
|
21579
|
-
|
|
21580
|
-
|
|
21581
|
-
|
|
21582
|
-
|
|
21583
|
-
|
|
21584
|
-
|
|
21585
|
-
|
|
21586
|
-
|
|
21587
|
-
|
|
21588
|
-
|
|
21589
|
-
|
|
21590
|
-
|
|
21591
|
-
|
|
21592
|
-
|
|
21612
|
+
function subscriptionState({ memory, version }) {
|
|
21613
|
+
const membership = memory.trust_tier === "quarantined" ? void 0 : String(!!memory.is_deleted);
|
|
21614
|
+
const hidden = membership === void 0 || memory.is_deleted || memory.archived_at !== void 0 && memory.archived_at !== null || !!memory.superseded_by;
|
|
21615
|
+
return {
|
|
21616
|
+
version,
|
|
21617
|
+
membership,
|
|
21618
|
+
fingerprint: hidden ? void 0 : uuidv5(
|
|
21619
|
+
JSON.stringify([
|
|
21620
|
+
memory.content,
|
|
21621
|
+
memory.scope,
|
|
21622
|
+
memory.updated_at,
|
|
21623
|
+
memory.fact_type,
|
|
21624
|
+
memory.event_time_start,
|
|
21625
|
+
memory.event_time_end,
|
|
21626
|
+
memory.event_time_kind,
|
|
21627
|
+
memory.trust_tier,
|
|
21628
|
+
memory.visibility,
|
|
21629
|
+
memory.published_at,
|
|
21630
|
+
memory.geohash,
|
|
21631
|
+
memory.topics,
|
|
21632
|
+
memory.topics_user_managed,
|
|
21633
|
+
memory.media,
|
|
21634
|
+
memory.source
|
|
21635
|
+
]),
|
|
21636
|
+
uuidv5.URL
|
|
21637
|
+
)
|
|
21638
|
+
};
|
|
21639
|
+
}
|
|
21640
|
+
function subscriptionKey(state, options) {
|
|
21641
|
+
if (options.includeDeleted) return state.membership;
|
|
21642
|
+
if (state.fingerprint === void 0) return void 0;
|
|
21643
|
+
return options.embeddings ? `${state.version}:${state.fingerprint}` : state.fingerprint;
|
|
21593
21644
|
}
|
|
21594
21645
|
function topicInputs(topics, source) {
|
|
21595
21646
|
return topics.flatMap((topic2) => {
|
|
@@ -21667,7 +21718,7 @@ function createRemoteMemoryStore(options) {
|
|
|
21667
21718
|
for (const record2 of records) {
|
|
21668
21719
|
const previous = seen.get(record2.memory.memory_id);
|
|
21669
21720
|
if ((previous?.version ?? 0) + 1 === record2.version)
|
|
21670
|
-
seen.set(record2.memory.memory_id, record2);
|
|
21721
|
+
seen.set(record2.memory.memory_id, subscriptionState(record2));
|
|
21671
21722
|
}
|
|
21672
21723
|
for (const subscriber of [...subscribers])
|
|
21673
21724
|
if (relevant(change, subscriber.options)) safely(subscriber.onChange);
|
|
@@ -22174,7 +22225,8 @@ function createRemoteMemoryStore(options) {
|
|
|
22174
22225
|
const failed = /* @__PURE__ */ new Map();
|
|
22175
22226
|
const collect = (page) => {
|
|
22176
22227
|
warnFailed(page.failed);
|
|
22177
|
-
|
|
22228
|
+
for (const record2 of page.items)
|
|
22229
|
+
records.push({ id: record2.memory.memory_id, state: subscriptionState(record2) });
|
|
22178
22230
|
for (const failure of page.failed) failed.set(failure.memory_id, failure.version);
|
|
22179
22231
|
};
|
|
22180
22232
|
let resume = cursor2;
|
|
@@ -22279,14 +22331,13 @@ function createRemoteMemoryStore(options) {
|
|
|
22279
22331
|
if (subscriber.options.topics) changed.add(subscriber);
|
|
22280
22332
|
}
|
|
22281
22333
|
if (topicState !== void 0) topicFingerprint = topicState;
|
|
22282
|
-
for (const
|
|
22283
|
-
const id2 = record2.memory.memory_id;
|
|
22334
|
+
for (const { id: id2, state } of records) {
|
|
22284
22335
|
const previous = seen.get(id2);
|
|
22285
|
-
seen.set(id2,
|
|
22336
|
+
seen.set(id2, state);
|
|
22286
22337
|
if (!ready) continue;
|
|
22287
22338
|
for (const subscriber of subscribers) {
|
|
22288
22339
|
const before = previous && subscriptionKey(previous, subscriber.options);
|
|
22289
|
-
if (before !== subscriptionKey(
|
|
22340
|
+
if (before !== subscriptionKey(state, subscriber.options)) changed.add(subscriber);
|
|
22290
22341
|
}
|
|
22291
22342
|
}
|
|
22292
22343
|
ready = true;
|
|
@@ -22888,7 +22939,7 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
22888
22939
|
};
|
|
22889
22940
|
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
22890
22941
|
const listOptions = { scopes, includeDeleted: true, includeSuperseded: true };
|
|
22891
|
-
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await
|
|
22942
|
+
const [memories, projections] = store ? await Promise.all([store.list(listOptions), store.listProjections(listOptions)]) : [await getVaultProfileMetadataOp(vaultCtx, { scopes }), []];
|
|
22892
22943
|
const watermark = computeVaultWatermark(memories);
|
|
22893
22944
|
const observationTrends = summarizeObservationTrends(
|
|
22894
22945
|
memories.filter((m) => !m.isDeleted && m.supersededBy === null).map((m) => ({
|
|
@@ -22924,7 +22975,8 @@ async function synthesizeProfile(ctx, options = {}) {
|
|
|
22924
22975
|
previous,
|
|
22925
22976
|
watermark,
|
|
22926
22977
|
options.reviewedMemoryIds,
|
|
22927
|
-
previousUnreadable
|
|
22978
|
+
previousUnreadable,
|
|
22979
|
+
store ? void 0 : (ids) => getVaultEmbeddingsByIdsOp(vaultCtx, ids)
|
|
22928
22980
|
);
|
|
22929
22981
|
const memoriesById = new Map(memories.map((memory) => [memory.uniqueId, memory]));
|
|
22930
22982
|
const fallbackPriors = /* @__PURE__ */ new Map();
|
|
@@ -23011,7 +23063,7 @@ function computeVaultWatermark(memories) {
|
|
|
23011
23063
|
}
|
|
23012
23064
|
return max;
|
|
23013
23065
|
}
|
|
23014
|
-
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable) {
|
|
23066
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark, reviewedMemoryIds, previouslyUnreadable, loadEmbeddings) {
|
|
23015
23067
|
const allKeys = new Set(facets.map((f) => f.key));
|
|
23016
23068
|
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
23017
23069
|
if (!previous) return allKeys;
|
|
@@ -23044,7 +23096,9 @@ async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark,
|
|
|
23044
23096
|
toAttribute = toAttribute.filter((m) => allowed.has(m.uniqueId));
|
|
23045
23097
|
}
|
|
23046
23098
|
if (toAttribute.length > 0) {
|
|
23047
|
-
const
|
|
23099
|
+
const candidates = loadEmbeddings ? await loadEmbeddings(toAttribute.map((m) => m.uniqueId)) : toAttribute;
|
|
23100
|
+
if (candidates.length !== toAttribute.length) return allKeys;
|
|
23101
|
+
const attributed = await attributeFacts(ctx, candidates, facets);
|
|
23048
23102
|
if (attributed === null) return allKeys;
|
|
23049
23103
|
for (const k of attributed) stale.add(k);
|
|
23050
23104
|
}
|
|
@@ -23468,17 +23522,17 @@ async function assembleMemoryContext(options) {
|
|
|
23468
23522
|
}
|
|
23469
23523
|
|
|
23470
23524
|
// src/lib/memory/durableExtraction.ts
|
|
23471
|
-
import { Q as
|
|
23525
|
+
import { Q as Q11 } from "@nozbe/watermelondb";
|
|
23472
23526
|
async function messagePositions(storage, ids) {
|
|
23473
23527
|
try {
|
|
23474
23528
|
return await storage.messagesCollection.query(
|
|
23475
|
-
|
|
23529
|
+
Q11.unsafeSqlQuery(
|
|
23476
23530
|
`select "id", "conversation_id", "message_id" from "history" where "_status" is not 'deleted' and "id" in (${ids.map(() => "?").join(",")})`,
|
|
23477
23531
|
ids
|
|
23478
23532
|
)
|
|
23479
23533
|
).unsafeFetchRaw();
|
|
23480
23534
|
} catch {
|
|
23481
|
-
return await storage.messagesCollection.query(
|
|
23535
|
+
return await storage.messagesCollection.query(Q11.where("id", Q11.oneOf(ids))).unsafeFetchRaw();
|
|
23482
23536
|
}
|
|
23483
23537
|
}
|
|
23484
23538
|
var MAX_JOBS_PER_PASS = 3;
|
|
@@ -23651,7 +23705,7 @@ function createDurableAutoExtractor(options) {
|
|
|
23651
23705
|
const source = options.messageSource?.(conversationId);
|
|
23652
23706
|
if (source)
|
|
23653
23707
|
return await fromSource(source.status(conversationId)) === "ready" && (await loadFromSource(source, conversationId, ids)).every(Boolean);
|
|
23654
|
-
return await storage.conversationsCollection.query(
|
|
23708
|
+
return await storage.conversationsCollection.query(Q11.where("conversation_id", conversationId), Q11.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(Q11.where("conversation_id", conversationId), Q11.where("id", Q11.oneOf(ids))).fetchCount() === ids.length;
|
|
23655
23709
|
}
|
|
23656
23710
|
function schedule(delay) {
|
|
23657
23711
|
if (disposed) return;
|
|
@@ -23825,7 +23879,7 @@ function createDurableAutoExtractor(options) {
|
|
|
23825
23879
|
let sourceWaiting = false;
|
|
23826
23880
|
try {
|
|
23827
23881
|
await writes;
|
|
23828
|
-
const pending = await jobs.query(
|
|
23882
|
+
const pending = await jobs.query(Q11.where("owner_key", owner), Q11.where("message_ids", Q11.notEq("[]"))).fetch();
|
|
23829
23883
|
storeFailures = 0;
|
|
23830
23884
|
let processed = 0;
|
|
23831
23885
|
for (const job of pending) {
|
|
@@ -23857,7 +23911,7 @@ function createDurableAutoExtractor(options) {
|
|
|
23857
23911
|
let ids = [];
|
|
23858
23912
|
let loaded = [];
|
|
23859
23913
|
try {
|
|
23860
|
-
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(
|
|
23914
|
+
const present = source ? sourceStatus === "ready" : await storage.conversationsCollection.query(Q11.where("conversation_id", conversationId), Q11.where("is_deleted", false)).fetchCount() > 0;
|
|
23861
23915
|
if (!present) {
|
|
23862
23916
|
await database.write(() => job.destroyPermanently());
|
|
23863
23917
|
continue;
|
|
@@ -24025,7 +24079,7 @@ function createDurableAutoExtractor(options) {
|
|
|
24025
24079
|
const scope = currentScope();
|
|
24026
24080
|
writes = writes.then(
|
|
24027
24081
|
() => database.write(async () => {
|
|
24028
|
-
const existing = await jobs.query(
|
|
24082
|
+
const existing = await jobs.query(Q11.where("owner_key", owner), Q11.where("conversation_id", conversationId)).fetch();
|
|
24029
24083
|
const job = existing.find(
|
|
24030
24084
|
(candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
|
|
24031
24085
|
);
|
|
@@ -24038,8 +24092,8 @@ function createDurableAutoExtractor(options) {
|
|
|
24038
24092
|
if (watermarks.length) {
|
|
24039
24093
|
const misplaced = new Set(
|
|
24040
24094
|
await storage.messagesCollection.query(
|
|
24041
|
-
|
|
24042
|
-
|
|
24095
|
+
Q11.where("id", Q11.oneOf(watermarks)),
|
|
24096
|
+
Q11.where("conversation_id", Q11.notEq(conversationId))
|
|
24043
24097
|
).fetchIds()
|
|
24044
24098
|
);
|
|
24045
24099
|
for (const prior of existing)
|
|
@@ -27265,7 +27319,7 @@ async function cleanupConversationSummary(database, conversationId) {
|
|
|
27265
27319
|
}
|
|
27266
27320
|
|
|
27267
27321
|
// src/lib/db/media/operations.ts
|
|
27268
|
-
import { Q as
|
|
27322
|
+
import { Q as Q12 } from "@nozbe/watermelondb";
|
|
27269
27323
|
|
|
27270
27324
|
// src/lib/storage/opfs.ts
|
|
27271
27325
|
function isOPFSSupported() {
|
|
@@ -27456,7 +27510,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
27456
27510
|
})
|
|
27457
27511
|
);
|
|
27458
27512
|
});
|
|
27459
|
-
const results = await mediaCollection.query(
|
|
27513
|
+
const results = await mediaCollection.query(Q12.where("media_id", Q12.oneOf(mediaIds))).fetch();
|
|
27460
27514
|
return Promise.all(
|
|
27461
27515
|
results.map(
|
|
27462
27516
|
(m) => mediaToStored(m, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
@@ -27466,7 +27520,7 @@ async function createMediaBatchOp(ctx, optionsArray) {
|
|
|
27466
27520
|
var IMAGE_VIDEO_MIMES = VIDEO_EXTENSIONS.map((ext) => `image/${ext}`);
|
|
27467
27521
|
async function deleteMediaByConversationOp(ctx, conversationId) {
|
|
27468
27522
|
const mediaCollection = ctx.database.get("media");
|
|
27469
|
-
const results = await mediaCollection.query(
|
|
27523
|
+
const results = await mediaCollection.query(Q12.where("conversation_id", conversationId), Q12.where("is_deleted", false)).fetch();
|
|
27470
27524
|
if (results.length === 0) {
|
|
27471
27525
|
return 0;
|
|
27472
27526
|
}
|