@anuma/sdk 1.1.0 → 1.1.2

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.
@@ -12343,7 +12343,7 @@ var require_Query = __commonJS({
12343
12343
  var _subscribeToCount = _interopRequireDefault(require_subscribeToCount());
12344
12344
  var _subscribeToQuery = _interopRequireDefault(require_subscribeToQuery());
12345
12345
  var _subscribeToQueryWithColumns = _interopRequireDefault(require_subscribeToQueryWithColumns());
12346
- var Q10 = _interopRequireWildcard(require_QueryDescription());
12346
+ var Q11 = _interopRequireWildcard(require_QueryDescription());
12347
12347
  var _helpers = require_helpers2();
12348
12348
  var _class;
12349
12349
  var _descriptor;
@@ -12375,8 +12375,8 @@ var require_Query = __commonJS({
12375
12375
  (0, _initializerDefineProperty2.default)(this, "_cachedCountSubscribable", _descriptor2, this);
12376
12376
  (0, _initializerDefineProperty2.default)(this, "_cachedCountThrottledSubscribable", _descriptor3, this);
12377
12377
  this.collection = collection;
12378
- this._rawDescription = Q10.buildQueryDescription(clauses);
12379
- this.description = Q10.queryWithoutDeleted(this._rawDescription);
12378
+ this._rawDescription = Q11.buildQueryDescription(clauses);
12379
+ this.description = Q11.queryWithoutDeleted(this._rawDescription);
12380
12380
  }
12381
12381
  var _proto = Query2.prototype;
12382
12382
  _proto.extend = function(...args) {
@@ -12395,12 +12395,12 @@ var require_Query = __commonJS({
12395
12395
  sql
12396
12396
  } = this._rawDescription;
12397
12397
  (0, _invariant.default)(!sql, "Cannot extend an unsafe SQL query");
12398
- return new Query2(collection, [Q10.experimentalJoinTables(joinTables)].concat((0, _toConsumableArray2.default)(nestedJoinTables.map(function({
12398
+ return new Query2(collection, [Q11.experimentalJoinTables(joinTables)].concat((0, _toConsumableArray2.default)(nestedJoinTables.map(function({
12399
12399
  from,
12400
12400
  to
12401
12401
  }) {
12402
- return Q10.experimentalNestedJoin(from, to);
12403
- })), (0, _toConsumableArray2.default)(where), (0, _toConsumableArray2.default)(sortBy), (0, _toConsumableArray2.default)(take ? [Q10.take(take)] : []), (0, _toConsumableArray2.default)(skip ? [Q10.skip(skip)] : []), (0, _toConsumableArray2.default)(lokiTransform ? [Q10.unsafeLokiTransform(lokiTransform)] : []), (0, _toConsumableArray2.default)(clauses)));
12402
+ return Q11.experimentalNestedJoin(from, to);
12403
+ })), (0, _toConsumableArray2.default)(where), (0, _toConsumableArray2.default)(sortBy), (0, _toConsumableArray2.default)(take ? [Q11.take(take)] : []), (0, _toConsumableArray2.default)(skip ? [Q11.skip(skip)] : []), (0, _toConsumableArray2.default)(lokiTransform ? [Q11.unsafeLokiTransform(lokiTransform)] : []), (0, _toConsumableArray2.default)(clauses)));
12404
12404
  };
12405
12405
  _proto.pipe = function(transform) {
12406
12406
  return transform(this);
@@ -13842,7 +13842,7 @@ var require_helpers5 = __commonJS({
13842
13842
  exports2.createTimestampsFor = void 0;
13843
13843
  exports2.fetchDescendants = fetchDescendants;
13844
13844
  var _fp = require_fp();
13845
- var Q10 = _interopRequireWildcard(require_QueryDescription());
13845
+ var Q11 = _interopRequireWildcard(require_QueryDescription());
13846
13846
  function _getRequireWildcardCache(e) {
13847
13847
  if ("function" != typeof WeakMap) return null;
13848
13848
  var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
@@ -13880,7 +13880,7 @@ var require_helpers5 = __commonJS({
13880
13880
  });
13881
13881
  var childrenQueries = hasManyAssociations.map(function([key, value]) {
13882
13882
  var childCollection = model.collections.get(key);
13883
- return childCollection.query(Q10.where(value.foreignKey, model.id));
13883
+ return childCollection.query(Q11.where(value.foreignKey, model.id));
13884
13884
  });
13885
13885
  return childrenQueries;
13886
13886
  }
@@ -14261,8 +14261,8 @@ var require_watermelondb = __commonJS({
14261
14261
  var _interopRequireDefault = require_interopRequireDefault();
14262
14262
  exports2.__esModule = true;
14263
14263
  exports2.tableSchema = exports2.tableName = exports2.localStorageKey = exports2.columnName = exports2.associations = exports2.appSchema = exports2.Relation = exports2.Query = exports2.Q = exports2.Model = exports2.Database = exports2.Collection = void 0;
14264
- var Q10 = _interopRequireWildcard(require_QueryDescription());
14265
- exports2.Q = Q10;
14264
+ var Q11 = _interopRequireWildcard(require_QueryDescription());
14265
+ exports2.Q = Q11;
14266
14266
  var _Collection = _interopRequireDefault(require_Collection());
14267
14267
  exports2.Collection = _Collection.default;
14268
14268
  var _Database = _interopRequireDefault(require_Database());
@@ -14466,7 +14466,7 @@ var require_children = __commonJS({
14466
14466
  var _makeDecorator = _interopRequireDefault(require_makeDecorator());
14467
14467
  var _logError = _interopRequireDefault(require_logError());
14468
14468
  var _invariant = _interopRequireDefault(require_invariant());
14469
- var Q10 = _interopRequireWildcard(require_QueryDescription());
14469
+ var Q11 = _interopRequireWildcard(require_QueryDescription());
14470
14470
  function _getRequireWildcardCache(e) {
14471
14471
  if ("function" != typeof WeakMap) return null;
14472
14472
  var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
@@ -14500,7 +14500,7 @@ var require_children = __commonJS({
14500
14500
  var childCollection = model.collections.get(childTable);
14501
14501
  var association = model.constructor.associations[childTable];
14502
14502
  (0, _invariant.default)(association && "has_many" === association.type, "@children decorator used for a table that's not has_many");
14503
- var query = childCollection.query(Q10.where(association.foreignKey, model.id));
14503
+ var query = childCollection.query(Q11.where(association.foreignKey, model.id));
14504
14504
  that._childrenQueryCache[childTable] = query;
14505
14505
  return query;
14506
14506
  },
@@ -16781,6 +16781,7 @@ function vaultMemoryToStoredRaw(memory) {
16781
16781
  eventTimeStart: memory.eventTimeStart ?? null,
16782
16782
  eventTimeEnd: memory.eventTimeEnd ?? null,
16783
16783
  eventTimeKind: memory.eventTimeKind ?? null,
16784
+ topicsUserManaged: memory.topicsUserManaged ?? false,
16784
16785
  createdAt: memory.createdAt,
16785
16786
  updatedAt: memory.updatedAt,
16786
16787
  isDeleted: memory.isDeleted
@@ -16962,9 +16963,10 @@ function vaultMemoryRawToStoredRaw(raw) {
16962
16963
  eventTimeStart: raw.event_time_start ?? null,
16963
16964
  eventTimeEnd: raw.event_time_end ?? null,
16964
16965
  eventTimeKind: raw.event_time_kind ?? null,
16966
+ // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
16967
+ topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1,
16965
16968
  createdAt: new Date(raw.created_at),
16966
16969
  updatedAt: new Date(raw.updated_at),
16967
- // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
16968
16970
  isDeleted: raw.is_deleted === true || raw.is_deleted === 1
16969
16971
  };
16970
16972
  }
@@ -17048,6 +17050,9 @@ async function updateVaultMemoryOp(ctx, id, opts) {
17048
17050
  r._setRaw("event_time_end", opts.eventTime.end ?? null);
17049
17051
  r._setRaw("event_time_kind", opts.eventTime.kind ?? null);
17050
17052
  }
17053
+ if (opts.topicsUserManaged !== void 0) {
17054
+ r._setRaw("topics_user_managed", opts.topicsUserManaged);
17055
+ }
17051
17056
  if (opts.preserveUpdatedAt) {
17052
17057
  r._setRaw("updated_at", originalUpdatedAt);
17053
17058
  }
@@ -21908,6 +21913,9 @@ __decorateClass([
21908
21913
  __decorateClass([
21909
21914
  (0, import_decorators5.field)("event_time_kind")
21910
21915
  ], VaultMemory.prototype, "eventTimeKind", 2);
21916
+ __decorateClass([
21917
+ (0, import_decorators5.field)("topics_user_managed")
21918
+ ], VaultMemory.prototype, "topicsUserManaged", 2);
21911
21919
  __decorateClass([
21912
21920
  import_decorators5.readonly,
21913
21921
  (0, import_decorators5.date)("created_at")
@@ -22055,7 +22063,7 @@ __decorateClass([
22055
22063
  ], VaultFolder.prototype, "context", 2);
22056
22064
 
22057
22065
  // src/lib/db/schema.ts
22058
- var SDK_SCHEMA_VERSION = 33;
22066
+ var SDK_SCHEMA_VERSION = 34;
22059
22067
  var sdkSchema = (0, import_watermelondb11.appSchema)({
22060
22068
  version: SDK_SCHEMA_VERSION,
22061
22069
  tables: [
@@ -22172,7 +22180,11 @@ var sdkSchema = (0, import_watermelondb11.appSchema)({
22172
22180
  // (start set, end null + kind='ongoing'), or none (both null).
22173
22181
  { name: "event_time_start", type: "number", isOptional: true, isIndexed: true },
22174
22182
  { name: "event_time_end", type: "number", isOptional: true },
22175
- { name: "event_time_kind", type: "string", isOptional: true }
22183
+ { name: "event_time_kind", type: "string", isOptional: true },
22184
+ // When true, the user has manually set this memory's topics (entity
22185
+ // links). Auto-extraction then leaves its links alone — the user owns
22186
+ // them. Null/false = topics are auto-derived (default).
22187
+ { name: "topics_user_managed", type: "boolean", isOptional: true }
22176
22188
  ]
22177
22189
  }),
22178
22190
  // Entity table — canonical names extracted from auto-extraction (W5).
@@ -22731,6 +22743,18 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
22731
22743
  columns: [{ name: "embedding_model", type: "string", isOptional: true }]
22732
22744
  })
22733
22745
  ]
22746
+ },
22747
+ // v33 -> v34: user-managed topics. `topics_user_managed` marks a memory
22748
+ // whose entity links the user has taken manual control of, so
22749
+ // auto-extraction stops touching them.
22750
+ {
22751
+ toVersion: 34,
22752
+ steps: [
22753
+ (0, import_migrations.addColumns)({
22754
+ table: "memory_vault",
22755
+ columns: [{ name: "topics_user_managed", type: "boolean", isOptional: true }]
22756
+ })
22757
+ ]
22734
22758
  }
22735
22759
  ]
22736
22760
  });
@@ -25433,6 +25457,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
25433
25457
  }
25434
25458
 
25435
25459
  // src/lib/memory/autoExtract.ts
25460
+ var import_watermelondb22 = __toESM(require_watermelondb());
25436
25461
  init_operations2();
25437
25462
  init_types3();
25438
25463
  init_logger();
@@ -25490,12 +25515,15 @@ async function retain(content, ctx, options = {}) {
25490
25515
  preserveUpdatedAt: true,
25491
25516
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
25492
25517
  });
25493
- return {
25494
- action: "merge",
25495
- memoryId: targetId,
25496
- targetId,
25497
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
25498
- };
25518
+ if (updated) {
25519
+ return {
25520
+ action: "merge",
25521
+ memoryId: targetId,
25522
+ targetId,
25523
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
25524
+ };
25525
+ }
25526
+ await assertMergeTargetGoneOrThrow(ctx, targetId);
25499
25527
  }
25500
25528
  }
25501
25529
  }
@@ -25578,11 +25606,15 @@ async function tryConsolidate(trimmed, ctx, options) {
25578
25606
  preserveUpdatedAt: true,
25579
25607
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
25580
25608
  });
25609
+ if (!updated) {
25610
+ await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
25611
+ return null;
25612
+ }
25581
25613
  return {
25582
25614
  action: "merge",
25583
25615
  memoryId: decision.targetId,
25584
25616
  targetId: decision.targetId,
25585
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
25617
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
25586
25618
  };
25587
25619
  }
25588
25620
  if (decision.action === "update" && decision.targetId && decision.content) {
@@ -25609,17 +25641,35 @@ async function tryConsolidate(trimmed, ctx, options) {
25609
25641
  preserveUpdatedAt: true,
25610
25642
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
25611
25643
  });
25644
+ if (!updated) {
25645
+ await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
25646
+ return null;
25647
+ }
25612
25648
  return {
25613
25649
  action: "update",
25614
25650
  memoryId: decision.targetId,
25615
25651
  targetId: decision.targetId,
25616
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
25652
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
25617
25653
  };
25618
25654
  }
25619
25655
  return null;
25620
25656
  }
25657
+ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
25658
+ const stillExists = await getVaultMemoryOp(ctx.vaultCtx, targetId);
25659
+ if (stillExists) {
25660
+ throw new Error(`retain: merge into memory ${targetId} failed to persist`);
25661
+ }
25662
+ }
25621
25663
 
25622
25664
  // src/lib/memory/autoExtract.ts
25665
+ async function isMemoryTopicsUserManaged(ctx, memoryId) {
25666
+ try {
25667
+ const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb22.Q.where("id", memoryId)).fetch();
25668
+ return rows[0]?.topicsUserManaged === true;
25669
+ } catch {
25670
+ return true;
25671
+ }
25672
+ }
25623
25673
  var DEFAULT_MODEL3 = "gpt-oss/gpt-oss-120b";
25624
25674
  var DEFAULT_MIN_CONFIDENCE = 0.7;
25625
25675
  var MAX_CONTENT_LENGTH = 200;
@@ -25778,7 +25828,9 @@ async function extractAndRetain(messages, retainCtx, options) {
25778
25828
  results.push(result);
25779
25829
  if (options.entityCtx && candidate.entities.length > 0) {
25780
25830
  try {
25781
- await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities);
25831
+ if (!await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
25832
+ await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities);
25833
+ }
25782
25834
  } catch (err) {
25783
25835
  log.warn("[memory/extract] linkMemoryEntitiesOp failed", err);
25784
25836
  }
@@ -48,7 +48,7 @@ import { ResultCallback } from '@nozbe/watermelondb/utils/fp/Result';
48
48
  * detectable and re-embeddable after an embedding-model change (null = legacy
49
49
  * rows, grandfathered as compatible with the current model)
50
50
  */
51
- declare const SDK_SCHEMA_VERSION = 33;
51
+ declare const SDK_SCHEMA_VERSION = 34;
52
52
  /**
53
53
  * Combined WatermelonDB schema for all SDK storage modules.
54
54
  *
@@ -4079,6 +4079,9 @@ declare class VaultMemory extends Model$1 {
4079
4079
  eventTimeEnd: number | null;
4080
4080
  /** W6 temporal lane — `point | range | ongoing | null`. */
4081
4081
  eventTimeKind: string | null;
4082
+ /** When true, the user has manually set this memory's topics; auto-extraction
4083
+ * leaves its entity links alone. Null on legacy rows (treated as false). */
4084
+ topicsUserManaged: boolean | null;
4082
4085
  createdAt: Date;
4083
4086
  updatedAt: Date;
4084
4087
  isDeleted: boolean;
@@ -4179,6 +4182,9 @@ interface StoredVaultMemory {
4179
4182
  eventTimeEnd: number | null;
4180
4183
  /** W6 temporal lane — `point | range | ongoing | null`. */
4181
4184
  eventTimeKind: string | null;
4185
+ /** When true, the user has manually set this memory's topics (entity links);
4186
+ * auto-extraction leaves them alone. False on legacy/auto rows. */
4187
+ topicsUserManaged: boolean;
4182
4188
  createdAt: Date;
4183
4189
  updatedAt: Date;
4184
4190
  isDeleted: boolean;
@@ -4252,6 +4258,9 @@ interface UpdateVaultMemoryOptions {
4252
4258
  * without inflating recency on top.
4253
4259
  */
4254
4260
  preserveUpdatedAt?: boolean;
4261
+ /** If provided, sets whether the user has taken manual control of this
4262
+ * memory's topics. Set by {@link setMemoryEntitiesOp}. */
4263
+ topicsUserManaged?: boolean;
4255
4264
  }
4256
4265
 
4257
4266
  interface VaultMemoryOperationsContext {
@@ -48,7 +48,7 @@ import { ResultCallback } from '@nozbe/watermelondb/utils/fp/Result';
48
48
  * detectable and re-embeddable after an embedding-model change (null = legacy
49
49
  * rows, grandfathered as compatible with the current model)
50
50
  */
51
- declare const SDK_SCHEMA_VERSION = 33;
51
+ declare const SDK_SCHEMA_VERSION = 34;
52
52
  /**
53
53
  * Combined WatermelonDB schema for all SDK storage modules.
54
54
  *
@@ -4079,6 +4079,9 @@ declare class VaultMemory extends Model$1 {
4079
4079
  eventTimeEnd: number | null;
4080
4080
  /** W6 temporal lane — `point | range | ongoing | null`. */
4081
4081
  eventTimeKind: string | null;
4082
+ /** When true, the user has manually set this memory's topics; auto-extraction
4083
+ * leaves its entity links alone. Null on legacy rows (treated as false). */
4084
+ topicsUserManaged: boolean | null;
4082
4085
  createdAt: Date;
4083
4086
  updatedAt: Date;
4084
4087
  isDeleted: boolean;
@@ -4179,6 +4182,9 @@ interface StoredVaultMemory {
4179
4182
  eventTimeEnd: number | null;
4180
4183
  /** W6 temporal lane — `point | range | ongoing | null`. */
4181
4184
  eventTimeKind: string | null;
4185
+ /** When true, the user has manually set this memory's topics (entity links);
4186
+ * auto-extraction leaves them alone. False on legacy/auto rows. */
4187
+ topicsUserManaged: boolean;
4182
4188
  createdAt: Date;
4183
4189
  updatedAt: Date;
4184
4190
  isDeleted: boolean;
@@ -4252,6 +4258,9 @@ interface UpdateVaultMemoryOptions {
4252
4258
  * without inflating recency on top.
4253
4259
  */
4254
4260
  preserveUpdatedAt?: boolean;
4261
+ /** If provided, sets whether the user has taken manual control of this
4262
+ * memory's topics. Set by {@link setMemoryEntitiesOp}. */
4263
+ topicsUserManaged?: boolean;
4255
4264
  }
4256
4265
 
4257
4266
  interface VaultMemoryOperationsContext {
@@ -95,7 +95,7 @@ import {
95
95
  updateVaultMemoryEmbeddingOp,
96
96
  updateVaultMemoryOp,
97
97
  upsertMessageOp
98
- } from "./chunk-HPURS22B.mjs";
98
+ } from "./chunk-G3DC7QBH.mjs";
99
99
  import {
100
100
  createStreamingDeAnonymizer,
101
101
  resolvePiiRedactor
@@ -277,7 +277,7 @@ var require_children = __commonJS({
277
277
  var _makeDecorator = _interopRequireDefault(require_makeDecorator());
278
278
  var _logError = _interopRequireDefault(require_logError());
279
279
  var _invariant = _interopRequireDefault(require_invariant());
280
- var Q7 = _interopRequireWildcard(require_QueryDescription());
280
+ var Q8 = _interopRequireWildcard(require_QueryDescription());
281
281
  function _getRequireWildcardCache(e) {
282
282
  if ("function" != typeof WeakMap) return null;
283
283
  var r = /* @__PURE__ */ new WeakMap(), t = /* @__PURE__ */ new WeakMap();
@@ -311,7 +311,7 @@ var require_children = __commonJS({
311
311
  var childCollection = model.collections.get(childTable);
312
312
  var association = model.constructor.associations[childTable];
313
313
  (0, _invariant.default)(association && "has_many" === association.type, "@children decorator used for a table that's not has_many");
314
- var query = childCollection.query(Q7.where(association.foreignKey, model.id));
314
+ var query = childCollection.query(Q8.where(association.foreignKey, model.id));
315
315
  that._childrenQueryCache[childTable] = query;
316
316
  return query;
317
317
  },
@@ -1062,6 +1062,9 @@ __decorateClass([
1062
1062
  __decorateClass([
1063
1063
  (0, import_decorators5.field)("event_time_kind")
1064
1064
  ], VaultMemory.prototype, "eventTimeKind", 2);
1065
+ __decorateClass([
1066
+ (0, import_decorators5.field)("topics_user_managed")
1067
+ ], VaultMemory.prototype, "topicsUserManaged", 2);
1065
1068
  __decorateClass([
1066
1069
  import_decorators5.readonly,
1067
1070
  (0, import_decorators5.date)("created_at")
@@ -1209,7 +1212,7 @@ __decorateClass([
1209
1212
  ], VaultFolder.prototype, "context", 2);
1210
1213
 
1211
1214
  // src/lib/db/schema.ts
1212
- var SDK_SCHEMA_VERSION = 33;
1215
+ var SDK_SCHEMA_VERSION = 34;
1213
1216
  var sdkSchema = (0, import_watermelondb11.appSchema)({
1214
1217
  version: SDK_SCHEMA_VERSION,
1215
1218
  tables: [
@@ -1326,7 +1329,11 @@ var sdkSchema = (0, import_watermelondb11.appSchema)({
1326
1329
  // (start set, end null + kind='ongoing'), or none (both null).
1327
1330
  { name: "event_time_start", type: "number", isOptional: true, isIndexed: true },
1328
1331
  { name: "event_time_end", type: "number", isOptional: true },
1329
- { name: "event_time_kind", type: "string", isOptional: true }
1332
+ { name: "event_time_kind", type: "string", isOptional: true },
1333
+ // When true, the user has manually set this memory's topics (entity
1334
+ // links). Auto-extraction then leaves its links alone — the user owns
1335
+ // them. Null/false = topics are auto-derived (default).
1336
+ { name: "topics_user_managed", type: "boolean", isOptional: true }
1330
1337
  ]
1331
1338
  }),
1332
1339
  // Entity table — canonical names extracted from auto-extraction (W5).
@@ -1885,6 +1892,18 @@ var sdkMigrations = (0, import_migrations.schemaMigrations)({
1885
1892
  columns: [{ name: "embedding_model", type: "string", isOptional: true }]
1886
1893
  })
1887
1894
  ]
1895
+ },
1896
+ // v33 -> v34: user-managed topics. `topics_user_managed` marks a memory
1897
+ // whose entity links the user has taken manual control of, so
1898
+ // auto-extraction stops touching them.
1899
+ {
1900
+ toVersion: 34,
1901
+ steps: [
1902
+ (0, import_migrations.addColumns)({
1903
+ table: "memory_vault",
1904
+ columns: [{ name: "topics_user_managed", type: "boolean", isOptional: true }]
1905
+ })
1906
+ ]
1888
1907
  }
1889
1908
  ]
1890
1909
  });
@@ -4556,6 +4575,9 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
4556
4575
  };
4557
4576
  }
4558
4577
 
4578
+ // src/lib/memory/autoExtract.ts
4579
+ var import_watermelondb19 = __toESM(require_watermelondb());
4580
+
4559
4581
  // src/lib/memory/retain.ts
4560
4582
  var DEFAULT_AUTO_MERGE_THRESHOLD = 0.85;
4561
4583
  var DEFAULT_SCOPE = "private";
@@ -4603,12 +4625,15 @@ async function retain(content, ctx, options = {}) {
4603
4625
  preserveUpdatedAt: true,
4604
4626
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
4605
4627
  });
4606
- return {
4607
- action: "merge",
4608
- memoryId: targetId,
4609
- targetId,
4610
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
4611
- };
4628
+ if (updated) {
4629
+ return {
4630
+ action: "merge",
4631
+ memoryId: targetId,
4632
+ targetId,
4633
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
4634
+ };
4635
+ }
4636
+ await assertMergeTargetGoneOrThrow(ctx, targetId);
4612
4637
  }
4613
4638
  }
4614
4639
  }
@@ -4691,11 +4716,15 @@ async function tryConsolidate(trimmed, ctx, options) {
4691
4716
  preserveUpdatedAt: true,
4692
4717
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
4693
4718
  });
4719
+ if (!updated) {
4720
+ await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
4721
+ return null;
4722
+ }
4694
4723
  return {
4695
4724
  action: "merge",
4696
4725
  memoryId: decision.targetId,
4697
4726
  targetId: decision.targetId,
4698
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
4727
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
4699
4728
  };
4700
4729
  }
4701
4730
  if (decision.action === "update" && decision.targetId && decision.content) {
@@ -4722,17 +4751,35 @@ async function tryConsolidate(trimmed, ctx, options) {
4722
4751
  preserveUpdatedAt: true,
4723
4752
  ...eventTimeUpdate && { eventTime: eventTimeUpdate }
4724
4753
  });
4754
+ if (!updated) {
4755
+ await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
4756
+ return null;
4757
+ }
4725
4758
  return {
4726
4759
  action: "update",
4727
4760
  memoryId: decision.targetId,
4728
4761
  targetId: decision.targetId,
4729
- proofCount: updated?.proofCount ?? (existing.proofCount ?? 1) + 1
4762
+ proofCount: updated.proofCount ?? (existing.proofCount ?? 1) + 1
4730
4763
  };
4731
4764
  }
4732
4765
  return null;
4733
4766
  }
4767
+ async function assertMergeTargetGoneOrThrow(ctx, targetId) {
4768
+ const stillExists = await getVaultMemoryOp(ctx.vaultCtx, targetId);
4769
+ if (stillExists) {
4770
+ throw new Error(`retain: merge into memory ${targetId} failed to persist`);
4771
+ }
4772
+ }
4734
4773
 
4735
4774
  // src/lib/memory/autoExtract.ts
4775
+ async function isMemoryTopicsUserManaged(ctx, memoryId) {
4776
+ try {
4777
+ const rows = await ctx.database.get(VaultMemory.table).query(import_watermelondb19.Q.where("id", memoryId)).fetch();
4778
+ return rows[0]?.topicsUserManaged === true;
4779
+ } catch {
4780
+ return true;
4781
+ }
4782
+ }
4736
4783
  var DEFAULT_MODEL = "gpt-oss/gpt-oss-120b";
4737
4784
  var DEFAULT_MIN_CONFIDENCE = 0.7;
4738
4785
  var MAX_CONTENT_LENGTH = 200;
@@ -4891,7 +4938,9 @@ async function extractAndRetain(messages, retainCtx, options) {
4891
4938
  results.push(result);
4892
4939
  if (options.entityCtx && candidate.entities.length > 0) {
4893
4940
  try {
4894
- await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities);
4941
+ if (!await isMemoryTopicsUserManaged(options.entityCtx, result.memoryId)) {
4942
+ await linkMemoryEntitiesOp(options.entityCtx, result.memoryId, candidate.entities);
4943
+ }
4895
4944
  } catch (err) {
4896
4945
  log.warn("[memory/extract] linkMemoryEntitiesOp failed", err);
4897
4946
  }
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-HPURS22B.mjs";
3
+ } from "./chunk-G3DC7QBH.mjs";
4
4
  import "./chunk-RCCKRTBI.mjs";
5
5
  import "./chunk-FMGZTVXQ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -145,7 +145,7 @@
145
145
  "homepage": "https://github.com/anuma-ai/sdk#readme",
146
146
  "packageManager": "pnpm@10.23.0",
147
147
  "dependencies": {
148
- "@anuma/portal": "1.0.0-next.20260708031058",
148
+ "@anuma/portal": "1.0.0-next.20260709030454",
149
149
  "@babel/parser": "^7.29.2",
150
150
  "@babel/types": "^7.29.0",
151
151
  "ai": "6.0.202",