@anuma/sdk 6.21.1 → 6.23.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.
Files changed (32) hide show
  1. package/dist/expo/{chunk-CIMZZ7GQ.mjs → chunk-6BULYLRY.mjs} +92 -8
  2. package/dist/expo/index.cjs +761 -162
  3. package/dist/expo/index.d.mts +151 -9
  4. package/dist/expo/index.d.ts +151 -9
  5. package/dist/expo/index.mjs +516 -14
  6. package/dist/{react/recall-7Q3V337H.mjs → expo/recall-CUTJWQDQ.mjs} +1 -1
  7. package/dist/memory/context.cjs +183 -0
  8. package/dist/memory/context.d.mts +936 -0
  9. package/dist/memory/context.d.ts +936 -0
  10. package/dist/memory/context.mjs +157 -0
  11. package/dist/react/{chunk-AVYB5IXC.mjs → chunk-GPLMMMZN.mjs} +1 -1
  12. package/dist/react/{chunk-JRVAUZHM.mjs → chunk-K4N52PSK.mjs} +93 -9
  13. package/dist/react/{consolidate-URHGJT7I.mjs → consolidate-XKS6IZFC.mjs} +2 -2
  14. package/dist/react/index.cjs +876 -270
  15. package/dist/react/index.d.mts +209 -9
  16. package/dist/react/index.d.ts +209 -9
  17. package/dist/react/index.mjs +569 -65
  18. package/dist/{expo/recall-FQQGE6A2.mjs → react/recall-LFHIWONV.mjs} +2 -2
  19. package/dist/server/{chunk-4DSDATYG.mjs → chunk-FEDRFVHD.mjs} +182 -98
  20. package/dist/server/index.cjs +815 -216
  21. package/dist/server/index.d.mts +150 -5
  22. package/dist/server/index.d.ts +150 -5
  23. package/dist/server/index.mjs +509 -7
  24. package/dist/server/{recall-HA4UX4BB.mjs → recall-Z2WJGXOL.mjs} +1 -1
  25. package/dist/telemetry/index.d.mts +7 -1
  26. package/dist/telemetry/index.d.ts +7 -1
  27. package/dist/tools/index.cjs +347 -1
  28. package/dist/tools/index.d.mts +167 -1
  29. package/dist/tools/index.d.ts +167 -1
  30. package/dist/tools/index.mjs +343 -1
  31. package/package.json +8 -1
  32. package/dist/react/{chunk-WUG6GTHO.mjs → chunk-MHZB6KIX.mjs} +8 -8
@@ -942,6 +942,12 @@ async function decryptJsonField(value, address) {
942
942
  }
943
943
  }
944
944
 
945
+ // src/lib/db/extractionJobs/models.ts
946
+ import { Model } from "@nozbe/watermelondb";
947
+ var ExtractionJob = class extends Model {
948
+ };
949
+ ExtractionJob.table = "memory_extraction_jobs";
950
+
945
951
  // src/lib/db/chat/conversationEncryption.ts
946
952
  async function encryptConversationFields(conversation, address, signMessage, embeddedWalletSigner) {
947
953
  if (!address || !signMessage) {
@@ -1584,6 +1590,8 @@ async function deleteConversationOp(ctx, id) {
1584
1590
  await results[0].update((conv) => {
1585
1591
  conv._setRaw("is_deleted", true);
1586
1592
  });
1593
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", id)).fetch() : [];
1594
+ for (const job of jobs) await job.destroyPermanently();
1587
1595
  });
1588
1596
  return true;
1589
1597
  }
@@ -1704,8 +1712,16 @@ async function getToolCallEventIdsOp(ctx, convId) {
1704
1712
  return ids;
1705
1713
  }
1706
1714
  async function clearMessagesOp(ctx, convId) {
1707
- const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
1708
1715
  await ctx.database.write(async () => {
1716
+ const messages = await ctx.messagesCollection.query(Q.where("conversation_id", convId)).fetch();
1717
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", convId)).fetch() : [];
1718
+ for (const job of jobs) {
1719
+ await job.update((row) => {
1720
+ row._setRaw("message_ids", "[]");
1721
+ row._setRaw("watermark", null);
1722
+ row._setRaw("watermark_seq", null);
1723
+ });
1724
+ }
1709
1725
  for (const message of messages) {
1710
1726
  await message.update((msg) => {
1711
1727
  msg._setRaw("file_ids", null);
@@ -1715,6 +1731,30 @@ async function clearMessagesOp(ctx, convId) {
1715
1731
  }
1716
1732
  });
1717
1733
  }
1734
+ async function deleteMessageOp(ctx, uniqueId) {
1735
+ let message;
1736
+ try {
1737
+ message = await ctx.messagesCollection.find(uniqueId);
1738
+ } catch {
1739
+ return null;
1740
+ }
1741
+ await ctx.database.write(async () => {
1742
+ const jobs = ctx.database.schema?.tables[ExtractionJob.table] ? await ctx.database.get(ExtractionJob.table).query(Q.where("conversation_id", message.conversationId)).fetch() : [];
1743
+ for (const job of jobs) {
1744
+ const ids = JSON.parse(String(job._getRaw("message_ids")));
1745
+ await job.update((row) => {
1746
+ row._setRaw("message_ids", JSON.stringify(ids.filter((id) => id !== uniqueId)));
1747
+ if (row._getRaw("watermark") === uniqueId) row._setRaw("watermark", null);
1748
+ });
1749
+ }
1750
+ await message.update((msg) => {
1751
+ msg._setRaw("file_ids", null);
1752
+ msg._setRaw("files", null);
1753
+ });
1754
+ await message.destroyPermanently();
1755
+ });
1756
+ return uniqueId;
1757
+ }
1718
1758
  async function encryptMessageOptsIfNeeded(ctx, opts) {
1719
1759
  return ctx.walletAddress && ctx.signMessage ? await encryptMessageFields(opts, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner) : opts;
1720
1760
  }
@@ -2557,6 +2597,7 @@ function isOwnedByCtxUser(ctx, record) {
2557
2597
  }
2558
2598
  function baseVaultConditions(ctx, options) {
2559
2599
  return [
2600
+ ...options?.memoryIds !== void 0 ? [Q3.where("id", Q3.oneOf(options.memoryIds))] : [],
2560
2601
  ...options?.includeDeleted ? [] : [Q3.where("is_deleted", false)],
2561
2602
  ...options?.includeArchived ? [] : [Q3.where("archived_at", Q3.eq(null))],
2562
2603
  ...options?.includeQuarantined ? [] : [Q3.where("trust_tier", Q3.notEq("quarantined"))],
@@ -2641,6 +2682,8 @@ async function createVaultMemoryOp(ctx, opts) {
2641
2682
  ctx.embeddedWalletSigner
2642
2683
  ) : opts.content;
2643
2684
  const created = await ctx.database.write(async () => {
2685
+ if (ctx.canWrite && !await ctx.canWrite())
2686
+ throw new Error("Memory source is no longer eligible");
2644
2687
  return ctx.vaultMemoryCollection.create((record) => {
2645
2688
  record._setRaw("content", encryptedContent);
2646
2689
  record._setRaw("scope", scope);
@@ -2690,6 +2733,8 @@ async function createSupersedingMemoryOp(ctx, opts, targetId) {
2690
2733
  ) : opts.content;
2691
2734
  let createdRecord = null;
2692
2735
  await ctx.database.write(async () => {
2736
+ if (ctx.canWrite && !await ctx.canWrite())
2737
+ throw new Error("Memory source is no longer eligible");
2693
2738
  let target;
2694
2739
  try {
2695
2740
  target = await ctx.vaultMemoryCollection.find(targetId);
@@ -2794,6 +2839,8 @@ async function createVaultMemoriesBatchOp(ctx, optionsArray) {
2794
2839
  })
2795
2840
  );
2796
2841
  const created = await ctx.database.write(async () => {
2842
+ if (ctx.canWrite && !await ctx.canWrite())
2843
+ throw new Error("Memory source is no longer eligible");
2797
2844
  const prepared = optionsArray.map(
2798
2845
  (opts, i) => ctx.vaultMemoryCollection.prepareCreate((record) => {
2799
2846
  record._setRaw("content", encryptedContents[i]);
@@ -2980,6 +3027,11 @@ async function getVaultCandidateKeysOp(ctx, options) {
2980
3027
  });
2981
3028
  const clauses = [base.sql];
2982
3029
  const args = [...base.args];
3030
+ if (options?.memoryIds !== void 0) {
3031
+ if (options.memoryIds.length === 0) return [];
3032
+ clauses.push(`"id" in (${options.memoryIds.map(() => "?").join(",")})`);
3033
+ args.push(...options.memoryIds);
3034
+ }
2983
3035
  if (options?.scopes?.length) {
2984
3036
  clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
2985
3037
  args.push(...options.scopes);
@@ -3001,6 +3053,7 @@ async function getVaultCandidateKeysOp(ctx, options) {
3001
3053
  );
3002
3054
  const conditions = [
3003
3055
  ...baseVaultConditions(ctx, {
3056
+ memoryIds: options?.memoryIds,
3004
3057
  ...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
3005
3058
  }),
3006
3059
  ...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
@@ -3088,10 +3141,23 @@ async function updateVaultMemoryOp(ctx, id, opts) {
3088
3141
  const record = probe;
3089
3142
  const originalUpdatedAt = record.updatedAt.getTime();
3090
3143
  await ctx.database.write(async () => {
3144
+ if (ctx.canWrite && !await ctx.canWrite())
3145
+ throw new Error("Memory source is no longer eligible");
3091
3146
  if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
3092
3147
  stale = true;
3093
3148
  return;
3094
3149
  }
3150
+ let observedSources = [];
3151
+ let replayedObservation = false;
3152
+ if (opts.observationSourceIds?.length) {
3153
+ try {
3154
+ const parsed = JSON.parse(record.sourceChunkIds ?? "[]");
3155
+ if (Array.isArray(parsed))
3156
+ observedSources = parsed.filter((id2) => typeof id2 === "string");
3157
+ } catch {
3158
+ }
3159
+ replayedObservation = opts.observationSourceIds.every((id2) => observedSources.includes(id2));
3160
+ }
3095
3161
  await record.update((r) => {
3096
3162
  r._setRaw("content", encryptedContent);
3097
3163
  if (opts.scope !== void 0) {
@@ -3105,9 +3171,15 @@ async function updateVaultMemoryOp(ctx, id, opts) {
3105
3171
  r._setRaw("embedding_model", opts.embeddingModel ?? null);
3106
3172
  }
3107
3173
  if (opts.sourceChunkIds !== void 0) {
3108
- r._setRaw("source_chunk_ids", JSON.stringify(opts.sourceChunkIds));
3174
+ r._setRaw(
3175
+ "source_chunk_ids",
3176
+ JSON.stringify(
3177
+ opts.observationSourceIds?.length ? [.../* @__PURE__ */ new Set([...observedSources, ...opts.sourceChunkIds])] : opts.sourceChunkIds
3178
+ )
3179
+ );
3109
3180
  }
3110
- if (opts.proofCountIncrement !== void 0) {
3181
+ if (replayedObservation) {
3182
+ } else if (opts.proofCountIncrement !== void 0) {
3111
3183
  const current = r.proofCount ?? 1;
3112
3184
  r._setRaw("proof_count", current + opts.proofCountIncrement);
3113
3185
  } else if (opts.proofCount !== void 0) {
@@ -3124,7 +3196,7 @@ async function updateVaultMemoryOp(ctx, id, opts) {
3124
3196
  if (opts.topicsUserManaged !== void 0) {
3125
3197
  r._setRaw("topics_user_managed", opts.topicsUserManaged);
3126
3198
  }
3127
- if (opts.lastObservedAt !== void 0) {
3199
+ if (opts.lastObservedAt !== void 0 && !replayedObservation) {
3128
3200
  r._setRaw("last_observed_at", opts.lastObservedAt);
3129
3201
  }
3130
3202
  if (opts.factType !== void 0) {
@@ -3250,6 +3322,8 @@ async function supersedeVaultMemoryOp(ctx, id, supersededById) {
3250
3322
  }
3251
3323
  let stale = false;
3252
3324
  await ctx.database.write(async () => {
3325
+ if (ctx.canWrite && !await ctx.canWrite())
3326
+ throw new Error("Memory source is no longer eligible");
3253
3327
  if (record.isDeleted || record.supersededBy || !isOwnedByCtxUser(ctx, record)) {
3254
3328
  stale = true;
3255
3329
  return;
@@ -3542,6 +3616,7 @@ async function getDecayCandidatesRawOp(ctx) {
3542
3616
  eventTimeEnd: raw.event_time_end ?? null,
3543
3617
  eventTimeKind: raw.event_time_kind ?? null,
3544
3618
  updatedAt: raw.updated_at,
3619
+ lastObservedAt: raw.last_observed_at ?? null,
3545
3620
  archivedAt: raw.archived_at ?? null,
3546
3621
  source: raw.source ?? null,
3547
3622
  trustTier: raw.trust_tier ?? null
@@ -3558,7 +3633,7 @@ async function archiveVaultMemoryOp(ctx, id, opts) {
3558
3633
  stale = true;
3559
3634
  return;
3560
3635
  }
3561
- if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt) {
3636
+ if (opts?.expectedUpdatedAt !== void 0 && record.updatedAt.getTime() !== opts.expectedUpdatedAt || opts?.expectedLastObservedAt !== void 0 && (record.lastObservedAt ?? null) !== opts.expectedLastObservedAt) {
3562
3637
  stale = true;
3563
3638
  return;
3564
3639
  }
@@ -6388,6 +6463,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
6388
6463
  const scopes = searchOptions?.scopes;
6389
6464
  const folderId = searchOptions?.folderId;
6390
6465
  const queryOpts = {};
6466
+ if (searchOptions?.memoryIds !== void 0) queryOpts.memoryIds = searchOptions.memoryIds;
6391
6467
  if (scopes?.length) queryOpts.scopes = scopes;
6392
6468
  if (folderId !== void 0) queryOpts.folderId = folderId;
6393
6469
  if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
@@ -6912,7 +6988,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
6912
6988
  subQueries = decomp.subQueries;
6913
6989
  }
6914
6990
  }
6915
- const { recall: recall2 } = await import("./recall-FQQGE6A2.mjs");
6991
+ const { recall: recall2 } = await import("./recall-CUTJWQDQ.mjs");
6916
6992
  let recallDegraded = [];
6917
6993
  const result = await recall2(
6918
6994
  query,
@@ -7479,7 +7555,9 @@ function dedupeBy(items, ...keys) {
7479
7555
  return out;
7480
7556
  }
7481
7557
  async function recall(query, ctx, options = {}) {
7482
- const types = options.types ?? ["fact"];
7558
+ const requestedTypes = options.types ?? ["fact"];
7559
+ const chunksScopeRestricted = options.memoryIds !== void 0 && requestedTypes.includes("chunk");
7560
+ const types = options.memoryIds !== void 0 ? requestedTypes.filter((kind) => kind === "fact") : requestedTypes;
7483
7561
  const limit = options.limit ?? DEFAULT_LIMIT;
7484
7562
  const usedBudget = options.budget ?? DEFAULT_BUDGET;
7485
7563
  const flags = flagsForBudget(usedBudget);
@@ -7531,7 +7609,10 @@ async function recall(query, ctx, options = {}) {
7531
7609
  if (embeddingsUnavailable) degraded.push("embeddings-unavailable");
7532
7610
  if (graphLaneFailed) degraded.push("graph-lane-failed");
7533
7611
  if (temporalLaneFailed) degraded.push("temporal-lane-failed");
7534
- const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx;
7612
+ if (chunksScopeRestricted) degraded.push("chunks-scope-restricted");
7613
+ const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx || // The chunk lane was wired and deliberately dropped for the scope, which
7614
+ // is not the "requested kinds have no store" wiring bug `no-lanes` means.
7615
+ chunksScopeRestricted && !!ctx.storageCtx;
7535
7616
  const scores = admitted.map((m) => m.score);
7536
7617
  const minScoreApplied = factResults.length > 0 ? factFloor : chunkResults.length > 0 ? chunkFloor : factFloor >= 0 ? factFloor : chunkFloor;
7537
7618
  const diagnostics = {
@@ -7676,6 +7757,7 @@ async function recall(query, ctx, options = {}) {
7676
7757
  ...options.scopes && { scopes: options.scopes },
7677
7758
  ...options.folderId !== void 0 && { folderId: options.folderId },
7678
7759
  ...options.factTypes?.length && { factTypes: options.factTypes },
7760
+ ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
7679
7761
  ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
7680
7762
  ...entityRanking.length > 0 && { entityRanking },
7681
7763
  ...temporalRanking.length > 0 && { temporalRanking }
@@ -7940,6 +8022,7 @@ export {
7940
8022
  decryptField,
7941
8023
  encryptJsonField,
7942
8024
  decryptJsonField,
8025
+ ExtractionJob,
7943
8026
  getToolCallEvents,
7944
8027
  getToolsChecksum,
7945
8028
  getImageModel,
@@ -7965,6 +8048,7 @@ export {
7965
8048
  getMessageSkeletonsOp,
7966
8049
  getToolCallEventIdsOp,
7967
8050
  clearMessagesOp,
8051
+ deleteMessageOp,
7968
8052
  createMessageOp,
7969
8053
  upsertMessageOp,
7970
8054
  getMessageOp,