@anuma/sdk 6.1.1 → 6.3.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.
@@ -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-GIBV5GBW.mjs";
171
+ } from "./chunk-TI3UVQPF.mjs";
170
172
  import {
171
173
  PiiRedactor,
172
174
  createStreamingDeAnonymizer,
@@ -5344,6 +5346,43 @@ async function cleanupConversationSummary(database, conversationId) {
5344
5346
  }
5345
5347
  }
5346
5348
 
5349
+ // src/lib/chat/toolResultMessage.ts
5350
+ var HEADER = "[Tool Execution Results]\n\n";
5351
+ var FOOTER = "\n\nBased on these results, continue with the task.";
5352
+ var ENTRY_SEPARATOR = "\n\n";
5353
+ var MAX_PERSISTED_TOOL_RESULT_CHARS = 1e5;
5354
+ function buildToolResultContent(results) {
5355
+ const entries = results.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`);
5356
+ const framing = HEADER.length + FOOTER.length + ENTRY_SEPARATOR.length * Math.max(0, entries.length - 1);
5357
+ const summary = capEntries(entries, MAX_PERSISTED_TOOL_RESULT_CHARS - framing).join(
5358
+ ENTRY_SEPARATOR
5359
+ );
5360
+ return `${HEADER}${summary}${FOOTER}`;
5361
+ }
5362
+ function capEntries(entries, budget) {
5363
+ const smallestFirst = entries.map((_, index) => index).sort((a, b) => entries[a].length - entries[b].length);
5364
+ const capped = [...entries];
5365
+ let remaining = budget;
5366
+ let unassigned = entries.length;
5367
+ for (const index of smallestFirst) {
5368
+ capped[index] = truncateEntry(entries[index], Math.floor(remaining / unassigned));
5369
+ remaining -= capped[index].length;
5370
+ unassigned--;
5371
+ }
5372
+ return capped;
5373
+ }
5374
+ function truncateEntry(entry, allowance) {
5375
+ if (entry.length <= allowance) return entry;
5376
+ const keep = allowance - truncationMarker(entry.length).length;
5377
+ if (keep <= 0) return entry.slice(0, Math.max(0, allowance));
5378
+ return `${entry.slice(0, keep)}${truncationMarker(entry.length - keep)}`;
5379
+ }
5380
+ function truncationMarker(omitted) {
5381
+ return `
5382
+
5383
+ ... (tool output truncated, ${omitted} characters omitted)`;
5384
+ }
5385
+
5347
5386
  // src/lib/db/chat/lazyDecrypt.ts
5348
5387
  var LRU_CAPACITY = 256;
5349
5388
  var titleCache = /* @__PURE__ */ new Map();
@@ -5487,6 +5526,9 @@ __decorateClass([
5487
5526
  __decorateClass([
5488
5527
  json("tool_call_events", (raw) => raw)
5489
5528
  ], Message.prototype, "toolCallEvents", 2);
5529
+ __decorateClass([
5530
+ text("origin")
5531
+ ], Message.prototype, "origin", 2);
5490
5532
  var Conversation = class extends Model {
5491
5533
  };
5492
5534
  Conversation.table = "conversations";
@@ -6790,6 +6832,9 @@ __decorateClass([
6790
6832
  __decorateClass([
6791
6833
  field3("topics_updated_at")
6792
6834
  ], VaultMemory.prototype, "topicsUpdatedAt", 2);
6835
+ __decorateClass([
6836
+ field3("media")
6837
+ ], VaultMemory.prototype, "media", 2);
6793
6838
  __decorateClass([
6794
6839
  field3("topics_extracted_at")
6795
6840
  ], VaultMemory.prototype, "topicsExtractedAt", 2);
@@ -6837,6 +6882,133 @@ __decorateClass([
6837
6882
  field3("is_deleted")
6838
6883
  ], VaultMemory.prototype, "isDeleted", 2);
6839
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
+
6840
7012
  // src/lib/memory/autoExtract.ts
6841
7013
  import { Q as Q4 } from "@nozbe/watermelondb";
6842
7014
 
@@ -8253,70 +8425,6 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
8253
8425
  return new LRUCache(maxSize);
8254
8426
  }
8255
8427
 
8256
- // src/lib/memory/decay.ts
8257
- var DAY_MS = 24 * 60 * 60 * 1e3;
8258
- var SHORT_TTL_MS = 30 * DAY_MS;
8259
- var MEDIUM_TTL_MS = 180 * DAY_MS;
8260
- var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
8261
- var HARD_DELETE_WINDOW_MS = 30 * DAY_MS;
8262
- var PAST_EVENT_GRACE_MS = 7 * DAY_MS;
8263
- var DEFAULT_DECAY_POLICY = {
8264
- ttlByType: {
8265
- identity: NEVER_TTL_MS,
8266
- preference: NEVER_TTL_MS,
8267
- relationship: NEVER_TTL_MS,
8268
- constraint: NEVER_TTL_MS,
8269
- plan: SHORT_TTL_MS,
8270
- ongoing_context: SHORT_TTL_MS,
8271
- other: MEDIUM_TTL_MS
8272
- },
8273
- fallbackTtlMs: MEDIUM_TTL_MS,
8274
- hardDeleteWindowMs: HARD_DELETE_WINDOW_MS,
8275
- pastEventGraceMs: PAST_EVENT_GRACE_MS
8276
- };
8277
- function resolvePolicy(policy) {
8278
- if (!policy) return DEFAULT_DECAY_POLICY;
8279
- return {
8280
- ttlByType: { ...DEFAULT_DECAY_POLICY.ttlByType, ...policy.ttlByType },
8281
- fallbackTtlMs: policy.fallbackTtlMs ?? DEFAULT_DECAY_POLICY.fallbackTtlMs,
8282
- hardDeleteWindowMs: policy.hardDeleteWindowMs ?? DEFAULT_DECAY_POLICY.hardDeleteWindowMs,
8283
- pastEventGraceMs: policy.pastEventGraceMs ?? DEFAULT_DECAY_POLICY.pastEventGraceMs
8284
- };
8285
- }
8286
- function ttlForType(factType, policy) {
8287
- const resolved = resolvePolicy(policy);
8288
- if (factType === null) return resolved.fallbackTtlMs;
8289
- return resolved.ttlByType[factType] ?? resolved.fallbackTtlMs;
8290
- }
8291
- function isTimeSensitiveType(factType) {
8292
- return factType === "plan" || factType === "ongoing_context";
8293
- }
8294
- function hasFiniteTimestamps(m, now) {
8295
- return Number.isFinite(now) && Number.isFinite(m.updatedAt) && (m.archivedAt === null || Number.isFinite(m.archivedAt));
8296
- }
8297
- function classifyDecay(m, now, policy) {
8298
- const resolved = resolvePolicy(policy);
8299
- if (!hasFiniteTimestamps(m, now)) {
8300
- getLogger().warn("[memory/decay] non-finite timestamp on a memory row; keeping it", {
8301
- now,
8302
- updatedAt: m.updatedAt,
8303
- archivedAt: m.archivedAt,
8304
- factType: m.factType
8305
- });
8306
- return "keep";
8307
- }
8308
- if (m.archivedAt !== null) {
8309
- return now - m.archivedAt > resolved.hardDeleteWindowMs ? "delete" : "keep";
8310
- }
8311
- if (m.source === "manual") return "keep";
8312
- if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
8313
- if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
8314
- if (m.eventTimeEnd >= now) return "keep";
8315
- }
8316
- if (now - m.updatedAt > ttlForType(m.factType, resolved)) return "archive";
8317
- return "keep";
8318
- }
8319
-
8320
8428
  // src/lib/memory/decayClassifier.ts
8321
8429
  var DEFAULT_MODEL2 = "inclusionai/ling-2.6-flash";
8322
8430
  var DEFAULT_ATTEMPTS2 = 2;
@@ -8414,7 +8522,7 @@ function toDecayInput(c) {
8414
8522
  };
8415
8523
  }
8416
8524
  function isBorderline(input) {
8417
- if (input.source === "manual") return false;
8525
+ if (input.source === "manual" || input.source === SOURCE_PHOTO) return false;
8418
8526
  if (input.trustTier === "quarantined") return false;
8419
8527
  if (input.archivedAt !== null) return false;
8420
8528
  if (input.factType === null || input.factType === "other") return true;
@@ -13998,12 +14106,7 @@ function useChatStorage(options) {
13998
14106
  }
13999
14107
  const autoToolResults = result.autoExecutedToolResults;
14000
14108
  if (autoToolResults && autoToolResults.length > 0) {
14001
- const toolSummary = autoToolResults.map((r) => `Tool "${r.name}" returned: ${JSON.stringify(r.result)}`).join("\n\n");
14002
- const toolResultContent = `[Tool Execution Results]
14003
-
14004
- ${toolSummary}
14005
-
14006
- Based on these results, continue with the task.`;
14109
+ const toolResultContent = buildToolResultContent(autoToolResults);
14007
14110
  try {
14008
14111
  await writeOrQueue(
14009
14112
  "createMessage",
@@ -14012,21 +14115,24 @@ Based on these results, continue with the task.`;
14012
14115
  role: "user",
14013
14116
  content: toolResultContent,
14014
14117
  model: "",
14015
- parentMessageId: storedAssistantMessage.uniqueId
14118
+ parentMessageId: storedAssistantMessage.uniqueId,
14119
+ origin: "tool_result"
14016
14120
  },
14017
14121
  () => createMessageOp(storageCtx, {
14018
14122
  conversationId: convId,
14019
14123
  role: "user",
14020
14124
  content: toolResultContent,
14021
14125
  model: "",
14022
- parentMessageId: storedAssistantMessage.uniqueId
14126
+ parentMessageId: storedAssistantMessage.uniqueId,
14127
+ origin: "tool_result"
14023
14128
  }),
14024
14129
  () => makeSyntheticStoredMessage({
14025
14130
  conversationId: convId,
14026
14131
  role: "user",
14027
14132
  content: toolResultContent,
14028
14133
  model: "",
14029
- parentMessageId: storedAssistantMessage.uniqueId
14134
+ parentMessageId: storedAssistantMessage.uniqueId,
14135
+ origin: "tool_result"
14030
14136
  }),
14031
14137
  assistantMsgQueueId ? [assistantMsgQueueId] : []
14032
14138
  );
@@ -14339,7 +14445,7 @@ __decorateClass([
14339
14445
  ], VaultFolder.prototype, "context", 2);
14340
14446
 
14341
14447
  // src/lib/db/schema.ts
14342
- var SDK_SCHEMA_VERSION = 43;
14448
+ var SDK_SCHEMA_VERSION = 45;
14343
14449
  var sdkSchema = appSchema2({
14344
14450
  version: SDK_SCHEMA_VERSION,
14345
14451
  tables: [
@@ -14377,8 +14483,10 @@ var sdkSchema = appSchema2({
14377
14483
  // Parent message for branching
14378
14484
  { name: "feedback", type: "string", isOptional: true },
14379
14485
  // 'like' | 'dislike' | null
14380
- { name: "tool_call_events", type: "string", isOptional: true }
14486
+ { name: "tool_call_events", type: "string", isOptional: true },
14381
14487
  // JSON stringified LlmapiToolCallEvent[]
14488
+ { name: "origin", type: "string", isOptional: true }
14489
+ // MessageOrigin — provenance, NOT encrypted (see v44)
14382
14490
  ]
14383
14491
  }),
14384
14492
  tableSchema2({
@@ -14485,6 +14593,18 @@ var sdkSchema = appSchema2({
14485
14593
  // paths key on `updated_at` — so without this a topic-only change would
14486
14594
  // neither upload nor merge. Null = `topics` never written.
14487
14595
  { name: "topics_updated_at", type: "number", isOptional: true },
14596
+ // The photo(s) a SERVER-EXTRACTED memory was read out of, as a JSON
14597
+ // array of `{feed_item_id, object_key}` — exactly what
14598
+ // GET /api/memories/published returns in `media[]`. Enough to render the
14599
+ // source image without a second round-trip per memory.
14600
+ //
14601
+ // A JSON column rather than a join table: nothing on the client ever
14602
+ // queries BY photo (the only direction is memory -> render its image),
14603
+ // so a table would add a sync lane and a local-id space to serve a
14604
+ // question nobody asks. `topics` and `source_chunk_ids` set the
14605
+ // precedent for a list that is only ever read back whole. Null on
14606
+ // anything not extracted from a photo.
14607
+ { name: "media", type: "string", isOptional: true },
14488
14608
  // Unix ms of the last LLM topic-extraction pass over this memory's
14489
14609
  // content. Null = never extracted standalone (legacy rows with entity
14490
14610
  // links are grandfathered — see getMemoriesNeedingTopicExtractionOp).
@@ -15306,6 +15426,33 @@ var sdkMigrations = schemaMigrations2({
15306
15426
  "CREATE INDEX IF NOT EXISTS conversations_is_deleted_created_at ON conversations (is_deleted, created_at);"
15307
15427
  )
15308
15428
  ]
15429
+ },
15430
+ // v43 -> v44: Added origin column to history — the provenance tag the embedding
15431
+ // sweep reads to skip never-rendered tool-result rows. No backfill: NULL means
15432
+ // "legacy, provenance unknown" and keeps the pre-v44 behaviour of embedding the
15433
+ // row, so the only rows that stop being embedded are ones a v44+ producer tagged.
15434
+ {
15435
+ toVersion: 44,
15436
+ steps: [
15437
+ addColumns2({
15438
+ table: "history",
15439
+ columns: [{ name: "origin", type: "string", isOptional: true }]
15440
+ })
15441
+ ]
15442
+ },
15443
+ // v44 -> v45: `media` on memory_vault — the photo(s) a server-extracted
15444
+ // memory was read out of, as JSON `[{feed_item_id, object_key}]`, mirroring
15445
+ // the `media[]` that GET /api/memories/published already returns. Existing
15446
+ // rows keep NULL, which is the correct value for every memory that did not
15447
+ // come from a photo (i.e. all of them until photo ingest runs).
15448
+ {
15449
+ toVersion: 45,
15450
+ steps: [
15451
+ addColumns2({
15452
+ table: "memory_vault",
15453
+ columns: [{ name: "media", type: "string", isOptional: true }]
15454
+ })
15455
+ ]
15309
15456
  }
15310
15457
  ]
15311
15458
  });
@@ -23435,7 +23582,7 @@ IMPORTANT: For write operations (POST, PUT, PATCH, DELETE), always confirm with
23435
23582
  }
23436
23583
  try {
23437
23584
  const data = JSON.parse(text12);
23438
- const json4 = JSON.stringify(data, null, 2);
23585
+ const json4 = JSON.stringify(data);
23439
23586
  return truncate(json4, MAX_RESPONSE_SIZE);
23440
23587
  } catch {
23441
23588
  return truncate(text12, MAX_RESPONSE_SIZE);
@@ -25182,6 +25329,7 @@ export {
25182
25329
  hasICloudCredentials,
25183
25330
  hasKeyPair,
25184
25331
  hasNotionCredentials,
25332
+ ingestPublishedPhotoMemoriesOp,
25185
25333
  injectionSignatureCatalog,
25186
25334
  insertAfterId,
25187
25335
  insertChild,
@@ -25208,6 +25356,7 @@ export {
25208
25356
  noopLogger,
25209
25357
  onKeyAvailable,
25210
25358
  parseJsx,
25359
+ parseMedia,
25211
25360
  preEmbedVaultMemories,
25212
25361
  preprocessFiles,
25213
25362
  previewToolSelection,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-GIBV5GBW.mjs";
3
+ } from "./chunk-TI3UVQPF.mjs";
4
4
  import "./chunk-ILAWDQDE.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -15469,7 +15469,8 @@ function messageToStoredRaw(message, projection) {
15469
15469
  thinking: message.thinking,
15470
15470
  parentMessageId: message.parentMessageId,
15471
15471
  feedback: message.feedback || null,
15472
- toolCallEvents: parseJsonField(toolCallEventsRaw)
15472
+ toolCallEvents: parseJsonField(toolCallEventsRaw),
15473
+ origin: message.origin
15473
15474
  };
15474
15475
  }
15475
15476
  async function messageToStored(message, walletAddress, signMessage, embeddedWalletSigner, projection) {
@@ -15530,7 +15531,11 @@ function messageRawToStoredRaw(raw, projection) {
15530
15531
  thinking: raw.thinking,
15531
15532
  parentMessageId: raw.parent_message_id,
15532
15533
  feedback: raw.feedback || null,
15533
- toolCallEvents: parseJsonField(raw.tool_call_events)
15534
+ toolCallEvents: parseJsonField(raw.tool_call_events),
15535
+ // Load-bearing on this path specifically: getMessagesOp reads raws, and it is
15536
+ // what the deferred embedding sweep iterates, so the provenance gate depends
15537
+ // on `origin` surviving the raw mapper as well as the Model one.
15538
+ origin: raw.origin
15534
15539
  };
15535
15540
  }
15536
15541
  async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
@@ -15793,6 +15798,7 @@ function applyMessageFields(msg, encryptedOpts) {
15793
15798
  const tceValue = typeof encryptedOpts.toolCallEvents === "string" ? encryptedOpts.toolCallEvents : JSON.stringify(encryptedOpts.toolCallEvents);
15794
15799
  msg._setRaw("tool_call_events", tceValue);
15795
15800
  }
15801
+ if (encryptedOpts.origin) msg._setRaw("origin", encryptedOpts.origin);
15796
15802
  }
15797
15803
  async function createMessageOp(ctx, opts) {
15798
15804
  if (opts.uniqueId) {
@@ -16211,7 +16217,8 @@ function makeSyntheticStoredMessage(opts) {
16211
16217
  thoughtProcess: opts.thoughtProcess,
16212
16218
  thinking: opts.thinking,
16213
16219
  parentMessageId: opts.parentMessageId,
16214
- toolCallEvents: opts.toolCallEvents
16220
+ toolCallEvents: opts.toolCallEvents,
16221
+ origin: opts.origin
16215
16222
  };
16216
16223
  }
16217
16224
  function makeSyntheticStoredConversation(opts, defaultTitle) {
@@ -16605,6 +16612,22 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
16605
16612
  };
16606
16613
  }
16607
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
+
16608
16631
  // src/lib/db/memoryVault/operations.ts
16609
16632
  function visibilityOrPrivate(value) {
16610
16633
  return value === "public" ? value : "private";
@@ -16668,6 +16691,7 @@ function vaultMemoryToStoredRaw(memory) {
16668
16691
  sourceChunkIds,
16669
16692
  proofCount: memory.proofCount ?? null,
16670
16693
  source: memory.source ?? null,
16694
+ media: parseMedia(memory.media),
16671
16695
  eventTimeStart: memory.eventTimeStart ?? null,
16672
16696
  eventTimeEnd: memory.eventTimeEnd ?? null,
16673
16697
  eventTimeKind: memory.eventTimeKind ?? null,
@@ -16950,6 +16974,7 @@ function vaultMemoryRawToStoredRaw(raw) {
16950
16974
  eventTimeKind: raw.event_time_kind ?? null,
16951
16975
  // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
16952
16976
  topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1,
16977
+ media: parseMedia(raw.media),
16953
16978
  topics: parseTopics(raw.topics),
16954
16979
  topicsUpdatedAt: raw.topics_updated_at ?? null,
16955
16980
  topicsExtractedAt: raw.topics_extracted_at ?? null,
@@ -18795,6 +18820,7 @@ async function generateEmbeddings(texts, options) {
18795
18820
 
18796
18821
  // src/lib/memoryEngine/embeddings.ts
18797
18822
  var DEFAULT_MIN_CONTENT_LENGTH = 10;
18823
+ var NON_EMBEDDABLE_ORIGIN = "tool_result";
18798
18824
  async function embedMessage(ctx, messageId, options) {
18799
18825
  const message = await getMessageOp(ctx, messageId);
18800
18826
  if (!message) {
@@ -18803,6 +18829,9 @@ async function embedMessage(ctx, messageId, options) {
18803
18829
  if (message.vector && message.vector.length > 0) {
18804
18830
  return message;
18805
18831
  }
18832
+ if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18833
+ return message;
18834
+ }
18806
18835
  const embedding = await generateEmbedding(message.content, options);
18807
18836
  const embeddingModel = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
18808
18837
  return updateMessageEmbeddingOp(ctx, messageId, embedding, embeddingModel);
@@ -18824,6 +18853,9 @@ async function embedAllMessages(ctx, options, filter) {
18824
18853
  if (message.role === "system") {
18825
18854
  continue;
18826
18855
  }
18856
+ if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18857
+ continue;
18858
+ }
18827
18859
  const minLength = filter?.minContentLength ?? DEFAULT_MIN_CONTENT_LENGTH;
18828
18860
  if (message.content.length < minLength) {
18829
18861
  continue;
@@ -18849,6 +18881,9 @@ async function chunkAndEmbedMessage(ctx, messageId, options) {
18849
18881
  if (message.chunks && message.chunks.length > 0) {
18850
18882
  return message;
18851
18883
  }
18884
+ if (message.origin === NON_EMBEDDABLE_ORIGIN) {
18885
+ return message;
18886
+ }
18852
18887
  const embeddingModel = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
18853
18888
  if (!shouldChunkMessage(message.content, chunkSize)) {
18854
18889
  const embedding = await generateEmbedding(message.content, options);
@@ -18882,6 +18917,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
18882
18917
  if (hasVector && !filter?.rechunkExisting && !isStale) continue;
18883
18918
  if (filter?.roles && !filter.roles.includes(message.role)) continue;
18884
18919
  if (message.role === "system") continue;
18920
+ if (message.origin === NON_EMBEDDABLE_ORIGIN) continue;
18885
18921
  if (message.content.length < minLength) continue;
18886
18922
  if (shouldChunkMessage(message.content, chunkSize)) {
18887
18923
  longMessages.push({
@@ -20673,7 +20709,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
20673
20709
  subQueries = decomp.subQueries;
20674
20710
  }
20675
20711
  }
20676
- const { recall: recall2 } = await import("./recall-P2HA3MUA.mjs");
20712
+ const { recall: recall2 } = await import("./recall-BQSCJBGI.mjs");
20677
20713
  let recallDegraded = [];
20678
20714
  const result = await recall2(
20679
20715
  query,
@@ -21692,6 +21728,8 @@ export {
21692
21728
  ENTITY_KINDS,
21693
21729
  linkMemoryEntitiesOp,
21694
21730
  replaceMemoryEntitiesGuardedOp,
21731
+ encryptVaultMemoryContent,
21732
+ parseMedia,
21695
21733
  vaultMemoryToStored,
21696
21734
  createVaultMemoryOp,
21697
21735
  createSupersedingMemoryOp,