@anuma/sdk 6.33.2 → 6.35.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 +1304 -300
- package/dist/expo/index.d.mts +278 -11
- package/dist/expo/index.d.ts +278 -11
- package/dist/expo/index.mjs +1297 -300
- package/dist/index.cjs +18 -6
- package/dist/index.mjs +18 -6
- package/dist/memory/context.d.mts +21 -1
- package/dist/memory/context.d.ts +21 -1
- package/dist/react/index.cjs +1385 -381
- package/dist/react/index.d.mts +311 -11
- package/dist/react/index.d.ts +311 -11
- package/dist/react/index.mjs +1378 -381
- package/dist/server/index.cjs +319 -99
- package/dist/server/index.d.mts +138 -11
- package/dist/server/index.d.ts +138 -11
- package/dist/server/index.mjs +316 -99
- package/dist/telemetry/index.d.mts +3 -4
- package/dist/telemetry/index.d.ts +3 -4
- package/dist/tools/selection/index.cjs +18 -6
- package/dist/tools/selection/index.mjs +18 -6
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -16302,7 +16302,10 @@ __export(index_exports, {
|
|
|
16302
16302
|
MAX_HOPS: () => MAX_HOPS,
|
|
16303
16303
|
MAX_MESSAGES_PER_SUMMARIZATION: () => MAX_MESSAGES_PER_SUMMARIZATION,
|
|
16304
16304
|
MEDIUM_TTL_MS: () => MEDIUM_TTL_MS,
|
|
16305
|
+
MEMORY_KINDS: () => MEMORY_KINDS,
|
|
16306
|
+
MEMORY_LEVELS: () => MEMORY_LEVELS,
|
|
16305
16307
|
Media: () => Media,
|
|
16308
|
+
MemoryLevelError: () => MemoryLevelError,
|
|
16306
16309
|
Message: () => Message,
|
|
16307
16310
|
ModelPreference: () => ModelPreference,
|
|
16308
16311
|
NEVER_TTL_MS: () => NEVER_TTL_MS,
|
|
@@ -19969,7 +19972,7 @@ async function embedOne(text12, options, outer) {
|
|
|
19969
19972
|
}
|
|
19970
19973
|
var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
19971
19974
|
var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
19972
|
-
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs) {
|
|
19975
|
+
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs, outer) {
|
|
19973
19976
|
const response = await withEmbeddingRetry(
|
|
19974
19977
|
() => withDeadline(
|
|
19975
19978
|
(signal) => postApiV1Embeddings({
|
|
@@ -19979,8 +19982,10 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
19979
19982
|
...signal && { signal }
|
|
19980
19983
|
}),
|
|
19981
19984
|
timeoutMs,
|
|
19982
|
-
"embedding batch request"
|
|
19983
|
-
|
|
19985
|
+
"embedding batch request",
|
|
19986
|
+
outer
|
|
19987
|
+
),
|
|
19988
|
+
outer
|
|
19984
19989
|
);
|
|
19985
19990
|
if (response.error) {
|
|
19986
19991
|
throw embeddingErrorFrom(response);
|
|
@@ -19998,6 +20003,11 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
19998
20003
|
}
|
|
19999
20004
|
async function generateEmbeddings(texts, options) {
|
|
20000
20005
|
if (texts.length === 0) return [];
|
|
20006
|
+
const total = options.totalTimeoutMs;
|
|
20007
|
+
if (total === void 0) return embedMany(texts, options, void 0);
|
|
20008
|
+
return withDeadline((signal) => embedMany(texts, options, signal), total, "embedding batch");
|
|
20009
|
+
}
|
|
20010
|
+
async function embedMany(texts, options, outer) {
|
|
20001
20011
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
20002
20012
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
20003
20013
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
@@ -20018,7 +20028,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
20018
20028
|
if (uncachedTexts.length === 0) {
|
|
20019
20029
|
return results;
|
|
20020
20030
|
}
|
|
20021
|
-
const headers = await resolveAuthHeaders(options);
|
|
20031
|
+
const headers = await resolveAuthHeaders(options, outer);
|
|
20032
|
+
if (outer?.aborted) throw outer.reason;
|
|
20022
20033
|
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
20023
20034
|
let newEmbeddings;
|
|
20024
20035
|
if (uncachedTexts.length <= chunkSize) {
|
|
@@ -20029,7 +20040,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
20029
20040
|
embeddingModel,
|
|
20030
20041
|
options.onUsage,
|
|
20031
20042
|
options.maskInput,
|
|
20032
|
-
timeoutMs
|
|
20043
|
+
timeoutMs,
|
|
20044
|
+
outer
|
|
20033
20045
|
);
|
|
20034
20046
|
} else {
|
|
20035
20047
|
const chunks = [];
|
|
@@ -20040,6 +20052,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
20040
20052
|
let nextIndex = 0;
|
|
20041
20053
|
const worker = async () => {
|
|
20042
20054
|
while (nextIndex < chunks.length) {
|
|
20055
|
+
if (outer?.aborted) throw outer.reason;
|
|
20043
20056
|
const idx = nextIndex++;
|
|
20044
20057
|
allEmbeddings[idx] = await generateEmbeddingsBatch(
|
|
20045
20058
|
chunks[idx],
|
|
@@ -20048,7 +20061,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
20048
20061
|
embeddingModel,
|
|
20049
20062
|
options.onUsage,
|
|
20050
20063
|
options.maskInput,
|
|
20051
|
-
timeoutMs
|
|
20064
|
+
timeoutMs,
|
|
20065
|
+
outer
|
|
20052
20066
|
);
|
|
20053
20067
|
}
|
|
20054
20068
|
};
|
|
@@ -20059,6 +20073,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
20059
20073
|
await Promise.all(workers);
|
|
20060
20074
|
newEmbeddings = allEmbeddings.flat();
|
|
20061
20075
|
}
|
|
20076
|
+
if (outer?.aborted) throw outer.reason;
|
|
20062
20077
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
20063
20078
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
20064
20079
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
@@ -25395,6 +25410,15 @@ __decorateClass([
|
|
|
25395
25410
|
__decorateClass([
|
|
25396
25411
|
(0, import_decorators6.text)("scope")
|
|
25397
25412
|
], VaultMemory.prototype, "scope", 2);
|
|
25413
|
+
__decorateClass([
|
|
25414
|
+
(0, import_decorators6.field)("kind")
|
|
25415
|
+
], VaultMemory.prototype, "kind", 2);
|
|
25416
|
+
__decorateClass([
|
|
25417
|
+
(0, import_decorators6.field)("kind_value")
|
|
25418
|
+
], VaultMemory.prototype, "kindValue", 2);
|
|
25419
|
+
__decorateClass([
|
|
25420
|
+
(0, import_decorators6.field)("level")
|
|
25421
|
+
], VaultMemory.prototype, "level", 2);
|
|
25398
25422
|
__decorateClass([
|
|
25399
25423
|
(0, import_decorators6.field)("folder_id")
|
|
25400
25424
|
], VaultMemory.prototype, "folderId", 2);
|
|
@@ -25620,7 +25644,7 @@ __decorateClass([
|
|
|
25620
25644
|
], VaultFolder.prototype, "context", 2);
|
|
25621
25645
|
|
|
25622
25646
|
// src/lib/db/schema.ts
|
|
25623
|
-
var SDK_SCHEMA_VERSION =
|
|
25647
|
+
var SDK_SCHEMA_VERSION = 48;
|
|
25624
25648
|
var sdkSchema = (0, import_watermelondb15.appSchema)({
|
|
25625
25649
|
version: SDK_SCHEMA_VERSION,
|
|
25626
25650
|
tables: [
|
|
@@ -25715,6 +25739,9 @@ var sdkSchema = (0, import_watermelondb15.appSchema)({
|
|
|
25715
25739
|
columns: [
|
|
25716
25740
|
{ name: "content", type: "string" },
|
|
25717
25741
|
{ name: "scope", type: "string", isIndexed: true },
|
|
25742
|
+
{ name: "kind", type: "string", isOptional: true, isIndexed: true },
|
|
25743
|
+
{ name: "kind_value", type: "string", isOptional: true },
|
|
25744
|
+
{ name: "level", type: "string", isOptional: true, isIndexed: true },
|
|
25718
25745
|
{ name: "folder_id", type: "string", isOptional: true, isIndexed: true },
|
|
25719
25746
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
25720
25747
|
{ name: "updated_at", type: "number", isIndexed: true },
|
|
@@ -26391,6 +26418,22 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
|
|
|
26391
26418
|
]
|
|
26392
26419
|
})
|
|
26393
26420
|
]
|
|
26421
|
+
},
|
|
26422
|
+
{
|
|
26423
|
+
toVersion: 48,
|
|
26424
|
+
steps: [
|
|
26425
|
+
(0, import_migrations.addColumns)({
|
|
26426
|
+
table: "memory_vault",
|
|
26427
|
+
columns: [
|
|
26428
|
+
{ name: "kind", type: "string", isOptional: true, isIndexed: true },
|
|
26429
|
+
{ name: "kind_value", type: "string", isOptional: true },
|
|
26430
|
+
{ name: "level", type: "string", isOptional: true, isIndexed: true }
|
|
26431
|
+
]
|
|
26432
|
+
}),
|
|
26433
|
+
(0, import_migrations.unsafeExecuteSql)(
|
|
26434
|
+
"UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
|
|
26435
|
+
)
|
|
26436
|
+
]
|
|
26394
26437
|
}
|
|
26395
26438
|
]
|
|
26396
26439
|
});
|
|
@@ -27546,13 +27589,54 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
|
|
|
27546
27589
|
}
|
|
27547
27590
|
}
|
|
27548
27591
|
const decryptedContent = await decryptField(memory.content, address);
|
|
27592
|
+
const decryptedKindValue = typeof memory.kindValue === "string" ? await decryptField(memory.kindValue, address) : memory.kindValue;
|
|
27549
27593
|
return {
|
|
27550
27594
|
...memory,
|
|
27551
|
-
content: decryptedContent
|
|
27595
|
+
content: decryptedContent,
|
|
27596
|
+
...decryptedKindValue !== void 0 && { kindValue: decryptedKindValue }
|
|
27552
27597
|
};
|
|
27553
27598
|
}
|
|
27554
27599
|
|
|
27555
27600
|
// src/lib/db/memoryVault/types.ts
|
|
27601
|
+
var MEMORY_KINDS = [
|
|
27602
|
+
"display_name",
|
|
27603
|
+
"birth_date",
|
|
27604
|
+
"bio",
|
|
27605
|
+
"occupation",
|
|
27606
|
+
"interest",
|
|
27607
|
+
"gender",
|
|
27608
|
+
"height_cm",
|
|
27609
|
+
"looking_for",
|
|
27610
|
+
"politics",
|
|
27611
|
+
"religion",
|
|
27612
|
+
"ethnicity",
|
|
27613
|
+
"smoking",
|
|
27614
|
+
"drinking",
|
|
27615
|
+
"exercise",
|
|
27616
|
+
"sexuality",
|
|
27617
|
+
"prompt"
|
|
27618
|
+
];
|
|
27619
|
+
var MEMORY_LEVELS = ["private", "matching", "profile"];
|
|
27620
|
+
var MemoryLevelError = class extends Error {
|
|
27621
|
+
constructor(message) {
|
|
27622
|
+
super(message);
|
|
27623
|
+
this.name = "MemoryLevelError";
|
|
27624
|
+
}
|
|
27625
|
+
};
|
|
27626
|
+
var PUBLISHED_SCOPES = /* @__PURE__ */ new Set(["shared", "public"]);
|
|
27627
|
+
function levelFromScope(scope) {
|
|
27628
|
+
return typeof scope === "string" && PUBLISHED_SCOPES.has(scope) ? "matching" : "private";
|
|
27629
|
+
}
|
|
27630
|
+
function scopeForLevel(level) {
|
|
27631
|
+
return level === "private" ? "private" : "shared";
|
|
27632
|
+
}
|
|
27633
|
+
function resolveMemoryLevel(level, scope) {
|
|
27634
|
+
return typeof level === "string" && MEMORY_LEVELS.includes(level) ? level : levelFromScope(scope);
|
|
27635
|
+
}
|
|
27636
|
+
function levelForScopeChange(current, nextScope) {
|
|
27637
|
+
const implied = levelFromScope(nextScope);
|
|
27638
|
+
return implied === "matching" && resolveMemoryLevel(current.level, current.scope) === "profile" ? "profile" : implied;
|
|
27639
|
+
}
|
|
27556
27640
|
function parseMedia(value) {
|
|
27557
27641
|
if (typeof value !== "string" || value === "") return null;
|
|
27558
27642
|
try {
|
|
@@ -27582,6 +27666,56 @@ function visibilityConditions(requested) {
|
|
|
27582
27666
|
if (excluded.length === 0) return [];
|
|
27583
27667
|
return [import_watermelondb19.Q.or(import_watermelondb19.Q.where("visibility", null), import_watermelondb19.Q.where("visibility", import_watermelondb19.Q.notIn(excluded)))];
|
|
27584
27668
|
}
|
|
27669
|
+
function isKinded(record) {
|
|
27670
|
+
return record.kind !== null && record.kind !== void 0;
|
|
27671
|
+
}
|
|
27672
|
+
function assertValidKindLevel(kind, level) {
|
|
27673
|
+
const hasKind = kind !== null && kind !== void 0;
|
|
27674
|
+
if (hasKind && !MEMORY_KINDS.includes(kind)) {
|
|
27675
|
+
throw new MemoryLevelError(`Unknown memory kind: ${kind}`);
|
|
27676
|
+
}
|
|
27677
|
+
if (level !== void 0 && !MEMORY_LEVELS.includes(level)) {
|
|
27678
|
+
throw new MemoryLevelError(`Unknown memory level: ${level}`);
|
|
27679
|
+
}
|
|
27680
|
+
if (level === "profile" && !hasKind) {
|
|
27681
|
+
throw new MemoryLevelError("Only a memory with a kind can be at level 'profile'");
|
|
27682
|
+
}
|
|
27683
|
+
}
|
|
27684
|
+
function resolveCreateLevel(opts) {
|
|
27685
|
+
if (opts.level !== void 0) return { level: opts.level, scope: scopeForLevel(opts.level) };
|
|
27686
|
+
if (opts.scope !== void 0) return { level: levelFromScope(opts.scope), scope: opts.scope };
|
|
27687
|
+
return { level: "private", scope: "private" };
|
|
27688
|
+
}
|
|
27689
|
+
async function encryptKindValue(ctx, value) {
|
|
27690
|
+
if (typeof value !== "string" || !ctx.walletAddress || !ctx.signMessage) return value;
|
|
27691
|
+
return encryptVaultMemoryContent(
|
|
27692
|
+
value,
|
|
27693
|
+
ctx.walletAddress,
|
|
27694
|
+
ctx.signMessage,
|
|
27695
|
+
ctx.embeddedWalletSigner
|
|
27696
|
+
);
|
|
27697
|
+
}
|
|
27698
|
+
function levelConditions(requested) {
|
|
27699
|
+
if (!requested?.length) return [];
|
|
27700
|
+
const published = ["shared", "public"];
|
|
27701
|
+
const wantsMatching = requested.includes("matching");
|
|
27702
|
+
const wantsPrivate = requested.includes("private");
|
|
27703
|
+
const unresolved = import_watermelondb19.Q.or(import_watermelondb19.Q.where("level", null), import_watermelondb19.Q.where("level", import_watermelondb19.Q.notIn([...MEMORY_LEVELS])));
|
|
27704
|
+
const byLevel = import_watermelondb19.Q.where("level", import_watermelondb19.Q.oneOf([...requested]));
|
|
27705
|
+
if (wantsMatching && wantsPrivate) return [import_watermelondb19.Q.or(byLevel, unresolved)];
|
|
27706
|
+
if (wantsMatching) {
|
|
27707
|
+
return [import_watermelondb19.Q.or(byLevel, import_watermelondb19.Q.and(unresolved, import_watermelondb19.Q.where("scope", import_watermelondb19.Q.oneOf(published))))];
|
|
27708
|
+
}
|
|
27709
|
+
if (wantsPrivate) {
|
|
27710
|
+
return [
|
|
27711
|
+
import_watermelondb19.Q.or(
|
|
27712
|
+
byLevel,
|
|
27713
|
+
import_watermelondb19.Q.and(unresolved, import_watermelondb19.Q.or(import_watermelondb19.Q.where("scope", null), import_watermelondb19.Q.where("scope", import_watermelondb19.Q.notIn(published))))
|
|
27714
|
+
)
|
|
27715
|
+
];
|
|
27716
|
+
}
|
|
27717
|
+
return [byLevel];
|
|
27718
|
+
}
|
|
27585
27719
|
function isOwnedByCtxUser(ctx, record) {
|
|
27586
27720
|
return ctx.userId === void 0 || record.userId === ctx.userId;
|
|
27587
27721
|
}
|
|
@@ -27625,6 +27759,9 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
27625
27759
|
uniqueId: memory.id,
|
|
27626
27760
|
content: memory.content,
|
|
27627
27761
|
scope: memory.scope,
|
|
27762
|
+
kind: memory.kind ?? null,
|
|
27763
|
+
kindValue: memory.kindValue ?? null,
|
|
27764
|
+
level: resolveMemoryLevel(memory.level, memory.scope),
|
|
27628
27765
|
folderId: memory.folderId ?? null,
|
|
27629
27766
|
userId: memory.userId ?? null,
|
|
27630
27767
|
embedding: memory.embedding ?? null,
|
|
@@ -27663,9 +27800,13 @@ async function vaultMemoryToStored(memory, walletAddress, signMessage, embeddedW
|
|
|
27663
27800
|
}
|
|
27664
27801
|
return raw;
|
|
27665
27802
|
}
|
|
27666
|
-
function populateNewVaultMemory(record, ctx, opts, encryptedContent) {
|
|
27803
|
+
function populateNewVaultMemory(record, ctx, opts, encryptedContent, encryptedKindValue) {
|
|
27804
|
+
const { level, scope } = resolveCreateLevel(opts);
|
|
27667
27805
|
record._setRaw("content", encryptedContent);
|
|
27668
|
-
record._setRaw("scope",
|
|
27806
|
+
record._setRaw("scope", scope);
|
|
27807
|
+
record._setRaw("level", level);
|
|
27808
|
+
record._setRaw("kind", opts.kind ?? null);
|
|
27809
|
+
record._setRaw("kind_value", encryptedKindValue ?? null);
|
|
27669
27810
|
record._setRaw("folder_id", opts.folderId ?? null);
|
|
27670
27811
|
record._setRaw("user_id", ctx.userId ?? null);
|
|
27671
27812
|
record._setRaw("is_deleted", false);
|
|
@@ -27699,6 +27840,8 @@ function populateNewVaultMemory(record, ctx, opts, encryptedContent) {
|
|
|
27699
27840
|
}
|
|
27700
27841
|
}
|
|
27701
27842
|
async function createVaultMemoryOp(ctx, opts) {
|
|
27843
|
+
assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
27844
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
27702
27845
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
27703
27846
|
opts.content,
|
|
27704
27847
|
ctx.walletAddress,
|
|
@@ -27709,13 +27852,15 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
27709
27852
|
if (ctx.canWrite && !await ctx.canWrite())
|
|
27710
27853
|
throw new Error("Memory source is no longer eligible");
|
|
27711
27854
|
return ctx.vaultMemoryCollection.create(
|
|
27712
|
-
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContent)
|
|
27855
|
+
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContent, encryptedKindValue)
|
|
27713
27856
|
);
|
|
27714
27857
|
});
|
|
27715
27858
|
return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
27716
27859
|
}
|
|
27717
27860
|
async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
27718
27861
|
if (!targetId) return { created: null, retired: false };
|
|
27862
|
+
assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
27863
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
27719
27864
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
27720
27865
|
opts.content,
|
|
27721
27866
|
ctx.walletAddress,
|
|
@@ -27732,9 +27877,10 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
27732
27877
|
} catch {
|
|
27733
27878
|
return;
|
|
27734
27879
|
}
|
|
27735
|
-
if (target.isDeleted || target.supersededBy || !isOwnedByCtxUser(ctx, target))
|
|
27880
|
+
if (target.isDeleted || target.supersededBy || isKinded(target) || !isOwnedByCtxUser(ctx, target))
|
|
27881
|
+
return;
|
|
27736
27882
|
createdRecord = await ctx.vaultMemoryCollection.create(
|
|
27737
|
-
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContent)
|
|
27883
|
+
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContent, encryptedKindValue)
|
|
27738
27884
|
);
|
|
27739
27885
|
await target.update((r) => {
|
|
27740
27886
|
r._setRaw("superseded_by", createdRecord.id);
|
|
@@ -27798,6 +27944,10 @@ async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
|
27798
27944
|
}
|
|
27799
27945
|
async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
27800
27946
|
if (optionsArray.length === 0) return [];
|
|
27947
|
+
for (const opts of optionsArray) assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
27948
|
+
const encryptedKindValues = await Promise.all(
|
|
27949
|
+
optionsArray.map((opts) => encryptKindValue(ctx, opts.kindValue))
|
|
27950
|
+
);
|
|
27801
27951
|
const encryptedContents = await Promise.all(
|
|
27802
27952
|
optionsArray.map(async (opts) => {
|
|
27803
27953
|
if (ctx.walletAddress && ctx.signMessage) {
|
|
@@ -27816,7 +27966,7 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
27816
27966
|
throw new Error("Memory source is no longer eligible");
|
|
27817
27967
|
const prepared = optionsArray.map(
|
|
27818
27968
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate(
|
|
27819
|
-
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContents[i])
|
|
27969
|
+
(record) => populateNewVaultMemory(record, ctx, opts, encryptedContents[i], encryptedKindValues[i])
|
|
27820
27970
|
)
|
|
27821
27971
|
);
|
|
27822
27972
|
await ctx.database.batch(...prepared);
|
|
@@ -27859,6 +28009,9 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
27859
28009
|
uniqueId: raw.id,
|
|
27860
28010
|
content: raw.content ?? "",
|
|
27861
28011
|
scope: raw.scope ?? "",
|
|
28012
|
+
kind: raw.kind ?? null,
|
|
28013
|
+
kindValue: raw.kind_value ?? null,
|
|
28014
|
+
level: resolveMemoryLevel(raw.level, raw.scope),
|
|
27862
28015
|
folderId: raw.folder_id ?? null,
|
|
27863
28016
|
userId: raw.user_id ?? null,
|
|
27864
28017
|
embedding: raw.embedding ?? null,
|
|
@@ -27902,6 +28055,8 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
27902
28055
|
...baseVaultConditions(ctx, options),
|
|
27903
28056
|
...options?.scopes?.length ? [import_watermelondb19.Q.where("scope", import_watermelondb19.Q.oneOf(options.scopes))] : [],
|
|
27904
28057
|
...visibilityConditions(options?.visibility),
|
|
28058
|
+
...levelConditions(options?.levels),
|
|
28059
|
+
...options?.kinds?.length ? [import_watermelondb19.Q.where("kind", import_watermelondb19.Q.oneOf(options.kinds))] : [],
|
|
27905
28060
|
...options?.folderId !== void 0 ? [import_watermelondb19.Q.where("folder_id", options.folderId)] : [],
|
|
27906
28061
|
...options?.factTypes?.length ? [import_watermelondb19.Q.where("fact_type", import_watermelondb19.Q.oneOf(options.factTypes))] : [],
|
|
27907
28062
|
import_watermelondb19.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb19.Q.desc),
|
|
@@ -28068,6 +28223,14 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
28068
28223
|
try {
|
|
28069
28224
|
const probe = await ctx.vaultMemoryCollection.find(id);
|
|
28070
28225
|
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
28226
|
+
if (opts.freeFormOnly && isKinded(probe)) return null;
|
|
28227
|
+
const levelAfter = (current) => {
|
|
28228
|
+
if (opts.level !== void 0) return opts.level;
|
|
28229
|
+
if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
|
|
28230
|
+
return levelForScopeChange(current, opts.scope);
|
|
28231
|
+
};
|
|
28232
|
+
assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
|
|
28233
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
28071
28234
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
28072
28235
|
opts.content,
|
|
28073
28236
|
ctx.walletAddress,
|
|
@@ -28080,10 +28243,13 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
28080
28243
|
await ctx.database.write(async () => {
|
|
28081
28244
|
if (ctx.canWrite && !await ctx.canWrite())
|
|
28082
28245
|
throw new Error("Memory source is no longer eligible");
|
|
28083
|
-
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
|
|
28246
|
+
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record) || opts.freeFormOnly && isKinded(record)) {
|
|
28084
28247
|
stale = true;
|
|
28085
28248
|
return;
|
|
28086
28249
|
}
|
|
28250
|
+
const nextKind = opts.kind !== void 0 ? opts.kind : record.kind;
|
|
28251
|
+
const nextLevel = levelAfter(record);
|
|
28252
|
+
assertValidKindLevel(nextKind, nextLevel);
|
|
28087
28253
|
let observedSources = [];
|
|
28088
28254
|
let replayedObservation = false;
|
|
28089
28255
|
if (opts.observationSourceIds?.length) {
|
|
@@ -28097,8 +28263,18 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
28097
28263
|
}
|
|
28098
28264
|
await record.update((r) => {
|
|
28099
28265
|
r._setRaw("content", encryptedContent);
|
|
28100
|
-
if (opts.
|
|
28266
|
+
if (opts.level !== void 0) {
|
|
28267
|
+
r._setRaw("level", nextLevel);
|
|
28268
|
+
r._setRaw("scope", scopeForLevel(nextLevel));
|
|
28269
|
+
} else if (opts.scope !== void 0) {
|
|
28101
28270
|
r._setRaw("scope", opts.scope);
|
|
28271
|
+
r._setRaw("level", nextLevel);
|
|
28272
|
+
}
|
|
28273
|
+
if (opts.kind !== void 0) {
|
|
28274
|
+
r._setRaw("kind", opts.kind);
|
|
28275
|
+
}
|
|
28276
|
+
if (encryptedKindValue !== void 0) {
|
|
28277
|
+
r._setRaw("kind_value", encryptedKindValue);
|
|
28102
28278
|
}
|
|
28103
28279
|
if (opts.folderId !== void 0) {
|
|
28104
28280
|
r._setRaw("folder_id", opts.folderId);
|
|
@@ -28157,7 +28333,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
28157
28333
|
ctx.signMessage,
|
|
28158
28334
|
ctx.embeddedWalletSigner
|
|
28159
28335
|
);
|
|
28160
|
-
} catch {
|
|
28336
|
+
} catch (err) {
|
|
28337
|
+
if (err instanceof MemoryLevelError) throw err;
|
|
28161
28338
|
return null;
|
|
28162
28339
|
}
|
|
28163
28340
|
}
|
|
@@ -28293,6 +28470,7 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
28293
28470
|
try {
|
|
28294
28471
|
const record = await ctx.vaultMemoryCollection.find(id);
|
|
28295
28472
|
if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) return false;
|
|
28473
|
+
if (isKinded(record)) return false;
|
|
28296
28474
|
let successor;
|
|
28297
28475
|
try {
|
|
28298
28476
|
successor = await ctx.vaultMemoryCollection.find(supersededById);
|
|
@@ -28593,7 +28771,10 @@ function assertVaultScopeForSweep(ctx) {
|
|
|
28593
28771
|
}
|
|
28594
28772
|
async function getDecayCandidatesRawOp(ctx) {
|
|
28595
28773
|
assertVaultScopeForSweep(ctx);
|
|
28596
|
-
const results = await ctx.vaultMemoryCollection.query(
|
|
28774
|
+
const results = await ctx.vaultMemoryCollection.query(
|
|
28775
|
+
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
28776
|
+
import_watermelondb19.Q.where("kind", null)
|
|
28777
|
+
).unsafeFetchRaw();
|
|
28597
28778
|
return results.map((raw) => ({
|
|
28598
28779
|
uniqueId: raw.id,
|
|
28599
28780
|
factType: raw.fact_type ?? null,
|
|
@@ -28854,6 +29035,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
28854
29035
|
record._raw.id = row.memoryId;
|
|
28855
29036
|
record._setRaw("content", content);
|
|
28856
29037
|
record._setRaw("scope", "shared");
|
|
29038
|
+
record._setRaw("level", "matching");
|
|
28857
29039
|
record._setRaw("folder_id", null);
|
|
28858
29040
|
record._setRaw("user_id", ctx.userId ?? null);
|
|
28859
29041
|
record._setRaw("is_deleted", false);
|
|
@@ -31574,7 +31756,7 @@ async function rankPreparedVaultCandidates(query, prepared, embeddingOptions, se
|
|
|
31574
31756
|
if (useFusion && !embeddingsUnavailable && facetQueries) {
|
|
31575
31757
|
let subEmbeddings;
|
|
31576
31758
|
try {
|
|
31577
|
-
subEmbeddings = await generateEmbeddings(facetQueries, embeddingOptions);
|
|
31759
|
+
subEmbeddings = prepared.facetEmbeddings ?? await generateEmbeddings(facetQueries, embeddingOptions);
|
|
31578
31760
|
} catch (err) {
|
|
31579
31761
|
getLogger().warn(
|
|
31580
31762
|
"memoryVault: sub-query embedding failed \u2014 falling back to single-query ranking: " + (err instanceof Error ? err.message : String(err))
|
|
@@ -31760,6 +31942,35 @@ var DEFAULT_SCOPE = "private";
|
|
|
31760
31942
|
var DEFAULT_CONSOLIDATE_THRESHOLD = 0.55;
|
|
31761
31943
|
var DEFAULT_CONSOLIDATE_TOP_K = 20;
|
|
31762
31944
|
async function retain(content, ctx, options = {}) {
|
|
31945
|
+
return retainWithPersistence(
|
|
31946
|
+
content,
|
|
31947
|
+
{
|
|
31948
|
+
embeddingOptions: ctx.embeddingOptions,
|
|
31949
|
+
vaultCache: ctx.vaultCache,
|
|
31950
|
+
persistence: {
|
|
31951
|
+
prepare: (query, searchOptions) => prepareVaultCandidates(
|
|
31952
|
+
query,
|
|
31953
|
+
ctx.vaultCtx,
|
|
31954
|
+
ctx.embeddingOptions,
|
|
31955
|
+
ctx.vaultCache,
|
|
31956
|
+
searchOptions
|
|
31957
|
+
),
|
|
31958
|
+
get: (id) => getVaultMemoryOp(ctx.vaultCtx, id),
|
|
31959
|
+
tombstones: (_embedding, _model, scope, folderId) => getAllVaultMemoriesOp(ctx.vaultCtx, {
|
|
31960
|
+
includeDeleted: true,
|
|
31961
|
+
scopes: [scope],
|
|
31962
|
+
...folderId !== void 0 && { folderId }
|
|
31963
|
+
}),
|
|
31964
|
+
create: (input) => createVaultMemoryOp(ctx.vaultCtx, input),
|
|
31965
|
+
update: (id, patch) => updateVaultMemoryOp(ctx.vaultCtx, id, patch),
|
|
31966
|
+
supersede: (id, successor) => supersedeVaultMemoryOp(ctx.vaultCtx, id, successor),
|
|
31967
|
+
createSuperseding: (input, target) => createSupersedingMemoryOp(ctx.vaultCtx, input, target)
|
|
31968
|
+
}
|
|
31969
|
+
},
|
|
31970
|
+
options
|
|
31971
|
+
);
|
|
31972
|
+
}
|
|
31973
|
+
async function retainWithPersistence(content, ctx, options = {}) {
|
|
31763
31974
|
const trimmed = content.trim();
|
|
31764
31975
|
if (trimmed.length === 0) {
|
|
31765
31976
|
throw new Error("retain: content cannot be empty");
|
|
@@ -31772,19 +31983,14 @@ async function retain(content, ctx, options = {}) {
|
|
|
31772
31983
|
let supersedeContent;
|
|
31773
31984
|
let prepared;
|
|
31774
31985
|
if (enableAutoMerge) {
|
|
31775
|
-
prepared = await
|
|
31776
|
-
|
|
31777
|
-
|
|
31778
|
-
|
|
31779
|
-
|
|
31780
|
-
{
|
|
31781
|
-
|
|
31782
|
-
|
|
31783
|
-
scopes: [resolvedScope],
|
|
31784
|
-
includeArchived: true,
|
|
31785
|
-
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
31786
|
-
}
|
|
31787
|
-
);
|
|
31986
|
+
prepared = await ctx.persistence.prepare(trimmed, {
|
|
31987
|
+
limit: Math.max(options.consolidateTopK ?? DEFAULT_CONSOLIDATE_TOP_K, 1),
|
|
31988
|
+
useFusion: false,
|
|
31989
|
+
scopes: [resolvedScope],
|
|
31990
|
+
includeArchived: true,
|
|
31991
|
+
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
31992
|
+
});
|
|
31993
|
+
prepared = withoutKindedRows(prepared);
|
|
31788
31994
|
if (prepared.embeddingFailure || prepared.embeddingsUnavailable) {
|
|
31789
31995
|
throw new Error(
|
|
31790
31996
|
"retain: embeddings unavailable \u2014 refusing to auto-merge against an inert cosine lane, which would create a duplicate instead of merging into the existing memory. Retry when embeddings recover, or pass enableAutoMerge: false to force a create."
|
|
@@ -31815,7 +32021,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
31815
32021
|
);
|
|
31816
32022
|
if (matches.length > 0) {
|
|
31817
32023
|
const targetId = matches[0].uniqueId;
|
|
31818
|
-
const existing = await
|
|
32024
|
+
const existing = await ctx.persistence.get(targetId);
|
|
31819
32025
|
if (existing && !existing.supersededBy) {
|
|
31820
32026
|
const mergedSourceIds = unionStrings(
|
|
31821
32027
|
existing.sourceChunkIds ?? [],
|
|
@@ -31824,8 +32030,9 @@ async function retain(content, ctx, options = {}) {
|
|
|
31824
32030
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
31825
32031
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
31826
32032
|
const resurrect = resurrectFields(existing);
|
|
31827
|
-
const updated = await
|
|
32033
|
+
const updated = await ctx.persistence.update(targetId, {
|
|
31828
32034
|
content: existing.content,
|
|
32035
|
+
freeFormOnly: true,
|
|
31829
32036
|
proofCountIncrement: 1,
|
|
31830
32037
|
observationSourceIds: options.sourceChunkIds,
|
|
31831
32038
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -31851,7 +32058,8 @@ async function retain(content, ctx, options = {}) {
|
|
|
31851
32058
|
}
|
|
31852
32059
|
const contentToWrite = supersedeContent ?? trimmed;
|
|
31853
32060
|
const reusableQueryEmbedding = supersedeContent === void 0 && prepared && prepared.queryEmbedding.length > 0 ? prepared.queryEmbedding : void 0;
|
|
31854
|
-
const
|
|
32061
|
+
const generatedEmbedding = reusableQueryEmbedding ?? await generateEmbedding(contentToWrite, ctx.embeddingOptions);
|
|
32062
|
+
const embedding = ctx.normalizeEmbedding?.(generatedEmbedding) ?? generatedEmbedding;
|
|
31855
32063
|
const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
31856
32064
|
if (options.respectTombstones) {
|
|
31857
32065
|
const tombstone = await findTombstoneMatch(embedding, embeddingModel, resolvedScope, ctx, {
|
|
@@ -31891,8 +32099,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
31891
32099
|
};
|
|
31892
32100
|
if (supersedeTargetIds.length > 0) {
|
|
31893
32101
|
const [primaryTargetId, ...restTargetIds] = supersedeTargetIds;
|
|
31894
|
-
const { created: created2, retired } = await
|
|
31895
|
-
ctx.vaultCtx,
|
|
32102
|
+
const { created: created2, retired } = await ctx.persistence.createSuperseding(
|
|
31896
32103
|
createOpts,
|
|
31897
32104
|
primaryTargetId
|
|
31898
32105
|
);
|
|
@@ -31908,11 +32115,11 @@ async function retain(content, ctx, options = {}) {
|
|
|
31908
32115
|
for (const staleId of restTargetIds) {
|
|
31909
32116
|
let ok = false;
|
|
31910
32117
|
try {
|
|
31911
|
-
ok = await
|
|
32118
|
+
ok = await ctx.persistence.supersede(staleId, created2.uniqueId) === true;
|
|
31912
32119
|
} catch {
|
|
31913
32120
|
}
|
|
31914
32121
|
if (ok) continue;
|
|
31915
|
-
const stillLive = await
|
|
32122
|
+
const stillLive = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(staleId) : ctx.persistence.get(staleId)).catch(() => null);
|
|
31916
32123
|
if (stillLive && !stillLive.supersededBy) liveLeftovers.push(staleId);
|
|
31917
32124
|
}
|
|
31918
32125
|
if (liveLeftovers.length > 0) {
|
|
@@ -31939,7 +32146,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
31939
32146
|
`supersede: primary target ${primaryTargetId} retired or deleted inside the atomic write`
|
|
31940
32147
|
);
|
|
31941
32148
|
}
|
|
31942
|
-
const created = await
|
|
32149
|
+
const created = await ctx.persistence.create(createOpts);
|
|
31943
32150
|
cacheRowVector(
|
|
31944
32151
|
ctx.vaultCache,
|
|
31945
32152
|
created.uniqueId,
|
|
@@ -31954,15 +32161,22 @@ async function retain(content, ctx, options = {}) {
|
|
|
31954
32161
|
...consolidationDecidedCreate && { consolidation: "create" }
|
|
31955
32162
|
};
|
|
31956
32163
|
}
|
|
32164
|
+
function withoutKindedRows(prepared) {
|
|
32165
|
+
const kinded = new Set(
|
|
32166
|
+
prepared.memories.filter((m) => m.kind !== null && m.kind !== void 0).map((m) => m.uniqueId)
|
|
32167
|
+
);
|
|
32168
|
+
if (kinded.size === 0) return prepared;
|
|
32169
|
+
return {
|
|
32170
|
+
...prepared,
|
|
32171
|
+
memories: prepared.memories.filter((m) => !kinded.has(m.uniqueId)),
|
|
32172
|
+
embeddedItems: prepared.embeddedItems.filter((item) => !kinded.has(item.id))
|
|
32173
|
+
};
|
|
32174
|
+
}
|
|
31957
32175
|
function unionStrings(a, b) {
|
|
31958
32176
|
return [.../* @__PURE__ */ new Set([...a, ...b])];
|
|
31959
32177
|
}
|
|
31960
32178
|
async function findTombstoneMatch(embedding, embeddingModel, scope, ctx, opts) {
|
|
31961
|
-
const rows = await
|
|
31962
|
-
includeDeleted: true,
|
|
31963
|
-
scopes: [scope],
|
|
31964
|
-
...opts.folderId !== void 0 && { folderId: opts.folderId }
|
|
31965
|
-
});
|
|
32179
|
+
const rows = await ctx.persistence.tombstones(embedding, embeddingModel, scope, opts.folderId);
|
|
31966
32180
|
let bestId = null;
|
|
31967
32181
|
let bestSim = opts.threshold;
|
|
31968
32182
|
for (const row of rows) {
|
|
@@ -32029,7 +32243,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32029
32243
|
if (requestedIds.length === 0) return null;
|
|
32030
32244
|
const valid = [];
|
|
32031
32245
|
for (const id of requestedIds) {
|
|
32032
|
-
const existing = await
|
|
32246
|
+
const existing = await ctx.persistence.get(id);
|
|
32033
32247
|
if (existing && !existing.supersededBy) valid.push(id);
|
|
32034
32248
|
}
|
|
32035
32249
|
if (valid.length === 0) {
|
|
@@ -32041,7 +32255,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32041
32255
|
return { supersede: valid, content: decision.content };
|
|
32042
32256
|
}
|
|
32043
32257
|
if (decision.action === "noop" && decision.targetId) {
|
|
32044
|
-
const existing = await
|
|
32258
|
+
const existing = await ctx.persistence.get(decision.targetId);
|
|
32045
32259
|
if (!existing || existing.supersededBy) {
|
|
32046
32260
|
return abandonToRace(
|
|
32047
32261
|
options,
|
|
@@ -32055,8 +32269,9 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32055
32269
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
32056
32270
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
32057
32271
|
const resurrect = resurrectFields(existing);
|
|
32058
|
-
const updated = await
|
|
32272
|
+
const updated = await ctx.persistence.update(decision.targetId, {
|
|
32059
32273
|
content: existing.content,
|
|
32274
|
+
freeFormOnly: true,
|
|
32060
32275
|
proofCountIncrement: 1,
|
|
32061
32276
|
observationSourceIds: options.sourceChunkIds,
|
|
32062
32277
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -32083,7 +32298,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32083
32298
|
};
|
|
32084
32299
|
}
|
|
32085
32300
|
if (decision.action === "update" && decision.targetId && decision.content) {
|
|
32086
|
-
const existing = await
|
|
32301
|
+
const existing = await ctx.persistence.get(decision.targetId);
|
|
32087
32302
|
if (!existing || existing.supersededBy) {
|
|
32088
32303
|
return abandonToRace(
|
|
32089
32304
|
options,
|
|
@@ -32094,13 +32309,15 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32094
32309
|
existing.sourceChunkIds ?? [],
|
|
32095
32310
|
options.sourceChunkIds ?? []
|
|
32096
32311
|
);
|
|
32097
|
-
const
|
|
32312
|
+
const generatedEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
|
|
32313
|
+
const newEmbedding = ctx.normalizeEmbedding?.(generatedEmbedding) ?? generatedEmbedding;
|
|
32098
32314
|
const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
32099
32315
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
32100
32316
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
32101
32317
|
const resurrect = resurrectFields(existing);
|
|
32102
|
-
const updated = await
|
|
32318
|
+
const updated = await ctx.persistence.update(decision.targetId, {
|
|
32103
32319
|
content: decision.content,
|
|
32320
|
+
freeFormOnly: true,
|
|
32104
32321
|
proofCountIncrement: 1,
|
|
32105
32322
|
observationSourceIds: options.sourceChunkIds,
|
|
32106
32323
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -32143,8 +32360,8 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
32143
32360
|
return null;
|
|
32144
32361
|
}
|
|
32145
32362
|
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
32146
|
-
const stillExists = await
|
|
32147
|
-
if (stillExists) {
|
|
32363
|
+
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
32364
|
+
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
|
|
32148
32365
|
throw new Error(`retain: merge into memory ${targetId} failed to persist`);
|
|
32149
32366
|
}
|
|
32150
32367
|
}
|
|
@@ -33642,7 +33859,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
33642
33859
|
if (graphLaneFailed) degraded.push("graph-lane-failed");
|
|
33643
33860
|
if (temporalLaneFailed) degraded.push("temporal-lane-failed");
|
|
33644
33861
|
if (chunksScopeRestricted) degraded.push("chunks-scope-restricted");
|
|
33645
|
-
const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx || chunksScopeRestricted && !!ctx.storageCtx;
|
|
33862
|
+
const laneRan = types.includes("fact") && (!!ctx.factSource || !!ctx.vaultCtx && !!ctx.vaultCache) || types.includes("chunk") && !!ctx.storageCtx || chunksScopeRestricted && !!ctx.storageCtx;
|
|
33646
33863
|
const scores = admitted.map((m) => m.score);
|
|
33647
33864
|
const minScoreApplied = factResults.length > 0 ? factFloor : chunkResults.length > 0 ? chunkFloor : factFloor >= 0 ? factFloor : chunkFloor;
|
|
33648
33865
|
const diagnostics = {
|
|
@@ -33684,7 +33901,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
33684
33901
|
return { memories: [], usedBudget, reranked: false, candidateCount: 0 };
|
|
33685
33902
|
}
|
|
33686
33903
|
const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
|
|
33687
|
-
const wantsTemporal = types.includes("fact") && ctx.vaultCtx;
|
|
33904
|
+
const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
|
|
33688
33905
|
const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
33689
33906
|
const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
|
|
33690
33907
|
const prepStart = nowMs2();
|
|
@@ -33714,7 +33931,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
33714
33931
|
safeLane(
|
|
33715
33932
|
"graph",
|
|
33716
33933
|
() => graphLaneFailed = true,
|
|
33717
|
-
() => buildGraphLaneRanking(query, ctx, flags.traverse, {
|
|
33934
|
+
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(query, ctx, flags.traverse, {
|
|
33718
33935
|
...options.maxHops !== void 0 && { maxHops: options.maxHops },
|
|
33719
33936
|
...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
|
|
33720
33937
|
...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
|
|
@@ -33725,13 +33942,13 @@ async function recall(query, ctx, options = {}) {
|
|
|
33725
33942
|
wantsTemporal ? safeLane(
|
|
33726
33943
|
"temporal",
|
|
33727
33944
|
() => temporalLaneFailed = true,
|
|
33728
|
-
() => buildTemporalLaneRanking(query, ctx.vaultCtx, options.now)
|
|
33945
|
+
() => ctx.factSource ? ctx.factSource.temporalRanking(query, options.now) : buildTemporalLaneRanking(query, ctx.vaultCtx, options.now)
|
|
33729
33946
|
) : Promise.resolve([])
|
|
33730
33947
|
]);
|
|
33731
33948
|
prepMs = nowMs2() - prepStart;
|
|
33732
33949
|
graphLaneCount = entityRanking.length;
|
|
33733
33950
|
temporalLaneCount = temporalRanking.length;
|
|
33734
|
-
if (types.includes("fact") && ctx.vaultCtx && ctx.vaultCache) {
|
|
33951
|
+
if (types.includes("fact") && (ctx.factSource || ctx.vaultCtx && ctx.vaultCache)) {
|
|
33735
33952
|
const factStart = nowMs2();
|
|
33736
33953
|
const vaultMinScore = options.minScore ?? DEFAULT_FACT_MIN_SCORE;
|
|
33737
33954
|
factFloor = vaultMinScore;
|
|
@@ -33747,50 +33964,50 @@ async function recall(query, ctx, options = {}) {
|
|
|
33747
33964
|
rankedOnCosine: factRankedOnCosine,
|
|
33748
33965
|
decryptLast: factDecryptLast,
|
|
33749
33966
|
rowsDecrypted: factRowsDecrypted
|
|
33750
|
-
} = await searchVaultMemoriesWithSize(
|
|
33751
|
-
|
|
33967
|
+
} = await (ctx.factSource?.search.bind(ctx.factSource) ?? ((searchQuery, searchOptions) => searchVaultMemoriesWithSize(
|
|
33968
|
+
searchQuery,
|
|
33752
33969
|
ctx.vaultCtx,
|
|
33753
33970
|
ctx.embeddingOptions,
|
|
33754
33971
|
ctx.vaultCache,
|
|
33755
|
-
|
|
33756
|
-
|
|
33757
|
-
|
|
33758
|
-
|
|
33759
|
-
|
|
33760
|
-
|
|
33761
|
-
|
|
33762
|
-
|
|
33763
|
-
|
|
33764
|
-
|
|
33765
|
-
|
|
33766
|
-
|
|
33767
|
-
|
|
33768
|
-
|
|
33769
|
-
|
|
33770
|
-
|
|
33771
|
-
|
|
33772
|
-
|
|
33773
|
-
|
|
33774
|
-
|
|
33775
|
-
|
|
33776
|
-
|
|
33777
|
-
|
|
33778
|
-
|
|
33779
|
-
|
|
33780
|
-
|
|
33781
|
-
|
|
33782
|
-
|
|
33783
|
-
|
|
33784
|
-
|
|
33785
|
-
|
|
33786
|
-
|
|
33787
|
-
|
|
33788
|
-
|
|
33789
|
-
|
|
33790
|
-
|
|
33791
|
-
|
|
33792
|
-
|
|
33793
|
-
);
|
|
33972
|
+
searchOptions
|
|
33973
|
+
)))(query, {
|
|
33974
|
+
limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
|
|
33975
|
+
minSimilarity: vaultMinScore,
|
|
33976
|
+
useFusion: true,
|
|
33977
|
+
rerank: flags.rerank,
|
|
33978
|
+
...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
|
|
33979
|
+
...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
|
|
33980
|
+
...options.rerankLoadTimeoutMs !== void 0 && {
|
|
33981
|
+
rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
|
|
33982
|
+
},
|
|
33983
|
+
...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
33984
|
+
...options.recency && { recency: options.recency },
|
|
33985
|
+
...options.mmr !== void 0 && { mmr: options.mmr },
|
|
33986
|
+
...options.supersessionBoost !== void 0 && {
|
|
33987
|
+
supersessionBoost: options.supersessionBoost
|
|
33988
|
+
},
|
|
33989
|
+
...options.supersessionWindow !== void 0 && {
|
|
33990
|
+
supersessionWindow: options.supersessionWindow
|
|
33991
|
+
},
|
|
33992
|
+
...options.proofCountAlpha !== void 0 && {
|
|
33993
|
+
proofCountAlpha: options.proofCountAlpha
|
|
33994
|
+
},
|
|
33995
|
+
...options.bm25AdmissionDivisor !== void 0 && {
|
|
33996
|
+
bm25AdmissionDivisor: options.bm25AdmissionDivisor
|
|
33997
|
+
},
|
|
33998
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
33999
|
+
...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
|
|
34000
|
+
...subQueries && { subQueries },
|
|
34001
|
+
...options.scopes && { scopes: options.scopes },
|
|
34002
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
34003
|
+
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
34004
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
34005
|
+
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
34006
|
+
...entityRanking.length > 0 && { entityRanking },
|
|
34007
|
+
...temporalRanking.length > 0 && { temporalRanking },
|
|
34008
|
+
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
34009
|
+
queryEmbedTotalTimeoutMs
|
|
34010
|
+
});
|
|
33794
34011
|
factResults.push(
|
|
33795
34012
|
...dedupeBy(
|
|
33796
34013
|
results,
|
|
@@ -38547,7 +38764,10 @@ function serverPlatformStorage() {
|
|
|
38547
38764
|
MAX_HOPS,
|
|
38548
38765
|
MAX_MESSAGES_PER_SUMMARIZATION,
|
|
38549
38766
|
MEDIUM_TTL_MS,
|
|
38767
|
+
MEMORY_KINDS,
|
|
38768
|
+
MEMORY_LEVELS,
|
|
38550
38769
|
Media,
|
|
38770
|
+
MemoryLevelError,
|
|
38551
38771
|
Message,
|
|
38552
38772
|
ModelPreference,
|
|
38553
38773
|
NEVER_TTL_MS,
|