@anuma/sdk 3.1.2 → 3.2.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 +36 -0
- package/dist/client/index.d.mts +130 -1
- package/dist/client/index.d.ts +130 -1
- package/dist/client/index.mjs +33 -0
- package/dist/expo/{chunk-JVL5PLZS.mjs → chunk-KXIUA7ZV.mjs} +6 -1
- package/dist/expo/index.cjs +353 -2
- package/dist/expo/index.d.mts +143 -2
- package/dist/expo/index.d.ts +143 -2
- package/dist/expo/index.mjs +341 -3
- package/dist/expo/{recall-WPKWZM5N.mjs → recall-3YPU4PS2.mjs} +1 -1
- package/dist/react/{chunk-3KGACSSP.mjs → chunk-Y7PMXJT6.mjs} +6 -1
- package/dist/react/index.cjs +353 -2
- package/dist/react/index.d.mts +143 -2
- package/dist/react/index.d.ts +143 -2
- package/dist/react/index.mjs +341 -3
- package/dist/react/{recall-NG2P5ZQ7.mjs → recall-GYNSL2DS.mjs} +1 -1
- package/dist/server/{chunk-A4V7FRZ6.mjs → chunk-Y3ZS4OI3.mjs} +6 -1
- package/dist/server/index.cjs +353 -2
- package/dist/server/index.d.mts +143 -2
- package/dist/server/index.d.ts +143 -2
- package/dist/server/index.mjs +341 -3
- package/dist/server/{recall-2K7IOKY3.mjs → recall-Z72DM2JK.mjs} +1 -1
- package/package.json +2 -2
package/dist/server/index.cjs
CHANGED
|
@@ -17046,6 +17046,7 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
17046
17046
|
topicsExtractedVersion: memory.topicsExtractedVersion ?? null,
|
|
17047
17047
|
supersededBy: memory.supersededBy ?? null,
|
|
17048
17048
|
supersededAt: memory.supersededAt ?? null,
|
|
17049
|
+
lastObservedAt: memory.lastObservedAt ?? null,
|
|
17049
17050
|
createdAt: memory.createdAt,
|
|
17050
17051
|
updatedAt: memory.updatedAt,
|
|
17051
17052
|
isDeleted: memory.isDeleted
|
|
@@ -17286,6 +17287,7 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
17286
17287
|
topicsExtractedVersion: raw.topics_extracted_version ?? null,
|
|
17287
17288
|
supersededBy: raw.superseded_by ?? null,
|
|
17288
17289
|
supersededAt: raw.superseded_at ?? null,
|
|
17290
|
+
lastObservedAt: raw.last_observed_at ?? null,
|
|
17289
17291
|
createdAt: new Date(raw.created_at),
|
|
17290
17292
|
updatedAt: new Date(raw.updated_at),
|
|
17291
17293
|
isDeleted: raw.is_deleted === true || raw.is_deleted === 1
|
|
@@ -17374,6 +17376,9 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
17374
17376
|
if (opts.topicsUserManaged !== void 0) {
|
|
17375
17377
|
r._setRaw("topics_user_managed", opts.topicsUserManaged);
|
|
17376
17378
|
}
|
|
17379
|
+
if (opts.lastObservedAt !== void 0) {
|
|
17380
|
+
r._setRaw("last_observed_at", opts.lastObservedAt);
|
|
17381
|
+
}
|
|
17377
17382
|
if (opts.preserveUpdatedAt) {
|
|
17378
17383
|
r._setRaw("updated_at", originalUpdatedAt);
|
|
17379
17384
|
}
|
|
@@ -21113,6 +21118,7 @@ __export(index_exports, {
|
|
|
21113
21118
|
DEFAULT_MIN_CHUNK_SIZE: () => DEFAULT_MIN_CHUNK_SIZE,
|
|
21114
21119
|
DEFAULT_MIN_MESSAGES: () => DEFAULT_MIN_MESSAGES,
|
|
21115
21120
|
DEFAULT_PERSONALITY_SETTINGS: () => DEFAULT_PERSONALITY_SETTINGS,
|
|
21121
|
+
DEFAULT_PROFILE_FACETS: () => DEFAULT_PROFILE_FACETS,
|
|
21116
21122
|
DEFAULT_PROMPT_TEMPLATES: () => DEFAULT_PROMPT_TEMPLATES,
|
|
21117
21123
|
DEFAULT_REFRESH_EVERY_MESSAGES: () => DEFAULT_REFRESH_EVERY_MESSAGES,
|
|
21118
21124
|
DEFAULT_SERVER_TOOLS_MATCH_OPTIONS: () => DEFAULT_SERVER_TOOLS_MATCH_OPTIONS,
|
|
@@ -21127,6 +21133,7 @@ __export(index_exports, {
|
|
|
21127
21133
|
Media: () => Media,
|
|
21128
21134
|
Message: () => Message,
|
|
21129
21135
|
ModelPreference: () => ModelPreference,
|
|
21136
|
+
PROFILE_DOC_VERSION: () => PROFILE_DOC_VERSION,
|
|
21130
21137
|
PdfProcessor: () => PdfProcessor,
|
|
21131
21138
|
PostgreSQLAdapter: () => PostgreSQLAdapter,
|
|
21132
21139
|
ProcessorRegistry: () => ProcessorRegistry,
|
|
@@ -21333,6 +21340,7 @@ __export(index_exports, {
|
|
|
21333
21340
|
streamReplayPath: () => streamReplayPath,
|
|
21334
21341
|
summaryToSystemMessage: () => summaryToSystemMessage,
|
|
21335
21342
|
supersedeVaultMemoryOp: () => supersedeVaultMemoryOp,
|
|
21343
|
+
synthesizeProfile: () => synthesizeProfile,
|
|
21336
21344
|
toolSetSystemPrompts: () => toolSetSystemPrompts,
|
|
21337
21345
|
updateConversationProjectOp: () => updateConversationProjectOp,
|
|
21338
21346
|
updateConversationTitleOp: () => updateConversationTitleOp,
|
|
@@ -21696,6 +21704,9 @@ __decorateClass([
|
|
|
21696
21704
|
__decorateClass([
|
|
21697
21705
|
(0, import_decorators6.field)("topics_extracted_version")
|
|
21698
21706
|
], VaultMemory.prototype, "topicsExtractedVersion", 2);
|
|
21707
|
+
__decorateClass([
|
|
21708
|
+
(0, import_decorators6.field)("last_observed_at")
|
|
21709
|
+
], VaultMemory.prototype, "lastObservedAt", 2);
|
|
21699
21710
|
__decorateClass([
|
|
21700
21711
|
import_decorators6.readonly,
|
|
21701
21712
|
(0, import_decorators6.date)("created_at")
|
|
@@ -21843,7 +21854,7 @@ __decorateClass([
|
|
|
21843
21854
|
], VaultFolder.prototype, "context", 2);
|
|
21844
21855
|
|
|
21845
21856
|
// src/lib/db/schema.ts
|
|
21846
|
-
var SDK_SCHEMA_VERSION =
|
|
21857
|
+
var SDK_SCHEMA_VERSION = 39;
|
|
21847
21858
|
var sdkSchema = (0, import_watermelondb12.appSchema)({
|
|
21848
21859
|
version: SDK_SCHEMA_VERSION,
|
|
21849
21860
|
tables: [
|
|
@@ -21981,7 +21992,14 @@ var sdkSchema = (0, import_watermelondb12.appSchema)({
|
|
|
21981
21992
|
// The extraction-logic version this memory was last stamped under. Null
|
|
21982
21993
|
// (pre-v38) is treated as version 0, so a bump of TOPICS_EXTRACTION_VERSION
|
|
21983
21994
|
// re-extracts stale rows. See getMemoriesNeedingTopicExtractionOp.
|
|
21984
|
-
{ name: "topics_extracted_version", type: "number", isOptional: true }
|
|
21995
|
+
{ name: "topics_extracted_version", type: "number", isOptional: true },
|
|
21996
|
+
// Re-observation watermark (C3). Unix ms of the last time retain() merged
|
|
21997
|
+
// a duplicate observation into this fact (proof_count++). Distinct from
|
|
21998
|
+
// updated_at, which merges deliberately preserve (preserveUpdatedAt) so a
|
|
21999
|
+
// re-observation doesn't reorder the vault by edit time. Null = never
|
|
22000
|
+
// re-observed since the column was added. Indexed so recency-weighted
|
|
22001
|
+
// synthesis can filter/sort on it cheaply.
|
|
22002
|
+
{ name: "last_observed_at", type: "number", isOptional: true, isIndexed: true }
|
|
21985
22003
|
]
|
|
21986
22004
|
}),
|
|
21987
22005
|
// Entity table — canonical names extracted from auto-extraction (W5).
|
|
@@ -22620,6 +22638,20 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
|
|
|
22620
22638
|
columns: [{ name: "topics_extracted_version", type: "number", isOptional: true }]
|
|
22621
22639
|
})
|
|
22622
22640
|
]
|
|
22641
|
+
},
|
|
22642
|
+
// v38 -> v39: re-observation watermark on memory_vault (C3). Existing rows
|
|
22643
|
+
// keep NULL (= never re-observed since the column was added); synthesis
|
|
22644
|
+
// treats NULL as "fall back to updated_at" so no backfill is needed.
|
|
22645
|
+
{
|
|
22646
|
+
toVersion: 39,
|
|
22647
|
+
steps: [
|
|
22648
|
+
(0, import_migrations.addColumns)({
|
|
22649
|
+
table: "memory_vault",
|
|
22650
|
+
columns: [
|
|
22651
|
+
{ name: "last_observed_at", type: "number", isOptional: true, isIndexed: true }
|
|
22652
|
+
]
|
|
22653
|
+
})
|
|
22654
|
+
]
|
|
22623
22655
|
}
|
|
22624
22656
|
]
|
|
22625
22657
|
});
|
|
@@ -25395,6 +25427,8 @@ async function retain(content, ctx, options = {}) {
|
|
|
25395
25427
|
proofCountIncrement: 1,
|
|
25396
25428
|
sourceChunkIds: mergedSourceIds,
|
|
25397
25429
|
preserveUpdatedAt: true,
|
|
25430
|
+
// C3: record the re-observation without touching updated_at.
|
|
25431
|
+
lastObservedAt: Date.now(),
|
|
25398
25432
|
...eventTimeUpdate && { eventTime: eventTimeUpdate }
|
|
25399
25433
|
});
|
|
25400
25434
|
if (updated) {
|
|
@@ -25545,6 +25579,8 @@ async function tryConsolidate(trimmed, ctx, options) {
|
|
|
25545
25579
|
proofCountIncrement: 1,
|
|
25546
25580
|
sourceChunkIds: mergedSourceIds,
|
|
25547
25581
|
preserveUpdatedAt: true,
|
|
25582
|
+
// C3: record the re-observation without touching updated_at.
|
|
25583
|
+
lastObservedAt: Date.now(),
|
|
25548
25584
|
...eventTimeUpdate && { eventTime: eventTimeUpdate }
|
|
25549
25585
|
});
|
|
25550
25586
|
if (!updated) {
|
|
@@ -25581,6 +25617,8 @@ async function tryConsolidate(trimmed, ctx, options) {
|
|
|
25581
25617
|
// one. Preserving updated_at keeps the recency multiplier honest
|
|
25582
25618
|
// and matches the merge/noop paths above.
|
|
25583
25619
|
preserveUpdatedAt: true,
|
|
25620
|
+
// C3: record the re-observation without touching updated_at.
|
|
25621
|
+
lastObservedAt: Date.now(),
|
|
25584
25622
|
...eventTimeUpdate && { eventTime: eventTimeUpdate }
|
|
25585
25623
|
});
|
|
25586
25624
|
if (!updated) {
|
|
@@ -26400,6 +26438,316 @@ function parseAnswer(body, base, parseSchema) {
|
|
|
26400
26438
|
// src/lib/memory/index.ts
|
|
26401
26439
|
init_reranker();
|
|
26402
26440
|
|
|
26441
|
+
// src/lib/memory/synthesizeProfile.ts
|
|
26442
|
+
init_operations3();
|
|
26443
|
+
init_logger();
|
|
26444
|
+
init_constants();
|
|
26445
|
+
init_embeddings();
|
|
26446
|
+
init_vector();
|
|
26447
|
+
var DEFAULT_SYNTHESIS_MODEL = "inclusionai/ling-2.6-flash";
|
|
26448
|
+
var DEFAULT_FACET_RECALL_LIMIT = 20;
|
|
26449
|
+
var DEFAULT_FACET_MAX_TOKENS = 512;
|
|
26450
|
+
var DEFAULT_SCOPES = ["private"];
|
|
26451
|
+
var NEW_FACT_ATTRIBUTION_MIN_SCORE = 0.1;
|
|
26452
|
+
var PROFILE_DOC_VERSION = 1;
|
|
26453
|
+
var DEFAULT_PROFILE_FACETS = [
|
|
26454
|
+
{
|
|
26455
|
+
key: "bio",
|
|
26456
|
+
label: "Bio",
|
|
26457
|
+
query: "Who is this person? Their background, personality, values, and what defines them.",
|
|
26458
|
+
guidance: "Write a 1-2 sentence bio (max ~40 words) that captures what makes this person distinctive \u2014 their character, values, or a defining thread across the memories. Be specific and grounded; ban generic dating clich\xE9s ('loves to laugh', 'foodie', 'work hard play hard', 'living life to the fullest')."
|
|
26459
|
+
},
|
|
26460
|
+
{
|
|
26461
|
+
key: "interests",
|
|
26462
|
+
label: "Interests",
|
|
26463
|
+
query: "What are this person's hobbies, passions, pastimes, and interests?",
|
|
26464
|
+
guidance: "Return 3-6 specific interests as a comma-separated list (e.g. 'trail running, film photography, Thai cooking'). Prefer concrete activities the memories actually show over broad categories ('music', 'travel'). No sentence, just the list."
|
|
26465
|
+
},
|
|
26466
|
+
{
|
|
26467
|
+
key: "work_role",
|
|
26468
|
+
label: "Work & Role",
|
|
26469
|
+
query: "What does this person do for work \u2014 their profession, role, industry, or studies?",
|
|
26470
|
+
guidance: "State the person's current role/profession and field in one short line (e.g. 'Backend engineer at a fintech startup'). Use only what the memories support; if unclear or absent, return hasEvidence=false rather than guessing a title."
|
|
26471
|
+
},
|
|
26472
|
+
{
|
|
26473
|
+
key: "location_context",
|
|
26474
|
+
label: "Location",
|
|
26475
|
+
query: "Where does this person live, spend time, or come from?",
|
|
26476
|
+
guidance: "Summarize where the person is based or spends time at neighborhood-or-city granularity in one short line (e.g. 'Based in the Mission, SF'). PRIVACY: never emit a precise address, building, or workplace location \u2014 coarse-grain to the city/neighborhood."
|
|
26477
|
+
},
|
|
26478
|
+
{
|
|
26479
|
+
key: "communication_style",
|
|
26480
|
+
label: "Communication Style",
|
|
26481
|
+
query: "How does this person communicate, express themselves, and interact with others?",
|
|
26482
|
+
guidance: "Describe the person's communication and social style in one line using 2-4 concrete adjectives grounded in the memories (e.g. 'Direct, dry-humored, and a careful listener'). Avoid empty praise."
|
|
26483
|
+
},
|
|
26484
|
+
{
|
|
26485
|
+
key: "recent_activity",
|
|
26486
|
+
label: "Recently",
|
|
26487
|
+
query: "What has this person been doing, focused on, or working on recently?",
|
|
26488
|
+
guidance: "Summarize what the person has been up to lately in one line, favoring the most recently reinforced facts. Frame it as current/ongoing (e.g. 'Lately: training for a first half-marathon and learning Portuguese'). Omit if nothing recent stands out."
|
|
26489
|
+
}
|
|
26490
|
+
];
|
|
26491
|
+
var FACET_RESPONSE_SCHEMA = {
|
|
26492
|
+
type: "object",
|
|
26493
|
+
properties: {
|
|
26494
|
+
summary: {
|
|
26495
|
+
type: "string",
|
|
26496
|
+
description: "The synthesized section prose. Empty string if the memories don't cover it."
|
|
26497
|
+
},
|
|
26498
|
+
hasEvidence: {
|
|
26499
|
+
type: "boolean",
|
|
26500
|
+
description: "False when the supplied memories don't support any claim for this facet."
|
|
26501
|
+
}
|
|
26502
|
+
},
|
|
26503
|
+
required: ["summary", "hasEvidence"],
|
|
26504
|
+
additionalProperties: false
|
|
26505
|
+
};
|
|
26506
|
+
async function synthesizeProfile(ctx, options = {}) {
|
|
26507
|
+
if (!ctx.vaultCtx) {
|
|
26508
|
+
throw new Error("synthesizeProfile requires ctx.vaultCtx (vault-backed facts).");
|
|
26509
|
+
}
|
|
26510
|
+
if (!ctx.vaultCache) {
|
|
26511
|
+
throw new Error("synthesizeProfile requires ctx.vaultCache (semantic fact recall).");
|
|
26512
|
+
}
|
|
26513
|
+
const facets = options.facets ?? DEFAULT_PROFILE_FACETS;
|
|
26514
|
+
const scopes = options.scopes ?? DEFAULT_SCOPES;
|
|
26515
|
+
const config = {
|
|
26516
|
+
facetKeys: facets.map((f) => f.key).sort(),
|
|
26517
|
+
facetsSignature: facetsSignature(facets),
|
|
26518
|
+
scopes: [...scopes].sort(),
|
|
26519
|
+
redacted: options.redactor !== void 0
|
|
26520
|
+
};
|
|
26521
|
+
const previous = options.previous && options.previous.version === PROFILE_DOC_VERSION && configMatches(options.previous.config, config) ? options.previous : void 0;
|
|
26522
|
+
const memories = await getAllVaultMemoriesOp(ctx.vaultCtx, {
|
|
26523
|
+
// Scope the snapshot to the same scopes synthesis recalls from, so the
|
|
26524
|
+
// watermark, delta, and new-fact attribution all track only facts that can
|
|
26525
|
+
// actually appear in the profile — an out-of-scope change/new-fact must not
|
|
26526
|
+
// trigger a regeneration that scoped recall would never reflect.
|
|
26527
|
+
scopes,
|
|
26528
|
+
includeDeleted: true,
|
|
26529
|
+
includeSuperseded: true
|
|
26530
|
+
});
|
|
26531
|
+
const watermark = computeVaultWatermark(memories);
|
|
26532
|
+
const presentIds = new Set(memories.map((m) => m.uniqueId));
|
|
26533
|
+
const hasStaleSections = previous?.sections.some((s) => s.stale);
|
|
26534
|
+
const citesMissingFact = previous?.sections.some(
|
|
26535
|
+
(s) => s.sourceMemoryIds.some((id) => !presentIds.has(id))
|
|
26536
|
+
);
|
|
26537
|
+
if (previous && previous.vaultWatermark === watermark && !hasStaleSections && !citesMissingFact) {
|
|
26538
|
+
const sameOrder = previous.sections.length === facets.length && facets.every((f, i) => previous.sections[i]?.key === f.key);
|
|
26539
|
+
if (sameOrder) return previous;
|
|
26540
|
+
return {
|
|
26541
|
+
...previous,
|
|
26542
|
+
sections: facets.map((f) => previous.sections.find((s) => s.key === f.key))
|
|
26543
|
+
};
|
|
26544
|
+
}
|
|
26545
|
+
const staleKeys = await computeStaleFacetKeys(ctx, memories, facets, previous, watermark);
|
|
26546
|
+
const settled = await Promise.allSettled(
|
|
26547
|
+
facets.map(async (facet) => {
|
|
26548
|
+
const prior = previous?.sections.find((s) => s.key === facet.key);
|
|
26549
|
+
if (prior && !staleKeys.has(facet.key)) {
|
|
26550
|
+
return prior;
|
|
26551
|
+
}
|
|
26552
|
+
return synthesizeFacet(facet, ctx, options, prior);
|
|
26553
|
+
})
|
|
26554
|
+
);
|
|
26555
|
+
const sections = settled.map((r, i) => {
|
|
26556
|
+
if (r.status === "fulfilled") return r.value;
|
|
26557
|
+
const facet = facets[i];
|
|
26558
|
+
getLogger().warn(
|
|
26559
|
+
"[memory/synthesizeProfile] facet synthesis rejected; using fallback section",
|
|
26560
|
+
{
|
|
26561
|
+
facet: facet.key,
|
|
26562
|
+
error: r.reason instanceof Error ? r.reason.message : String(r.reason)
|
|
26563
|
+
}
|
|
26564
|
+
);
|
|
26565
|
+
return fallbackSection(
|
|
26566
|
+
facet,
|
|
26567
|
+
previous?.sections.find((s) => s.key === facet.key)
|
|
26568
|
+
);
|
|
26569
|
+
});
|
|
26570
|
+
return {
|
|
26571
|
+
version: PROFILE_DOC_VERSION,
|
|
26572
|
+
sections,
|
|
26573
|
+
vaultWatermark: watermark,
|
|
26574
|
+
config,
|
|
26575
|
+
generatedAt: Date.now()
|
|
26576
|
+
};
|
|
26577
|
+
}
|
|
26578
|
+
function configMatches(a, b) {
|
|
26579
|
+
if (!a) return false;
|
|
26580
|
+
return a.redacted === b.redacted && a.facetsSignature === b.facetsSignature && a.scopes.length === b.scopes.length && a.scopes.every((s, i) => s === b.scopes[i]);
|
|
26581
|
+
}
|
|
26582
|
+
function facetsSignature(facets) {
|
|
26583
|
+
return facets.map((f) => JSON.stringify([f.key, f.label, f.query, f.guidance])).sort().join("\n");
|
|
26584
|
+
}
|
|
26585
|
+
function changeTime(m) {
|
|
26586
|
+
return Math.max(m.updatedAt.getTime(), m.supersededAt ?? 0, m.lastObservedAt ?? 0);
|
|
26587
|
+
}
|
|
26588
|
+
function computeVaultWatermark(memories) {
|
|
26589
|
+
let max = 0;
|
|
26590
|
+
for (const m of memories) {
|
|
26591
|
+
const t = changeTime(m);
|
|
26592
|
+
if (t > max) max = t;
|
|
26593
|
+
}
|
|
26594
|
+
return max;
|
|
26595
|
+
}
|
|
26596
|
+
async function computeStaleFacetKeys(ctx, memories, facets, previous, watermark) {
|
|
26597
|
+
const allKeys = new Set(facets.map((f) => f.key));
|
|
26598
|
+
if (previous && watermark < previous.vaultWatermark) return allKeys;
|
|
26599
|
+
if (!previous) return allKeys;
|
|
26600
|
+
const changed = memories.filter((m) => changeTime(m) > previous.vaultWatermark);
|
|
26601
|
+
const changedIds = new Set(changed.map((m) => m.uniqueId));
|
|
26602
|
+
const presentIds = new Set(memories.map((m) => m.uniqueId));
|
|
26603
|
+
const stale = /* @__PURE__ */ new Set();
|
|
26604
|
+
for (const section of previous.sections) {
|
|
26605
|
+
if (section.sourceMemoryIds.some((id) => changedIds.has(id))) {
|
|
26606
|
+
stale.add(section.key);
|
|
26607
|
+
}
|
|
26608
|
+
if (section.sourceMemoryIds.some((id) => !presentIds.has(id))) {
|
|
26609
|
+
stale.add(section.key);
|
|
26610
|
+
}
|
|
26611
|
+
if (section.stale) {
|
|
26612
|
+
stale.add(section.key);
|
|
26613
|
+
}
|
|
26614
|
+
}
|
|
26615
|
+
for (const facet of facets) {
|
|
26616
|
+
if (!previous.sections.some((s) => s.key === facet.key)) stale.add(facet.key);
|
|
26617
|
+
}
|
|
26618
|
+
const citedIds = new Set(previous.sections.flatMap((s) => s.sourceMemoryIds));
|
|
26619
|
+
const toAttribute = changed.filter(
|
|
26620
|
+
(m) => !m.isDeleted && !m.supersededBy && !citedIds.has(m.uniqueId)
|
|
26621
|
+
);
|
|
26622
|
+
if (toAttribute.length > 0) {
|
|
26623
|
+
const attributed = await attributeFacts(ctx, toAttribute, facets);
|
|
26624
|
+
if (attributed === null) return allKeys;
|
|
26625
|
+
for (const k of attributed) stale.add(k);
|
|
26626
|
+
}
|
|
26627
|
+
return stale;
|
|
26628
|
+
}
|
|
26629
|
+
async function attributeFacts(ctx, candidates, facets) {
|
|
26630
|
+
const model = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
26631
|
+
const factVectors = [];
|
|
26632
|
+
for (const f of candidates) {
|
|
26633
|
+
if (!f.embedding || f.embeddingModel && f.embeddingModel !== model) {
|
|
26634
|
+
getLogger().warn(
|
|
26635
|
+
"[memory/synthesizeProfile] fact lacks a usable current-model embedding; regenerating all facets",
|
|
26636
|
+
{ memoryId: f.uniqueId, hasEmbedding: !!f.embedding, embeddingModel: f.embeddingModel }
|
|
26637
|
+
);
|
|
26638
|
+
return null;
|
|
26639
|
+
}
|
|
26640
|
+
let vec;
|
|
26641
|
+
try {
|
|
26642
|
+
vec = JSON.parse(f.embedding);
|
|
26643
|
+
} catch {
|
|
26644
|
+
getLogger().warn(
|
|
26645
|
+
"[memory/synthesizeProfile] fact embedding failed to parse; regenerating all facets",
|
|
26646
|
+
{ memoryId: f.uniqueId }
|
|
26647
|
+
);
|
|
26648
|
+
return null;
|
|
26649
|
+
}
|
|
26650
|
+
if (!Array.isArray(vec) || vec.length === 0) return null;
|
|
26651
|
+
factVectors.push(vec);
|
|
26652
|
+
}
|
|
26653
|
+
let queryVectors;
|
|
26654
|
+
try {
|
|
26655
|
+
queryVectors = await generateEmbeddings(
|
|
26656
|
+
facets.map((f) => f.query),
|
|
26657
|
+
ctx.embeddingOptions
|
|
26658
|
+
);
|
|
26659
|
+
} catch (err) {
|
|
26660
|
+
getLogger().warn(
|
|
26661
|
+
"[memory/synthesizeProfile] facet-query embedding failed; regenerating all facets",
|
|
26662
|
+
{ error: err instanceof Error ? err.message : String(err) }
|
|
26663
|
+
);
|
|
26664
|
+
return null;
|
|
26665
|
+
}
|
|
26666
|
+
const keys = /* @__PURE__ */ new Set();
|
|
26667
|
+
for (const fv of factVectors) {
|
|
26668
|
+
let matchedAny = false;
|
|
26669
|
+
for (let i = 0; i < facets.length; i++) {
|
|
26670
|
+
if (cosineSimilarity(fv, queryVectors[i]) >= NEW_FACT_ATTRIBUTION_MIN_SCORE) {
|
|
26671
|
+
keys.add(facets[i].key);
|
|
26672
|
+
matchedAny = true;
|
|
26673
|
+
}
|
|
26674
|
+
}
|
|
26675
|
+
if (!matchedAny) return null;
|
|
26676
|
+
}
|
|
26677
|
+
return keys;
|
|
26678
|
+
}
|
|
26679
|
+
async function synthesizeFacet(facet, ctx, options, prior) {
|
|
26680
|
+
const result = await reflect(facet.query, ctx, {
|
|
26681
|
+
apiKey: options.apiKey,
|
|
26682
|
+
getToken: options.getToken,
|
|
26683
|
+
llmModel: options.llmModel ?? DEFAULT_SYNTHESIS_MODEL,
|
|
26684
|
+
baseUrl: options.baseUrl,
|
|
26685
|
+
fetchFn: options.fetchFn,
|
|
26686
|
+
scopes: options.scopes ?? DEFAULT_SCOPES,
|
|
26687
|
+
limit: options.limit ?? DEFAULT_FACET_RECALL_LIMIT,
|
|
26688
|
+
types: ["fact"],
|
|
26689
|
+
maxTokens: DEFAULT_FACET_MAX_TOKENS,
|
|
26690
|
+
systemPrompt: buildFacetSystemPrompt(facet),
|
|
26691
|
+
responseSchema: FACET_RESPONSE_SCHEMA
|
|
26692
|
+
});
|
|
26693
|
+
const noEvidence = result.basedOn.memoryIds.length === 0;
|
|
26694
|
+
const { text: text12, legitimateEmpty } = extractFacetText(result.structuredOutput);
|
|
26695
|
+
if (!text12 && !legitimateEmpty && !noEvidence) {
|
|
26696
|
+
getLogger().warn(
|
|
26697
|
+
"[memory/synthesizeProfile] facet synthesis returned degraded-empty; keeping prior section",
|
|
26698
|
+
{ facet: facet.key, recalledCount: result.basedOn.memoryIds.length }
|
|
26699
|
+
);
|
|
26700
|
+
return fallbackSection(facet, prior);
|
|
26701
|
+
}
|
|
26702
|
+
const section = {
|
|
26703
|
+
key: facet.key,
|
|
26704
|
+
label: facet.label,
|
|
26705
|
+
text: text12,
|
|
26706
|
+
sourceMemoryIds: result.basedOn.memoryIds,
|
|
26707
|
+
generatedAt: Date.now()
|
|
26708
|
+
};
|
|
26709
|
+
if (options.redactor && text12) {
|
|
26710
|
+
const redacted = await options.redactor.redactTextAsync(text12);
|
|
26711
|
+
section.text = redacted.text;
|
|
26712
|
+
}
|
|
26713
|
+
return section;
|
|
26714
|
+
}
|
|
26715
|
+
function fallbackSection(facet, prior) {
|
|
26716
|
+
if (prior && prior.text) {
|
|
26717
|
+
return { ...prior, stale: true };
|
|
26718
|
+
}
|
|
26719
|
+
return {
|
|
26720
|
+
key: facet.key,
|
|
26721
|
+
label: facet.label,
|
|
26722
|
+
text: "",
|
|
26723
|
+
sourceMemoryIds: [],
|
|
26724
|
+
generatedAt: Date.now(),
|
|
26725
|
+
stale: true
|
|
26726
|
+
};
|
|
26727
|
+
}
|
|
26728
|
+
function buildFacetSystemPrompt(facet) {
|
|
26729
|
+
return `You are writing the "${facet.label}" section of a person's shareable profile, using their private memories (supplied as evidence) as the only source of truth.
|
|
26730
|
+
|
|
26731
|
+
Task for this section:
|
|
26732
|
+
${facet.guidance}
|
|
26733
|
+
|
|
26734
|
+
Rules:
|
|
26735
|
+
- Ground every claim in the supplied memories \u2014 never invent, infer beyond, or embellish what they support.
|
|
26736
|
+
- If the memories don't cover this section, return an empty summary with hasEvidence=false. Do not pad or guess.
|
|
26737
|
+
- Write in third person about the person, in a natural voice suitable for a public profile (no "I"/"you", no name repetition).
|
|
26738
|
+
- Be concise and specific; no preamble, hedging, or meta-commentary.
|
|
26739
|
+
- Respond as JSON: { "summary": <the section text, or "">, "hasEvidence": <true|false> }.`;
|
|
26740
|
+
}
|
|
26741
|
+
function extractFacetText(structured) {
|
|
26742
|
+
if (structured && typeof structured === "object") {
|
|
26743
|
+
const obj = structured;
|
|
26744
|
+
if (obj.hasEvidence === false) return { text: "", legitimateEmpty: true };
|
|
26745
|
+
if (typeof obj.summary === "string")
|
|
26746
|
+
return { text: obj.summary.trim(), legitimateEmpty: false };
|
|
26747
|
+
}
|
|
26748
|
+
return { text: "", legitimateEmpty: false };
|
|
26749
|
+
}
|
|
26750
|
+
|
|
26403
26751
|
// src/lib/memory/topicExtract.ts
|
|
26404
26752
|
init_operations2();
|
|
26405
26753
|
init_operations3();
|
|
@@ -32315,6 +32663,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
32315
32663
|
DEFAULT_MIN_CHUNK_SIZE,
|
|
32316
32664
|
DEFAULT_MIN_MESSAGES,
|
|
32317
32665
|
DEFAULT_PERSONALITY_SETTINGS,
|
|
32666
|
+
DEFAULT_PROFILE_FACETS,
|
|
32318
32667
|
DEFAULT_PROMPT_TEMPLATES,
|
|
32319
32668
|
DEFAULT_REFRESH_EVERY_MESSAGES,
|
|
32320
32669
|
DEFAULT_SERVER_TOOLS_MATCH_OPTIONS,
|
|
@@ -32329,6 +32678,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
32329
32678
|
Media,
|
|
32330
32679
|
Message,
|
|
32331
32680
|
ModelPreference,
|
|
32681
|
+
PROFILE_DOC_VERSION,
|
|
32332
32682
|
PdfProcessor,
|
|
32333
32683
|
PostgreSQLAdapter,
|
|
32334
32684
|
ProcessorRegistry,
|
|
@@ -32535,6 +32885,7 @@ function buildSystemPrompt(ctx, options) {
|
|
|
32535
32885
|
streamReplayPath,
|
|
32536
32886
|
summaryToSystemMessage,
|
|
32537
32887
|
supersedeVaultMemoryOp,
|
|
32888
|
+
synthesizeProfile,
|
|
32538
32889
|
toolSetSystemPrompts,
|
|
32539
32890
|
updateConversationProjectOp,
|
|
32540
32891
|
updateConversationTitleOp,
|