@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.
- package/dist/expo/{chunk-VBPZDIFV.mjs → chunk-PBCULYOW.mjs} +42 -4
- package/dist/expo/index.cjs +239 -79
- package/dist/expo/index.d.mts +172 -4
- package/dist/expo/index.d.ts +172 -4
- package/dist/expo/index.mjs +182 -68
- package/dist/expo/{recall-2IOGTAFJ.mjs → recall-UVM2366D.mjs} +1 -1
- package/dist/react/{chunk-GIBV5GBW.mjs → chunk-TI3UVQPF.mjs} +42 -4
- package/dist/react/index.cjs +284 -89
- package/dist/react/index.d.mts +172 -4
- package/dist/react/index.d.ts +172 -4
- package/dist/react/index.mjs +227 -78
- package/dist/react/{recall-KOKU2PPN.mjs → recall-PCM7H5TA.mjs} +1 -1
- package/dist/server/{chunk-FYT5MBVO.mjs → chunk-S5WEN7TE.mjs} +42 -4
- package/dist/server/index.cjs +239 -79
- package/dist/server/index.d.mts +172 -4
- package/dist/server/index.d.ts +172 -4
- package/dist/server/index.mjs +182 -68
- package/dist/server/{recall-P2HA3MUA.mjs → recall-BQSCJBGI.mjs} +1 -1
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.mjs +1 -1
- package/package.json +1 -1
package/dist/expo/index.mjs
CHANGED
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
embedMessage,
|
|
54
54
|
encryptField,
|
|
55
55
|
encryptJsonField,
|
|
56
|
+
encryptVaultMemoryContent,
|
|
56
57
|
extractAssistantText,
|
|
57
58
|
extractUserMessageFromMessages,
|
|
58
59
|
finalizeThoughtProcess,
|
|
@@ -90,6 +91,7 @@ import {
|
|
|
90
91
|
makeSyntheticStoredMessage,
|
|
91
92
|
onClearAllEncryptionState,
|
|
92
93
|
onKeyAvailable,
|
|
94
|
+
parseMedia,
|
|
93
95
|
postApiV1CreditsPurchase,
|
|
94
96
|
preEmbedVaultMemories,
|
|
95
97
|
prepareVaultCandidates,
|
|
@@ -121,7 +123,7 @@ import {
|
|
|
121
123
|
upsertMessageOp,
|
|
122
124
|
useEncryption,
|
|
123
125
|
vaultMemoryToStored
|
|
124
|
-
} from "./chunk-
|
|
126
|
+
} from "./chunk-PBCULYOW.mjs";
|
|
125
127
|
import {
|
|
126
128
|
PII_PATTERNS,
|
|
127
129
|
PiiRedactor,
|
|
@@ -5127,6 +5129,9 @@ __decorateClass([
|
|
|
5127
5129
|
__decorateClass([
|
|
5128
5130
|
json("tool_call_events", (raw) => raw)
|
|
5129
5131
|
], Message.prototype, "toolCallEvents", 2);
|
|
5132
|
+
__decorateClass([
|
|
5133
|
+
text("origin")
|
|
5134
|
+
], Message.prototype, "origin", 2);
|
|
5130
5135
|
var Conversation = class extends Model {
|
|
5131
5136
|
};
|
|
5132
5137
|
Conversation.table = "conversations";
|
|
@@ -5634,6 +5639,9 @@ __decorateClass([
|
|
|
5634
5639
|
__decorateClass([
|
|
5635
5640
|
field3("topics_updated_at")
|
|
5636
5641
|
], VaultMemory.prototype, "topicsUpdatedAt", 2);
|
|
5642
|
+
__decorateClass([
|
|
5643
|
+
field3("media")
|
|
5644
|
+
], VaultMemory.prototype, "media", 2);
|
|
5637
5645
|
__decorateClass([
|
|
5638
5646
|
field3("topics_extracted_at")
|
|
5639
5647
|
], VaultMemory.prototype, "topicsExtractedAt", 2);
|
|
@@ -5681,6 +5689,133 @@ __decorateClass([
|
|
|
5681
5689
|
field3("is_deleted")
|
|
5682
5690
|
], VaultMemory.prototype, "isDeleted", 2);
|
|
5683
5691
|
|
|
5692
|
+
// src/lib/memory/decay.ts
|
|
5693
|
+
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
5694
|
+
var SHORT_TTL_MS = 30 * DAY_MS;
|
|
5695
|
+
var MEDIUM_TTL_MS = 180 * DAY_MS;
|
|
5696
|
+
var SOURCE_PHOTO = "photo";
|
|
5697
|
+
var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
|
|
5698
|
+
var HARD_DELETE_WINDOW_MS = 30 * DAY_MS;
|
|
5699
|
+
var PAST_EVENT_GRACE_MS = 7 * DAY_MS;
|
|
5700
|
+
var DEFAULT_DECAY_POLICY = {
|
|
5701
|
+
ttlByType: {
|
|
5702
|
+
identity: NEVER_TTL_MS,
|
|
5703
|
+
preference: NEVER_TTL_MS,
|
|
5704
|
+
relationship: NEVER_TTL_MS,
|
|
5705
|
+
constraint: NEVER_TTL_MS,
|
|
5706
|
+
plan: SHORT_TTL_MS,
|
|
5707
|
+
ongoing_context: SHORT_TTL_MS,
|
|
5708
|
+
other: MEDIUM_TTL_MS
|
|
5709
|
+
},
|
|
5710
|
+
fallbackTtlMs: MEDIUM_TTL_MS,
|
|
5711
|
+
hardDeleteWindowMs: HARD_DELETE_WINDOW_MS,
|
|
5712
|
+
pastEventGraceMs: PAST_EVENT_GRACE_MS
|
|
5713
|
+
};
|
|
5714
|
+
function resolvePolicy(policy) {
|
|
5715
|
+
if (!policy) return DEFAULT_DECAY_POLICY;
|
|
5716
|
+
return {
|
|
5717
|
+
ttlByType: { ...DEFAULT_DECAY_POLICY.ttlByType, ...policy.ttlByType },
|
|
5718
|
+
fallbackTtlMs: policy.fallbackTtlMs ?? DEFAULT_DECAY_POLICY.fallbackTtlMs,
|
|
5719
|
+
hardDeleteWindowMs: policy.hardDeleteWindowMs ?? DEFAULT_DECAY_POLICY.hardDeleteWindowMs,
|
|
5720
|
+
pastEventGraceMs: policy.pastEventGraceMs ?? DEFAULT_DECAY_POLICY.pastEventGraceMs
|
|
5721
|
+
};
|
|
5722
|
+
}
|
|
5723
|
+
function ttlForType(factType, policy) {
|
|
5724
|
+
const resolved = resolvePolicy(policy);
|
|
5725
|
+
if (factType === null) return resolved.fallbackTtlMs;
|
|
5726
|
+
return resolved.ttlByType[factType] ?? resolved.fallbackTtlMs;
|
|
5727
|
+
}
|
|
5728
|
+
function isTimeSensitiveType(factType) {
|
|
5729
|
+
return factType === "plan" || factType === "ongoing_context";
|
|
5730
|
+
}
|
|
5731
|
+
function hasFiniteTimestamps(m, now) {
|
|
5732
|
+
return Number.isFinite(now) && Number.isFinite(m.updatedAt) && (m.archivedAt === null || Number.isFinite(m.archivedAt));
|
|
5733
|
+
}
|
|
5734
|
+
function classifyDecay(m, now, policy) {
|
|
5735
|
+
const resolved = resolvePolicy(policy);
|
|
5736
|
+
if (!hasFiniteTimestamps(m, now)) {
|
|
5737
|
+
getLogger().warn("[memory/decay] non-finite timestamp on a memory row; keeping it", {
|
|
5738
|
+
now,
|
|
5739
|
+
updatedAt: m.updatedAt,
|
|
5740
|
+
archivedAt: m.archivedAt,
|
|
5741
|
+
factType: m.factType
|
|
5742
|
+
});
|
|
5743
|
+
return "keep";
|
|
5744
|
+
}
|
|
5745
|
+
if (m.archivedAt !== null) {
|
|
5746
|
+
return now - m.archivedAt > resolved.hardDeleteWindowMs ? "delete" : "keep";
|
|
5747
|
+
}
|
|
5748
|
+
if (m.source === "manual" || m.source === SOURCE_PHOTO) return "keep";
|
|
5749
|
+
if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
|
|
5750
|
+
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
5751
|
+
if (m.eventTimeEnd >= now) return "keep";
|
|
5752
|
+
}
|
|
5753
|
+
if (now - m.updatedAt > ttlForType(m.factType, resolved)) return "archive";
|
|
5754
|
+
return "keep";
|
|
5755
|
+
}
|
|
5756
|
+
|
|
5757
|
+
// src/lib/db/memoryVault/photoIngest.ts
|
|
5758
|
+
var PHOTO_MEMORY_ID_PREFIX = "photo:";
|
|
5759
|
+
async function ingestPublishedPhotoMemoriesOp(ctx, rows) {
|
|
5760
|
+
const byId = /* @__PURE__ */ new Map();
|
|
5761
|
+
for (const r of rows) {
|
|
5762
|
+
if (typeof r.memoryId !== "string" || !r.memoryId.startsWith(PHOTO_MEMORY_ID_PREFIX)) continue;
|
|
5763
|
+
if (!byId.has(r.memoryId)) byId.set(r.memoryId, r);
|
|
5764
|
+
}
|
|
5765
|
+
const photoRows = [...byId.values()];
|
|
5766
|
+
if (photoRows.length === 0) return { inserted: 0, skipped: 0 };
|
|
5767
|
+
const known = await ctx.vaultMemoryCollection.query().fetchIds().then((ids) => new Set(ids));
|
|
5768
|
+
const candidates = photoRows.filter((r) => !known.has(r.memoryId));
|
|
5769
|
+
if (candidates.length === 0) return { inserted: 0, skipped: photoRows.length };
|
|
5770
|
+
const fresh = candidates;
|
|
5771
|
+
const contents = await Promise.all(
|
|
5772
|
+
fresh.map(async (r) => {
|
|
5773
|
+
if (ctx.walletAddress && ctx.signMessage) {
|
|
5774
|
+
return encryptVaultMemoryContent(
|
|
5775
|
+
r.text,
|
|
5776
|
+
ctx.walletAddress,
|
|
5777
|
+
ctx.signMessage,
|
|
5778
|
+
ctx.embeddedWalletSigner
|
|
5779
|
+
);
|
|
5780
|
+
}
|
|
5781
|
+
return r.text;
|
|
5782
|
+
})
|
|
5783
|
+
);
|
|
5784
|
+
const now = Date.now();
|
|
5785
|
+
let inserted = 0;
|
|
5786
|
+
await ctx.database.write(async () => {
|
|
5787
|
+
const present = new Set(await ctx.vaultMemoryCollection.query().fetchIds());
|
|
5788
|
+
const writable = fresh.map((row, i) => ({ row, content: contents[i] })).filter(({ row }) => !present.has(row.memoryId));
|
|
5789
|
+
inserted = writable.length;
|
|
5790
|
+
if (writable.length === 0) return;
|
|
5791
|
+
const prepared = writable.map(
|
|
5792
|
+
({ row, content }) => ctx.vaultMemoryCollection.prepareCreate((record) => {
|
|
5793
|
+
record._raw.id = row.memoryId;
|
|
5794
|
+
record._setRaw("content", content);
|
|
5795
|
+
record._setRaw("scope", "private");
|
|
5796
|
+
record._setRaw("folder_id", null);
|
|
5797
|
+
record._setRaw("user_id", ctx.userId ?? null);
|
|
5798
|
+
record._setRaw("is_deleted", false);
|
|
5799
|
+
record._setRaw("proof_count", 1);
|
|
5800
|
+
record._setRaw("source", SOURCE_PHOTO);
|
|
5801
|
+
record._setRaw(
|
|
5802
|
+
"media",
|
|
5803
|
+
row.media && row.media.length > 0 ? JSON.stringify(row.media) : null
|
|
5804
|
+
);
|
|
5805
|
+
record._setRaw("visibility", "public");
|
|
5806
|
+
record._setRaw("published_at", now);
|
|
5807
|
+
if (row.eventTime) {
|
|
5808
|
+
record._setRaw("event_time_start", row.eventTime.start ?? null);
|
|
5809
|
+
record._setRaw("event_time_end", row.eventTime.end ?? null);
|
|
5810
|
+
record._setRaw("event_time_kind", row.eventTime.kind ?? null);
|
|
5811
|
+
}
|
|
5812
|
+
})
|
|
5813
|
+
);
|
|
5814
|
+
await ctx.database.batch(...prepared);
|
|
5815
|
+
});
|
|
5816
|
+
return { inserted, skipped: photoRows.length - inserted };
|
|
5817
|
+
}
|
|
5818
|
+
|
|
5684
5819
|
// src/lib/db/queue/manager.ts
|
|
5685
5820
|
import { v7 as uuidv72 } from "uuid";
|
|
5686
5821
|
var MAX_OPERATIONS_PER_WALLET = 1e3;
|
|
@@ -7436,70 +7571,6 @@ function createChunkVectorCache(maxSize = DEFAULT_CHUNK_CACHE_SIZE) {
|
|
|
7436
7571
|
return new LRUCache(maxSize);
|
|
7437
7572
|
}
|
|
7438
7573
|
|
|
7439
|
-
// src/lib/memory/decay.ts
|
|
7440
|
-
var DAY_MS = 24 * 60 * 60 * 1e3;
|
|
7441
|
-
var SHORT_TTL_MS = 30 * DAY_MS;
|
|
7442
|
-
var MEDIUM_TTL_MS = 180 * DAY_MS;
|
|
7443
|
-
var NEVER_TTL_MS = Number.POSITIVE_INFINITY;
|
|
7444
|
-
var HARD_DELETE_WINDOW_MS = 30 * DAY_MS;
|
|
7445
|
-
var PAST_EVENT_GRACE_MS = 7 * DAY_MS;
|
|
7446
|
-
var DEFAULT_DECAY_POLICY = {
|
|
7447
|
-
ttlByType: {
|
|
7448
|
-
identity: NEVER_TTL_MS,
|
|
7449
|
-
preference: NEVER_TTL_MS,
|
|
7450
|
-
relationship: NEVER_TTL_MS,
|
|
7451
|
-
constraint: NEVER_TTL_MS,
|
|
7452
|
-
plan: SHORT_TTL_MS,
|
|
7453
|
-
ongoing_context: SHORT_TTL_MS,
|
|
7454
|
-
other: MEDIUM_TTL_MS
|
|
7455
|
-
},
|
|
7456
|
-
fallbackTtlMs: MEDIUM_TTL_MS,
|
|
7457
|
-
hardDeleteWindowMs: HARD_DELETE_WINDOW_MS,
|
|
7458
|
-
pastEventGraceMs: PAST_EVENT_GRACE_MS
|
|
7459
|
-
};
|
|
7460
|
-
function resolvePolicy(policy) {
|
|
7461
|
-
if (!policy) return DEFAULT_DECAY_POLICY;
|
|
7462
|
-
return {
|
|
7463
|
-
ttlByType: { ...DEFAULT_DECAY_POLICY.ttlByType, ...policy.ttlByType },
|
|
7464
|
-
fallbackTtlMs: policy.fallbackTtlMs ?? DEFAULT_DECAY_POLICY.fallbackTtlMs,
|
|
7465
|
-
hardDeleteWindowMs: policy.hardDeleteWindowMs ?? DEFAULT_DECAY_POLICY.hardDeleteWindowMs,
|
|
7466
|
-
pastEventGraceMs: policy.pastEventGraceMs ?? DEFAULT_DECAY_POLICY.pastEventGraceMs
|
|
7467
|
-
};
|
|
7468
|
-
}
|
|
7469
|
-
function ttlForType(factType, policy) {
|
|
7470
|
-
const resolved = resolvePolicy(policy);
|
|
7471
|
-
if (factType === null) return resolved.fallbackTtlMs;
|
|
7472
|
-
return resolved.ttlByType[factType] ?? resolved.fallbackTtlMs;
|
|
7473
|
-
}
|
|
7474
|
-
function isTimeSensitiveType(factType) {
|
|
7475
|
-
return factType === "plan" || factType === "ongoing_context";
|
|
7476
|
-
}
|
|
7477
|
-
function hasFiniteTimestamps(m, now) {
|
|
7478
|
-
return Number.isFinite(now) && Number.isFinite(m.updatedAt) && (m.archivedAt === null || Number.isFinite(m.archivedAt));
|
|
7479
|
-
}
|
|
7480
|
-
function classifyDecay(m, now, policy) {
|
|
7481
|
-
const resolved = resolvePolicy(policy);
|
|
7482
|
-
if (!hasFiniteTimestamps(m, now)) {
|
|
7483
|
-
getLogger().warn("[memory/decay] non-finite timestamp on a memory row; keeping it", {
|
|
7484
|
-
now,
|
|
7485
|
-
updatedAt: m.updatedAt,
|
|
7486
|
-
archivedAt: m.archivedAt,
|
|
7487
|
-
factType: m.factType
|
|
7488
|
-
});
|
|
7489
|
-
return "keep";
|
|
7490
|
-
}
|
|
7491
|
-
if (m.archivedAt !== null) {
|
|
7492
|
-
return now - m.archivedAt > resolved.hardDeleteWindowMs ? "delete" : "keep";
|
|
7493
|
-
}
|
|
7494
|
-
if (m.source === "manual") return "keep";
|
|
7495
|
-
if (isTimeSensitiveType(m.factType) && m.eventTimeEnd !== null) {
|
|
7496
|
-
if (m.eventTimeEnd < now - resolved.pastEventGraceMs) return "archive";
|
|
7497
|
-
if (m.eventTimeEnd >= now) return "keep";
|
|
7498
|
-
}
|
|
7499
|
-
if (now - m.updatedAt > ttlForType(m.factType, resolved)) return "archive";
|
|
7500
|
-
return "keep";
|
|
7501
|
-
}
|
|
7502
|
-
|
|
7503
7574
|
// src/lib/memory/decayClassifier.ts
|
|
7504
7575
|
var DEFAULT_MODEL2 = "inclusionai/ling-2.6-flash";
|
|
7505
7576
|
var DEFAULT_ATTEMPTS2 = 2;
|
|
@@ -7597,7 +7668,7 @@ function toDecayInput(c) {
|
|
|
7597
7668
|
};
|
|
7598
7669
|
}
|
|
7599
7670
|
function isBorderline(input) {
|
|
7600
|
-
if (input.source === "manual") return false;
|
|
7671
|
+
if (input.source === "manual" || input.source === SOURCE_PHOTO) return false;
|
|
7601
7672
|
if (input.trustTier === "quarantined") return false;
|
|
7602
7673
|
if (input.archivedAt !== null) return false;
|
|
7603
7674
|
if (input.factType === null || input.factType === "other") return true;
|
|
@@ -12255,7 +12326,7 @@ __decorateClass([
|
|
|
12255
12326
|
], VaultFolder.prototype, "context", 2);
|
|
12256
12327
|
|
|
12257
12328
|
// src/lib/db/schema.ts
|
|
12258
|
-
var SDK_SCHEMA_VERSION =
|
|
12329
|
+
var SDK_SCHEMA_VERSION = 45;
|
|
12259
12330
|
var sdkSchema = appSchema2({
|
|
12260
12331
|
version: SDK_SCHEMA_VERSION,
|
|
12261
12332
|
tables: [
|
|
@@ -12293,8 +12364,10 @@ var sdkSchema = appSchema2({
|
|
|
12293
12364
|
// Parent message for branching
|
|
12294
12365
|
{ name: "feedback", type: "string", isOptional: true },
|
|
12295
12366
|
// 'like' | 'dislike' | null
|
|
12296
|
-
{ name: "tool_call_events", type: "string", isOptional: true }
|
|
12367
|
+
{ name: "tool_call_events", type: "string", isOptional: true },
|
|
12297
12368
|
// JSON stringified LlmapiToolCallEvent[]
|
|
12369
|
+
{ name: "origin", type: "string", isOptional: true }
|
|
12370
|
+
// MessageOrigin — provenance, NOT encrypted (see v44)
|
|
12298
12371
|
]
|
|
12299
12372
|
}),
|
|
12300
12373
|
tableSchema2({
|
|
@@ -12401,6 +12474,18 @@ var sdkSchema = appSchema2({
|
|
|
12401
12474
|
// paths key on `updated_at` — so without this a topic-only change would
|
|
12402
12475
|
// neither upload nor merge. Null = `topics` never written.
|
|
12403
12476
|
{ name: "topics_updated_at", type: "number", isOptional: true },
|
|
12477
|
+
// The photo(s) a SERVER-EXTRACTED memory was read out of, as a JSON
|
|
12478
|
+
// array of `{feed_item_id, object_key}` — exactly what
|
|
12479
|
+
// GET /api/memories/published returns in `media[]`. Enough to render the
|
|
12480
|
+
// source image without a second round-trip per memory.
|
|
12481
|
+
//
|
|
12482
|
+
// A JSON column rather than a join table: nothing on the client ever
|
|
12483
|
+
// queries BY photo (the only direction is memory -> render its image),
|
|
12484
|
+
// so a table would add a sync lane and a local-id space to serve a
|
|
12485
|
+
// question nobody asks. `topics` and `source_chunk_ids` set the
|
|
12486
|
+
// precedent for a list that is only ever read back whole. Null on
|
|
12487
|
+
// anything not extracted from a photo.
|
|
12488
|
+
{ name: "media", type: "string", isOptional: true },
|
|
12404
12489
|
// Unix ms of the last LLM topic-extraction pass over this memory's
|
|
12405
12490
|
// content. Null = never extracted standalone (legacy rows with entity
|
|
12406
12491
|
// links are grandfathered — see getMemoriesNeedingTopicExtractionOp).
|
|
@@ -13222,6 +13307,33 @@ var sdkMigrations = schemaMigrations2({
|
|
|
13222
13307
|
"CREATE INDEX IF NOT EXISTS conversations_is_deleted_created_at ON conversations (is_deleted, created_at);"
|
|
13223
13308
|
)
|
|
13224
13309
|
]
|
|
13310
|
+
},
|
|
13311
|
+
// v43 -> v44: Added origin column to history — the provenance tag the embedding
|
|
13312
|
+
// sweep reads to skip never-rendered tool-result rows. No backfill: NULL means
|
|
13313
|
+
// "legacy, provenance unknown" and keeps the pre-v44 behaviour of embedding the
|
|
13314
|
+
// row, so the only rows that stop being embedded are ones a v44+ producer tagged.
|
|
13315
|
+
{
|
|
13316
|
+
toVersion: 44,
|
|
13317
|
+
steps: [
|
|
13318
|
+
addColumns2({
|
|
13319
|
+
table: "history",
|
|
13320
|
+
columns: [{ name: "origin", type: "string", isOptional: true }]
|
|
13321
|
+
})
|
|
13322
|
+
]
|
|
13323
|
+
},
|
|
13324
|
+
// v44 -> v45: `media` on memory_vault — the photo(s) a server-extracted
|
|
13325
|
+
// memory was read out of, as JSON `[{feed_item_id, object_key}]`, mirroring
|
|
13326
|
+
// the `media[]` that GET /api/memories/published already returns. Existing
|
|
13327
|
+
// rows keep NULL, which is the correct value for every memory that did not
|
|
13328
|
+
// come from a photo (i.e. all of them until photo ingest runs).
|
|
13329
|
+
{
|
|
13330
|
+
toVersion: 45,
|
|
13331
|
+
steps: [
|
|
13332
|
+
addColumns2({
|
|
13333
|
+
table: "memory_vault",
|
|
13334
|
+
columns: [{ name: "media", type: "string", isOptional: true }]
|
|
13335
|
+
})
|
|
13336
|
+
]
|
|
13225
13337
|
}
|
|
13226
13338
|
]
|
|
13227
13339
|
});
|
|
@@ -14688,12 +14800,14 @@ export {
|
|
|
14688
14800
|
getVaultMemoryOp,
|
|
14689
14801
|
hardDeleteDecayedOp,
|
|
14690
14802
|
hasEncryptionKey,
|
|
14803
|
+
ingestPublishedPhotoMemoriesOp,
|
|
14691
14804
|
injectionSignatureCatalog,
|
|
14692
14805
|
isPiiRedactor,
|
|
14693
14806
|
isRerankerAvailable,
|
|
14694
14807
|
moveMemoriesToFolderOp,
|
|
14695
14808
|
noopLogger,
|
|
14696
14809
|
onKeyAvailable,
|
|
14810
|
+
parseMedia,
|
|
14697
14811
|
preEmbedVaultMemories,
|
|
14698
14812
|
quantizeEmbedding,
|
|
14699
14813
|
queueManager,
|
|
@@ -1335,7 +1335,8 @@ function messageToStoredRaw(message, projection) {
|
|
|
1335
1335
|
thinking: message.thinking,
|
|
1336
1336
|
parentMessageId: message.parentMessageId,
|
|
1337
1337
|
feedback: message.feedback || null,
|
|
1338
|
-
toolCallEvents: parseJsonField(toolCallEventsRaw)
|
|
1338
|
+
toolCallEvents: parseJsonField(toolCallEventsRaw),
|
|
1339
|
+
origin: message.origin
|
|
1339
1340
|
};
|
|
1340
1341
|
}
|
|
1341
1342
|
async function messageToStored(message, walletAddress, signMessage, embeddedWalletSigner, projection) {
|
|
@@ -1396,7 +1397,11 @@ function messageRawToStoredRaw(raw, projection) {
|
|
|
1396
1397
|
thinking: raw.thinking,
|
|
1397
1398
|
parentMessageId: raw.parent_message_id,
|
|
1398
1399
|
feedback: raw.feedback || null,
|
|
1399
|
-
toolCallEvents: parseJsonField(raw.tool_call_events)
|
|
1400
|
+
toolCallEvents: parseJsonField(raw.tool_call_events),
|
|
1401
|
+
// Load-bearing on this path specifically: getMessagesOp reads raws, and it is
|
|
1402
|
+
// what the deferred embedding sweep iterates, so the provenance gate depends
|
|
1403
|
+
// on `origin` surviving the raw mapper as well as the Model one.
|
|
1404
|
+
origin: raw.origin
|
|
1400
1405
|
};
|
|
1401
1406
|
}
|
|
1402
1407
|
async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
|
|
@@ -1742,6 +1747,7 @@ function applyMessageFields(msg, encryptedOpts) {
|
|
|
1742
1747
|
const tceValue = typeof encryptedOpts.toolCallEvents === "string" ? encryptedOpts.toolCallEvents : JSON.stringify(encryptedOpts.toolCallEvents);
|
|
1743
1748
|
msg._setRaw("tool_call_events", tceValue);
|
|
1744
1749
|
}
|
|
1750
|
+
if (encryptedOpts.origin) msg._setRaw("origin", encryptedOpts.origin);
|
|
1745
1751
|
}
|
|
1746
1752
|
async function createMessageOp(ctx, opts) {
|
|
1747
1753
|
if (opts.uniqueId) {
|
|
@@ -2137,7 +2143,8 @@ function makeSyntheticStoredMessage(opts) {
|
|
|
2137
2143
|
thoughtProcess: opts.thoughtProcess,
|
|
2138
2144
|
thinking: opts.thinking,
|
|
2139
2145
|
parentMessageId: opts.parentMessageId,
|
|
2140
|
-
toolCallEvents: opts.toolCallEvents
|
|
2146
|
+
toolCallEvents: opts.toolCallEvents,
|
|
2147
|
+
origin: opts.origin
|
|
2141
2148
|
};
|
|
2142
2149
|
}
|
|
2143
2150
|
function makeSyntheticStoredConversation(opts, defaultTitle) {
|
|
@@ -2553,6 +2560,22 @@ async function decryptVaultMemoryFields(memory, address, signMessage, embeddedWa
|
|
|
2553
2560
|
};
|
|
2554
2561
|
}
|
|
2555
2562
|
|
|
2563
|
+
// src/lib/db/memoryVault/types.ts
|
|
2564
|
+
function parseMedia(value) {
|
|
2565
|
+
if (typeof value !== "string" || value === "") return null;
|
|
2566
|
+
try {
|
|
2567
|
+
const parsed = JSON.parse(value);
|
|
2568
|
+
if (!Array.isArray(parsed)) return null;
|
|
2569
|
+
const refs = parsed.filter((r) => typeof r === "object" && r !== null).map((r) => ({
|
|
2570
|
+
feedItemId: Number(r.feedItemId ?? r.feed_item_id),
|
|
2571
|
+
objectKey: r.objectKey ?? r.object_key ?? null
|
|
2572
|
+
})).filter((r) => Number.isFinite(r.feedItemId));
|
|
2573
|
+
return refs.length > 0 ? refs : null;
|
|
2574
|
+
} catch {
|
|
2575
|
+
return null;
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2556
2579
|
// src/lib/db/memoryVault/operations.ts
|
|
2557
2580
|
function visibilityOrPrivate(value) {
|
|
2558
2581
|
return value === "public" ? value : "private";
|
|
@@ -2616,6 +2639,7 @@ function vaultMemoryToStoredRaw(memory) {
|
|
|
2616
2639
|
sourceChunkIds,
|
|
2617
2640
|
proofCount: memory.proofCount ?? null,
|
|
2618
2641
|
source: memory.source ?? null,
|
|
2642
|
+
media: parseMedia(memory.media),
|
|
2619
2643
|
eventTimeStart: memory.eventTimeStart ?? null,
|
|
2620
2644
|
eventTimeEnd: memory.eventTimeEnd ?? null,
|
|
2621
2645
|
eventTimeKind: memory.eventTimeKind ?? null,
|
|
@@ -2898,6 +2922,7 @@ function vaultMemoryRawToStoredRaw(raw) {
|
|
|
2898
2922
|
eventTimeKind: raw.event_time_kind ?? null,
|
|
2899
2923
|
// SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
|
|
2900
2924
|
topicsUserManaged: raw.topics_user_managed === true || raw.topics_user_managed === 1,
|
|
2925
|
+
media: parseMedia(raw.media),
|
|
2901
2926
|
topics: parseTopics(raw.topics),
|
|
2902
2927
|
topicsUpdatedAt: raw.topics_updated_at ?? null,
|
|
2903
2928
|
topicsExtractedAt: raw.topics_extracted_at ?? null,
|
|
@@ -4887,6 +4912,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
4887
4912
|
|
|
4888
4913
|
// src/lib/memoryEngine/embeddings.ts
|
|
4889
4914
|
var DEFAULT_MIN_CONTENT_LENGTH = 10;
|
|
4915
|
+
var NON_EMBEDDABLE_ORIGIN = "tool_result";
|
|
4890
4916
|
async function embedMessage(ctx, messageId, options) {
|
|
4891
4917
|
const message = await getMessageOp(ctx, messageId);
|
|
4892
4918
|
if (!message) {
|
|
@@ -4895,6 +4921,9 @@ async function embedMessage(ctx, messageId, options) {
|
|
|
4895
4921
|
if (message.vector && message.vector.length > 0) {
|
|
4896
4922
|
return message;
|
|
4897
4923
|
}
|
|
4924
|
+
if (message.origin === NON_EMBEDDABLE_ORIGIN) {
|
|
4925
|
+
return message;
|
|
4926
|
+
}
|
|
4898
4927
|
const embedding = await generateEmbedding(message.content, options);
|
|
4899
4928
|
const embeddingModel = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
4900
4929
|
return updateMessageEmbeddingOp(ctx, messageId, embedding, embeddingModel);
|
|
@@ -4916,6 +4945,9 @@ async function embedAllMessages(ctx, options, filter) {
|
|
|
4916
4945
|
if (message.role === "system") {
|
|
4917
4946
|
continue;
|
|
4918
4947
|
}
|
|
4948
|
+
if (message.origin === NON_EMBEDDABLE_ORIGIN) {
|
|
4949
|
+
continue;
|
|
4950
|
+
}
|
|
4919
4951
|
const minLength = filter?.minContentLength ?? DEFAULT_MIN_CONTENT_LENGTH;
|
|
4920
4952
|
if (message.content.length < minLength) {
|
|
4921
4953
|
continue;
|
|
@@ -4941,6 +4973,9 @@ async function chunkAndEmbedMessage(ctx, messageId, options) {
|
|
|
4941
4973
|
if (message.chunks && message.chunks.length > 0) {
|
|
4942
4974
|
return message;
|
|
4943
4975
|
}
|
|
4976
|
+
if (message.origin === NON_EMBEDDABLE_ORIGIN) {
|
|
4977
|
+
return message;
|
|
4978
|
+
}
|
|
4944
4979
|
const embeddingModel = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
4945
4980
|
if (!shouldChunkMessage(message.content, chunkSize)) {
|
|
4946
4981
|
const embedding = await generateEmbedding(message.content, options);
|
|
@@ -4974,6 +5009,7 @@ async function chunkAndEmbedAllMessages(ctx, options, filter) {
|
|
|
4974
5009
|
if (hasVector && !filter?.rechunkExisting && !isStale) continue;
|
|
4975
5010
|
if (filter?.roles && !filter.roles.includes(message.role)) continue;
|
|
4976
5011
|
if (message.role === "system") continue;
|
|
5012
|
+
if (message.origin === NON_EMBEDDABLE_ORIGIN) continue;
|
|
4977
5013
|
if (message.content.length < minLength) continue;
|
|
4978
5014
|
if (shouldChunkMessage(message.content, chunkSize)) {
|
|
4979
5015
|
longMessages.push({
|
|
@@ -6765,7 +6801,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
6765
6801
|
subQueries = decomp.subQueries;
|
|
6766
6802
|
}
|
|
6767
6803
|
}
|
|
6768
|
-
const { recall: recall2 } = await import("./recall-
|
|
6804
|
+
const { recall: recall2 } = await import("./recall-PCM7H5TA.mjs");
|
|
6769
6805
|
let recallDegraded = [];
|
|
6770
6806
|
const result = await recall2(
|
|
6771
6807
|
query,
|
|
@@ -7820,6 +7856,8 @@ export {
|
|
|
7820
7856
|
backfillMemoryEntityUserIdsOp,
|
|
7821
7857
|
getMemoriesByEntityNamesOp,
|
|
7822
7858
|
getEntitiesByMemoryIdsOp,
|
|
7859
|
+
encryptVaultMemoryContent,
|
|
7860
|
+
parseMedia,
|
|
7823
7861
|
vaultMemoryToStored,
|
|
7824
7862
|
createVaultMemoryOp,
|
|
7825
7863
|
createSupersedingMemoryOp,
|