@anuma/sdk 6.2.0 → 6.3.1

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.
@@ -68,6 +68,7 @@ import {
68
68
  encryptDataWithKey,
69
69
  encryptField,
70
70
  encryptJsonField,
71
+ encryptVaultMemoryContent,
71
72
  exportPublicKey,
72
73
  extractAssistantText,
73
74
  extractUserMessageFromMessages,
@@ -120,6 +121,7 @@ import {
120
121
  makeSyntheticStoredMessage,
121
122
  onClearAllEncryptionState,
122
123
  onKeyAvailable,
124
+ parseMedia,
123
125
  postApiV1CreditsPurchase,
124
126
  postApiV1PhoneCalls,
125
127
  postApiV1SubscriptionsCancel,
@@ -166,7 +168,7 @@ import {
166
168
  updateVaultMemoryOp,
167
169
  useEncryption,
168
170
  vaultMemoryToStored
169
- } from "./chunk-EMVLDEPB.mjs";
171
+ } from "./chunk-TI3UVQPF.mjs";
170
172
  import {
171
173
  PiiRedactor,
172
174
  createStreamingDeAnonymizer,
@@ -6830,6 +6832,9 @@ __decorateClass([
6830
6832
  __decorateClass([
6831
6833
  field3("topics_updated_at")
6832
6834
  ], VaultMemory.prototype, "topicsUpdatedAt", 2);
6835
+ __decorateClass([
6836
+ field3("media")
6837
+ ], VaultMemory.prototype, "media", 2);
6833
6838
  __decorateClass([
6834
6839
  field3("topics_extracted_at")
6835
6840
  ], VaultMemory.prototype, "topicsExtractedAt", 2);
@@ -6877,6 +6882,133 @@ __decorateClass([
6877
6882
  field3("is_deleted")
6878
6883
  ], VaultMemory.prototype, "isDeleted", 2);
6879
6884
 
6885
+ // src/lib/memory/decay.ts
6886
+ var DAY_MS = 24 * 60 * 60 * 1e3;
6887
+ var SHORT_TTL_MS = 30 * DAY_MS;
6888
+ var MEDIUM_TTL_MS = 180 * DAY_MS;
6889
+ var SOURCE_PHOTO = "photo";
6890
+ var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
6891
+ var HARD_DELETE_WINDOW_MS = 30 * DAY_MS;
6892
+ var PAST_EVENT_GRACE_MS = 7 * DAY_MS;
6893
+ var DEFAULT_DECAY_POLICY = {
6894
+ ttlByType: {
6895
+ identity: NEVER_TTL_MS,
6896
+ preference: NEVER_TTL_MS,
6897
+ relationship: NEVER_TTL_MS,
6898
+ constraint: NEVER_TTL_MS,
6899
+ plan: SHORT_TTL_MS,
6900
+ ongoing_context: SHORT_TTL_MS,
6901
+ other: MEDIUM_TTL_MS
6902
+ },
6903
+ fallbackTtlMs: MEDIUM_TTL_MS,
6904
+ hardDeleteWindowMs: HARD_DELETE_WINDOW_MS,
6905
+ pastEventGraceMs: PAST_EVENT_GRACE_MS
6906
+ };
6907
+ function resolvePolicy(policy) {
6908
+ if (!policy) return DEFAULT_DECAY_POLICY;
6909
+ return {
6910
+ ttlByType: { ...DEFAULT_DECAY_POLICY.ttlByType, ...policy.ttlByType },
6911
+ fallbackTtlMs: policy.fallbackTtlMs ?? DEFAULT_DECAY_POLICY.fallbackTtlMs,
6912
+ hardDeleteWindowMs: policy.hardDeleteWindowMs ?? DEFAULT_DECAY_POLICY.hardDeleteWindowMs,
6913
+ pastEventGraceMs: policy.pastEventGraceMs ?? DEFAULT_DECAY_POLICY.pastEventGraceMs
6914
+ };
6915
+ }
6916
+ function ttlForType(factType, policy) {
6917
+ const resolved = resolvePolicy(policy);
6918
+ if (factType === null) return resolved.fallbackTtlMs;
6919
+ return resolved.ttlByType[factType] ?? resolved.fallbackTtlMs;
6920
+ }
6921
+ function isTimeSensitiveType(factType) {
6922
+ return factType === "plan" || factType === "ongoing_context";
6923
+ }
6924
+ function hasFiniteTimestamps(m, now) {
6925
+ return Number.isFinite(now) && Number.isFinite(m.updatedAt) && (m.archivedAt === null || Number.isFinite(m.archivedAt));
6926
+ }
6927
+ function classifyDecay(m, now, policy) {
6928
+ const resolved = resolvePolicy(policy);
6929
+ if (!hasFiniteTimestamps(m, now)) {
6930
+ getLogger().warn("[memory/decay] non-finite timestamp on a memory row; keeping it", {
6931
+ now,
6932
+ updatedAt: m.updatedAt,
6933
+ archivedAt: m.archivedAt,
6934
+ factType: m.factType
6935
+ });
6936
+ return "keep";
6937
+ }
6938
+ if (m.archivedAt !== null) {
6939
+ return now - m.archivedAt > resolved.hardDeleteWindowMs ? "delete" : "keep";
6940
+ }
6941
+ if (m.source === "manual" || m.source === SOURCE_PHOTO) return "keep";
6942
+ if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
6943
+ if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
6944
+ if (m.eventTimeEnd >= now) return "keep";
6945
+ }
6946
+ if (now - m.updatedAt > ttlForType(m.factType, resolved)) return "archive";
6947
+ return "keep";
6948
+ }
6949
+
6950
+ // src/lib/db/memoryVault/photoIngest.ts
6951
+ var PHOTO_MEMORY_ID_PREFIX = "photo:";
6952
+ async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
6953
+ const byId = /* @__PURE__ */ new Map();
6954
+ for (const r of rows) {
6955
+ if (typeof r.memoryId !== "string" || !r.memoryId.startsWith(PHOTO_MEMORY_ID_PREFIX)) continue;
6956
+ if (!byId.has(r.memoryId)) byId.set(r.memoryId, r);
6957
+ }
6958
+ const photoRows = [...byId.values()];
6959
+ if (photoRows.length === 0) return { inserted: 0, skipped: 0 };
6960
+ const known = await ctx.vaultMemoryCollection.query().fetchIds().then((ids) => new Set(ids));
6961
+ const candidates = photoRows.filter((r) => !known.has(r.memoryId));
6962
+ if (candidates.length === 0) return { inserted: 0, skipped: photoRows.length };
6963
+ const fresh = candidates;
6964
+ const contents = await Promise.all(
6965
+ fresh.map(async (r) => {
6966
+ if (ctx.walletAddress && ctx.signMessage) {
6967
+ return encryptVaultMemoryContent(
6968
+ r.text,
6969
+ ctx.walletAddress,
6970
+ ctx.signMessage,
6971
+ ctx.embeddedWalletSigner
6972
+ );
6973
+ }
6974
+ return r.text;
6975
+ })
6976
+ );
6977
+ const now = Date.now();
6978
+ let inserted = 0;
6979
+ await ctx.database.write(async () => {
6980
+ const present = new Set(await ctx.vaultMemoryCollection.query().fetchIds());
6981
+ const writable = fresh.map((row, i) => ({ row, content: contents[i] })).filter(({ row }) => !present.has(row.memoryId));
6982
+ inserted = writable.length;
6983
+ if (writable.length === 0) return;
6984
+ const prepared = writable.map(
6985
+ ({ row, content }) => ctx.vaultMemoryCollection.prepareCreate((record) => {
6986
+ record._raw.id = row.memoryId;
6987
+ record._setRaw("content", content);
6988
+ record._setRaw("scope", "private");
6989
+ record._setRaw("folder_id", null);
6990
+ record._setRaw("user_id", ctx.userId ?? null);
6991
+ record._setRaw("is_deleted", false);
6992
+ record._setRaw("proof_count", 1);
6993
+ record._setRaw("source", SOURCE_PHOTO);
6994
+ record._setRaw(
6995
+ "media",
6996
+ row.media && row.media.length > 0 ? JSON.stringify(row.media) : null
6997
+ );
6998
+ record._setRaw("visibility", "public");
6999
+ record._setRaw("published_at", now);
7000
+ if (row.eventTime) {
7001
+ record._setRaw("event_time_start", row.eventTime.start ?? null);
7002
+ record._setRaw("event_time_end", row.eventTime.end ?? null);
7003
+ record._setRaw("event_time_kind", row.eventTime.kind ?? null);
7004
+ }
7005
+ })
7006
+ );
7007
+ await ctx.database.batch(...prepared);
7008
+ });
7009
+ return { inserted, skipped: photoRows.length - inserted };
7010
+ }
7011
+
6880
7012
  // src/lib/memory/autoExtract.ts
6881
7013
  import { Q as Q4 } from "@nozbe/watermelondb";
6882
7014
 
@@ -7783,6 +7915,9 @@ async function extractFacts(messages, options) {
7783
7915
  ...options.apiKey !== void 0 && { apiKey: options.apiKey },
7784
7916
  ...options.getToken !== void 0 && { getToken: options.getToken },
7785
7917
  ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
7918
+ ...options.endpointOverride !== void 0 && {
7919
+ endpointOverride: options.endpointOverride
7920
+ },
7786
7921
  model: options.model ?? DEFAULT_EXTRACTION_MODEL,
7787
7922
  systemPrompt: SYSTEM_PROMPT2,
7788
7923
  userMessage: `Today's date is ${today}. Resolve any relative dates ("yesterday", "next week") against it.
@@ -8293,70 +8428,6 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
8293
8428
  return new LRUCache(maxSize);
8294
8429
  }
8295
8430
 
8296
- // src/lib/memory/decay.ts
8297
- var DAY_MS = 24 * 60 * 60 * 1e3;
8298
- var SHORT_TTL_MS = 30 * DAY_MS;
8299
- var MEDIUM_TTL_MS = 180 * DAY_MS;
8300
- var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
8301
- var HARD_DELETE_WINDOW_MS = 30 * DAY_MS;
8302
- var PAST_EVENT_GRACE_MS = 7 * DAY_MS;
8303
- var DEFAULT_DECAY_POLICY = {
8304
- ttlByType: {
8305
- identity: NEVER_TTL_MS,
8306
- preference: NEVER_TTL_MS,
8307
- relationship: NEVER_TTL_MS,
8308
- constraint: NEVER_TTL_MS,
8309
- plan: SHORT_TTL_MS,
8310
- ongoing_context: SHORT_TTL_MS,
8311
- other: MEDIUM_TTL_MS
8312
- },
8313
- fallbackTtlMs: MEDIUM_TTL_MS,
8314
- hardDeleteWindowMs: HARD_DELETE_WINDOW_MS,
8315
- pastEventGraceMs: PAST_EVENT_GRACE_MS
8316
- };
8317
- function resolvePolicy(policy) {
8318
- if (!policy) return DEFAULT_DECAY_POLICY;
8319
- return {
8320
- ttlByType: { ...DEFAULT_DECAY_POLICY.ttlByType, ...policy.ttlByType },
8321
- fallbackTtlMs: policy.fallbackTtlMs ?? DEFAULT_DECAY_POLICY.fallbackTtlMs,
8322
- hardDeleteWindowMs: policy.hardDeleteWindowMs ?? DEFAULT_DECAY_POLICY.hardDeleteWindowMs,
8323
- pastEventGraceMs: policy.pastEventGraceMs ?? DEFAULT_DECAY_POLICY.pastEventGraceMs
8324
- };
8325
- }
8326
- function ttlForType(factType, policy) {
8327
- const resolved = resolvePolicy(policy);
8328
- if (factType === null) return resolved.fallbackTtlMs;
8329
- return resolved.ttlByType[factType] ?? resolved.fallbackTtlMs;
8330
- }
8331
- function isTimeSensitiveType(factType) {
8332
- return factType === "plan" || factType === "ongoing_context";
8333
- }
8334
- function hasFiniteTimestamps(m, now) {
8335
- return Number.isFinite(now) && Number.isFinite(m.updatedAt) && (m.archivedAt === null || Number.isFinite(m.archivedAt));
8336
- }
8337
- function classifyDecay(m, now, policy) {
8338
- const resolved = resolvePolicy(policy);
8339
- if (!hasFiniteTimestamps(m, now)) {
8340
- getLogger().warn("[memory/decay] non-finite timestamp on a memory row; keeping it", {
8341
- now,
8342
- updatedAt: m.updatedAt,
8343
- archivedAt: m.archivedAt,
8344
- factType: m.factType
8345
- });
8346
- return "keep";
8347
- }
8348
- if (m.archivedAt !== null) {
8349
- return now - m.archivedAt > resolved.hardDeleteWindowMs ? "delete" : "keep";
8350
- }
8351
- if (m.source === "manual") return "keep";
8352
- if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
8353
- if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
8354
- if (m.eventTimeEnd >= now) return "keep";
8355
- }
8356
- if (now - m.updatedAt > ttlForType(m.factType, resolved)) return "archive";
8357
- return "keep";
8358
- }
8359
-
8360
8431
  // src/lib/memory/decayClassifier.ts
8361
8432
  var DEFAULT_MODEL2 = "inclusionai/ling-2.6-flash";
8362
8433
  var DEFAULT_ATTEMPTS2 = 2;
@@ -8454,7 +8525,7 @@ function toDecayInput(c) {
8454
8525
  };
8455
8526
  }
8456
8527
  function isBorderline(input) {
8457
- if (input.source === "manual") return false;
8528
+ if (input.source === "manual" || input.source === SOURCE_PHOTO) return false;
8458
8529
  if (input.trustTier === "quarantined") return false;
8459
8530
  if (input.archivedAt !== null) return false;
8460
8531
  if (input.factType === null || input.factType === "other") return true;
@@ -14377,7 +14448,7 @@ __decorateClass([
14377
14448
  ], VaultFolder.prototype, "context", 2);
14378
14449
 
14379
14450
  // src/lib/db/schema.ts
14380
- var SDK_SCHEMA_VERSION = 44;
14451
+ var SDK_SCHEMA_VERSION = 45;
14381
14452
  var sdkSchema = appSchema2({
14382
14453
  version: SDK_SCHEMA_VERSION,
14383
14454
  tables: [
@@ -14525,6 +14596,18 @@ var sdkSchema = appSchema2({
14525
14596
  // paths key on `updated_at` — so without this a topic-only change would
14526
14597
  // neither upload nor merge. Null = `topics` never written.
14527
14598
  { name: "topics_updated_at", type: "number", isOptional: true },
14599
+ // The photo(s) a SERVER-EXTRACTED memory was read out of, as a JSON
14600
+ // array of `{feed_item_id, object_key}` — exactly what
14601
+ // GET /api/memories/published returns in `media[]`. Enough to render the
14602
+ // source image without a second round-trip per memory.
14603
+ //
14604
+ // A JSON column rather than a join table: nothing on the client ever
14605
+ // queries BY photo (the only direction is memory -> render its image),
14606
+ // so a table would add a sync lane and a local-id space to serve a
14607
+ // question nobody asks. `topics` and `source_chunk_ids` set the
14608
+ // precedent for a list that is only ever read back whole. Null on
14609
+ // anything not extracted from a photo.
14610
+ { name: "media", type: "string", isOptional: true },
14528
14611
  // Unix ms of the last LLM topic-extraction pass over this memory's
14529
14612
  // content. Null = never extracted standalone (legacy rows with entity
14530
14613
  // links are grandfathered — see getMemoriesNeedingTopicExtractionOp).
@@ -15359,6 +15442,20 @@ var sdkMigrations = schemaMigrations2({
15359
15442
  columns: [{ name: "origin", type: "string", isOptional: true }]
15360
15443
  })
15361
15444
  ]
15445
+ },
15446
+ // v44 -> v45: `media` on memory_vault — the photo(s) a server-extracted
15447
+ // memory was read out of, as JSON `[{feed_item_id, object_key}]`, mirroring
15448
+ // the `media[]` that GET /api/memories/published already returns. Existing
15449
+ // rows keep NULL, which is the correct value for every memory that did not
15450
+ // come from a photo (i.e. all of them until photo ingest runs).
15451
+ {
15452
+ toVersion: 45,
15453
+ steps: [
15454
+ addColumns2({
15455
+ table: "memory_vault",
15456
+ columns: [{ name: "media", type: "string", isOptional: true }]
15457
+ })
15458
+ ]
15362
15459
  }
15363
15460
  ]
15364
15461
  });
@@ -25235,6 +25332,7 @@ export {
25235
25332
  hasICloudCredentials,
25236
25333
  hasKeyPair,
25237
25334
  hasNotionCredentials,
25335
+ ingestPublishedPhotoMemoriesOp,
25238
25336
  injectionSignatureCatalog,
25239
25337
  insertAfterId,
25240
25338
  insertChild,
@@ -25261,6 +25359,7 @@ export {
25261
25359
  noopLogger,
25262
25360
  onKeyAvailable,
25263
25361
  parseJsx,
25362
+ parseMedia,
25264
25363
  preEmbedVaultMemories,
25265
25364
  preprocessFiles,
25266
25365
  previewToolSelection,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-EMVLDEPB.mjs";
3
+ } from "./chunk-TI3UVQPF.mjs";
4
4
  import "./chunk-ILAWDQDE.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -16612,6 +16612,22 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
16612
16612
  };
16613
16613
  }
16614
16614
 
16615
+ // src/lib/db/memoryVault/types.ts
16616
+ function parseMedia(value) {
16617
+ if (typeof value !== "string" || value === "") return null;
16618
+ try {
16619
+ const parsed = JSON.parse(value);
16620
+ if (!Array.isArray(parsed)) return null;
16621
+ const refs = parsed.filter((r) => typeof r === "object" && r !== null).map((r) => ({
16622
+ feedItemId: Number(r.feedItemId ?? r.feed_item_id),
16623
+ objectKey: r.objectKey ?? r.object_key ?? null
16624
+ })).filter((r) => Number.isFinite(r.feedItemId));
16625
+ return refs.length > 0 ? refs : null;
16626
+ } catch {
16627
+ return null;
16628
+ }
16629
+ }
16630
+
16615
16631
  // src/lib/db/memoryVault/operations.ts
16616
16632
  function visibilityOrPrivate(value) {
16617
16633
  return value === "public" ? value : "private";
@@ -16675,6 +16691,7 @@ function vaultMemoryToStoredRaw(memory) {
16675
16691
  sourceChunkIds,
16676
16692
  proofCount: memory.proofCount ?? null,
16677
16693
  source: memory.source ?? null,
16694
+ media: parseMedia(memory.media),
16678
16695
  eventTimeStart: memory.eventTimeStart ?? null,
16679
16696
  eventTimeEnd: memory.eventTimeEnd ?? null,
16680
16697
  eventTimeKind: memory.eventTimeKind ?? null,
@@ -16957,6 +16974,7 @@ function vaultMemoryRawToStoredRaw(raw) {
16957
16974
  eventTimeKind: raw.event_time_kind ?? null,
16958
16975
  // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
16959
16976
  topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1,
16977
+ media: parseMedia(raw.media),
16960
16978
  topics: parseTopics(raw.topics),
16961
16979
  topicsUpdatedAt: raw.topics_updated_at ?? null,
16962
16980
  topicsExtractedAt: raw.topics_extracted_at ?? null,
@@ -20691,7 +20709,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
20691
20709
  subQueries = decomp.subQueries;
20692
20710
  }
20693
20711
  }
20694
- const { recall: recall2 } = await import("./recall-IM6RLRI6.mjs");
20712
+ const { recall: recall2 } = await import("./recall-BQSCJBGI.mjs");
20695
20713
  let recallDegraded = [];
20696
20714
  const result = await recall2(
20697
20715
  query,
@@ -21710,6 +21728,8 @@ export {
21710
21728
  ENTITY_KINDS,
21711
21729
  linkMemoryEntitiesOp,
21712
21730
  replaceMemoryEntitiesGuardedOp,
21731
+ encryptVaultMemoryContent,
21732
+ parseMedia,
21713
21733
  vaultMemoryToStored,
21714
21734
  createVaultMemoryOp,
21715
21735
  createSupersedingMemoryOp,