@anuma/sdk 6.21.1 → 6.22.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-CIMZZ7GQ.mjs → chunk-6BULYLRY.mjs} +92 -8
- package/dist/expo/index.cjs +761 -162
- package/dist/expo/index.d.mts +151 -9
- package/dist/expo/index.d.ts +151 -9
- package/dist/expo/index.mjs +516 -14
- package/dist/{react/recall-7Q3V337H.mjs → expo/recall-CUTJWQDQ.mjs} +1 -1
- package/dist/memory/context.cjs +183 -0
- package/dist/memory/context.d.mts +936 -0
- package/dist/memory/context.d.ts +936 -0
- package/dist/memory/context.mjs +157 -0
- package/dist/react/{chunk-AVYB5IXC.mjs → chunk-GPLMMMZN.mjs} +1 -1
- package/dist/react/{chunk-JRVAUZHM.mjs → chunk-K4N52PSK.mjs} +93 -9
- package/dist/react/{consolidate-URHGJT7I.mjs → consolidate-XKS6IZFC.mjs} +2 -2
- package/dist/react/index.cjs +876 -270
- package/dist/react/index.d.mts +209 -9
- package/dist/react/index.d.ts +209 -9
- package/dist/react/index.mjs +569 -65
- package/dist/{expo/recall-FQQGE6A2.mjs → react/recall-LFHIWONV.mjs} +2 -2
- package/dist/server/{chunk-4DSDATYG.mjs → chunk-FEDRFVHD.mjs} +182 -98
- package/dist/server/index.cjs +815 -216
- package/dist/server/index.d.mts +150 -5
- package/dist/server/index.d.ts +150 -5
- package/dist/server/index.mjs +509 -7
- package/dist/server/{recall-HA4UX4BB.mjs → recall-Z2WJGXOL.mjs} +1 -1
- package/dist/telemetry/index.d.mts +7 -1
- package/dist/telemetry/index.d.ts +7 -1
- package/package.json +8 -1
- package/dist/react/{chunk-WUG6GTHO.mjs → chunk-MHZB6KIX.mjs} +8 -8
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// src/lib/memory/context.ts
|
|
2
|
+
function shouldRecallMemory(query) {
|
|
3
|
+
const normalized = query.trim().toLowerCase().replace(/[.!?。!?¡¿]+$/u, "").replace(/^[¡¿]+/u, "");
|
|
4
|
+
return normalized.length > 0 && !/^(hi|hi there|hello|hey|yes|no|yep|nope|sure|k|ok|okay|thanks|thank you|thank you very much|thanks a lot|cool|great|got it|sounds good|hola|buenos días|buenas|sí|si|gracias|muchas gracias|vale|bonjour|salut|oui|non|merci|merci beaucoup|d'accord|hallo|guten tag|ja|nein|danke|danke schön|alles klar|olá|obrigado|obrigada|ciao|grazie|sì|你好|谢谢|好的|こんにちは|ありがとう|안녕하세요|감사합니다)$/u.test(
|
|
5
|
+
normalized
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
async function assembleMemoryContext(options) {
|
|
9
|
+
const { query, recall, loadFacts, loadSessionRefs } = options;
|
|
10
|
+
const memoryIds = options.memoryIds ?? options.recallOptions?.memoryIds;
|
|
11
|
+
const ranked = shouldRecallMemory(query);
|
|
12
|
+
const degraded = [];
|
|
13
|
+
const guard = async (lane, run, fallback) => {
|
|
14
|
+
try {
|
|
15
|
+
return await run();
|
|
16
|
+
} catch (error) {
|
|
17
|
+
degraded.push(lane);
|
|
18
|
+
try {
|
|
19
|
+
options.onDegraded?.(lane, error);
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const scoped = memoryIds !== void 0 || options.recallOptions?.scopes !== void 0 || options.recallOptions?.folderId !== void 0;
|
|
26
|
+
const allowed = memoryIds !== void 0 ? new Set(memoryIds) : void 0;
|
|
27
|
+
const filters = {
|
|
28
|
+
...options.recallOptions?.scopes && { scopes: options.recallOptions.scopes },
|
|
29
|
+
...options.recallOptions?.folderId !== void 0 && {
|
|
30
|
+
folderId: options.recallOptions.folderId
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const active = (m) => !m.isDeleted && !m.archivedAt && !m.supersededBy && m.trustTier !== "quarantined" && (!allowed || allowed.has(m.uniqueId));
|
|
34
|
+
const asItem = (m, lane, score = 1) => ({
|
|
35
|
+
id: m.uniqueId,
|
|
36
|
+
content: m.content,
|
|
37
|
+
score,
|
|
38
|
+
lane,
|
|
39
|
+
sourceIds: m.sourceChunkIds ?? []
|
|
40
|
+
});
|
|
41
|
+
const empty = {
|
|
42
|
+
memories: [],
|
|
43
|
+
usedBudget: options.recallOptions?.budget ?? "low",
|
|
44
|
+
reranked: false,
|
|
45
|
+
candidateCount: 0
|
|
46
|
+
};
|
|
47
|
+
const [facts, episodes, profile, session] = await Promise.all([
|
|
48
|
+
ranked ? guard(
|
|
49
|
+
"fact",
|
|
50
|
+
() => recall(query, { ...options.recallOptions, types: ["fact"], limit: 20, memoryIds }),
|
|
51
|
+
empty
|
|
52
|
+
) : empty,
|
|
53
|
+
ranked && !scoped && options.includeEpisodes !== false ? guard(
|
|
54
|
+
"episode",
|
|
55
|
+
() => recall(query, {
|
|
56
|
+
...options.recallOptions,
|
|
57
|
+
types: ["chunk"],
|
|
58
|
+
limit: 4,
|
|
59
|
+
minScore: 0.5,
|
|
60
|
+
onDiagnostics: void 0
|
|
61
|
+
}),
|
|
62
|
+
empty
|
|
63
|
+
) : empty,
|
|
64
|
+
loadFacts ? guard(
|
|
65
|
+
"profile",
|
|
66
|
+
async () => {
|
|
67
|
+
const stable = await loadFacts({
|
|
68
|
+
...filters,
|
|
69
|
+
memoryIds,
|
|
70
|
+
factTypes: ["identity", "preference", "constraint", "relationship"],
|
|
71
|
+
limit: 8
|
|
72
|
+
});
|
|
73
|
+
const dynamic = await loadFacts({
|
|
74
|
+
...filters,
|
|
75
|
+
memoryIds,
|
|
76
|
+
factTypes: ["ongoing_context", "plan"],
|
|
77
|
+
limit: 4
|
|
78
|
+
});
|
|
79
|
+
return [...stable, ...dynamic].filter(active).map((m) => asItem(m, "profile"));
|
|
80
|
+
},
|
|
81
|
+
[]
|
|
82
|
+
) : [],
|
|
83
|
+
loadFacts && loadSessionRefs ? guard(
|
|
84
|
+
"session",
|
|
85
|
+
async () => {
|
|
86
|
+
const refs = (await loadSessionRefs()).filter((r) => !allowed || allowed.has(r.memoryId)).sort((a, b) => b.score - a.score).slice(0, 10);
|
|
87
|
+
if (!refs.length) return [];
|
|
88
|
+
const rows = await loadFacts({ ...filters, memoryIds: refs.map((r) => r.memoryId) });
|
|
89
|
+
const byId = new Map(rows.filter(active).map((m) => [m.uniqueId, m]));
|
|
90
|
+
return refs.flatMap((ref) => {
|
|
91
|
+
const m = byId.get(ref.memoryId);
|
|
92
|
+
return m ? [asItem(m, "session", ref.score)] : [];
|
|
93
|
+
});
|
|
94
|
+
},
|
|
95
|
+
[]
|
|
96
|
+
) : []
|
|
97
|
+
]);
|
|
98
|
+
const toItems = (result, lane) => result.memories.filter((m) => !allowed || allowed.has(m.id)).map((m) => ({
|
|
99
|
+
id: m.id,
|
|
100
|
+
content: m.content,
|
|
101
|
+
score: m.score,
|
|
102
|
+
lane,
|
|
103
|
+
...lane === "fact" && { recalled: true },
|
|
104
|
+
sourceIds: m.sourceChunkIds ?? (m.messageId ? [m.messageId] : [])
|
|
105
|
+
}));
|
|
106
|
+
const recalledFacts = toItems(facts, "fact");
|
|
107
|
+
const recalledScores = /* @__PURE__ */ new Map();
|
|
108
|
+
const recalledContentScores = /* @__PURE__ */ new Map();
|
|
109
|
+
for (const item of recalledFacts) {
|
|
110
|
+
recalledScores.set(item.id, Math.max(recalledScores.get(item.id) ?? -Infinity, item.score));
|
|
111
|
+
const content = item.content.trim();
|
|
112
|
+
recalledContentScores.set(
|
|
113
|
+
content,
|
|
114
|
+
Math.max(recalledContentScores.get(content) ?? -Infinity, item.score)
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
const rankedProfile = profile.map((item) => {
|
|
118
|
+
const score = Math.max(
|
|
119
|
+
recalledScores.get(item.id) ?? -Infinity,
|
|
120
|
+
recalledContentScores.get(item.content.trim()) ?? -Infinity
|
|
121
|
+
);
|
|
122
|
+
return score === -Infinity ? item : { ...item, score, recalled: true };
|
|
123
|
+
});
|
|
124
|
+
const lanes = [
|
|
125
|
+
[rankedProfile, 2e3],
|
|
126
|
+
[recalledFacts, 6e3],
|
|
127
|
+
[toItems(episodes, "episode"), 3e3],
|
|
128
|
+
[session, 1e3]
|
|
129
|
+
];
|
|
130
|
+
const items = [];
|
|
131
|
+
const seenIds = /* @__PURE__ */ new Set();
|
|
132
|
+
const seenContent = /* @__PURE__ */ new Set();
|
|
133
|
+
let remaining = Math.max(0, options.maxChars ?? 12e3);
|
|
134
|
+
let truncated = false;
|
|
135
|
+
for (const [candidates, laneBudget] of lanes) {
|
|
136
|
+
let laneRemaining = Math.min(laneBudget, remaining);
|
|
137
|
+
for (const item of candidates) {
|
|
138
|
+
const content = item.content?.trim();
|
|
139
|
+
const key = `${item.lane === "episode" ? "episode" : "fact"}:${item.id}`;
|
|
140
|
+
if (!content || seenIds.has(key) || seenContent.has(content)) continue;
|
|
141
|
+
if (content.length > laneRemaining) {
|
|
142
|
+
truncated = true;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
items.push({ ...item, content });
|
|
146
|
+
seenIds.add(key);
|
|
147
|
+
seenContent.add(content);
|
|
148
|
+
remaining -= content.length;
|
|
149
|
+
laneRemaining -= content.length;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return { items, ranked, rankedCount: recalledFacts.length, degraded, truncated };
|
|
153
|
+
}
|
|
154
|
+
export {
|
|
155
|
+
assembleMemoryContext,
|
|
156
|
+
shouldRecallMemory
|
|
157
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
callPortalJsonCompletion,
|
|
3
3
|
getLogger
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-MHZB6KIX.mjs";
|
|
5
5
|
import {
|
|
6
6
|
BASE_URL,
|
|
7
7
|
createClientConfig
|
|
@@ -1011,6 +1011,12 @@ async function decryptJsonField(value, address) {
|
|
|
1011
1011
|
}
|
|
1012
1012
|
}
|
|
1013
1013
|
|
|
1014
|
+
// src/lib/db/extractionJobs/models.ts
|
|
1015
|
+
import { Model } from "@nozbe/watermelondb";
|
|
1016
|
+
var ExtractionJob = class extends Model {
|
|
1017
|
+
};
|
|
1018
|
+
ExtractionJob.table = "memory_extraction_jobs";
|
|
1019
|
+
|
|
1014
1020
|
// src/lib/db/chat/conversationEncryption.ts
|
|
1015
1021
|
async function encryptConversationFields(conversation, address, signMessage, embeddedWalletSigner) {
|
|
1016
1022
|
if (!address || !signMessage) {
|
|
@@ -1653,6 +1659,8 @@ async function deleteConversationOp(ctx, id) {
|
|
|
1653
1659
|
await results[0].update((conv) => {
|
|
1654
1660
|
conv._setRaw("is_deleted", true);
|
|
1655
1661
|
});
|
|
1662
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", id)).fetch() : [];
|
|
1663
|
+
for (const job of jobs) await job.destroyPermanently();
|
|
1656
1664
|
});
|
|
1657
1665
|
return true;
|
|
1658
1666
|
}
|
|
@@ -1797,8 +1805,16 @@ async function getToolCallEventIdsOp(ctx, convId) {
|
|
|
1797
1805
|
return ids;
|
|
1798
1806
|
}
|
|
1799
1807
|
async function clearMessagesOp(ctx, convId) {
|
|
1800
|
-
const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
|
|
1801
1808
|
await ctx.database.write(async () => {
|
|
1809
|
+
const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
|
|
1810
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", convId)).fetch() : [];
|
|
1811
|
+
for (const job of jobs) {
|
|
1812
|
+
await job.update((row) => {
|
|
1813
|
+
row._setRaw("message_ids", "[]");
|
|
1814
|
+
row._setRaw("watermark", null);
|
|
1815
|
+
row._setRaw("watermark_seq", null);
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1802
1818
|
for (const message of messages) {
|
|
1803
1819
|
await message.update((msg) => {
|
|
1804
1820
|
msg._setRaw("file_ids", null);
|
|
@@ -1808,6 +1824,30 @@ async function clearMessagesOp(ctx, convId) {
|
|
|
1808
1824
|
}
|
|
1809
1825
|
});
|
|
1810
1826
|
}
|
|
1827
|
+
async function deleteMessageOp(ctx, uniqueId) {
|
|
1828
|
+
let message;
|
|
1829
|
+
try {
|
|
1830
|
+
message = await ctx.messagesCollection.find(uniqueId);
|
|
1831
|
+
} catch {
|
|
1832
|
+
return null;
|
|
1833
|
+
}
|
|
1834
|
+
await ctx.database.write(async () => {
|
|
1835
|
+
const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", message.conversationId)).fetch() : [];
|
|
1836
|
+
for (const job of jobs) {
|
|
1837
|
+
const ids = JSON.parse(String(job._getRaw("message_ids")));
|
|
1838
|
+
await job.update((row) => {
|
|
1839
|
+
row._setRaw("message_ids", JSON.stringify(ids.filter((id) => id !== uniqueId)));
|
|
1840
|
+
if (row._getRaw("watermark") === uniqueId) row._setRaw("watermark", null);
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
await message.update((msg) => {
|
|
1844
|
+
msg._setRaw("file_ids", null);
|
|
1845
|
+
msg._setRaw("files", null);
|
|
1846
|
+
});
|
|
1847
|
+
await message.destroyPermanently();
|
|
1848
|
+
});
|
|
1849
|
+
return uniqueId;
|
|
1850
|
+
}
|
|
1811
1851
|
async function encryptMessageOptsIfNeeded(ctx, opts) {
|
|
1812
1852
|
return ctx.walletAddress && ctx.signMessage ? await encryptMessageFields(opts, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : opts;
|
|
1813
1853
|
}
|
|
@@ -2725,6 +2765,7 @@ function isOwnedByCtxUser(ctx, record) {
|
|
|
2725
2765
|
}
|
|
2726
2766
|
function baseVaultConditions(ctx, options) {
|
|
2727
2767
|
return [
|
|
2768
|
+
...options?.memoryIds !== void 0 ? [Q3.where("id", Q3.oneOf(options.memoryIds))] : [],
|
|
2728
2769
|
...options?.includeDeleted ? [] : [Q3.where("is_deleted", false)],
|
|
2729
2770
|
...options?.includeArchived ? [] : [Q3.where("archived_at", Q3.eq(null))],
|
|
2730
2771
|
...options?.includeQuarantined ? [] : [Q3.where("trust_tier", Q3.notEq("quarantined"))],
|
|
@@ -2809,6 +2850,8 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
2809
2850
|
ctx.embeddedWalletSigner
|
|
2810
2851
|
) : opts.content;
|
|
2811
2852
|
const created = await ctx.database.write(async () => {
|
|
2853
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
2854
|
+
throw new Error("Memory source is no longer eligible");
|
|
2812
2855
|
return ctx.vaultMemoryCollection.create((record) => {
|
|
2813
2856
|
record._setRaw("content", encryptedContent);
|
|
2814
2857
|
record._setRaw("scope", scope);
|
|
@@ -2858,6 +2901,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
2858
2901
|
) : opts.content;
|
|
2859
2902
|
let createdRecord = null;
|
|
2860
2903
|
await ctx.database.write(async () => {
|
|
2904
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
2905
|
+
throw new Error("Memory source is no longer eligible");
|
|
2861
2906
|
let target;
|
|
2862
2907
|
try {
|
|
2863
2908
|
target = await ctx.vaultMemoryCollection.find(targetId);
|
|
@@ -2962,6 +3007,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
2962
3007
|
})
|
|
2963
3008
|
);
|
|
2964
3009
|
const created = await ctx.database.write(async () => {
|
|
3010
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
3011
|
+
throw new Error("Memory source is no longer eligible");
|
|
2965
3012
|
const prepared = optionsArray.map(
|
|
2966
3013
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate((record) => {
|
|
2967
3014
|
record._setRaw("content", encryptedContents[i]);
|
|
@@ -3148,6 +3195,11 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
3148
3195
|
});
|
|
3149
3196
|
const clauses = [base.sql];
|
|
3150
3197
|
const args = [...base.args];
|
|
3198
|
+
if (options?.memoryIds !== void 0) {
|
|
3199
|
+
if (options.memoryIds.length === 0) return [];
|
|
3200
|
+
clauses.push(`"id" in (${options.memoryIds.map(() => "?").join(",")})`);
|
|
3201
|
+
args.push(...options.memoryIds);
|
|
3202
|
+
}
|
|
3151
3203
|
if (options?.scopes?.length) {
|
|
3152
3204
|
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
3153
3205
|
args.push(...options.scopes);
|
|
@@ -3169,6 +3221,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
3169
3221
|
);
|
|
3170
3222
|
const conditions = [
|
|
3171
3223
|
...baseVaultConditions(ctx, {
|
|
3224
|
+
memoryIds: options?.memoryIds,
|
|
3172
3225
|
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
3173
3226
|
}),
|
|
3174
3227
|
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
@@ -3256,10 +3309,23 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
3256
3309
|
const record = probe;
|
|
3257
3310
|
const originalUpdatedAt = record.updatedAt.getTime();
|
|
3258
3311
|
await ctx.database.write(async () => {
|
|
3312
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
3313
|
+
throw new Error("Memory source is no longer eligible");
|
|
3259
3314
|
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
3260
3315
|
stale = true;
|
|
3261
3316
|
return;
|
|
3262
3317
|
}
|
|
3318
|
+
let observedSources = [];
|
|
3319
|
+
let replayedObservation = false;
|
|
3320
|
+
if (opts.observationSourceIds?.length) {
|
|
3321
|
+
try {
|
|
3322
|
+
const parsed = JSON.parse(record.sourceChunkIds ?? "[]");
|
|
3323
|
+
if (Array.isArray(parsed))
|
|
3324
|
+
observedSources = parsed.filter((id2) => typeof id2 === "string");
|
|
3325
|
+
} catch {
|
|
3326
|
+
}
|
|
3327
|
+
replayedObservation = opts.observationSourceIds.every((id2) => observedSources.includes(id2));
|
|
3328
|
+
}
|
|
3263
3329
|
await record.update((r) => {
|
|
3264
3330
|
r._setRaw("content", encryptedContent);
|
|
3265
3331
|
if (opts.scope !== void 0) {
|
|
@@ -3273,9 +3339,15 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
3273
3339
|
r._setRaw("embedding_model", opts.embeddingModel ?? null);
|
|
3274
3340
|
}
|
|
3275
3341
|
if (opts.sourceChunkIds !== void 0) {
|
|
3276
|
-
r._setRaw(
|
|
3342
|
+
r._setRaw(
|
|
3343
|
+
"source_chunk_ids",
|
|
3344
|
+
JSON.stringify(
|
|
3345
|
+
opts.observationSourceIds?.length ? [.../* @__PURE__ */ new Set([...observedSources, ...opts.sourceChunkIds])] : opts.sourceChunkIds
|
|
3346
|
+
)
|
|
3347
|
+
);
|
|
3277
3348
|
}
|
|
3278
|
-
if (
|
|
3349
|
+
if (replayedObservation) {
|
|
3350
|
+
} else if (opts.proofCountIncrement !== void 0) {
|
|
3279
3351
|
const current = r.proofCount ?? 1;
|
|
3280
3352
|
r._setRaw("proof_count", current + opts.proofCountIncrement);
|
|
3281
3353
|
} else if (opts.proofCount !== void 0) {
|
|
@@ -3292,7 +3364,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
3292
3364
|
if (opts.topicsUserManaged !== void 0) {
|
|
3293
3365
|
r._setRaw("topics_user_managed", opts.topicsUserManaged);
|
|
3294
3366
|
}
|
|
3295
|
-
if (opts.lastObservedAt !== void 0) {
|
|
3367
|
+
if (opts.lastObservedAt !== void 0 && !replayedObservation) {
|
|
3296
3368
|
r._setRaw("last_observed_at", opts.lastObservedAt);
|
|
3297
3369
|
}
|
|
3298
3370
|
if (opts.factType !== void 0) {
|
|
@@ -3463,6 +3535,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
3463
3535
|
}
|
|
3464
3536
|
let stale = false;
|
|
3465
3537
|
await ctx.database.write(async () => {
|
|
3538
|
+
if (ctx.canWrite && !await ctx.canWrite())
|
|
3539
|
+
throw new Error("Memory source is no longer eligible");
|
|
3466
3540
|
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
3467
3541
|
stale = true;
|
|
3468
3542
|
return;
|
|
@@ -3755,6 +3829,7 @@ async function getDecayCandidatesRawOp(ctx) {
|
|
|
3755
3829
|
eventTimeEnd: raw.event_time_end ?? null,
|
|
3756
3830
|
eventTimeKind: raw.event_time_kind ?? null,
|
|
3757
3831
|
updatedAt: raw.updated_at,
|
|
3832
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
3758
3833
|
archivedAt: raw.archived_at ?? null,
|
|
3759
3834
|
source: raw.source ?? null,
|
|
3760
3835
|
trustTier: raw.trust_tier ?? null
|
|
@@ -3771,7 +3846,7 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
|
|
|
3771
3846
|
stale = true;
|
|
3772
3847
|
return;
|
|
3773
3848
|
}
|
|
3774
|
-
if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt) {
|
|
3849
|
+
if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt || opts?.expectedLastObservedAt !== void 0 && (record.lastObservedAt ?? null) !== opts.expectedLastObservedAt) {
|
|
3775
3850
|
stale = true;
|
|
3776
3851
|
return;
|
|
3777
3852
|
}
|
|
@@ -6672,6 +6747,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
6672
6747
|
const scopes = searchOptions?.scopes;
|
|
6673
6748
|
const folderId = searchOptions?.folderId;
|
|
6674
6749
|
const queryOpts = {};
|
|
6750
|
+
if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
|
|
6675
6751
|
if (scopes?.length) queryOpts.scopes = scopes;
|
|
6676
6752
|
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
6677
6753
|
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
@@ -7196,7 +7272,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
7196
7272
|
subQueries = decomp.subQueries;
|
|
7197
7273
|
}
|
|
7198
7274
|
}
|
|
7199
|
-
const { recall: recall2 } = await import("./recall-
|
|
7275
|
+
const { recall: recall2 } = await import("./recall-LFHIWONV.mjs");
|
|
7200
7276
|
let recallDegraded = [];
|
|
7201
7277
|
const result = await recall2(
|
|
7202
7278
|
query,
|
|
@@ -7763,7 +7839,9 @@ function dedupeBy(items, ...keys) {
|
|
|
7763
7839
|
return out;
|
|
7764
7840
|
}
|
|
7765
7841
|
async function recall(query, ctx, options = {}) {
|
|
7766
|
-
const
|
|
7842
|
+
const requestedTypes = options.types ?? ["fact"];
|
|
7843
|
+
const chunksScopeRestricted = options.memoryIds !== void 0 && requestedTypes.includes("chunk");
|
|
7844
|
+
const types = options.memoryIds !== void 0 ? requestedTypes.filter((kind) => kind === "fact") : requestedTypes;
|
|
7767
7845
|
const limit = options.limit ?? DEFAULT_LIMIT;
|
|
7768
7846
|
const usedBudget = options.budget ?? DEFAULT_BUDGET;
|
|
7769
7847
|
const flags = flagsForBudget(usedBudget);
|
|
@@ -7815,7 +7893,10 @@ async function recall(query, ctx, options = {}) {
|
|
|
7815
7893
|
if (embeddingsUnavailable) degraded.push("embeddings-unavailable");
|
|
7816
7894
|
if (graphLaneFailed) degraded.push("graph-lane-failed");
|
|
7817
7895
|
if (temporalLaneFailed) degraded.push("temporal-lane-failed");
|
|
7818
|
-
|
|
7896
|
+
if (chunksScopeRestricted) degraded.push("chunks-scope-restricted");
|
|
7897
|
+
const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx || // The chunk lane was wired and deliberately dropped for the scope, which
|
|
7898
|
+
// is not the "requested kinds have no store" wiring bug `no-lanes` means.
|
|
7899
|
+
chunksScopeRestricted && !!ctx.storageCtx;
|
|
7819
7900
|
const scores = admitted.map((m) => m.score);
|
|
7820
7901
|
const minScoreApplied = factResults.length > 0 ? factFloor : chunkResults.length > 0 ? chunkFloor : factFloor >= 0 ? factFloor : chunkFloor;
|
|
7821
7902
|
const diagnostics = {
|
|
@@ -7960,6 +8041,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
7960
8041
|
...options.scopes && { scopes: options.scopes },
|
|
7961
8042
|
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
7962
8043
|
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
8044
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
7963
8045
|
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
7964
8046
|
...entityRanking.length > 0 && { entityRanking },
|
|
7965
8047
|
...temporalRanking.length > 0 && { temporalRanking }
|
|
@@ -8243,6 +8325,7 @@ export {
|
|
|
8243
8325
|
decryptField,
|
|
8244
8326
|
encryptJsonField,
|
|
8245
8327
|
decryptJsonField,
|
|
8328
|
+
ExtractionJob,
|
|
8246
8329
|
getToolCallEvents,
|
|
8247
8330
|
getToolsChecksum,
|
|
8248
8331
|
getImageModel,
|
|
@@ -8271,6 +8354,7 @@ export {
|
|
|
8271
8354
|
getMessageSkeletonsOp,
|
|
8272
8355
|
getToolCallEventIdsOp,
|
|
8273
8356
|
clearMessagesOp,
|
|
8357
|
+
deleteMessageOp,
|
|
8274
8358
|
createMessageOp,
|
|
8275
8359
|
getMessageOp,
|
|
8276
8360
|
updateMessageEmbeddingOp,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
notifyConsolidationFallback,
|
|
3
3
|
resolvePiiRedactor
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-GPLMMMZN.mjs";
|
|
5
5
|
import {
|
|
6
6
|
callPortalJsonCompletion
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-MHZB6KIX.mjs";
|
|
8
8
|
import "./chunk-GYKJOWEO.mjs";
|
|
9
9
|
|
|
10
10
|
// src/lib/memory/consolidate.ts
|