@anuma/sdk 3.9.5 → 3.10.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-HXBDHRKJ.mjs → chunk-CFGUZHAY.mjs} +95 -14
- package/dist/expo/{consolidate-HKN32P5W.mjs → consolidate-NC5DOC5J.mjs} +3 -2
- package/dist/expo/index.cjs +168 -35
- package/dist/expo/index.d.mts +88 -2
- package/dist/expo/index.d.ts +88 -2
- package/dist/expo/index.mjs +68 -16
- package/dist/{react/recall-7NVXMANO.mjs → expo/recall-34WI57Z7.mjs} +1 -1
- package/dist/react/{chunk-IWR7BNER.mjs → chunk-SCFNOAWH.mjs} +95 -14
- package/dist/react/{consolidate-7UUX56GM.mjs → consolidate-54UWIMP6.mjs} +3 -2
- package/dist/react/index.cjs +168 -35
- package/dist/react/index.d.mts +88 -2
- package/dist/react/index.d.ts +88 -2
- package/dist/react/index.mjs +68 -16
- package/dist/{expo/recall-I5AZFOUM.mjs → react/recall-GCW2EV4V.mjs} +1 -1
- package/dist/server/{chunk-UU2F523R.mjs → chunk-Q4ACA4RO.mjs} +95 -14
- package/dist/server/{consolidate-BKLNVH5Y.mjs → consolidate-YCD45CXO.mjs} +3 -2
- package/dist/server/index.cjs +168 -35
- package/dist/server/index.d.mts +88 -2
- package/dist/server/index.d.ts +88 -2
- package/dist/server/index.mjs +68 -16
- package/dist/server/{recall-RVRZ4RQT.mjs → recall-XO6QTDMG.mjs} +1 -1
- package/package.json +3 -2
|
@@ -2187,6 +2187,19 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
|
|
|
2187
2187
|
}
|
|
2188
2188
|
|
|
2189
2189
|
// src/lib/db/memoryVault/operations.ts
|
|
2190
|
+
function visibilityOrPrivate(value) {
|
|
2191
|
+
return value === "public" ? value : "private";
|
|
2192
|
+
}
|
|
2193
|
+
var NON_PRIVATE_VISIBILITIES = ["public"];
|
|
2194
|
+
function visibilityConditions(requested) {
|
|
2195
|
+
if (!requested?.length) return [];
|
|
2196
|
+
if (!requested.includes("private")) {
|
|
2197
|
+
return [Q3.where("visibility", Q3.oneOf([...requested]))];
|
|
2198
|
+
}
|
|
2199
|
+
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
2200
|
+
if (excluded.length === 0) return [];
|
|
2201
|
+
return [Q3.or(Q3.where("visibility", null), Q3.where("visibility", Q3.notIn(excluded)))];
|
|
2202
|
+
}
|
|
2190
2203
|
function isOwnedByCtxUser(ctx, record) {
|
|
2191
2204
|
return ctx.userId === void 0 || record.userId === ctx.userId;
|
|
2192
2205
|
}
|
|
@@ -2248,6 +2261,10 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
2248
2261
|
factType: memory.factType ?? null,
|
|
2249
2262
|
archivedAt: memory.archivedAt ?? null,
|
|
2250
2263
|
trustTier: memory.trustTier ?? null,
|
|
2264
|
+
visibility: visibilityOrPrivate(memory.visibility),
|
|
2265
|
+
twinOptIn: memory.twinOptIn ?? false,
|
|
2266
|
+
publishedAt: memory.publishedAt ?? null,
|
|
2267
|
+
geohash: memory.geohash ?? null,
|
|
2251
2268
|
createdAt: memory.createdAt,
|
|
2252
2269
|
updatedAt: memory.updatedAt,
|
|
2253
2270
|
isDeleted: memory.isDeleted
|
|
@@ -2295,6 +2312,14 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
2295
2312
|
if (opts.trustTier !== void 0) {
|
|
2296
2313
|
record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
|
|
2297
2314
|
}
|
|
2315
|
+
record._setRaw("visibility", opts.visibility ?? "private");
|
|
2316
|
+
record._setRaw(
|
|
2317
|
+
"published_at",
|
|
2318
|
+
opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
|
|
2319
|
+
);
|
|
2320
|
+
if (opts.geohash !== void 0) {
|
|
2321
|
+
record._setRaw("geohash", opts.geohash);
|
|
2322
|
+
}
|
|
2298
2323
|
});
|
|
2299
2324
|
});
|
|
2300
2325
|
return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
@@ -2441,6 +2466,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
2441
2466
|
if (opts.trustTier !== void 0) {
|
|
2442
2467
|
record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
|
|
2443
2468
|
}
|
|
2469
|
+
record._setRaw("visibility", opts.visibility ?? "private");
|
|
2470
|
+
record._setRaw(
|
|
2471
|
+
"published_at",
|
|
2472
|
+
opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
|
|
2473
|
+
);
|
|
2474
|
+
if (opts.geohash !== void 0) {
|
|
2475
|
+
record._setRaw("geohash", opts.geohash);
|
|
2476
|
+
}
|
|
2444
2477
|
})
|
|
2445
2478
|
);
|
|
2446
2479
|
await ctx.database.batch(...prepared);
|
|
@@ -2504,6 +2537,10 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
2504
2537
|
factType: raw.fact_type ?? null,
|
|
2505
2538
|
archivedAt: raw.archived_at ?? null,
|
|
2506
2539
|
trustTier: raw.trust_tier ?? null,
|
|
2540
|
+
visibility: visibilityOrPrivate(raw.visibility),
|
|
2541
|
+
twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
|
|
2542
|
+
publishedAt: raw.published_at ?? null,
|
|
2543
|
+
geohash: raw.geohash ?? null,
|
|
2507
2544
|
createdAt: new Date(raw.created_at),
|
|
2508
2545
|
updatedAt: new Date(raw.updated_at),
|
|
2509
2546
|
isDeleted: raw.is_deleted === true || raw.is_deleted === 1
|
|
@@ -2520,6 +2557,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
2520
2557
|
const conditions = [
|
|
2521
2558
|
...baseVaultConditions(ctx, options),
|
|
2522
2559
|
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
2560
|
+
...visibilityConditions(options?.visibility),
|
|
2523
2561
|
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
|
|
2524
2562
|
...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : [],
|
|
2525
2563
|
Q3.sortBy(options?.since ? "updated_at" : "created_at", Q3.desc),
|
|
@@ -2813,6 +2851,38 @@ async function clearMemoryTopicsOverrideOp(ctx, memoryId) {
|
|
|
2813
2851
|
});
|
|
2814
2852
|
return true;
|
|
2815
2853
|
}
|
|
2854
|
+
async function setMemoryVisibilityOp(ctx, id, opts) {
|
|
2855
|
+
let record;
|
|
2856
|
+
try {
|
|
2857
|
+
record = await ctx.vaultMemoryCollection.find(id);
|
|
2858
|
+
} catch {
|
|
2859
|
+
return null;
|
|
2860
|
+
}
|
|
2861
|
+
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
|
|
2862
|
+
let stale = false;
|
|
2863
|
+
await ctx.database.write(async () => {
|
|
2864
|
+
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
|
|
2865
|
+
stale = true;
|
|
2866
|
+
return;
|
|
2867
|
+
}
|
|
2868
|
+
const currentUpdatedAt = record.updatedAt.getTime();
|
|
2869
|
+
const currentPublishedAt = record.publishedAt ?? null;
|
|
2870
|
+
await record.update((r) => {
|
|
2871
|
+
r._setRaw("visibility", opts.visibility);
|
|
2872
|
+
if (opts.visibility === "private") {
|
|
2873
|
+
r._setRaw("published_at", null);
|
|
2874
|
+
} else if (currentPublishedAt === null) {
|
|
2875
|
+
r._setRaw("published_at", Date.now());
|
|
2876
|
+
}
|
|
2877
|
+
if (opts.twinOptIn !== void 0) {
|
|
2878
|
+
r._setRaw("twin_opt_in", opts.twinOptIn);
|
|
2879
|
+
}
|
|
2880
|
+
r._setRaw("updated_at", currentUpdatedAt);
|
|
2881
|
+
});
|
|
2882
|
+
});
|
|
2883
|
+
if (stale) return null;
|
|
2884
|
+
return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
2885
|
+
}
|
|
2816
2886
|
async function deleteVaultMemoryOp(ctx, id) {
|
|
2817
2887
|
try {
|
|
2818
2888
|
const record = await ctx.vaultMemoryCollection.find(id);
|
|
@@ -4786,24 +4856,25 @@ function tokenize(text) {
|
|
|
4786
4856
|
if (!m) return [];
|
|
4787
4857
|
return m.filter((t) => !STOPWORDS.has(t));
|
|
4788
4858
|
}
|
|
4789
|
-
function
|
|
4790
|
-
const
|
|
4791
|
-
if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
|
|
4859
|
+
function prepareBM25Corpus(items) {
|
|
4860
|
+
const ids = items.map((i) => i.id);
|
|
4792
4861
|
const docTokens = items.map((i) => tokenize(i.content));
|
|
4793
4862
|
const docLens = docTokens.map((t) => t.length);
|
|
4794
|
-
const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
|
|
4795
|
-
const queryTermSet = new Set(queryTerms);
|
|
4863
|
+
const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
|
|
4796
4864
|
const df = /* @__PURE__ */ new Map();
|
|
4797
4865
|
for (const tokens of docTokens) {
|
|
4798
|
-
const seen =
|
|
4799
|
-
for (const t of tokens) {
|
|
4800
|
-
if (queryTermSet.has(t)) seen.add(t);
|
|
4801
|
-
}
|
|
4866
|
+
const seen = new Set(tokens);
|
|
4802
4867
|
for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
|
|
4803
4868
|
}
|
|
4804
|
-
|
|
4869
|
+
return { ids, docTokens, docLens, avgdl, df, n: items.length };
|
|
4870
|
+
}
|
|
4871
|
+
function scoreBM25Prepared(query, corpus) {
|
|
4872
|
+
const queryTerms = tokenize(query);
|
|
4805
4873
|
const scores = /* @__PURE__ */ new Map();
|
|
4806
|
-
|
|
4874
|
+
if (queryTerms.length === 0 || corpus.n === 0) return scores;
|
|
4875
|
+
const queryTermSet = new Set(queryTerms);
|
|
4876
|
+
const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
|
|
4877
|
+
for (let i = 0; i < N; i++) {
|
|
4807
4878
|
const tokens = docTokens[i];
|
|
4808
4879
|
const dl = docLens[i];
|
|
4809
4880
|
if (dl === 0) continue;
|
|
@@ -4819,10 +4890,15 @@ function scoreBM25(query, items) {
|
|
|
4819
4890
|
const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
|
|
4820
4891
|
score += idf * tfNorm;
|
|
4821
4892
|
}
|
|
4822
|
-
scores.set(
|
|
4893
|
+
scores.set(ids[i], score);
|
|
4823
4894
|
}
|
|
4824
4895
|
return scores;
|
|
4825
4896
|
}
|
|
4897
|
+
function scoreBM25(query, items) {
|
|
4898
|
+
if (items.length === 0) return /* @__PURE__ */ new Map();
|
|
4899
|
+
if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
|
|
4900
|
+
return scoreBM25Prepared(query, prepareBM25Corpus(items));
|
|
4901
|
+
}
|
|
4826
4902
|
|
|
4827
4903
|
// src/lib/memoryVault/decomposeQuery.ts
|
|
4828
4904
|
var DEFAULT_MODEL = "inclusionai/ling-2.6-flash";
|
|
@@ -5077,7 +5153,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
5077
5153
|
}
|
|
5078
5154
|
});
|
|
5079
5155
|
const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
|
|
5080
|
-
const bm25Scores = scoreBM25(
|
|
5156
|
+
const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
|
|
5081
5157
|
query,
|
|
5082
5158
|
items.map((i) => ({ id: i.id, content: i.content }))
|
|
5083
5159
|
);
|
|
@@ -5274,7 +5350,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
5274
5350
|
const limit = options?.limit ?? 5;
|
|
5275
5351
|
const perFacetTopN = options?.perFacetTopN ?? 10;
|
|
5276
5352
|
if (items.length === 0 || subQueries.length === 0) return [];
|
|
5353
|
+
const preparedBM25Corpus = prepareBM25Corpus(
|
|
5354
|
+
items.map((i) => ({ id: i.id, content: i.content }))
|
|
5355
|
+
);
|
|
5277
5356
|
const facetTuning = {
|
|
5357
|
+
preparedBM25Corpus,
|
|
5278
5358
|
...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
5279
5359
|
...options?.recency && { recency: options.recency },
|
|
5280
5360
|
...options?.supersessionBoost !== void 0 && {
|
|
@@ -5949,7 +6029,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
5949
6029
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
5950
6030
|
);
|
|
5951
6031
|
}
|
|
5952
|
-
const { recall: recall2 } = await import("./recall-
|
|
6032
|
+
const { recall: recall2 } = await import("./recall-GCW2EV4V.mjs");
|
|
5953
6033
|
const result = await recall2(
|
|
5954
6034
|
query,
|
|
5955
6035
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -6976,6 +7056,7 @@ export {
|
|
|
6976
7056
|
updateVaultMemoryOp,
|
|
6977
7057
|
setMemoryEntitiesOp,
|
|
6978
7058
|
clearMemoryTopicsOverrideOp,
|
|
7059
|
+
setMemoryVisibilityOp,
|
|
6979
7060
|
deleteVaultMemoryOp,
|
|
6980
7061
|
supersedeVaultMemoryOp,
|
|
6981
7062
|
getUnfiledVaultMemoriesOp,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import "./chunk-GYKJOWEO.mjs";
|
|
9
9
|
|
|
10
10
|
// src/lib/memory/consolidate.ts
|
|
11
|
-
var
|
|
11
|
+
var DEFAULT_CONSOLIDATION_MODEL = "inclusionai/ling-2.6-flash";
|
|
12
12
|
var DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
|
|
13
13
|
var DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
|
|
14
14
|
var SYSTEM_PROMPT = `You consolidate a new memory against existing memories from the same user.
|
|
@@ -70,7 +70,7 @@ ${candidateText}`;
|
|
|
70
70
|
...options.apiKey !== void 0 && { apiKey: options.apiKey },
|
|
71
71
|
...options.getToken !== void 0 && { getToken: options.getToken },
|
|
72
72
|
...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
|
|
73
|
-
model: options.model ??
|
|
73
|
+
model: options.model ?? DEFAULT_CONSOLIDATION_MODEL,
|
|
74
74
|
systemPrompt: SYSTEM_PROMPT,
|
|
75
75
|
userMessage,
|
|
76
76
|
tag: "memory/consolidate",
|
|
@@ -147,5 +147,6 @@ function validate(parsed, newContent, validIds) {
|
|
|
147
147
|
return { action: "update", targetId, content: c };
|
|
148
148
|
}
|
|
149
149
|
export {
|
|
150
|
+
DEFAULT_CONSOLIDATION_MODEL,
|
|
150
151
|
consolidateMemory
|
|
151
152
|
};
|
package/dist/react/index.cjs
CHANGED
|
@@ -4500,6 +4500,18 @@ var init_encryption2 = __esm({
|
|
|
4500
4500
|
});
|
|
4501
4501
|
|
|
4502
4502
|
// src/lib/db/memoryVault/operations.ts
|
|
4503
|
+
function visibilityOrPrivate(value) {
|
|
4504
|
+
return value === "public" ? value : "private";
|
|
4505
|
+
}
|
|
4506
|
+
function visibilityConditions(requested) {
|
|
4507
|
+
if (!requested?.length) return [];
|
|
4508
|
+
if (!requested.includes("private")) {
|
|
4509
|
+
return [import_watermelondb10.Q.where("visibility", import_watermelondb10.Q.oneOf([...requested]))];
|
|
4510
|
+
}
|
|
4511
|
+
const excluded = NON_PRIVATE_VISIBILITIES.filter((v) => !requested.includes(v));
|
|
4512
|
+
if (excluded.length === 0) return [];
|
|
4513
|
+
return [import_watermelondb10.Q.or(import_watermelondb10.Q.where("visibility", null), import_watermelondb10.Q.where("visibility", import_watermelondb10.Q.notIn(excluded)))];
|
|
4514
|
+
}
|
|
4503
4515
|
function isOwnedByCtxUser(ctx, record) {
|
|
4504
4516
|
return ctx.userId === void 0 || record.userId === ctx.userId;
|
|
4505
4517
|
}
|
|
@@ -4560,6 +4572,10 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
4560
4572
|
factType: memory.factType ?? null,
|
|
4561
4573
|
archivedAt: memory.archivedAt ?? null,
|
|
4562
4574
|
trustTier: memory.trustTier ?? null,
|
|
4575
|
+
visibility: visibilityOrPrivate(memory.visibility),
|
|
4576
|
+
twinOptIn: memory.twinOptIn ?? false,
|
|
4577
|
+
publishedAt: memory.publishedAt ?? null,
|
|
4578
|
+
geohash: memory.geohash ?? null,
|
|
4563
4579
|
createdAt: memory.createdAt,
|
|
4564
4580
|
updatedAt: memory.updatedAt,
|
|
4565
4581
|
isDeleted: memory.isDeleted
|
|
@@ -4607,6 +4623,14 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
4607
4623
|
if (opts.trustTier !== void 0) {
|
|
4608
4624
|
record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
|
|
4609
4625
|
}
|
|
4626
|
+
record._setRaw("visibility", opts.visibility ?? "private");
|
|
4627
|
+
record._setRaw(
|
|
4628
|
+
"published_at",
|
|
4629
|
+
opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
|
|
4630
|
+
);
|
|
4631
|
+
if (opts.geohash !== void 0) {
|
|
4632
|
+
record._setRaw("geohash", opts.geohash);
|
|
4633
|
+
}
|
|
4610
4634
|
});
|
|
4611
4635
|
});
|
|
4612
4636
|
return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
@@ -4753,6 +4777,14 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
4753
4777
|
if (opts.trustTier !== void 0) {
|
|
4754
4778
|
record._setRaw("trust_tier", normalizeTrustTier(opts.trustTier));
|
|
4755
4779
|
}
|
|
4780
|
+
record._setRaw("visibility", opts.visibility ?? "private");
|
|
4781
|
+
record._setRaw(
|
|
4782
|
+
"published_at",
|
|
4783
|
+
opts.visibility && opts.visibility !== "private" ? opts.publishedAt ?? Date.now() : null
|
|
4784
|
+
);
|
|
4785
|
+
if (opts.geohash !== void 0) {
|
|
4786
|
+
record._setRaw("geohash", opts.geohash);
|
|
4787
|
+
}
|
|
4756
4788
|
})
|
|
4757
4789
|
);
|
|
4758
4790
|
await ctx.database.batch(...prepared);
|
|
@@ -4816,6 +4848,10 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
4816
4848
|
factType: raw.fact_type ?? null,
|
|
4817
4849
|
archivedAt: raw.archived_at ?? null,
|
|
4818
4850
|
trustTier: raw.trust_tier ?? null,
|
|
4851
|
+
visibility: visibilityOrPrivate(raw.visibility),
|
|
4852
|
+
twinOptIn: raw.twin_opt_in === true || raw.twin_opt_in === 1,
|
|
4853
|
+
publishedAt: raw.published_at ?? null,
|
|
4854
|
+
geohash: raw.geohash ?? null,
|
|
4819
4855
|
createdAt: new Date(raw.created_at),
|
|
4820
4856
|
updatedAt: new Date(raw.updated_at),
|
|
4821
4857
|
isDeleted: raw.is_deleted === true || raw.is_deleted === 1
|
|
@@ -4832,6 +4868,7 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
4832
4868
|
const conditions = [
|
|
4833
4869
|
...baseVaultConditions(ctx, options),
|
|
4834
4870
|
...options?.scopes?.length ? [import_watermelondb10.Q.where("scope", import_watermelondb10.Q.oneOf(options.scopes))] : [],
|
|
4871
|
+
...visibilityConditions(options?.visibility),
|
|
4835
4872
|
...options?.folderId !== void 0 ? [import_watermelondb10.Q.where("folder_id", options.folderId)] : [],
|
|
4836
4873
|
...options?.factTypes?.length ? [import_watermelondb10.Q.where("fact_type", import_watermelondb10.Q.oneOf(options.factTypes))] : [],
|
|
4837
4874
|
import_watermelondb10.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb10.Q.desc),
|
|
@@ -5125,6 +5162,38 @@ async function clearMemoryTopicsOverrideOp(ctx, memoryId) {
|
|
|
5125
5162
|
});
|
|
5126
5163
|
return true;
|
|
5127
5164
|
}
|
|
5165
|
+
async function setMemoryVisibilityOp(ctx, id, opts) {
|
|
5166
|
+
let record;
|
|
5167
|
+
try {
|
|
5168
|
+
record = await ctx.vaultMemoryCollection.find(id);
|
|
5169
|
+
} catch {
|
|
5170
|
+
return null;
|
|
5171
|
+
}
|
|
5172
|
+
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) return null;
|
|
5173
|
+
let stale = false;
|
|
5174
|
+
await ctx.database.write(async () => {
|
|
5175
|
+
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
|
|
5176
|
+
stale = true;
|
|
5177
|
+
return;
|
|
5178
|
+
}
|
|
5179
|
+
const currentUpdatedAt = record.updatedAt.getTime();
|
|
5180
|
+
const currentPublishedAt = record.publishedAt ?? null;
|
|
5181
|
+
await record.update((r) => {
|
|
5182
|
+
r._setRaw("visibility", opts.visibility);
|
|
5183
|
+
if (opts.visibility === "private") {
|
|
5184
|
+
r._setRaw("published_at", null);
|
|
5185
|
+
} else if (currentPublishedAt === null) {
|
|
5186
|
+
r._setRaw("published_at", Date.now());
|
|
5187
|
+
}
|
|
5188
|
+
if (opts.twinOptIn !== void 0) {
|
|
5189
|
+
r._setRaw("twin_opt_in", opts.twinOptIn);
|
|
5190
|
+
}
|
|
5191
|
+
r._setRaw("updated_at", currentUpdatedAt);
|
|
5192
|
+
});
|
|
5193
|
+
});
|
|
5194
|
+
if (stale) return null;
|
|
5195
|
+
return vaultMemoryToStored(record, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
5196
|
+
}
|
|
5128
5197
|
async function deleteVaultMemoryOp(ctx, id) {
|
|
5129
5198
|
try {
|
|
5130
5199
|
const record = await ctx.vaultMemoryCollection.find(id);
|
|
@@ -5414,7 +5483,7 @@ async function updateVaultMemoryEmbeddingOp(ctx, id, embedding, embeddingModel)
|
|
|
5414
5483
|
return false;
|
|
5415
5484
|
}
|
|
5416
5485
|
}
|
|
5417
|
-
var import_watermelondb10, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
|
|
5486
|
+
var import_watermelondb10, NON_PRIVATE_VISIBILITIES, KNOWN_TRUST_TIERS, TOPICS_EXTRACTION_VERSION;
|
|
5418
5487
|
var init_operations3 = __esm({
|
|
5419
5488
|
"src/lib/db/memoryVault/operations.ts"() {
|
|
5420
5489
|
"use strict";
|
|
@@ -5422,6 +5491,7 @@ var init_operations3 = __esm({
|
|
|
5422
5491
|
init_logger();
|
|
5423
5492
|
init_operations2();
|
|
5424
5493
|
init_encryption2();
|
|
5494
|
+
NON_PRIVATE_VISIBILITIES = ["public"];
|
|
5425
5495
|
KNOWN_TRUST_TIERS = /* @__PURE__ */ new Set(["quarantined", "trusted"]);
|
|
5426
5496
|
TOPICS_EXTRACTION_VERSION = 3;
|
|
5427
5497
|
}
|
|
@@ -5869,24 +5939,25 @@ function tokenize(text12) {
|
|
|
5869
5939
|
if (!m) return [];
|
|
5870
5940
|
return m.filter((t) => !STOPWORDS.has(t));
|
|
5871
5941
|
}
|
|
5872
|
-
function
|
|
5873
|
-
const
|
|
5874
|
-
if (queryTerms.length === 0 || items.length === 0) return /* @__PURE__ */ new Map();
|
|
5942
|
+
function prepareBM25Corpus(items) {
|
|
5943
|
+
const ids = items.map((i) => i.id);
|
|
5875
5944
|
const docTokens = items.map((i) => tokenize(i.content));
|
|
5876
5945
|
const docLens = docTokens.map((t) => t.length);
|
|
5877
|
-
const avgdl = docLens.reduce((a, b) => a + b, 0) / docLens.length;
|
|
5878
|
-
const queryTermSet = new Set(queryTerms);
|
|
5946
|
+
const avgdl = docLens.length ? docLens.reduce((a, b) => a + b, 0) / docLens.length : 0;
|
|
5879
5947
|
const df = /* @__PURE__ */ new Map();
|
|
5880
5948
|
for (const tokens of docTokens) {
|
|
5881
|
-
const seen =
|
|
5882
|
-
for (const t of tokens) {
|
|
5883
|
-
if (queryTermSet.has(t)) seen.add(t);
|
|
5884
|
-
}
|
|
5949
|
+
const seen = new Set(tokens);
|
|
5885
5950
|
for (const t of seen) df.set(t, (df.get(t) ?? 0) + 1);
|
|
5886
5951
|
}
|
|
5887
|
-
|
|
5952
|
+
return { ids, docTokens, docLens, avgdl, df, n: items.length };
|
|
5953
|
+
}
|
|
5954
|
+
function scoreBM25Prepared(query, corpus) {
|
|
5955
|
+
const queryTerms = tokenize(query);
|
|
5888
5956
|
const scores = /* @__PURE__ */ new Map();
|
|
5889
|
-
|
|
5957
|
+
if (queryTerms.length === 0 || corpus.n === 0) return scores;
|
|
5958
|
+
const queryTermSet = new Set(queryTerms);
|
|
5959
|
+
const { ids, docTokens, docLens, avgdl, df, n: N } = corpus;
|
|
5960
|
+
for (let i = 0; i < N; i++) {
|
|
5890
5961
|
const tokens = docTokens[i];
|
|
5891
5962
|
const dl = docLens[i];
|
|
5892
5963
|
if (dl === 0) continue;
|
|
@@ -5902,10 +5973,15 @@ function scoreBM25(query, items) {
|
|
|
5902
5973
|
const tfNorm = f * (K1 + 1) / (f + K1 * (1 - B + B * dl / avgdl));
|
|
5903
5974
|
score += idf * tfNorm;
|
|
5904
5975
|
}
|
|
5905
|
-
scores.set(
|
|
5976
|
+
scores.set(ids[i], score);
|
|
5906
5977
|
}
|
|
5907
5978
|
return scores;
|
|
5908
5979
|
}
|
|
5980
|
+
function scoreBM25(query, items) {
|
|
5981
|
+
if (items.length === 0) return /* @__PURE__ */ new Map();
|
|
5982
|
+
if (tokenize(query).length === 0) return /* @__PURE__ */ new Map();
|
|
5983
|
+
return scoreBM25Prepared(query, prepareBM25Corpus(items));
|
|
5984
|
+
}
|
|
5909
5985
|
var K1, B, TOKEN_RE, STOPWORDS;
|
|
5910
5986
|
var init_bm25 = __esm({
|
|
5911
5987
|
"src/lib/memoryVault/bm25.ts"() {
|
|
@@ -7226,7 +7302,7 @@ function rankFusedVaultMemories(query, queryEmbedding, items, options) {
|
|
|
7226
7302
|
}
|
|
7227
7303
|
});
|
|
7228
7304
|
const baseIds = new Set(baseRanked.map((r) => r.uniqueId));
|
|
7229
|
-
const bm25Scores = scoreBM25(
|
|
7305
|
+
const bm25Scores = options?.preparedBM25Corpus ? scoreBM25Prepared(query, options.preparedBM25Corpus) : scoreBM25(
|
|
7230
7306
|
query,
|
|
7231
7307
|
items.map((i) => ({ id: i.id, content: i.content }))
|
|
7232
7308
|
);
|
|
@@ -7423,7 +7499,11 @@ async function rankComposite(originalQuery, originalQueryEmbedding, subQueries,
|
|
|
7423
7499
|
const limit = options?.limit ?? 5;
|
|
7424
7500
|
const perFacetTopN = options?.perFacetTopN ?? 10;
|
|
7425
7501
|
if (items.length === 0 || subQueries.length === 0) return [];
|
|
7502
|
+
const preparedBM25Corpus = prepareBM25Corpus(
|
|
7503
|
+
items.map((i) => ({ id: i.id, content: i.content }))
|
|
7504
|
+
);
|
|
7426
7505
|
const facetTuning = {
|
|
7506
|
+
preparedBM25Corpus,
|
|
7427
7507
|
...options?.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
7428
7508
|
...options?.recency && { recency: options.recency },
|
|
7429
7509
|
...options?.supersessionBoost !== void 0 && {
|
|
@@ -8169,6 +8249,7 @@ var init_searchTool = __esm({
|
|
|
8169
8249
|
// src/lib/memory/consolidate.ts
|
|
8170
8250
|
var consolidate_exports = {};
|
|
8171
8251
|
__export(consolidate_exports, {
|
|
8252
|
+
DEFAULT_CONSOLIDATION_MODEL: () => DEFAULT_CONSOLIDATION_MODEL,
|
|
8172
8253
|
consolidateMemory: () => consolidateMemory
|
|
8173
8254
|
});
|
|
8174
8255
|
async function consolidateMemory(newContent, candidates, options) {
|
|
@@ -8197,7 +8278,7 @@ ${candidateText}`;
|
|
|
8197
8278
|
...options.apiKey !== void 0 && { apiKey: options.apiKey },
|
|
8198
8279
|
...options.getToken !== void 0 && { getToken: options.getToken },
|
|
8199
8280
|
...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
|
|
8200
|
-
model: options.model ??
|
|
8281
|
+
model: options.model ?? DEFAULT_CONSOLIDATION_MODEL,
|
|
8201
8282
|
systemPrompt: SYSTEM_PROMPT3,
|
|
8202
8283
|
userMessage,
|
|
8203
8284
|
tag: "memory/consolidate",
|
|
@@ -8273,14 +8354,14 @@ function validate2(parsed, newContent, validIds) {
|
|
|
8273
8354
|
if (!targetId || !validIds.has(targetId)) return null;
|
|
8274
8355
|
return { action: "update", targetId, content: c };
|
|
8275
8356
|
}
|
|
8276
|
-
var
|
|
8357
|
+
var DEFAULT_CONSOLIDATION_MODEL, DEFAULT_CONSOLIDATE_ATTEMPTS, DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS, SYSTEM_PROMPT3;
|
|
8277
8358
|
var init_consolidate = __esm({
|
|
8278
8359
|
"src/lib/memory/consolidate.ts"() {
|
|
8279
8360
|
"use strict";
|
|
8280
8361
|
init_logger();
|
|
8281
8362
|
init_redactor();
|
|
8282
8363
|
init_portalLlm();
|
|
8283
|
-
|
|
8364
|
+
DEFAULT_CONSOLIDATION_MODEL = "inclusionai/ling-2.6-flash";
|
|
8284
8365
|
DEFAULT_CONSOLIDATE_ATTEMPTS = 3;
|
|
8285
8366
|
DEFAULT_CONSOLIDATE_TOTAL_TIMEOUT_MS = 2e4;
|
|
8286
8367
|
SYSTEM_PROMPT3 = `You consolidate a new memory against existing memories from the same user.
|
|
@@ -8690,6 +8771,7 @@ __export(index_exports, {
|
|
|
8690
8771
|
serializeJsx: () => serializeJsx,
|
|
8691
8772
|
setLogger: () => setLogger,
|
|
8692
8773
|
setMemoryEntitiesOp: () => setMemoryEntitiesOp,
|
|
8774
|
+
setMemoryVisibilityOp: () => setMemoryVisibilityOp,
|
|
8693
8775
|
settingsStorageSchema: () => settingsStorageSchema,
|
|
8694
8776
|
shouldChunkMessage: () => shouldChunkMessage,
|
|
8695
8777
|
shouldRefreshTools: () => shouldRefreshTools,
|
|
@@ -15354,6 +15436,18 @@ __decorateClass([
|
|
|
15354
15436
|
__decorateClass([
|
|
15355
15437
|
(0, import_decorators3.field)("trust_tier")
|
|
15356
15438
|
], VaultMemory.prototype, "trustTier", 2);
|
|
15439
|
+
__decorateClass([
|
|
15440
|
+
(0, import_decorators3.field)("visibility")
|
|
15441
|
+
], VaultMemory.prototype, "visibility", 2);
|
|
15442
|
+
__decorateClass([
|
|
15443
|
+
(0, import_decorators3.field)("twin_opt_in")
|
|
15444
|
+
], VaultMemory.prototype, "twinOptIn", 2);
|
|
15445
|
+
__decorateClass([
|
|
15446
|
+
(0, import_decorators3.field)("published_at")
|
|
15447
|
+
], VaultMemory.prototype, "publishedAt", 2);
|
|
15448
|
+
__decorateClass([
|
|
15449
|
+
(0, import_decorators3.field)("geohash")
|
|
15450
|
+
], VaultMemory.prototype, "geohash", 2);
|
|
15357
15451
|
__decorateClass([
|
|
15358
15452
|
import_decorators3.readonly,
|
|
15359
15453
|
(0, import_decorators3.date)("created_at")
|
|
@@ -16630,18 +16724,16 @@ function createAutoExtractor(options) {
|
|
|
16630
16724
|
} catch {
|
|
16631
16725
|
}
|
|
16632
16726
|
};
|
|
16633
|
-
const
|
|
16634
|
-
|
|
16635
|
-
|
|
16636
|
-
|
|
16637
|
-
|
|
16638
|
-
|
|
16639
|
-
|
|
16640
|
-
|
|
16641
|
-
|
|
16642
|
-
|
|
16643
|
-
// extractAndRetain (so direct callers are covered too), not copied here.
|
|
16644
|
-
} : void 0;
|
|
16727
|
+
const subPassAuth = (baseUrlOverride) => {
|
|
16728
|
+
const baseUrl = baseUrlOverride ?? options.extract.baseUrl;
|
|
16729
|
+
return {
|
|
16730
|
+
...options.extract.apiKey !== void 0 && { apiKey: options.extract.apiKey },
|
|
16731
|
+
...options.extract.getToken !== void 0 && { getToken: options.extract.getToken },
|
|
16732
|
+
...baseUrl !== void 0 && { baseUrl }
|
|
16733
|
+
};
|
|
16734
|
+
};
|
|
16735
|
+
const consolidateOptions = options.consolidate ? { ...options.consolidate, ...subPassAuth(options.consolidate.baseUrl) } : void 0;
|
|
16736
|
+
const injectionClassifierOptions = options.injectionClassifier ? { ...options.injectionClassifier, ...subPassAuth(options.injectionClassifier.baseUrl) } : void 0;
|
|
16645
16737
|
if (options.retainCtx.vaultCtx.entityCtx && !options.entityCtx) {
|
|
16646
16738
|
getLogger().warn(
|
|
16647
16739
|
"[memory/extract] retainCtx.vaultCtx.entityCtx is set but extractor was created without `entityCtx` \u2014 W5 graph lane will receive no writes"
|
|
@@ -16695,6 +16787,9 @@ function createAutoExtractor(options) {
|
|
|
16695
16787
|
...options.scope !== void 0 && { scope: options.scope },
|
|
16696
16788
|
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
16697
16789
|
...consolidateOptions !== void 0 && { consolidateOptions },
|
|
16790
|
+
...injectionClassifierOptions !== void 0 && {
|
|
16791
|
+
injectionClassifier: injectionClassifierOptions
|
|
16792
|
+
},
|
|
16698
16793
|
...options.onCandidateFailed && {
|
|
16699
16794
|
onCandidateFailed: (candidate, error) => options.onCandidateFailed?.({ candidate, error, conversationId })
|
|
16700
16795
|
},
|
|
@@ -16830,7 +16925,7 @@ function classifyDecay(m, now, policy) {
|
|
|
16830
16925
|
init_logger();
|
|
16831
16926
|
init_redactor();
|
|
16832
16927
|
init_portalLlm();
|
|
16833
|
-
var
|
|
16928
|
+
var DEFAULT_MODEL3 = "inclusionai/ling-2.6-flash";
|
|
16834
16929
|
var DEFAULT_ATTEMPTS2 = 2;
|
|
16835
16930
|
var DEFAULT_TOTAL_TIMEOUT_MS2 = 12e3;
|
|
16836
16931
|
var MAX_CONTENT_CHARS = 400;
|
|
@@ -16869,7 +16964,7 @@ function createLlmDecayClassifier(options) {
|
|
|
16869
16964
|
...options.apiKey !== void 0 && { apiKey: options.apiKey },
|
|
16870
16965
|
...options.getToken !== void 0 && { getToken: options.getToken },
|
|
16871
16966
|
...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
|
|
16872
|
-
model: options.model ??
|
|
16967
|
+
model: options.model ?? DEFAULT_MODEL3,
|
|
16873
16968
|
systemPrompt: SYSTEM_PROMPT5,
|
|
16874
16969
|
userMessage: `Memory content:
|
|
16875
16970
|
${safe}
|
|
@@ -17302,7 +17397,7 @@ init_logger();
|
|
|
17302
17397
|
init_portalLlm();
|
|
17303
17398
|
init_recall();
|
|
17304
17399
|
var DEFAULT_BASE_URL2 = BASE_URL;
|
|
17305
|
-
var
|
|
17400
|
+
var DEFAULT_MODEL4 = "anthropic/claude-sonnet-4-6";
|
|
17306
17401
|
var DEFAULT_MAX_TOKENS = 4096;
|
|
17307
17402
|
var REQUEST_TIMEOUT_MS = 6e4;
|
|
17308
17403
|
var DEFAULT_SYSTEM_PROMPT = `You are a personal assistant with access to the user's memory. Answer the user's question using the supplied memories as evidence.
|
|
@@ -17334,7 +17429,7 @@ async function reflect(query, ctx, options) {
|
|
|
17334
17429
|
const evidence = recalledMemories.map((m, i) => `[${i + 1}] (id: ${m.id}, kind: ${m.kind})
|
|
17335
17430
|
${m.content}`).join("\n\n");
|
|
17336
17431
|
const baseUrl = options.baseUrl ?? DEFAULT_BASE_URL2;
|
|
17337
|
-
const model = options.llmModel ??
|
|
17432
|
+
const model = options.llmModel ?? DEFAULT_MODEL4;
|
|
17338
17433
|
const wantsStructured = !!options.responseSchema;
|
|
17339
17434
|
const sendResponseFormat = wantsStructured && supportsResponseFormat(model, "json_schema");
|
|
17340
17435
|
const basePrompt = options.systemPrompt ?? DEFAULT_SYSTEM_PROMPT;
|
|
@@ -22465,7 +22560,7 @@ __decorateClass([
|
|
|
22465
22560
|
], VaultFolder.prototype, "context", 2);
|
|
22466
22561
|
|
|
22467
22562
|
// src/lib/db/schema.ts
|
|
22468
|
-
var SDK_SCHEMA_VERSION =
|
|
22563
|
+
var SDK_SCHEMA_VERSION = 41;
|
|
22469
22564
|
var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
22470
22565
|
version: SDK_SCHEMA_VERSION,
|
|
22471
22566
|
tables: [
|
|
@@ -22624,7 +22719,26 @@ var sdkSchema = (0, import_watermelondb20.appSchema)({
|
|
|
22624
22719
|
// Tier-0 security (PR3) — "quarantined" when the write-time injection
|
|
22625
22720
|
// screen flagged this fact, else null/"trusted". Indexed so the recall
|
|
22626
22721
|
// choke point can default-exclude quarantined rows.
|
|
22627
|
-
{ name: "trust_tier", type: "string", isOptional: true, isIndexed: true }
|
|
22722
|
+
{ name: "trust_tier", type: "string", isOptional: true, isIndexed: true },
|
|
22723
|
+
// People Nearby cross-user visibility axis — ORTHOGONAL to `scope`
|
|
22724
|
+
// (which partitions by MODEL access: private vs shared providers).
|
|
22725
|
+
// TWO tiers: 'private' (or null, or any unrecognised value —
|
|
22726
|
+
// grandfathered / fail-safe) = local-only; 'public' = embedding +
|
|
22727
|
+
// plaintext may be published (matching/profile/discovery/twin).
|
|
22728
|
+
// The server index is the authority for what IS published; this
|
|
22729
|
+
// column records the user's intent.
|
|
22730
|
+
{ name: "visibility", type: "string", isOptional: true, isIndexed: true },
|
|
22731
|
+
// When true, the owner opted this memory into their own digital twin
|
|
22732
|
+
// even if it is otherwise private (twin-scoped upload only — never
|
|
22733
|
+
// indexed for matching, never displayed). Null/false = follows visibility.
|
|
22734
|
+
{ name: "twin_opt_in", type: "boolean", isOptional: true },
|
|
22735
|
+
// Unix ms when visibility last became non-private. Null when private
|
|
22736
|
+
// (cleared on revoke) — the publish reconciler uses it to diff local
|
|
22737
|
+
// intent against the server index.
|
|
22738
|
+
{ name: "published_at", type: "number", isOptional: true },
|
|
22739
|
+
// Reserved geo slot (coarse geohash) for landmark/Trail memories.
|
|
22740
|
+
// Unused at launch; populated by location-tagged memory sources.
|
|
22741
|
+
{ name: "geohash", type: "string", isOptional: true }
|
|
22628
22742
|
]
|
|
22629
22743
|
}),
|
|
22630
22744
|
// Entity table — canonical names extracted from auto-extraction (W5).
|
|
@@ -23299,6 +23413,24 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
|
23299
23413
|
]
|
|
23300
23414
|
})
|
|
23301
23415
|
]
|
|
23416
|
+
},
|
|
23417
|
+
// v40 -> v41: People Nearby visibility axis on memory_vault. Existing rows
|
|
23418
|
+
// keep visibility NULL — read as 'private' (nothing pre-existing is ever
|
|
23419
|
+
// published without an explicit user action; the consent posture requires
|
|
23420
|
+
// opt-in, never a retroactive default).
|
|
23421
|
+
{
|
|
23422
|
+
toVersion: 41,
|
|
23423
|
+
steps: [
|
|
23424
|
+
(0, import_migrations2.addColumns)({
|
|
23425
|
+
table: "memory_vault",
|
|
23426
|
+
columns: [
|
|
23427
|
+
{ name: "visibility", type: "string", isOptional: true, isIndexed: true },
|
|
23428
|
+
{ name: "twin_opt_in", type: "boolean", isOptional: true },
|
|
23429
|
+
{ name: "published_at", type: "number", isOptional: true },
|
|
23430
|
+
{ name: "geohash", type: "string", isOptional: true }
|
|
23431
|
+
]
|
|
23432
|
+
})
|
|
23433
|
+
]
|
|
23302
23434
|
}
|
|
23303
23435
|
]
|
|
23304
23436
|
});
|
|
@@ -33270,6 +33402,7 @@ function renderAnumaJsx(jsx3) {
|
|
|
33270
33402
|
serializeJsx,
|
|
33271
33403
|
setLogger,
|
|
33272
33404
|
setMemoryEntitiesOp,
|
|
33405
|
+
setMemoryVisibilityOp,
|
|
33273
33406
|
settingsStorageSchema,
|
|
33274
33407
|
shouldChunkMessage,
|
|
33275
33408
|
shouldRefreshTools,
|