@anuma/sdk 2.4.1 → 2.5.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/client/index.cjs +8 -0
- package/dist/client/index.d.mts +44 -1
- package/dist/client/index.d.ts +44 -1
- package/dist/client/index.mjs +7 -0
- package/dist/expo/{chunk-UOUJUZM4.mjs → chunk-A26RBLTJ.mjs} +97 -3
- package/dist/expo/{consolidate-HEMQGOUD.mjs → consolidate-3QQPUWD6.mjs} +15 -9
- package/dist/expo/index.cjs +232 -67
- package/dist/expo/index.d.mts +44 -7
- package/dist/expo/index.d.ts +44 -7
- package/dist/expo/index.mjs +126 -58
- package/dist/{react/recall-G3CS444F.mjs → expo/recall-JC5GF5CX.mjs} +1 -1
- package/dist/react/{chunk-IYDQBFS2.mjs → chunk-V5GC3ES7.mjs} +97 -3
- package/dist/react/{consolidate-IJH7LD2T.mjs → consolidate-3MXZV3G7.mjs} +15 -9
- package/dist/react/index.cjs +232 -67
- package/dist/react/index.d.mts +44 -7
- package/dist/react/index.d.ts +44 -7
- package/dist/react/index.mjs +126 -58
- package/dist/{expo/recall-HI7VO3VM.mjs → react/recall-IRTSMKYI.mjs} +1 -1
- package/dist/server/{chunk-3MLG7SUH.mjs → chunk-TWWLE6P3.mjs} +97 -3
- package/dist/server/{consolidate-TDT4HRHG.mjs → consolidate-CN2GQV4D.mjs} +15 -9
- package/dist/server/index.cjs +232 -67
- package/dist/server/index.d.mts +44 -7
- package/dist/server/index.d.ts +44 -7
- package/dist/server/index.mjs +126 -58
- package/dist/server/{recall-MJHGXMHZ.mjs → recall-44FIK2MJ.mjs} +1 -1
- package/package.json +2 -2
package/dist/client/index.mjs
CHANGED
|
@@ -2053,6 +2053,12 @@ var getHealth = (options) => {
|
|
|
2053
2053
|
...options
|
|
2054
2054
|
});
|
|
2055
2055
|
};
|
|
2056
|
+
var getInternalAccountsByDidByDid = (options) => {
|
|
2057
|
+
return (options.client ?? client).get({
|
|
2058
|
+
url: "/internal/accounts/by-did/{did}",
|
|
2059
|
+
...options
|
|
2060
|
+
});
|
|
2061
|
+
};
|
|
2056
2062
|
var getOauthAuthorize = (options) => {
|
|
2057
2063
|
return (options.client ?? client).get({
|
|
2058
2064
|
url: "/oauth/authorize",
|
|
@@ -2174,6 +2180,7 @@ export {
|
|
|
2174
2180
|
getConnectorsByProviderCallback,
|
|
2175
2181
|
getConnectorsByProviderConnect,
|
|
2176
2182
|
getHealth,
|
|
2183
|
+
getInternalAccountsByDidByDid,
|
|
2177
2184
|
getOauthAuthorize,
|
|
2178
2185
|
getOauthConsent,
|
|
2179
2186
|
getWellKnownJwksJson,
|
|
@@ -1871,6 +1871,7 @@ function isOwnedByCtxUser(ctx, record) {
|
|
|
1871
1871
|
function baseVaultConditions(ctx, options) {
|
|
1872
1872
|
return [
|
|
1873
1873
|
...options?.includeDeleted ? [] : [Q3.where("is_deleted", false)],
|
|
1874
|
+
...options?.includeSuperseded ? [] : [Q3.where("superseded_by", null)],
|
|
1874
1875
|
...ctx.userId !== void 0 ? [Q3.where("user_id", ctx.userId)] : [],
|
|
1875
1876
|
...options?.since ? [Q3.where("updated_at", Q3.gt(options.since.getTime()))] : []
|
|
1876
1877
|
];
|
|
@@ -1911,6 +1912,8 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
1911
1912
|
eventTimeKind: memory.eventTimeKind ?? null,
|
|
1912
1913
|
topicsUserManaged: memory.topicsUserManaged ?? false,
|
|
1913
1914
|
topicsExtractedAt: memory.topicsExtractedAt ?? null,
|
|
1915
|
+
supersededBy: memory.supersededBy ?? null,
|
|
1916
|
+
supersededAt: memory.supersededAt ?? null,
|
|
1914
1917
|
createdAt: memory.createdAt,
|
|
1915
1918
|
updatedAt: memory.updatedAt,
|
|
1916
1919
|
isDeleted: memory.isDeleted
|
|
@@ -1956,6 +1959,59 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
1956
1959
|
});
|
|
1957
1960
|
return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
1958
1961
|
}
|
|
1962
|
+
async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
1963
|
+
if (!targetId) return { created: null, retired: false };
|
|
1964
|
+
const scope = opts.scope ?? "private";
|
|
1965
|
+
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
1966
|
+
opts.content,
|
|
1967
|
+
ctx.walletAddress,
|
|
1968
|
+
ctx.signMessage,
|
|
1969
|
+
ctx.embeddedWalletSigner
|
|
1970
|
+
) : opts.content;
|
|
1971
|
+
let createdRecord = null;
|
|
1972
|
+
await ctx.database.write(async () => {
|
|
1973
|
+
let target;
|
|
1974
|
+
try {
|
|
1975
|
+
target = await ctx.vaultMemoryCollection.find(targetId);
|
|
1976
|
+
} catch {
|
|
1977
|
+
return;
|
|
1978
|
+
}
|
|
1979
|
+
if (target.isDeleted || target.supersededBy || !isOwnedByCtxUser(ctx, target)) return;
|
|
1980
|
+
createdRecord = await ctx.vaultMemoryCollection.create((record) => {
|
|
1981
|
+
record._setRaw("content", encryptedContent);
|
|
1982
|
+
record._setRaw("scope", scope);
|
|
1983
|
+
record._setRaw("folder_id", opts.folderId ?? null);
|
|
1984
|
+
record._setRaw("user_id", ctx.userId ?? null);
|
|
1985
|
+
record._setRaw("is_deleted", false);
|
|
1986
|
+
if (opts.embedding !== void 0) {
|
|
1987
|
+
record._setRaw("embedding", opts.embedding);
|
|
1988
|
+
record._setRaw("embedding_model", opts.embeddingModel ?? null);
|
|
1989
|
+
}
|
|
1990
|
+
if (opts.sourceChunkIds !== void 0) {
|
|
1991
|
+
record._setRaw("source_chunk_ids", JSON.stringify(opts.sourceChunkIds));
|
|
1992
|
+
}
|
|
1993
|
+
record._setRaw("proof_count", opts.proofCount ?? 1);
|
|
1994
|
+
record._setRaw("source", opts.source ?? "manual");
|
|
1995
|
+
if (opts.eventTime) {
|
|
1996
|
+
record._setRaw("event_time_start", opts.eventTime.start ?? null);
|
|
1997
|
+
record._setRaw("event_time_end", opts.eventTime.end ?? null);
|
|
1998
|
+
record._setRaw("event_time_kind", opts.eventTime.kind ?? null);
|
|
1999
|
+
}
|
|
2000
|
+
});
|
|
2001
|
+
await target.update((r) => {
|
|
2002
|
+
r._setRaw("superseded_by", createdRecord.id);
|
|
2003
|
+
r._setRaw("superseded_at", Date.now());
|
|
2004
|
+
});
|
|
2005
|
+
});
|
|
2006
|
+
if (!createdRecord) return { created: null, retired: false };
|
|
2007
|
+
const created = await vaultMemoryToStored(
|
|
2008
|
+
createdRecord,
|
|
2009
|
+
ctx.walletAddress,
|
|
2010
|
+
ctx.signMessage,
|
|
2011
|
+
ctx.embeddedWalletSigner
|
|
2012
|
+
);
|
|
2013
|
+
return { created, retired: true };
|
|
2014
|
+
}
|
|
1959
2015
|
async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
1960
2016
|
const records = await ctx.vaultMemoryCollection.query(
|
|
1961
2017
|
...baseVaultConditions(ctx),
|
|
@@ -2095,6 +2151,8 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
2095
2151
|
// SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
|
|
2096
2152
|
topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1,
|
|
2097
2153
|
topicsExtractedAt: raw.topics_extracted_at ?? null,
|
|
2154
|
+
supersededBy: raw.superseded_by ?? null,
|
|
2155
|
+
supersededAt: raw.superseded_at ?? null,
|
|
2098
2156
|
createdAt: new Date(raw.created_at),
|
|
2099
2157
|
updatedAt: new Date(raw.updated_at),
|
|
2100
2158
|
isDeleted: raw.is_deleted === true || raw.is_deleted === 1
|
|
@@ -2136,7 +2194,7 @@ async function getAllVaultMemoryContentsOp(ctx, options) {
|
|
|
2136
2194
|
async function updateVaultMemoryOp(ctx, id, opts) {
|
|
2137
2195
|
try {
|
|
2138
2196
|
const probe = await ctx.vaultMemoryCollection.find(id);
|
|
2139
|
-
if (probe.isDeleted || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
2197
|
+
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
2140
2198
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
2141
2199
|
opts.content,
|
|
2142
2200
|
ctx.walletAddress,
|
|
@@ -2147,7 +2205,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
2147
2205
|
const record = probe;
|
|
2148
2206
|
const originalUpdatedAt = record.updatedAt.getTime();
|
|
2149
2207
|
await ctx.database.write(async () => {
|
|
2150
|
-
if (record.isDeleted || !isOwnedByCtxUser(ctx, record)) {
|
|
2208
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
2151
2209
|
stale = true;
|
|
2152
2210
|
return;
|
|
2153
2211
|
}
|
|
@@ -2225,6 +2283,40 @@ async function deleteVaultMemoryOp(ctx, id) {
|
|
|
2225
2283
|
return false;
|
|
2226
2284
|
}
|
|
2227
2285
|
}
|
|
2286
|
+
async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
2287
|
+
if (id === supersededById) return false;
|
|
2288
|
+
try {
|
|
2289
|
+
const record = await ctx.vaultMemoryCollection.find(id);
|
|
2290
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) return false;
|
|
2291
|
+
let successor;
|
|
2292
|
+
try {
|
|
2293
|
+
successor = await ctx.vaultMemoryCollection.find(supersededById);
|
|
2294
|
+
} catch {
|
|
2295
|
+
return false;
|
|
2296
|
+
}
|
|
2297
|
+
if (successor.isDeleted || successor.supersededBy || !isOwnedByCtxUser(ctx, successor)) {
|
|
2298
|
+
return false;
|
|
2299
|
+
}
|
|
2300
|
+
let stale = false;
|
|
2301
|
+
await ctx.database.write(async () => {
|
|
2302
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
2303
|
+
stale = true;
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
if (successor.isDeleted || successor.supersededBy || !isOwnedByCtxUser(ctx, successor)) {
|
|
2307
|
+
stale = true;
|
|
2308
|
+
return;
|
|
2309
|
+
}
|
|
2310
|
+
await record.update((r) => {
|
|
2311
|
+
r._setRaw("superseded_by", supersededById);
|
|
2312
|
+
r._setRaw("superseded_at", Date.now());
|
|
2313
|
+
});
|
|
2314
|
+
});
|
|
2315
|
+
return !stale;
|
|
2316
|
+
} catch {
|
|
2317
|
+
return false;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2228
2320
|
async function getUnfiledVaultMemoriesOp(ctx) {
|
|
2229
2321
|
const conditions = [
|
|
2230
2322
|
Q3.where("folder_id", null),
|
|
@@ -4950,7 +5042,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
4950
5042
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
4951
5043
|
);
|
|
4952
5044
|
}
|
|
4953
|
-
const { recall: recall2 } = await import("./recall-
|
|
5045
|
+
const { recall: recall2 } = await import("./recall-JC5GF5CX.mjs");
|
|
4954
5046
|
const result = await recall2(
|
|
4955
5047
|
query,
|
|
4956
5048
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -5636,12 +5728,14 @@ export {
|
|
|
5636
5728
|
replaceMemoryEntitiesGuardedOp,
|
|
5637
5729
|
vaultMemoryToStored,
|
|
5638
5730
|
createVaultMemoryOp,
|
|
5731
|
+
createSupersedingMemoryOp,
|
|
5639
5732
|
createVaultMemoriesBatchOp,
|
|
5640
5733
|
getVaultMemoryOp,
|
|
5641
5734
|
getAllVaultMemoriesOp,
|
|
5642
5735
|
getAllVaultMemoryContentsOp,
|
|
5643
5736
|
updateVaultMemoryOp,
|
|
5644
5737
|
deleteVaultMemoryOp,
|
|
5738
|
+
supersedeVaultMemoryOp,
|
|
5645
5739
|
getUnfiledVaultMemoriesOp,
|
|
5646
5740
|
getMemoriesNeedingTopicExtractionOp,
|
|
5647
5741
|
stampTopicsExtractedAtOp,
|
|
@@ -15,10 +15,11 @@ var SYSTEM_PROMPT = `You consolidate a new memory against existing memories from
|
|
|
15
15
|
|
|
16
16
|
A "memory" is a self-contained natural-language fact about the user. Multiple memories about the same EXACT FACET (the same dimension of the same subject) should never coexist \u2014 they should be merged into one. Different facets on the same subject (e.g. user's dog's name vs user's dog's age) are SEPARATE memories.
|
|
17
17
|
|
|
18
|
-
Decide one of
|
|
18
|
+
Decide one of four actions:
|
|
19
19
|
|
|
20
20
|
- "create": the new memory describes a distinct fact not covered by any existing memory. Write it as new.
|
|
21
|
-
- "update": the new memory describes the SAME FACET as exactly one existing memory
|
|
21
|
+
- "update": the new memory describes the SAME FACET as exactly one existing memory and is COMPATIBLE with it \u2014 it adds detail, fixes an incomplete value, or rephrases the same still-true fact. Return targetId of that existing memory + the consolidated content (richest version of the two).
|
|
22
|
+
- "supersede": the new memory REPLACES a standing fact whose value has CHANGED and is now INCOMPATIBLE with an existing memory \u2014 the old fact was true before but is false now (a state change). Return targetId of the STALE existing memory to retire + content = the NEW fact. The old memory is kept as history, not overwritten or deleted; do not re-state it.
|
|
22
23
|
- "noop": the new memory is already fully captured by an existing memory \u2014 same facet, no new information. Skip the write.
|
|
23
24
|
|
|
24
25
|
RULES (carry these strictly):
|
|
@@ -26,18 +27,21 @@ RULES (carry these strictly):
|
|
|
26
27
|
1. ONE OBSERVATION PER DISTINCT FACET. If the new memory is about "user's aunt's twins" and an existing memory is also about "user's aunt's twins", they are the same facet \u2192 update, never create.
|
|
27
28
|
2. MATCH BY FACET, NOT TOPIC. Two memories both mentioning "Zara" is not enough to merge \u2014 only merge if they describe the same property (e.g. both about "user's pending Zara boot exchange"). Two memories about Zara on different topics (e.g. "user shops at Zara" + "user returned a sweater to Zara last week") are separate facets.
|
|
28
29
|
3. NO COMPUTATION. Do not sum counts, decrement quantities, or derive new facts from existing ones. If the new memory says "user spent $200 today" and an existing memory says "user spent $150 yesterday", these are TWO SEPARATE EVENTS \u2014 create.
|
|
29
|
-
4.
|
|
30
|
-
|
|
30
|
+
4. EVENTS vs STANDING STATE.
|
|
31
|
+
- Distinct EVENTS (episodic \u2014 something that happened on a date) are separate memories, even if the same activity: "user went to gym Monday" vs "user went to gym Friday" \u2192 create; keep both.
|
|
32
|
+
- A STANDING ATTRIBUTE (an ongoing state: where the user lives/works, relationship status, current role) has ONE current value. When the new memory changes that value ("Lives in Portland" \u2192 "Lives in San Francisco"; "Works at Google" \u2192 "Works at Riverbend"; "Engaged" \u2192 "Broke up"), the old value is no longer true \u2192 supersede (retire the old, record the new). Do NOT create (that leaves a stale contradiction) and do NOT update (that erases the history that the old value was once true).
|
|
33
|
+
5. When in doubt between create and update, choose create \u2014 EXCEPT when the new memory directly contradicts the current value of a standing attribute in an existing memory; then choose supersede. Over-merging loses information; a live contradiction is worse than either.
|
|
31
34
|
|
|
32
35
|
OUTPUT \u2014 strict JSON, no prose:
|
|
33
36
|
{
|
|
34
|
-
"action": "create" | "update" | "noop",
|
|
35
|
-
"targetId": "<existing memory id
|
|
36
|
-
"content": "<
|
|
37
|
+
"action": "create" | "update" | "supersede" | "noop",
|
|
38
|
+
"targetId": "<existing memory id \u2014 required for update/supersede/noop, omit for create>",
|
|
39
|
+
"content": "<content \u2014 required for create/update/supersede, omit for noop>"
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
For "create": content is the new memory verbatim (or a slight refinement).
|
|
40
43
|
For "update": content is the merged richest-version, \u226480 words.
|
|
44
|
+
For "supersede": content is the NEW fact only (\u226480 words); targetId is the stale memory being retired.
|
|
41
45
|
For "noop": no content (existing memory is already correct).`;
|
|
42
46
|
async function consolidateMemory(newContent, candidates, options) {
|
|
43
47
|
const fallback = {
|
|
@@ -112,7 +116,9 @@ function validate(parsed, newContent, validIds) {
|
|
|
112
116
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
113
117
|
const obj = parsed;
|
|
114
118
|
const action = obj.action;
|
|
115
|
-
if (action !== "create" && action !== "update" && action !== "noop")
|
|
119
|
+
if (action !== "create" && action !== "update" && action !== "noop" && action !== "supersede") {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
116
122
|
if (action === "create") {
|
|
117
123
|
const c2 = typeof obj.content === "string" ? obj.content.trim() : "";
|
|
118
124
|
return { action: "create", content: c2.length > 0 ? c2 : newContent };
|
|
@@ -124,7 +130,7 @@ function validate(parsed, newContent, validIds) {
|
|
|
124
130
|
}
|
|
125
131
|
const c = typeof obj.content === "string" ? obj.content.trim() : "";
|
|
126
132
|
if (c.length === 0) return null;
|
|
127
|
-
return { action
|
|
133
|
+
return { action, targetId, content: c };
|
|
128
134
|
}
|
|
129
135
|
export {
|
|
130
136
|
consolidateMemory
|