@anuma/sdk 6.34.0 → 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 +212 -14
- package/dist/expo/index.d.mts +61 -8
- package/dist/expo/index.d.ts +61 -8
- package/dist/expo/index.mjs +209 -14
- package/dist/memory/context.d.mts +21 -1
- package/dist/memory/context.d.ts +21 -1
- package/dist/react/index.cjs +212 -14
- package/dist/react/index.d.mts +61 -8
- package/dist/react/index.d.ts +61 -8
- package/dist/react/index.mjs +209 -14
- package/dist/server/index.cjs +201 -13
- package/dist/server/index.d.mts +61 -8
- package/dist/server/index.d.ts +61 -8
- package/dist/server/index.mjs +198 -13
- package/package.json +1 -1
|
@@ -28,6 +28,12 @@ declare class VaultMemory extends Model {
|
|
|
28
28
|
static table: string;
|
|
29
29
|
content: string;
|
|
30
30
|
scope: string;
|
|
31
|
+
/** Profile kind, or null for a free-form memory. */
|
|
32
|
+
kind: string | null;
|
|
33
|
+
/** Canonical JSON value of a kinded memory, encrypted at rest. */
|
|
34
|
+
kindValue: string | null;
|
|
35
|
+
/** private | matching | profile. */
|
|
36
|
+
level: string | null;
|
|
31
37
|
folderId: string | null;
|
|
32
38
|
userId: string | null;
|
|
33
39
|
embedding: string | null;
|
|
@@ -674,13 +680,23 @@ type FactType = (typeof FACT_TYPES)[number];
|
|
|
674
680
|
* the fail-safe direction: it un-publishes rather than exposes.
|
|
675
681
|
*/
|
|
676
682
|
type VaultMemoryVisibility = "private" | "public";
|
|
683
|
+
/** Who a memory reaches. */
|
|
684
|
+
declare const MEMORY_LEVELS: readonly ["private", "matching", "profile"];
|
|
685
|
+
/** One of {@link MEMORY_LEVELS}. */
|
|
686
|
+
type MemoryLevel = (typeof MEMORY_LEVELS)[number];
|
|
677
687
|
interface StoredVaultMemory {
|
|
678
688
|
/** WatermelonDB internal ID */
|
|
679
689
|
uniqueId: string;
|
|
680
690
|
/** Plain text memory content */
|
|
681
691
|
content: string;
|
|
682
|
-
/** Scope for partitioning memories (e.g., "private", "shared") */
|
|
692
|
+
/** Scope for partitioning memories (e.g., "private", "shared"). */
|
|
683
693
|
scope: string;
|
|
694
|
+
/** Profile kind ({@link MEMORY_KINDS}) or null for a free-form memory. */
|
|
695
|
+
kind?: string | null;
|
|
696
|
+
/** Canonical value of a kinded memory, JSON-encoded (slug, slug[], int, date, text). */
|
|
697
|
+
kindValue?: string | null;
|
|
698
|
+
/** Who this memory reaches. */
|
|
699
|
+
level?: MemoryLevel;
|
|
684
700
|
/** Folder ID for organization, null if unfiled */
|
|
685
701
|
folderId: string | null;
|
|
686
702
|
/** User ID for multi-user server-side scoping, null on client */
|
|
@@ -837,6 +853,10 @@ declare function getAllVaultMemoriesOp(ctx: VaultMemoryOperationsContext, option
|
|
|
837
853
|
* published set to diff against the server index.
|
|
838
854
|
*/
|
|
839
855
|
visibility?: VaultMemoryVisibility[];
|
|
856
|
+
/** Filter by level. */
|
|
857
|
+
levels?: MemoryLevel[];
|
|
858
|
+
/** Restrict to these profile kinds. */
|
|
859
|
+
kinds?: string[];
|
|
840
860
|
}): Promise<StoredVaultMemory[]>;
|
|
841
861
|
|
|
842
862
|
type MemoryContextLane = "profile" | "fact" | "episode" | "session";
|
package/dist/memory/context.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ declare class VaultMemory extends Model {
|
|
|
28
28
|
static table: string;
|
|
29
29
|
content: string;
|
|
30
30
|
scope: string;
|
|
31
|
+
/** Profile kind, or null for a free-form memory. */
|
|
32
|
+
kind: string | null;
|
|
33
|
+
/** Canonical JSON value of a kinded memory, encrypted at rest. */
|
|
34
|
+
kindValue: string | null;
|
|
35
|
+
/** private | matching | profile. */
|
|
36
|
+
level: string | null;
|
|
31
37
|
folderId: string | null;
|
|
32
38
|
userId: string | null;
|
|
33
39
|
embedding: string | null;
|
|
@@ -674,13 +680,23 @@ type FactType = (typeof FACT_TYPES)[number];
|
|
|
674
680
|
* the fail-safe direction: it un-publishes rather than exposes.
|
|
675
681
|
*/
|
|
676
682
|
type VaultMemoryVisibility = "private" | "public";
|
|
683
|
+
/** Who a memory reaches. */
|
|
684
|
+
declare const MEMORY_LEVELS: readonly ["private", "matching", "profile"];
|
|
685
|
+
/** One of {@link MEMORY_LEVELS}. */
|
|
686
|
+
type MemoryLevel = (typeof MEMORY_LEVELS)[number];
|
|
677
687
|
interface StoredVaultMemory {
|
|
678
688
|
/** WatermelonDB internal ID */
|
|
679
689
|
uniqueId: string;
|
|
680
690
|
/** Plain text memory content */
|
|
681
691
|
content: string;
|
|
682
|
-
/** Scope for partitioning memories (e.g., "private", "shared") */
|
|
692
|
+
/** Scope for partitioning memories (e.g., "private", "shared"). */
|
|
683
693
|
scope: string;
|
|
694
|
+
/** Profile kind ({@link MEMORY_KINDS}) or null for a free-form memory. */
|
|
695
|
+
kind?: string | null;
|
|
696
|
+
/** Canonical value of a kinded memory, JSON-encoded (slug, slug[], int, date, text). */
|
|
697
|
+
kindValue?: string | null;
|
|
698
|
+
/** Who this memory reaches. */
|
|
699
|
+
level?: MemoryLevel;
|
|
684
700
|
/** Folder ID for organization, null if unfiled */
|
|
685
701
|
folderId: string | null;
|
|
686
702
|
/** User ID for multi-user server-side scoping, null on client */
|
|
@@ -837,6 +853,10 @@ declare function getAllVaultMemoriesOp(ctx: VaultMemoryOperationsContext, option
|
|
|
837
853
|
* published set to diff against the server index.
|
|
838
854
|
*/
|
|
839
855
|
visibility?: VaultMemoryVisibility[];
|
|
856
|
+
/** Filter by level. */
|
|
857
|
+
levels?: MemoryLevel[];
|
|
858
|
+
/** Restrict to these profile kinds. */
|
|
859
|
+
kinds?: string[];
|
|
840
860
|
}): Promise<StoredVaultMemory[]>;
|
|
841
861
|
|
|
842
862
|
type MemoryContextLane = "profile" | "fact" | "episode" | "session";
|
package/dist/react/index.cjs
CHANGED
|
@@ -1424,7 +1424,10 @@ __export(index_exports, {
|
|
|
1424
1424
|
LoggerProvider: () => LoggerProvider,
|
|
1425
1425
|
MAX_HOPS: () => MAX_HOPS,
|
|
1426
1426
|
MEDIUM_TTL_MS: () => MEDIUM_TTL_MS,
|
|
1427
|
+
MEMORY_KINDS: () => MEMORY_KINDS,
|
|
1428
|
+
MEMORY_LEVELS: () => MEMORY_LEVELS,
|
|
1427
1429
|
MemoryEntityModel: () => MemoryEntity,
|
|
1430
|
+
MemoryLevelError: () => MemoryLevelError,
|
|
1428
1431
|
NEVER_TTL_MS: () => NEVER_TTL_MS,
|
|
1429
1432
|
NODE_BUDGET: () => NODE_BUDGET,
|
|
1430
1433
|
PAST_EVENT_GRACE_MS: () => PAST_EVENT_GRACE_MS,
|
|
@@ -13155,6 +13158,15 @@ __decorateClass([
|
|
|
13155
13158
|
__decorateClass([
|
|
13156
13159
|
(0, import_decorators6.text)("scope")
|
|
13157
13160
|
], VaultMemory.prototype, "scope", 2);
|
|
13161
|
+
__decorateClass([
|
|
13162
|
+
(0, import_decorators6.field)("kind")
|
|
13163
|
+
], VaultMemory.prototype, "kind", 2);
|
|
13164
|
+
__decorateClass([
|
|
13165
|
+
(0, import_decorators6.field)("kind_value")
|
|
13166
|
+
], VaultMemory.prototype, "kindValue", 2);
|
|
13167
|
+
__decorateClass([
|
|
13168
|
+
(0, import_decorators6.field)("level")
|
|
13169
|
+
], VaultMemory.prototype, "level", 2);
|
|
13158
13170
|
__decorateClass([
|
|
13159
13171
|
(0, import_decorators6.field)("folder_id")
|
|
13160
13172
|
], VaultMemory.prototype, "folderId", 2);
|
|
@@ -13380,7 +13392,7 @@ __decorateClass([
|
|
|
13380
13392
|
], VaultFolder.prototype, "context", 2);
|
|
13381
13393
|
|
|
13382
13394
|
// src/lib/db/schema.ts
|
|
13383
|
-
var SDK_SCHEMA_VERSION =
|
|
13395
|
+
var SDK_SCHEMA_VERSION = 48;
|
|
13384
13396
|
var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
13385
13397
|
version: SDK_SCHEMA_VERSION,
|
|
13386
13398
|
tables: [
|
|
@@ -13475,6 +13487,9 @@ var sdkSchema = (0, import_watermelondb19.appSchema)({
|
|
|
13475
13487
|
columns: [
|
|
13476
13488
|
{ name: "content", type: "string" },
|
|
13477
13489
|
{ name: "scope", type: "string", isIndexed: true },
|
|
13490
|
+
{ name: "kind", type: "string", isOptional: true, isIndexed: true },
|
|
13491
|
+
{ name: "kind_value", type: "string", isOptional: true },
|
|
13492
|
+
{ name: "level", type: "string", isOptional: true, isIndexed: true },
|
|
13478
13493
|
{ name: "folder_id", type: "string", isOptional: true, isIndexed: true },
|
|
13479
13494
|
{ name: "created_at", type: "number", isIndexed: true },
|
|
13480
13495
|
{ name: "updated_at", type: "number", isIndexed: true },
|
|
@@ -14151,6 +14166,22 @@ var sdkMigrations = (0, import_migrations2.schemaMigrations)({
|
|
|
14151
14166
|
]
|
|
14152
14167
|
})
|
|
14153
14168
|
]
|
|
14169
|
+
},
|
|
14170
|
+
{
|
|
14171
|
+
toVersion: 48,
|
|
14172
|
+
steps: [
|
|
14173
|
+
(0, import_migrations2.addColumns)({
|
|
14174
|
+
table: "memory_vault",
|
|
14175
|
+
columns: [
|
|
14176
|
+
{ name: "kind", type: "string", isOptional: true, isIndexed: true },
|
|
14177
|
+
{ name: "kind_value", type: "string", isOptional: true },
|
|
14178
|
+
{ name: "level", type: "string", isOptional: true, isIndexed: true }
|
|
14179
|
+
]
|
|
14180
|
+
}),
|
|
14181
|
+
(0, import_migrations2.unsafeExecuteSql)(
|
|
14182
|
+
"UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
|
|
14183
|
+
)
|
|
14184
|
+
]
|
|
14154
14185
|
}
|
|
14155
14186
|
]
|
|
14156
14187
|
});
|
|
@@ -15292,13 +15323,54 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
|
|
|
15292
15323
|
}
|
|
15293
15324
|
}
|
|
15294
15325
|
const decryptedContent = await decryptField(memory.content, address);
|
|
15326
|
+
const decryptedKindValue = typeof memory.kindValue === "string" ? await decryptField(memory.kindValue, address) : memory.kindValue;
|
|
15295
15327
|
return {
|
|
15296
15328
|
...memory,
|
|
15297
|
-
content: decryptedContent
|
|
15329
|
+
content: decryptedContent,
|
|
15330
|
+
...decryptedKindValue !== void 0 && { kindValue: decryptedKindValue }
|
|
15298
15331
|
};
|
|
15299
15332
|
}
|
|
15300
15333
|
|
|
15301
15334
|
// src/lib/db/memoryVault/types.ts
|
|
15335
|
+
var MEMORY_KINDS = [
|
|
15336
|
+
"display_name",
|
|
15337
|
+
"birth_date",
|
|
15338
|
+
"bio",
|
|
15339
|
+
"occupation",
|
|
15340
|
+
"interest",
|
|
15341
|
+
"gender",
|
|
15342
|
+
"height_cm",
|
|
15343
|
+
"looking_for",
|
|
15344
|
+
"politics",
|
|
15345
|
+
"religion",
|
|
15346
|
+
"ethnicity",
|
|
15347
|
+
"smoking",
|
|
15348
|
+
"drinking",
|
|
15349
|
+
"exercise",
|
|
15350
|
+
"sexuality",
|
|
15351
|
+
"prompt"
|
|
15352
|
+
];
|
|
15353
|
+
var MEMORY_LEVELS = ["private", "matching", "profile"];
|
|
15354
|
+
var MemoryLevelError = class extends Error {
|
|
15355
|
+
constructor(message) {
|
|
15356
|
+
super(message);
|
|
15357
|
+
this.name = "MemoryLevelError";
|
|
15358
|
+
}
|
|
15359
|
+
};
|
|
15360
|
+
var PUBLISHED_SCOPES = /* @__PURE__ */ new Set(["shared", "public"]);
|
|
15361
|
+
function levelFromScope(scope) {
|
|
15362
|
+
return typeof scope === "string" && PUBLISHED_SCOPES.has(scope) ? "matching" : "private";
|
|
15363
|
+
}
|
|
15364
|
+
function scopeForLevel(level) {
|
|
15365
|
+
return level === "private" ? "private" : "shared";
|
|
15366
|
+
}
|
|
15367
|
+
function resolveMemoryLevel(level, scope) {
|
|
15368
|
+
return typeof level === "string" && MEMORY_LEVELS.includes(level) ? level : levelFromScope(scope);
|
|
15369
|
+
}
|
|
15370
|
+
function levelForScopeChange(current, nextScope) {
|
|
15371
|
+
const implied = levelFromScope(nextScope);
|
|
15372
|
+
return implied === "matching" && resolveMemoryLevel(current.level, current.scope) === "profile" ? "profile" : implied;
|
|
15373
|
+
}
|
|
15302
15374
|
function parseMedia(value) {
|
|
15303
15375
|
if (typeof value !== "string" || value === "") return null;
|
|
15304
15376
|
try {
|
|
@@ -15328,6 +15400,56 @@ function visibilityConditions(requested) {
|
|
|
15328
15400
|
if (excluded.length === 0) return [];
|
|
15329
15401
|
return [import_watermelondb23.Q.or(import_watermelondb23.Q.where("visibility", null), import_watermelondb23.Q.where("visibility", import_watermelondb23.Q.notIn(excluded)))];
|
|
15330
15402
|
}
|
|
15403
|
+
function isKinded(record2) {
|
|
15404
|
+
return record2.kind !== null && record2.kind !== void 0;
|
|
15405
|
+
}
|
|
15406
|
+
function assertValidKindLevel(kind, level) {
|
|
15407
|
+
const hasKind = kind !== null && kind !== void 0;
|
|
15408
|
+
if (hasKind && !MEMORY_KINDS.includes(kind)) {
|
|
15409
|
+
throw new MemoryLevelError(`Unknown memory kind: ${kind}`);
|
|
15410
|
+
}
|
|
15411
|
+
if (level !== void 0 && !MEMORY_LEVELS.includes(level)) {
|
|
15412
|
+
throw new MemoryLevelError(`Unknown memory level: ${level}`);
|
|
15413
|
+
}
|
|
15414
|
+
if (level === "profile" && !hasKind) {
|
|
15415
|
+
throw new MemoryLevelError("Only a memory with a kind can be at level 'profile'");
|
|
15416
|
+
}
|
|
15417
|
+
}
|
|
15418
|
+
function resolveCreateLevel(opts) {
|
|
15419
|
+
if (opts.level !== void 0) return { level: opts.level, scope: scopeForLevel(opts.level) };
|
|
15420
|
+
if (opts.scope !== void 0) return { level: levelFromScope(opts.scope), scope: opts.scope };
|
|
15421
|
+
return { level: "private", scope: "private" };
|
|
15422
|
+
}
|
|
15423
|
+
async function encryptKindValue(ctx, value) {
|
|
15424
|
+
if (typeof value !== "string" || !ctx.walletAddress || !ctx.signMessage) return value;
|
|
15425
|
+
return encryptVaultMemoryContent(
|
|
15426
|
+
value,
|
|
15427
|
+
ctx.walletAddress,
|
|
15428
|
+
ctx.signMessage,
|
|
15429
|
+
ctx.embeddedWalletSigner
|
|
15430
|
+
);
|
|
15431
|
+
}
|
|
15432
|
+
function levelConditions(requested) {
|
|
15433
|
+
if (!requested?.length) return [];
|
|
15434
|
+
const published = ["shared", "public"];
|
|
15435
|
+
const wantsMatching = requested.includes("matching");
|
|
15436
|
+
const wantsPrivate = requested.includes("private");
|
|
15437
|
+
const unresolved = import_watermelondb23.Q.or(import_watermelondb23.Q.where("level", null), import_watermelondb23.Q.where("level", import_watermelondb23.Q.notIn([...MEMORY_LEVELS])));
|
|
15438
|
+
const byLevel = import_watermelondb23.Q.where("level", import_watermelondb23.Q.oneOf([...requested]));
|
|
15439
|
+
if (wantsMatching && wantsPrivate) return [import_watermelondb23.Q.or(byLevel, unresolved)];
|
|
15440
|
+
if (wantsMatching) {
|
|
15441
|
+
return [import_watermelondb23.Q.or(byLevel, import_watermelondb23.Q.and(unresolved, import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(published))))];
|
|
15442
|
+
}
|
|
15443
|
+
if (wantsPrivate) {
|
|
15444
|
+
return [
|
|
15445
|
+
import_watermelondb23.Q.or(
|
|
15446
|
+
byLevel,
|
|
15447
|
+
import_watermelondb23.Q.and(unresolved, import_watermelondb23.Q.or(import_watermelondb23.Q.where("scope", null), import_watermelondb23.Q.where("scope", import_watermelondb23.Q.notIn(published))))
|
|
15448
|
+
)
|
|
15449
|
+
];
|
|
15450
|
+
}
|
|
15451
|
+
return [byLevel];
|
|
15452
|
+
}
|
|
15331
15453
|
function isOwnedByCtxUser(ctx, record2) {
|
|
15332
15454
|
return ctx.userId === void 0 || record2.userId === ctx.userId;
|
|
15333
15455
|
}
|
|
@@ -15371,6 +15493,9 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
15371
15493
|
uniqueId: memory.id,
|
|
15372
15494
|
content: memory.content,
|
|
15373
15495
|
scope: memory.scope,
|
|
15496
|
+
kind: memory.kind ?? null,
|
|
15497
|
+
kindValue: memory.kindValue ?? null,
|
|
15498
|
+
level: resolveMemoryLevel(memory.level, memory.scope),
|
|
15374
15499
|
folderId: memory.folderId ?? null,
|
|
15375
15500
|
userId: memory.userId ?? null,
|
|
15376
15501
|
embedding: memory.embedding ?? null,
|
|
@@ -15409,9 +15534,13 @@ async function vaultMemoryToStored(memory, walletAddress, signMessage, embeddedW
|
|
|
15409
15534
|
}
|
|
15410
15535
|
return raw;
|
|
15411
15536
|
}
|
|
15412
|
-
function populateNewVaultMemory(record2, ctx, opts, encryptedContent) {
|
|
15537
|
+
function populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue) {
|
|
15538
|
+
const { level, scope } = resolveCreateLevel(opts);
|
|
15413
15539
|
record2._setRaw("content", encryptedContent);
|
|
15414
|
-
record2._setRaw("scope",
|
|
15540
|
+
record2._setRaw("scope", scope);
|
|
15541
|
+
record2._setRaw("level", level);
|
|
15542
|
+
record2._setRaw("kind", opts.kind ?? null);
|
|
15543
|
+
record2._setRaw("kind_value", encryptedKindValue ?? null);
|
|
15415
15544
|
record2._setRaw("folder_id", opts.folderId ?? null);
|
|
15416
15545
|
record2._setRaw("user_id", ctx.userId ?? null);
|
|
15417
15546
|
record2._setRaw("is_deleted", false);
|
|
@@ -15445,6 +15574,8 @@ function populateNewVaultMemory(record2, ctx, opts, encryptedContent) {
|
|
|
15445
15574
|
}
|
|
15446
15575
|
}
|
|
15447
15576
|
async function createVaultMemoryOp(ctx, opts) {
|
|
15577
|
+
assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
15578
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
15448
15579
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
15449
15580
|
opts.content,
|
|
15450
15581
|
ctx.walletAddress,
|
|
@@ -15455,13 +15586,15 @@ async function createVaultMemoryOp(ctx, opts) {
|
|
|
15455
15586
|
if (ctx.canWrite && !await ctx.canWrite())
|
|
15456
15587
|
throw new Error("Memory source is no longer eligible");
|
|
15457
15588
|
return ctx.vaultMemoryCollection.create(
|
|
15458
|
-
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent)
|
|
15589
|
+
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
|
|
15459
15590
|
);
|
|
15460
15591
|
});
|
|
15461
15592
|
return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
|
|
15462
15593
|
}
|
|
15463
15594
|
async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
15464
15595
|
if (!targetId) return { created: null, retired: false };
|
|
15596
|
+
assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
15597
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
15465
15598
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
15466
15599
|
opts.content,
|
|
15467
15600
|
ctx.walletAddress,
|
|
@@ -15478,9 +15611,10 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
|
|
|
15478
15611
|
} catch {
|
|
15479
15612
|
return;
|
|
15480
15613
|
}
|
|
15481
|
-
if (target.isDeleted || target.supersededBy || !isOwnedByCtxUser(ctx, target))
|
|
15614
|
+
if (target.isDeleted || target.supersededBy || isKinded(target) || !isOwnedByCtxUser(ctx, target))
|
|
15615
|
+
return;
|
|
15482
15616
|
createdRecord = await ctx.vaultMemoryCollection.create(
|
|
15483
|
-
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent)
|
|
15617
|
+
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
|
|
15484
15618
|
);
|
|
15485
15619
|
await target.update((r) => {
|
|
15486
15620
|
r._setRaw("superseded_by", createdRecord.id);
|
|
@@ -15544,6 +15678,10 @@ async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
|
|
|
15544
15678
|
}
|
|
15545
15679
|
async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
15546
15680
|
if (optionsArray.length === 0) return [];
|
|
15681
|
+
for (const opts of optionsArray) assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
|
|
15682
|
+
const encryptedKindValues = await Promise.all(
|
|
15683
|
+
optionsArray.map((opts) => encryptKindValue(ctx, opts.kindValue))
|
|
15684
|
+
);
|
|
15547
15685
|
const encryptedContents = await Promise.all(
|
|
15548
15686
|
optionsArray.map(async (opts) => {
|
|
15549
15687
|
if (ctx.walletAddress && ctx.signMessage) {
|
|
@@ -15562,7 +15700,7 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
|
|
|
15562
15700
|
throw new Error("Memory source is no longer eligible");
|
|
15563
15701
|
const prepared = optionsArray.map(
|
|
15564
15702
|
(opts, i) => ctx.vaultMemoryCollection.prepareCreate(
|
|
15565
|
-
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i])
|
|
15703
|
+
(record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i], encryptedKindValues[i])
|
|
15566
15704
|
)
|
|
15567
15705
|
);
|
|
15568
15706
|
await ctx.database.batch(...prepared);
|
|
@@ -15605,6 +15743,9 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
15605
15743
|
uniqueId: raw.id,
|
|
15606
15744
|
content: raw.content ?? "",
|
|
15607
15745
|
scope: raw.scope ?? "",
|
|
15746
|
+
kind: raw.kind ?? null,
|
|
15747
|
+
kindValue: raw.kind_value ?? null,
|
|
15748
|
+
level: resolveMemoryLevel(raw.level, raw.scope),
|
|
15608
15749
|
folderId: raw.folder_id ?? null,
|
|
15609
15750
|
userId: raw.user_id ?? null,
|
|
15610
15751
|
embedding: raw.embedding ?? null,
|
|
@@ -15648,6 +15789,8 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
15648
15789
|
...baseVaultConditions(ctx, options),
|
|
15649
15790
|
...options?.scopes?.length ? [import_watermelondb23.Q.where("scope", import_watermelondb23.Q.oneOf(options.scopes))] : [],
|
|
15650
15791
|
...visibilityConditions(options?.visibility),
|
|
15792
|
+
...levelConditions(options?.levels),
|
|
15793
|
+
...options?.kinds?.length ? [import_watermelondb23.Q.where("kind", import_watermelondb23.Q.oneOf(options.kinds))] : [],
|
|
15651
15794
|
...options?.folderId !== void 0 ? [import_watermelondb23.Q.where("folder_id", options.folderId)] : [],
|
|
15652
15795
|
...options?.factTypes?.length ? [import_watermelondb23.Q.where("fact_type", import_watermelondb23.Q.oneOf(options.factTypes))] : [],
|
|
15653
15796
|
import_watermelondb23.Q.sortBy(options?.since ? "updated_at" : "created_at", import_watermelondb23.Q.desc),
|
|
@@ -15814,6 +15957,14 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
15814
15957
|
try {
|
|
15815
15958
|
const probe = await ctx.vaultMemoryCollection.find(id);
|
|
15816
15959
|
if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
|
|
15960
|
+
if (opts.freeFormOnly && isKinded(probe)) return null;
|
|
15961
|
+
const levelAfter = (current) => {
|
|
15962
|
+
if (opts.level !== void 0) return opts.level;
|
|
15963
|
+
if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
|
|
15964
|
+
return levelForScopeChange(current, opts.scope);
|
|
15965
|
+
};
|
|
15966
|
+
assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
|
|
15967
|
+
const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
|
|
15817
15968
|
const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
|
|
15818
15969
|
opts.content,
|
|
15819
15970
|
ctx.walletAddress,
|
|
@@ -15826,10 +15977,13 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
15826
15977
|
await ctx.database.write(async () => {
|
|
15827
15978
|
if (ctx.canWrite && !await ctx.canWrite())
|
|
15828
15979
|
throw new Error("Memory source is no longer eligible");
|
|
15829
|
-
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) {
|
|
15980
|
+
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2)) {
|
|
15830
15981
|
stale = true;
|
|
15831
15982
|
return;
|
|
15832
15983
|
}
|
|
15984
|
+
const nextKind = opts.kind !== void 0 ? opts.kind : record2.kind;
|
|
15985
|
+
const nextLevel = levelAfter(record2);
|
|
15986
|
+
assertValidKindLevel(nextKind, nextLevel);
|
|
15833
15987
|
let observedSources = [];
|
|
15834
15988
|
let replayedObservation = false;
|
|
15835
15989
|
if (opts.observationSourceIds?.length) {
|
|
@@ -15843,8 +15997,18 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
15843
15997
|
}
|
|
15844
15998
|
await record2.update((r) => {
|
|
15845
15999
|
r._setRaw("content", encryptedContent);
|
|
15846
|
-
if (opts.
|
|
16000
|
+
if (opts.level !== void 0) {
|
|
16001
|
+
r._setRaw("level", nextLevel);
|
|
16002
|
+
r._setRaw("scope", scopeForLevel(nextLevel));
|
|
16003
|
+
} else if (opts.scope !== void 0) {
|
|
15847
16004
|
r._setRaw("scope", opts.scope);
|
|
16005
|
+
r._setRaw("level", nextLevel);
|
|
16006
|
+
}
|
|
16007
|
+
if (opts.kind !== void 0) {
|
|
16008
|
+
r._setRaw("kind", opts.kind);
|
|
16009
|
+
}
|
|
16010
|
+
if (encryptedKindValue !== void 0) {
|
|
16011
|
+
r._setRaw("kind_value", encryptedKindValue);
|
|
15848
16012
|
}
|
|
15849
16013
|
if (opts.folderId !== void 0) {
|
|
15850
16014
|
r._setRaw("folder_id", opts.folderId);
|
|
@@ -15903,7 +16067,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
|
|
|
15903
16067
|
ctx.signMessage,
|
|
15904
16068
|
ctx.embeddedWalletSigner
|
|
15905
16069
|
);
|
|
15906
|
-
} catch {
|
|
16070
|
+
} catch (err) {
|
|
16071
|
+
if (err instanceof MemoryLevelError) throw err;
|
|
15907
16072
|
return null;
|
|
15908
16073
|
}
|
|
15909
16074
|
}
|
|
@@ -16039,6 +16204,7 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
|
|
|
16039
16204
|
try {
|
|
16040
16205
|
const record2 = await ctx.vaultMemoryCollection.find(id);
|
|
16041
16206
|
if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) return false;
|
|
16207
|
+
if (isKinded(record2)) return false;
|
|
16042
16208
|
let successor;
|
|
16043
16209
|
try {
|
|
16044
16210
|
successor = await ctx.vaultMemoryCollection.find(supersededById);
|
|
@@ -16339,7 +16505,10 @@ function assertVaultScopeForSweep(ctx) {
|
|
|
16339
16505
|
}
|
|
16340
16506
|
async function getDecayCandidatesRawOp(ctx) {
|
|
16341
16507
|
assertVaultScopeForSweep(ctx);
|
|
16342
|
-
const results = await ctx.vaultMemoryCollection.query(
|
|
16508
|
+
const results = await ctx.vaultMemoryCollection.query(
|
|
16509
|
+
...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
|
|
16510
|
+
import_watermelondb23.Q.where("kind", null)
|
|
16511
|
+
).unsafeFetchRaw();
|
|
16343
16512
|
return results.map((raw) => ({
|
|
16344
16513
|
uniqueId: raw.id,
|
|
16345
16514
|
factType: raw.fact_type ?? null,
|
|
@@ -16600,6 +16769,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
|
16600
16769
|
record2._raw.id = row.memoryId;
|
|
16601
16770
|
record2._setRaw("content", content);
|
|
16602
16771
|
record2._setRaw("scope", "shared");
|
|
16772
|
+
record2._setRaw("level", "matching");
|
|
16603
16773
|
record2._setRaw("folder_id", null);
|
|
16604
16774
|
record2._setRaw("user_id", ctx.userId ?? null);
|
|
16605
16775
|
record2._setRaw("is_deleted", false);
|
|
@@ -17466,6 +17636,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
|
|
|
17466
17636
|
for (const memory of memories) {
|
|
17467
17637
|
updates.push(
|
|
17468
17638
|
memory.prepareUpdate((r) => {
|
|
17639
|
+
r._setRaw("level", levelForScopeChange(r, opts.scope));
|
|
17469
17640
|
r._setRaw("scope", opts.scope);
|
|
17470
17641
|
})
|
|
17471
17642
|
);
|
|
@@ -17487,6 +17658,7 @@ async function deleteVaultFolderOp(ctx, id) {
|
|
|
17487
17658
|
const preparedMemories = memories.map(
|
|
17488
17659
|
(memory) => memory.prepareUpdate((r) => {
|
|
17489
17660
|
r._setRaw("folder_id", null);
|
|
17661
|
+
r._setRaw("level", levelForScopeChange(r, "private"));
|
|
17490
17662
|
r._setRaw("scope", "private");
|
|
17491
17663
|
})
|
|
17492
17664
|
);
|
|
@@ -17523,6 +17695,7 @@ async function moveMemoriesToFolderOp(ctx, memoryIds, folderId) {
|
|
|
17523
17695
|
const prepared = memories.map(
|
|
17524
17696
|
(memory) => memory.prepareUpdate((r) => {
|
|
17525
17697
|
r._setRaw("folder_id", folderId);
|
|
17698
|
+
r._setRaw("level", levelForScopeChange(r, targetScope));
|
|
17526
17699
|
r._setRaw("scope", targetScope);
|
|
17527
17700
|
})
|
|
17528
17701
|
);
|
|
@@ -19855,6 +20028,7 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
19855
20028
|
includeArchived: true,
|
|
19856
20029
|
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
19857
20030
|
});
|
|
20031
|
+
prepared = withoutKindedRows(prepared);
|
|
19858
20032
|
if (prepared.embeddingFailure || prepared.embeddingsUnavailable) {
|
|
19859
20033
|
throw new Error(
|
|
19860
20034
|
"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."
|
|
@@ -19896,6 +20070,7 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
19896
20070
|
const resurrect = resurrectFields(existing);
|
|
19897
20071
|
const updated = await ctx.persistence.update(targetId, {
|
|
19898
20072
|
content: existing.content,
|
|
20073
|
+
freeFormOnly: true,
|
|
19899
20074
|
proofCountIncrement: 1,
|
|
19900
20075
|
observationSourceIds: options.sourceChunkIds,
|
|
19901
20076
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -20024,6 +20199,17 @@ async function retainWithPersistence(content, ctx, options = {}) {
|
|
|
20024
20199
|
...consolidationDecidedCreate && { consolidation: "create" }
|
|
20025
20200
|
};
|
|
20026
20201
|
}
|
|
20202
|
+
function withoutKindedRows(prepared) {
|
|
20203
|
+
const kinded = new Set(
|
|
20204
|
+
prepared.memories.filter((m) => m.kind !== null && m.kind !== void 0).map((m) => m.uniqueId)
|
|
20205
|
+
);
|
|
20206
|
+
if (kinded.size === 0) return prepared;
|
|
20207
|
+
return {
|
|
20208
|
+
...prepared,
|
|
20209
|
+
memories: prepared.memories.filter((m) => !kinded.has(m.uniqueId)),
|
|
20210
|
+
embeddedItems: prepared.embeddedItems.filter((item) => !kinded.has(item.id))
|
|
20211
|
+
};
|
|
20212
|
+
}
|
|
20027
20213
|
function unionStrings(a, b) {
|
|
20028
20214
|
return [.../* @__PURE__ */ new Set([...a, ...b])];
|
|
20029
20215
|
}
|
|
@@ -20123,6 +20309,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
20123
20309
|
const resurrect = resurrectFields(existing);
|
|
20124
20310
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
20125
20311
|
content: existing.content,
|
|
20312
|
+
freeFormOnly: true,
|
|
20126
20313
|
proofCountIncrement: 1,
|
|
20127
20314
|
observationSourceIds: options.sourceChunkIds,
|
|
20128
20315
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -20168,6 +20355,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
20168
20355
|
const resurrect = resurrectFields(existing);
|
|
20169
20356
|
const updated = await ctx.persistence.update(decision.targetId, {
|
|
20170
20357
|
content: decision.content,
|
|
20358
|
+
freeFormOnly: true,
|
|
20171
20359
|
proofCountIncrement: 1,
|
|
20172
20360
|
observationSourceIds: options.sourceChunkIds,
|
|
20173
20361
|
sourceChunkIds: mergedSourceIds,
|
|
@@ -20211,7 +20399,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
20211
20399
|
}
|
|
20212
20400
|
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
20213
20401
|
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
20214
|
-
if (stillExists) {
|
|
20402
|
+
if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
|
|
20215
20403
|
throw new Error(`retain: merge into memory ${targetId} failed to persist`);
|
|
20216
20404
|
}
|
|
20217
20405
|
}
|
|
@@ -23285,6 +23473,9 @@ function sourceIds(value) {
|
|
|
23285
23473
|
return [];
|
|
23286
23474
|
}
|
|
23287
23475
|
}
|
|
23476
|
+
function isMemoryLevel(value) {
|
|
23477
|
+
return MEMORY_LEVELS.includes(value);
|
|
23478
|
+
}
|
|
23288
23479
|
function stored(row) {
|
|
23289
23480
|
return {
|
|
23290
23481
|
uniqueId: row.memory_id,
|
|
@@ -23292,6 +23483,9 @@ function stored(row) {
|
|
|
23292
23483
|
scope: row.scope,
|
|
23293
23484
|
folderId: row.folder_id ?? null,
|
|
23294
23485
|
userId: null,
|
|
23486
|
+
kind: row.kind ?? null,
|
|
23487
|
+
kindValue: row.kind_value ?? null,
|
|
23488
|
+
...isMemoryLevel(row.level) && { level: row.level },
|
|
23295
23489
|
embedding: row.embedding ? JSON.stringify(row.embedding) : null,
|
|
23296
23490
|
embeddingModel: row.embedding_model ?? null,
|
|
23297
23491
|
sourceChunkIds: row.source_chunk_ids === void 0 ? null : sourceIds(row.source_chunk_ids),
|
|
@@ -23513,7 +23707,8 @@ function createRemoteMemoryPipeline(options) {
|
|
|
23513
23707
|
create: (input) => write(createRow(input), 0),
|
|
23514
23708
|
update: async (id, patch) => {
|
|
23515
23709
|
const existing = await get(id);
|
|
23516
|
-
if (!existing
|
|
23710
|
+
if (!existing || patch.freeFormOnly && existing.kind !== null && existing.kind !== void 0)
|
|
23711
|
+
return null;
|
|
23517
23712
|
const snapshot = snapshots.get(id);
|
|
23518
23713
|
const memory = {
|
|
23519
23714
|
...snapshot.memory,
|
|
@@ -37621,7 +37816,10 @@ function useWalletBinding(options = {}) {
|
|
|
37621
37816
|
LoggerProvider,
|
|
37622
37817
|
MAX_HOPS,
|
|
37623
37818
|
MEDIUM_TTL_MS,
|
|
37819
|
+
MEMORY_KINDS,
|
|
37820
|
+
MEMORY_LEVELS,
|
|
37624
37821
|
MemoryEntityModel,
|
|
37822
|
+
MemoryLevelError,
|
|
37625
37823
|
NEVER_TTL_MS,
|
|
37626
37824
|
NODE_BUDGET,
|
|
37627
37825
|
PAST_EVENT_GRACE_MS,
|