@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.
@@ -11318,6 +11318,15 @@ __decorateClass([
11318
11318
  __decorateClass([
11319
11319
  text6("scope")
11320
11320
  ], VaultMemory.prototype, "scope", 2);
11321
+ __decorateClass([
11322
+ field5("kind")
11323
+ ], VaultMemory.prototype, "kind", 2);
11324
+ __decorateClass([
11325
+ field5("kind_value")
11326
+ ], VaultMemory.prototype, "kindValue", 2);
11327
+ __decorateClass([
11328
+ field5("level")
11329
+ ], VaultMemory.prototype, "level", 2);
11321
11330
  __decorateClass([
11322
11331
  field5("folder_id")
11323
11332
  ], VaultMemory.prototype, "folderId", 2);
@@ -11543,7 +11552,7 @@ __decorateClass([
11543
11552
  ], VaultFolder.prototype, "context", 2);
11544
11553
 
11545
11554
  // src/lib/db/schema.ts
11546
- var SDK_SCHEMA_VERSION = 47;
11555
+ var SDK_SCHEMA_VERSION = 48;
11547
11556
  var sdkSchema = appSchema2({
11548
11557
  version: SDK_SCHEMA_VERSION,
11549
11558
  tables: [
@@ -11638,6 +11647,9 @@ var sdkSchema = appSchema2({
11638
11647
  columns: [
11639
11648
  { name: "content", type: "string" },
11640
11649
  { name: "scope", type: "string", isIndexed: true },
11650
+ { name: "kind", type: "string", isOptional: true, isIndexed: true },
11651
+ { name: "kind_value", type: "string", isOptional: true },
11652
+ { name: "level", type: "string", isOptional: true, isIndexed: true },
11641
11653
  { name: "folder_id", type: "string", isOptional: true, isIndexed: true },
11642
11654
  { name: "created_at", type: "number", isIndexed: true },
11643
11655
  { name: "updated_at", type: "number", isIndexed: true },
@@ -12314,6 +12326,22 @@ var sdkMigrations = schemaMigrations2({
12314
12326
  ]
12315
12327
  })
12316
12328
  ]
12329
+ },
12330
+ {
12331
+ toVersion: 48,
12332
+ steps: [
12333
+ addColumns2({
12334
+ table: "memory_vault",
12335
+ columns: [
12336
+ { name: "kind", type: "string", isOptional: true, isIndexed: true },
12337
+ { name: "kind_value", type: "string", isOptional: true },
12338
+ { name: "level", type: "string", isOptional: true, isIndexed: true }
12339
+ ]
12340
+ }),
12341
+ unsafeExecuteSql(
12342
+ "UPDATE memory_vault SET level = CASE WHEN scope IN ('shared', 'public') THEN 'matching' ELSE 'private' END WHERE level IS NULL;"
12343
+ )
12344
+ ]
12317
12345
  }
12318
12346
  ]
12319
12347
  });
@@ -13450,13 +13478,54 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
13450
13478
  }
13451
13479
  }
13452
13480
  const decryptedContent = await decryptField(memory.content, address);
13481
+ const decryptedKindValue = typeof memory.kindValue === "string" ? await decryptField(memory.kindValue, address) : memory.kindValue;
13453
13482
  return {
13454
13483
  ...memory,
13455
- content: decryptedContent
13484
+ content: decryptedContent,
13485
+ ...decryptedKindValue !== void 0 && { kindValue: decryptedKindValue }
13456
13486
  };
13457
13487
  }
13458
13488
 
13459
13489
  // src/lib/db/memoryVault/types.ts
13490
+ var MEMORY_KINDS = [
13491
+ "display_name",
13492
+ "birth_date",
13493
+ "bio",
13494
+ "occupation",
13495
+ "interest",
13496
+ "gender",
13497
+ "height_cm",
13498
+ "looking_for",
13499
+ "politics",
13500
+ "religion",
13501
+ "ethnicity",
13502
+ "smoking",
13503
+ "drinking",
13504
+ "exercise",
13505
+ "sexuality",
13506
+ "prompt"
13507
+ ];
13508
+ var MEMORY_LEVELS = ["private", "matching", "profile"];
13509
+ var MemoryLevelError = class extends Error {
13510
+ constructor(message) {
13511
+ super(message);
13512
+ this.name = "MemoryLevelError";
13513
+ }
13514
+ };
13515
+ var PUBLISHED_SCOPES = /* @__PURE__ */ new Set(["shared", "public"]);
13516
+ function levelFromScope(scope) {
13517
+ return typeof scope === "string" && PUBLISHED_SCOPES.has(scope) ? "matching" : "private";
13518
+ }
13519
+ function scopeForLevel(level) {
13520
+ return level === "private" ? "private" : "shared";
13521
+ }
13522
+ function resolveMemoryLevel(level, scope) {
13523
+ return typeof level === "string" && MEMORY_LEVELS.includes(level) ? level : levelFromScope(scope);
13524
+ }
13525
+ function levelForScopeChange(current, nextScope) {
13526
+ const implied = levelFromScope(nextScope);
13527
+ return implied === "matching" && resolveMemoryLevel(current.level, current.scope) === "profile" ? "profile" : implied;
13528
+ }
13460
13529
  function parseMedia(value) {
13461
13530
  if (typeof value !== "string" || value === "") return null;
13462
13531
  try {
@@ -13486,6 +13555,56 @@ function visibilityConditions(requested) {
13486
13555
  if (excluded.length === 0) return [];
13487
13556
  return [Q8.or(Q8.where("visibility", null), Q8.where("visibility", Q8.notIn(excluded)))];
13488
13557
  }
13558
+ function isKinded(record2) {
13559
+ return record2.kind !== null && record2.kind !== void 0;
13560
+ }
13561
+ function assertValidKindLevel(kind, level) {
13562
+ const hasKind = kind !== null && kind !== void 0;
13563
+ if (hasKind && !MEMORY_KINDS.includes(kind)) {
13564
+ throw new MemoryLevelError(`Unknown memory kind: ${kind}`);
13565
+ }
13566
+ if (level !== void 0 && !MEMORY_LEVELS.includes(level)) {
13567
+ throw new MemoryLevelError(`Unknown memory level: ${level}`);
13568
+ }
13569
+ if (level === "profile" && !hasKind) {
13570
+ throw new MemoryLevelError("Only a memory with a kind can be at level 'profile'");
13571
+ }
13572
+ }
13573
+ function resolveCreateLevel(opts) {
13574
+ if (opts.level !== void 0) return { level: opts.level, scope: scopeForLevel(opts.level) };
13575
+ if (opts.scope !== void 0) return { level: levelFromScope(opts.scope), scope: opts.scope };
13576
+ return { level: "private", scope: "private" };
13577
+ }
13578
+ async function encryptKindValue(ctx, value) {
13579
+ if (typeof value !== "string" || !ctx.walletAddress || !ctx.signMessage) return value;
13580
+ return encryptVaultMemoryContent(
13581
+ value,
13582
+ ctx.walletAddress,
13583
+ ctx.signMessage,
13584
+ ctx.embeddedWalletSigner
13585
+ );
13586
+ }
13587
+ function levelConditions(requested) {
13588
+ if (!requested?.length) return [];
13589
+ const published = ["shared", "public"];
13590
+ const wantsMatching = requested.includes("matching");
13591
+ const wantsPrivate = requested.includes("private");
13592
+ const unresolved = Q8.or(Q8.where("level", null), Q8.where("level", Q8.notIn([...MEMORY_LEVELS])));
13593
+ const byLevel = Q8.where("level", Q8.oneOf([...requested]));
13594
+ if (wantsMatching && wantsPrivate) return [Q8.or(byLevel, unresolved)];
13595
+ if (wantsMatching) {
13596
+ return [Q8.or(byLevel, Q8.and(unresolved, Q8.where("scope", Q8.oneOf(published))))];
13597
+ }
13598
+ if (wantsPrivate) {
13599
+ return [
13600
+ Q8.or(
13601
+ byLevel,
13602
+ Q8.and(unresolved, Q8.or(Q8.where("scope", null), Q8.where("scope", Q8.notIn(published))))
13603
+ )
13604
+ ];
13605
+ }
13606
+ return [byLevel];
13607
+ }
13489
13608
  function isOwnedByCtxUser(ctx, record2) {
13490
13609
  return ctx.userId === void 0 || record2.userId === ctx.userId;
13491
13610
  }
@@ -13529,6 +13648,9 @@ function vaultMemoryToStoredRaw(memory) {
13529
13648
  uniqueId: memory.id,
13530
13649
  content: memory.content,
13531
13650
  scope: memory.scope,
13651
+ kind: memory.kind ?? null,
13652
+ kindValue: memory.kindValue ?? null,
13653
+ level: resolveMemoryLevel(memory.level, memory.scope),
13532
13654
  folderId: memory.folderId ?? null,
13533
13655
  userId: memory.userId ?? null,
13534
13656
  embedding: memory.embedding ?? null,
@@ -13567,9 +13689,13 @@ async function vaultMemoryToStored(memory, walletAddress, signMessage, embeddedW
13567
13689
  }
13568
13690
  return raw;
13569
13691
  }
13570
- function populateNewVaultMemory(record2, ctx, opts, encryptedContent) {
13692
+ function populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue) {
13693
+ const { level, scope } = resolveCreateLevel(opts);
13571
13694
  record2._setRaw("content", encryptedContent);
13572
- record2._setRaw("scope", opts.scope ?? "private");
13695
+ record2._setRaw("scope", scope);
13696
+ record2._setRaw("level", level);
13697
+ record2._setRaw("kind", opts.kind ?? null);
13698
+ record2._setRaw("kind_value", encryptedKindValue ?? null);
13573
13699
  record2._setRaw("folder_id", opts.folderId ?? null);
13574
13700
  record2._setRaw("user_id", ctx.userId ?? null);
13575
13701
  record2._setRaw("is_deleted", false);
@@ -13603,6 +13729,8 @@ function populateNewVaultMemory(record2, ctx, opts, encryptedContent) {
13603
13729
  }
13604
13730
  }
13605
13731
  async function createVaultMemoryOp(ctx, opts) {
13732
+ assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
13733
+ const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
13606
13734
  const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
13607
13735
  opts.content,
13608
13736
  ctx.walletAddress,
@@ -13613,13 +13741,15 @@ async function createVaultMemoryOp(ctx, opts) {
13613
13741
  if (ctx.canWrite && !await ctx.canWrite())
13614
13742
  throw new Error("Memory source is no longer eligible");
13615
13743
  return ctx.vaultMemoryCollection.create(
13616
- (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent)
13744
+ (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
13617
13745
  );
13618
13746
  });
13619
13747
  return vaultMemoryToStored(created, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
13620
13748
  }
13621
13749
  async function createSupersedingMemoryOp(ctx, opts, targetId) {
13622
13750
  if (!targetId) return { created: null, retired: false };
13751
+ assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
13752
+ const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
13623
13753
  const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
13624
13754
  opts.content,
13625
13755
  ctx.walletAddress,
@@ -13636,9 +13766,10 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
13636
13766
  } catch {
13637
13767
  return;
13638
13768
  }
13639
- if (target.isDeleted || target.supersededBy || !isOwnedByCtxUser(ctx, target)) return;
13769
+ if (target.isDeleted || target.supersededBy || isKinded(target) || !isOwnedByCtxUser(ctx, target))
13770
+ return;
13640
13771
  createdRecord = await ctx.vaultMemoryCollection.create(
13641
- (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent)
13772
+ (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContent, encryptedKindValue)
13642
13773
  );
13643
13774
  await target.update((r) => {
13644
13775
  r._setRaw("superseded_by", createdRecord.id);
@@ -13702,6 +13833,10 @@ async function getMemoriesByEventTimeOp(ctx, windowStart, windowEnd) {
13702
13833
  }
13703
13834
  async function createVaultMemoriesBatchOp(ctx, optionsArray) {
13704
13835
  if (optionsArray.length === 0) return [];
13836
+ for (const opts of optionsArray) assertValidKindLevel(opts.kind, resolveCreateLevel(opts).level);
13837
+ const encryptedKindValues = await Promise.all(
13838
+ optionsArray.map((opts) => encryptKindValue(ctx, opts.kindValue))
13839
+ );
13705
13840
  const encryptedContents = await Promise.all(
13706
13841
  optionsArray.map(async (opts) => {
13707
13842
  if (ctx.walletAddress && ctx.signMessage) {
@@ -13720,7 +13855,7 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
13720
13855
  throw new Error("Memory source is no longer eligible");
13721
13856
  const prepared = optionsArray.map(
13722
13857
  (opts, i) => ctx.vaultMemoryCollection.prepareCreate(
13723
- (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i])
13858
+ (record2) => populateNewVaultMemory(record2, ctx, opts, encryptedContents[i], encryptedKindValues[i])
13724
13859
  )
13725
13860
  );
13726
13861
  await ctx.database.batch(...prepared);
@@ -13763,6 +13898,9 @@ function vaultMemoryRawToStoredRaw(raw) {
13763
13898
  uniqueId: raw.id,
13764
13899
  content: raw.content ?? "",
13765
13900
  scope: raw.scope ?? "",
13901
+ kind: raw.kind ?? null,
13902
+ kindValue: raw.kind_value ?? null,
13903
+ level: resolveMemoryLevel(raw.level, raw.scope),
13766
13904
  folderId: raw.folder_id ?? null,
13767
13905
  userId: raw.user_id ?? null,
13768
13906
  embedding: raw.embedding ?? null,
@@ -13806,6 +13944,8 @@ async function getAllVaultMemoriesOp(ctx, options) {
13806
13944
  ...baseVaultConditions(ctx, options),
13807
13945
  ...options?.scopes?.length ? [Q8.where("scope", Q8.oneOf(options.scopes))] : [],
13808
13946
  ...visibilityConditions(options?.visibility),
13947
+ ...levelConditions(options?.levels),
13948
+ ...options?.kinds?.length ? [Q8.where("kind", Q8.oneOf(options.kinds))] : [],
13809
13949
  ...options?.folderId !== void 0 ? [Q8.where("folder_id", options.folderId)] : [],
13810
13950
  ...options?.factTypes?.length ? [Q8.where("fact_type", Q8.oneOf(options.factTypes))] : [],
13811
13951
  Q8.sortBy(options?.since ? "updated_at" : "created_at", Q8.desc),
@@ -13972,6 +14112,14 @@ async function updateVaultMemoryOp(ctx, id, opts) {
13972
14112
  try {
13973
14113
  const probe = await ctx.vaultMemoryCollection.find(id);
13974
14114
  if (probe.isDeleted || probe.supersededBy || !isOwnedByCtxUser(ctx, probe)) return null;
14115
+ if (opts.freeFormOnly && isKinded(probe)) return null;
14116
+ const levelAfter = (current) => {
14117
+ if (opts.level !== void 0) return opts.level;
14118
+ if (opts.scope === void 0) return resolveMemoryLevel(current.level, current.scope);
14119
+ return levelForScopeChange(current, opts.scope);
14120
+ };
14121
+ assertValidKindLevel(opts.kind !== void 0 ? opts.kind : probe.kind, levelAfter(probe));
14122
+ const encryptedKindValue = await encryptKindValue(ctx, opts.kindValue);
13975
14123
  const encryptedContent = ctx.walletAddress && ctx.signMessage ? await encryptVaultMemoryContent(
13976
14124
  opts.content,
13977
14125
  ctx.walletAddress,
@@ -13984,10 +14132,13 @@ async function updateVaultMemoryOp(ctx, id, opts) {
13984
14132
  await ctx.database.write(async () => {
13985
14133
  if (ctx.canWrite && !await ctx.canWrite())
13986
14134
  throw new Error("Memory source is no longer eligible");
13987
- if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) {
14135
+ if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2) || opts.freeFormOnly && isKinded(record2)) {
13988
14136
  stale = true;
13989
14137
  return;
13990
14138
  }
14139
+ const nextKind = opts.kind !== void 0 ? opts.kind : record2.kind;
14140
+ const nextLevel = levelAfter(record2);
14141
+ assertValidKindLevel(nextKind, nextLevel);
13991
14142
  let observedSources = [];
13992
14143
  let replayedObservation = false;
13993
14144
  if (opts.observationSourceIds?.length) {
@@ -14001,8 +14152,18 @@ async function updateVaultMemoryOp(ctx, id, opts) {
14001
14152
  }
14002
14153
  await record2.update((r) => {
14003
14154
  r._setRaw("content", encryptedContent);
14004
- if (opts.scope !== void 0) {
14155
+ if (opts.level !== void 0) {
14156
+ r._setRaw("level", nextLevel);
14157
+ r._setRaw("scope", scopeForLevel(nextLevel));
14158
+ } else if (opts.scope !== void 0) {
14005
14159
  r._setRaw("scope", opts.scope);
14160
+ r._setRaw("level", nextLevel);
14161
+ }
14162
+ if (opts.kind !== void 0) {
14163
+ r._setRaw("kind", opts.kind);
14164
+ }
14165
+ if (encryptedKindValue !== void 0) {
14166
+ r._setRaw("kind_value", encryptedKindValue);
14006
14167
  }
14007
14168
  if (opts.folderId !== void 0) {
14008
14169
  r._setRaw("folder_id", opts.folderId);
@@ -14061,7 +14222,8 @@ async function updateVaultMemoryOp(ctx, id, opts) {
14061
14222
  ctx.signMessage,
14062
14223
  ctx.embeddedWalletSigner
14063
14224
  );
14064
- } catch {
14225
+ } catch (err) {
14226
+ if (err instanceof MemoryLevelError) throw err;
14065
14227
  return null;
14066
14228
  }
14067
14229
  }
@@ -14197,6 +14359,7 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
14197
14359
  try {
14198
14360
  const record2 = await ctx.vaultMemoryCollection.find(id);
14199
14361
  if (record2.isDeleted || record2.supersededBy || !isOwnedByCtxUser(ctx, record2)) return false;
14362
+ if (isKinded(record2)) return false;
14200
14363
  let successor;
14201
14364
  try {
14202
14365
  successor = await ctx.vaultMemoryCollection.find(supersededById);
@@ -14497,7 +14660,10 @@ function assertVaultScopeForSweep(ctx) {
14497
14660
  }
14498
14661
  async function getDecayCandidatesRawOp(ctx) {
14499
14662
  assertVaultScopeForSweep(ctx);
14500
- const results = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true })).unsafeFetchRaw();
14663
+ const results = await ctx.vaultMemoryCollection.query(
14664
+ ...baseVaultConditions(ctx, { includeArchived: true, includeQuarantined: true }),
14665
+ Q8.where("kind", null)
14666
+ ).unsafeFetchRaw();
14501
14667
  return results.map((raw) => ({
14502
14668
  uniqueId: raw.id,
14503
14669
  factType: raw.fact_type ?? null,
@@ -14757,6 +14923,7 @@ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
14757
14923
  record2._raw.id = row.memoryId;
14758
14924
  record2._setRaw("content", content);
14759
14925
  record2._setRaw("scope", "shared");
14926
+ record2._setRaw("level", "matching");
14760
14927
  record2._setRaw("folder_id", null);
14761
14928
  record2._setRaw("user_id", ctx.userId ?? null);
14762
14929
  record2._setRaw("is_deleted", false);
@@ -15622,6 +15789,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
15622
15789
  for (const memory of memories) {
15623
15790
  updates.push(
15624
15791
  memory.prepareUpdate((r) => {
15792
+ r._setRaw("level", levelForScopeChange(r, opts.scope));
15625
15793
  r._setRaw("scope", opts.scope);
15626
15794
  })
15627
15795
  );
@@ -15643,6 +15811,7 @@ async function deleteVaultFolderOp(ctx, id) {
15643
15811
  const preparedMemories = memories.map(
15644
15812
  (memory) => memory.prepareUpdate((r) => {
15645
15813
  r._setRaw("folder_id", null);
15814
+ r._setRaw("level", levelForScopeChange(r, "private"));
15646
15815
  r._setRaw("scope", "private");
15647
15816
  })
15648
15817
  );
@@ -15679,6 +15848,7 @@ async function moveMemoriesToFolderOp(ctx, memoryIds, folderId) {
15679
15848
  const prepared = memories.map(
15680
15849
  (memory) => memory.prepareUpdate((r) => {
15681
15850
  r._setRaw("folder_id", folderId);
15851
+ r._setRaw("level", levelForScopeChange(r, targetScope));
15682
15852
  r._setRaw("scope", targetScope);
15683
15853
  })
15684
15854
  );
@@ -17986,6 +18156,7 @@ async function retainWithPersistence(content, ctx, options = {}) {
17986
18156
  includeArchived: true,
17987
18157
  ...options.folderId !== void 0 && { folderId: options.folderId }
17988
18158
  });
18159
+ prepared = withoutKindedRows(prepared);
17989
18160
  if (prepared.embeddingFailure || prepared.embeddingsUnavailable) {
17990
18161
  throw new Error(
17991
18162
  "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."
@@ -18027,6 +18198,7 @@ async function retainWithPersistence(content, ctx, options = {}) {
18027
18198
  const resurrect = resurrectFields(existing);
18028
18199
  const updated = await ctx.persistence.update(targetId, {
18029
18200
  content: existing.content,
18201
+ freeFormOnly: true,
18030
18202
  proofCountIncrement: 1,
18031
18203
  observationSourceIds: options.sourceChunkIds,
18032
18204
  sourceChunkIds: mergedSourceIds,
@@ -18155,6 +18327,17 @@ async function retainWithPersistence(content, ctx, options = {}) {
18155
18327
  ...consolidationDecidedCreate && { consolidation: "create" }
18156
18328
  };
18157
18329
  }
18330
+ function withoutKindedRows(prepared) {
18331
+ const kinded = new Set(
18332
+ prepared.memories.filter((m) => m.kind !== null && m.kind !== void 0).map((m) => m.uniqueId)
18333
+ );
18334
+ if (kinded.size === 0) return prepared;
18335
+ return {
18336
+ ...prepared,
18337
+ memories: prepared.memories.filter((m) => !kinded.has(m.uniqueId)),
18338
+ embeddedItems: prepared.embeddedItems.filter((item) => !kinded.has(item.id))
18339
+ };
18340
+ }
18158
18341
  function unionStrings(a, b) {
18159
18342
  return [.../* @__PURE__ */ new Set([...a, ...b])];
18160
18343
  }
@@ -18254,6 +18437,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
18254
18437
  const resurrect = resurrectFields(existing);
18255
18438
  const updated = await ctx.persistence.update(decision.targetId, {
18256
18439
  content: existing.content,
18440
+ freeFormOnly: true,
18257
18441
  proofCountIncrement: 1,
18258
18442
  observationSourceIds: options.sourceChunkIds,
18259
18443
  sourceChunkIds: mergedSourceIds,
@@ -18299,6 +18483,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
18299
18483
  const resurrect = resurrectFields(existing);
18300
18484
  const updated = await ctx.persistence.update(decision.targetId, {
18301
18485
  content: decision.content,
18486
+ freeFormOnly: true,
18302
18487
  proofCountIncrement: 1,
18303
18488
  observationSourceIds: options.sourceChunkIds,
18304
18489
  sourceChunkIds: mergedSourceIds,
@@ -18342,7 +18527,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
18342
18527
  }
18343
18528
  async function assertMergeTargetGoneOrThrow(ctx, targetId) {
18344
18529
  const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
18345
- if (stillExists) {
18530
+ if (stillExists && (stillExists.kind === null || stillExists.kind === void 0)) {
18346
18531
  throw new Error(`retain: merge into memory ${targetId} failed to persist`);
18347
18532
  }
18348
18533
  }
@@ -21394,6 +21579,9 @@ function sourceIds(value) {
21394
21579
  return [];
21395
21580
  }
21396
21581
  }
21582
+ function isMemoryLevel(value) {
21583
+ return MEMORY_LEVELS.includes(value);
21584
+ }
21397
21585
  function stored(row) {
21398
21586
  return {
21399
21587
  uniqueId: row.memory_id,
@@ -21401,6 +21589,9 @@ function stored(row) {
21401
21589
  scope: row.scope,
21402
21590
  folderId: row.folder_id ?? null,
21403
21591
  userId: null,
21592
+ kind: row.kind ?? null,
21593
+ kindValue: row.kind_value ?? null,
21594
+ ...isMemoryLevel(row.level) && { level: row.level },
21404
21595
  embedding: row.embedding ? JSON.stringify(row.embedding) : null,
21405
21596
  embeddingModel: row.embedding_model ?? null,
21406
21597
  sourceChunkIds: row.source_chunk_ids === void 0 ? null : sourceIds(row.source_chunk_ids),
@@ -21622,7 +21813,8 @@ function createRemoteMemoryPipeline(options) {
21622
21813
  create: (input) => write(createRow(input), 0),
21623
21814
  update: async (id, patch) => {
21624
21815
  const existing = await get(id);
21625
- if (!existing) return null;
21816
+ if (!existing || patch.freeFormOnly && existing.kind !== null && existing.kind !== void 0)
21817
+ return null;
21626
21818
  const snapshot = snapshots.get(id);
21627
21819
  const memory = {
21628
21820
  ...snapshot.memory,
@@ -35729,7 +35921,10 @@ export {
35729
35921
  LoggerProvider,
35730
35922
  MAX_HOPS,
35731
35923
  MEDIUM_TTL_MS,
35924
+ MEMORY_KINDS,
35925
+ MEMORY_LEVELS,
35732
35926
  MemoryEntity as MemoryEntityModel,
35927
+ MemoryLevelError,
35733
35928
  NEVER_TTL_MS,
35734
35929
  NODE_BUDGET,
35735
35930
  PAST_EVENT_GRACE_MS,