@anuma/sdk 6.39.3 → 6.41.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/index.cjs +360 -92
- package/dist/expo/index.d.mts +49 -2
- package/dist/expo/index.d.ts +49 -2
- package/dist/expo/index.mjs +357 -92
- package/dist/memory/context.d.mts +2 -0
- package/dist/memory/context.d.ts +2 -0
- package/dist/react/index.cjs +322 -52
- package/dist/react/index.d.mts +49 -2
- package/dist/react/index.d.ts +49 -2
- package/dist/react/index.mjs +319 -52
- package/dist/server/index.cjs +90 -40
- package/dist/server/index.d.mts +28 -2
- package/dist/server/index.d.ts +28 -2
- package/dist/server/index.mjs +90 -40
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -25703,6 +25703,10 @@ var ENTITY_KINDS = [
|
|
|
25703
25703
|
function normalizeEntityName(name) {
|
|
25704
25704
|
return name.trim().toLowerCase();
|
|
25705
25705
|
}
|
|
25706
|
+
var TOPIC_SALIENCE_WEIGHTS = { primary: 1, secondary: 0.6, mention: 0.3 };
|
|
25707
|
+
function parseTopicWeight(value) {
|
|
25708
|
+
return typeof value === "number" && value > 0 && value <= 1 ? value : void 0;
|
|
25709
|
+
}
|
|
25706
25710
|
function serializeTopics(topics) {
|
|
25707
25711
|
return JSON.stringify(topics);
|
|
25708
25712
|
}
|
|
@@ -25718,12 +25722,14 @@ function parseTopics(value) {
|
|
|
25718
25722
|
const out = [];
|
|
25719
25723
|
for (const raw of parsed) {
|
|
25720
25724
|
if (typeof raw !== "object" || raw === null) continue;
|
|
25721
|
-
const { name, kind, source } = raw;
|
|
25725
|
+
const { name, kind, source, weight } = raw;
|
|
25722
25726
|
if (typeof name !== "string" || name.trim().length === 0) continue;
|
|
25727
|
+
const parsedWeight = parseTopicWeight(weight);
|
|
25723
25728
|
out.push({
|
|
25724
25729
|
name,
|
|
25725
25730
|
...typeof kind === "string" && kind.length > 0 ? { kind } : {},
|
|
25726
|
-
source: source === "user" ? "user" : "auto"
|
|
25731
|
+
source: source === "user" ? "user" : "auto",
|
|
25732
|
+
...parsedWeight !== void 0 ? { weight: parsedWeight } : {}
|
|
25727
25733
|
});
|
|
25728
25734
|
}
|
|
25729
25735
|
return out;
|
|
@@ -25810,21 +25816,47 @@ function displayNamesOf(entities) {
|
|
|
25810
25816
|
}
|
|
25811
25817
|
function topicsEqual(stored, computed) {
|
|
25812
25818
|
if (stored === null || stored.length !== computed.length) return false;
|
|
25813
|
-
const key = (t) => JSON.stringify([t.name, t.kind ?? null, t.source]);
|
|
25819
|
+
const key = (t) => JSON.stringify([t.name, t.kind ?? null, t.source, t.weight ?? null]);
|
|
25814
25820
|
const storedKeys = stored.map(key).sort();
|
|
25815
25821
|
const computedKeys = computed.map(key).sort();
|
|
25816
25822
|
return storedKeys.every((k, i) => k === computedKeys[i]);
|
|
25817
25823
|
}
|
|
25818
|
-
function resolveTopicsWrite(row, linked,
|
|
25824
|
+
function resolveTopicsWrite(row, linked, inputs, source, mode) {
|
|
25819
25825
|
if (row === null || source === null) return null;
|
|
25820
|
-
const
|
|
25821
|
-
|
|
25826
|
+
const stored = parseTopics(row.topics);
|
|
25827
|
+
const carried = mode === "merge" ? stored : null;
|
|
25828
|
+
const weights = source === "auto" ? weightsOf(carried, inputs) : null;
|
|
25829
|
+
const displayNames = displayNamesOf([...inputs, ...carried ?? []]);
|
|
25830
|
+
const topics = topicsForEntities(linked, displayNames, source, weights);
|
|
25831
|
+
if (topicsEqual(stored, topics)) return null;
|
|
25822
25832
|
return { row, topics };
|
|
25823
25833
|
}
|
|
25824
|
-
function
|
|
25834
|
+
function weightsOf(stored, inputs) {
|
|
25835
|
+
const out = /* @__PURE__ */ new Map();
|
|
25836
|
+
for (const topic of stored ?? []) out.set(normalizeEntityName(topic.name), topic.weight);
|
|
25837
|
+
for (const input of inputs) {
|
|
25838
|
+
const weight = parseTopicWeight(input.weight);
|
|
25839
|
+
if (weight === void 0) continue;
|
|
25840
|
+
const name = normalizeEntityName(input.name);
|
|
25841
|
+
if (!out.has(name)) {
|
|
25842
|
+
out.set(name, weight);
|
|
25843
|
+
continue;
|
|
25844
|
+
}
|
|
25845
|
+
const current = out.get(name);
|
|
25846
|
+
if (current !== void 0 && weight > current) out.set(name, weight);
|
|
25847
|
+
}
|
|
25848
|
+
return out;
|
|
25849
|
+
}
|
|
25850
|
+
function topicsForEntities(entities, displayNames, source, weights) {
|
|
25825
25851
|
return entities.map((e) => {
|
|
25826
25852
|
const name = displayNames.get(e.canonicalName) ?? e.canonicalName;
|
|
25827
|
-
|
|
25853
|
+
const weight = weights?.get(e.canonicalName);
|
|
25854
|
+
return {
|
|
25855
|
+
name,
|
|
25856
|
+
...e.kind ? { kind: e.kind } : {},
|
|
25857
|
+
source,
|
|
25858
|
+
...weight !== void 0 ? { weight } : {}
|
|
25859
|
+
};
|
|
25828
25860
|
});
|
|
25829
25861
|
}
|
|
25830
25862
|
function toEntityObjects(entityInputs) {
|
|
@@ -25832,7 +25864,7 @@ function toEntityObjects(entityInputs) {
|
|
|
25832
25864
|
}
|
|
25833
25865
|
async function resolveMemoryTopicsWrite(ctx, memoryId, linked, inputs, source) {
|
|
25834
25866
|
const row = await findVaultRowInWrite(ctx, memoryId);
|
|
25835
|
-
return resolveTopicsWrite(row, linked,
|
|
25867
|
+
return resolveTopicsWrite(row, linked, toEntityObjects(inputs), source, "replace");
|
|
25836
25868
|
}
|
|
25837
25869
|
function prepareMemoryTopicsUpdate(write) {
|
|
25838
25870
|
return prepareTopicsUpdate(write.row, write.topics, Date.now());
|
|
@@ -25870,8 +25902,9 @@ async function linkMemoryEntitiesOp(ctx, memoryId, entityInputs, options) {
|
|
|
25870
25902
|
const topicsWrite = resolveTopicsWrite(
|
|
25871
25903
|
vaultRow,
|
|
25872
25904
|
[...carriedOver, ...entities],
|
|
25873
|
-
|
|
25874
|
-
options?.topicsSource ?? "auto"
|
|
25905
|
+
normalized,
|
|
25906
|
+
options?.topicsSource ?? "auto",
|
|
25907
|
+
"merge"
|
|
25875
25908
|
);
|
|
25876
25909
|
if (entityOps.length === 0 && kindBackfills.length === 0 && toCreate.length === 0 && topicsWrite === null) {
|
|
25877
25910
|
return;
|
|
@@ -25937,8 +25970,9 @@ async function replaceMemoryEntities(ctx, memoryId, entityInputs, options) {
|
|
|
25937
25970
|
const topicsWrite = resolveTopicsWrite(
|
|
25938
25971
|
vaultRow,
|
|
25939
25972
|
entities,
|
|
25940
|
-
|
|
25941
|
-
options.topicsSource
|
|
25973
|
+
normalized,
|
|
25974
|
+
options.topicsSource,
|
|
25975
|
+
"replace"
|
|
25942
25976
|
);
|
|
25943
25977
|
if (entityOps.length === 0 && kindBackfills.length === 0 && toCreate.length === 0 && toDestroy.length === 0 && topicsWrite === null) {
|
|
25944
25978
|
return;
|
|
@@ -30897,9 +30931,9 @@ For each durable fact, output:
|
|
|
30897
30931
|
- type: one of identity | preference | relationship | plan | ongoing_context | constraint | other
|
|
30898
30932
|
- confidence: 0.0-1.0; how sure you are this is durable AND true. Only include facts >= 0.7.
|
|
30899
30933
|
- sourceMessageIds: which message IDs from the conversation contained the evidence
|
|
30900
|
-
- entities: named entities mentioned, each as an object { "name": string, "kind": one of "person" | "organization" | "place" | "event" | "product" | "thing" | "concept" | "other" }. Optional \u2014 include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES} Examples:
|
|
30901
|
-
- "started a new job at Hollowpoint Labs and I'm learning Haskell for it" \u2192 entities: [{ "name": "Hollowpoint Labs", "kind": "organization" }, { "name": "Haskell", "kind": "concept" }]
|
|
30902
|
-
- "running the Berlin Half in May and I track workouts in Whoop" \u2192 entities: [{ "name": "Berlin Half", "kind": "event" }, { "name": "Whoop", "kind": "product" }]
|
|
30934
|
+
- entities: named entities mentioned, each as an object { "name": string, "kind": one of "person" | "organization" | "place" | "event" | "product" | "thing" | "concept" | "other", "salience": one of "primary" | "secondary" | "mention" }. Optional \u2014 include only NAMED entities, skip generic/common nouns. ${ENTITY_KIND_GUIDELINES} Salience is how central the entity is to the fact: "primary" = the fact is ABOUT it (usually exactly one per fact), "secondary" = a meaningful part of it, "mention" = named in passing. Examples:
|
|
30935
|
+
- "started a new job at Hollowpoint Labs and I'm learning Haskell for it" \u2192 entities: [{ "name": "Hollowpoint Labs", "kind": "organization", "salience": "primary" }, { "name": "Haskell", "kind": "concept", "salience": "secondary" }]
|
|
30936
|
+
- "running the Berlin Half in May and I track workouts in Whoop" \u2192 entities: [{ "name": "Berlin Half", "kind": "event", "salience": "primary" }, { "name": "Whoop", "kind": "product", "salience": "mention" }]
|
|
30903
30937
|
- eventTime: when the event in this fact occurs/occurred. Resolve relative phrases ("yesterday", "next week") against the current date given in the user message. Output one of:
|
|
30904
30938
|
- { "kind": "point", "start": "YYYY-MM-DD" } for a single date ("met Sara on March 14, 2026")
|
|
30905
30939
|
- { "kind": "range", "start": "YYYY-MM-DD", "end": "YYYY-MM-DD" } for a span ("Japan trip May 4\u201315, 2026")
|
|
@@ -30980,9 +31014,10 @@ function restoreCandidates(candidates, redactor, ownNames) {
|
|
|
30980
31014
|
candidate: {
|
|
30981
31015
|
...c,
|
|
30982
31016
|
content: content.text,
|
|
30983
|
-
entities: c.entities.
|
|
30984
|
-
|
|
30985
|
-
|
|
31017
|
+
entities: c.entities.flatMap((e) => {
|
|
31018
|
+
const restored = redactor.restoreForStorage(e.name);
|
|
31019
|
+
return restored.unresolved ? [] : [{ ...e, name: restored.text }];
|
|
31020
|
+
})
|
|
30986
31021
|
},
|
|
30987
31022
|
unresolved: content.unresolved
|
|
30988
31023
|
};
|
|
@@ -31211,7 +31246,12 @@ function parseEntities(raw) {
|
|
|
31211
31246
|
const name = typeof obj.name === "string" ? obj.name.trim() : "";
|
|
31212
31247
|
if (name.length === 0 || isGenericEntityName(name)) continue;
|
|
31213
31248
|
const kind = typeof obj.kind === "string" && ENTITY_KINDS.includes(obj.kind) ? obj.kind : void 0;
|
|
31214
|
-
|
|
31249
|
+
const weight = typeof obj.salience === "string" && Object.keys(TOPIC_SALIENCE_WEIGHTS).includes(obj.salience) ? TOPIC_SALIENCE_WEIGHTS[obj.salience] : void 0;
|
|
31250
|
+
out.push({
|
|
31251
|
+
name,
|
|
31252
|
+
...kind !== void 0 ? { kind } : {},
|
|
31253
|
+
...weight !== void 0 ? { weight } : {}
|
|
31254
|
+
});
|
|
31215
31255
|
}
|
|
31216
31256
|
return out;
|
|
31217
31257
|
}
|
|
@@ -33170,7 +33210,13 @@ Include only NAMED entities, skip generic/common nouns. A topic must identify a
|
|
|
33170
33210
|
- Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
|
|
33171
33211
|
${ENTITY_KIND_GUIDELINES}
|
|
33172
33212
|
|
|
33173
|
-
|
|
33213
|
+
Give each entity a "salience" \u2014 how central it is to the memory:
|
|
33214
|
+
- "primary": the memory is ABOUT it. A memory with entities usually has exactly one primary; never more than two.
|
|
33215
|
+
- "secondary": a meaningful part of the memory, but not its subject.
|
|
33216
|
+
- "mention": named in passing; the memory would say much the same without it.
|
|
33217
|
+
Example: "Ran the Chicago Marathon with my sister Ana in 3:41" \u2192 Chicago Marathon primary, Ana secondary.
|
|
33218
|
+
|
|
33219
|
+
Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string, "salience": "primary" | "secondary" | "mention"}]}]}
|
|
33174
33220
|
- exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
|
|
33175
33221
|
- "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
|
|
33176
33222
|
No prose.`;
|
|
@@ -33241,9 +33287,10 @@ List each memory's named entities.`,
|
|
|
33241
33287
|
return out;
|
|
33242
33288
|
}
|
|
33243
33289
|
function restoreEntities(entities, redactor) {
|
|
33244
|
-
return entities.
|
|
33245
|
-
|
|
33246
|
-
|
|
33290
|
+
return entities.flatMap((e) => {
|
|
33291
|
+
const restored = redactor.restoreForStorage(e.name);
|
|
33292
|
+
return restored.unresolved ? [] : [{ ...e, name: restored.text }];
|
|
33293
|
+
});
|
|
33247
33294
|
}
|
|
33248
33295
|
function parseTopicResponse(parsed, validIds) {
|
|
33249
33296
|
if (typeof parsed !== "object" || parsed === null) return null;
|
|
@@ -33404,6 +33451,14 @@ function createLocalMemoryStore(options) {
|
|
|
33404
33451
|
getLogger().warn("[memory/store] Failed to embed memory:", err);
|
|
33405
33452
|
});
|
|
33406
33453
|
};
|
|
33454
|
+
const maintenance = {
|
|
33455
|
+
createDecaySweeper: (sweeperOptions) => createDecaySweeper({ ...sweeperOptions, vaultCtx }),
|
|
33456
|
+
getTopicBacklog: (backlogOptions) => getMemoriesNeedingTopicExtractionOp(vaultCtx, backlogOptions),
|
|
33457
|
+
extractTopics: (memoryIds, extractOptions) => extractAndLinkEntitiesForMemoriesOp(vaultCtx, memoryIds, extractOptions),
|
|
33458
|
+
stampTopicsExtracted: (memoryIds, extractedAt, version) => stampTopicsExtractedAtOp(vaultCtx, memoryIds, extractedAt, version),
|
|
33459
|
+
relinkTopics: (memoryIds) => relinkMemoryTopicsOp(vaultCtx, memoryIds),
|
|
33460
|
+
backfillTopics: (memoryIds) => backfillMemoryTopicsOp(vaultCtx, memoryIds)
|
|
33461
|
+
};
|
|
33407
33462
|
return {
|
|
33408
33463
|
masksEmbeddingInput: options.embeddingOptions.maskInput !== void 0,
|
|
33409
33464
|
list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
|
|
@@ -33417,21 +33472,22 @@ function createLocalMemoryStore(options) {
|
|
|
33417
33472
|
memoriesByTopics: (names) => getMemoriesByEntityNamesOp(entityCtx, names),
|
|
33418
33473
|
topicsByMemories: (memoryIds) => getEntitiesByMemoryIdsOp(entityCtx, memoryIds),
|
|
33419
33474
|
listTopics: async () => {
|
|
33420
|
-
const links = await entityCtx.memoryEntityCollection.query(...linksOwnedBy).
|
|
33475
|
+
const links = await entityCtx.memoryEntityCollection.query(...linksOwnedBy).unsafeFetchRaw();
|
|
33421
33476
|
const members = /* @__PURE__ */ new Map();
|
|
33422
33477
|
for (const link of links) {
|
|
33423
|
-
const entityId = String(link.
|
|
33478
|
+
const entityId = String(link.entity_id);
|
|
33424
33479
|
const set = members.get(entityId) ?? /* @__PURE__ */ new Set();
|
|
33425
|
-
set.add(String(link.
|
|
33480
|
+
set.add(String(link.memory_id));
|
|
33426
33481
|
members.set(entityId, set);
|
|
33427
33482
|
}
|
|
33428
|
-
const entities = userId === void 0 ? await entityCtx.entityCollection.query().
|
|
33483
|
+
const entities = userId === void 0 ? await entityCtx.entityCollection.query().unsafeFetchRaw() : members.size ? await entityCtx.entityCollection.query(import_watermelondb24.Q.where("id", import_watermelondb24.Q.oneOf([...members.keys()]))).unsafeFetchRaw() : [];
|
|
33429
33484
|
const byName = /* @__PURE__ */ new Map();
|
|
33430
33485
|
for (const entity of entities) {
|
|
33431
|
-
const
|
|
33432
|
-
const
|
|
33433
|
-
byName.
|
|
33434
|
-
|
|
33486
|
+
const name = String(entity.canonical_name);
|
|
33487
|
+
const count = members.get(String(entity.id))?.size ?? 0;
|
|
33488
|
+
const existing = byName.get(name);
|
|
33489
|
+
byName.set(name, {
|
|
33490
|
+
name,
|
|
33435
33491
|
kind: existing?.kind ?? entity.kind ?? null,
|
|
33436
33492
|
memoryCount: (existing?.memoryCount ?? 0) + count
|
|
33437
33493
|
});
|
|
@@ -33522,14 +33578,8 @@ function createLocalMemoryStore(options) {
|
|
|
33522
33578
|
}
|
|
33523
33579
|
return () => subscriptions.forEach((s) => s.unsubscribe());
|
|
33524
33580
|
},
|
|
33525
|
-
maintenance
|
|
33526
|
-
|
|
33527
|
-
getTopicBacklog: (backlogOptions) => getMemoriesNeedingTopicExtractionOp(vaultCtx, backlogOptions),
|
|
33528
|
-
extractTopics: (memoryIds, extractOptions) => extractAndLinkEntitiesForMemoriesOp(vaultCtx, memoryIds, extractOptions),
|
|
33529
|
-
stampTopicsExtracted: (memoryIds, extractedAt, version) => stampTopicsExtractedAtOp(vaultCtx, memoryIds, extractedAt, version),
|
|
33530
|
-
relinkTopics: (memoryIds) => relinkMemoryTopicsOp(vaultCtx, memoryIds),
|
|
33531
|
-
backfillTopics: (memoryIds) => backfillMemoryTopicsOp(vaultCtx, memoryIds)
|
|
33532
|
-
}
|
|
33581
|
+
maintenance,
|
|
33582
|
+
topicMaintenance: maintenance
|
|
33533
33583
|
};
|
|
33534
33584
|
}
|
|
33535
33585
|
|