@anuma/sdk 7.6.1 → 8.0.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.
@@ -1505,6 +1505,7 @@ __export(index_exports, {
1505
1505
  createWebSearchPreProcessor: () => createWebSearchPreProcessor,
1506
1506
  decodeChunkVector: () => decodeChunkVector,
1507
1507
  decryptConversationTitle: () => decryptConversationTitle,
1508
+ decryptMessageEmbeddingFields: () => decryptMessageEmbeddingFields,
1508
1509
  deleteAllVaultMemoriesForUserOp: () => deleteAllVaultMemoriesForUserOp,
1509
1510
  deleteMessageOp: () => deleteMessageOp,
1510
1511
  deleteVaultFolderOp: () => deleteVaultFolderOp,
@@ -1585,6 +1586,7 @@ __export(index_exports, {
1585
1586
  sdkMigrations: () => sdkMigrations,
1586
1587
  sdkModelClasses: () => sdkModelClasses,
1587
1588
  sdkSchema: () => sdkSchema,
1589
+ sealLegacyMessageEmbeddingsOp: () => sealLegacyMessageEmbeddingsOp,
1588
1590
  searchVaultMemories: () => searchVaultMemories,
1589
1591
  seedEncryptionKeys: () => seedEncryptionKeys,
1590
1592
  setLogger: () => setLogger,
@@ -4015,16 +4017,19 @@ async function updateMessageEmbeddingOp(ctx, uniqueId, vector, embeddingModel) {
4015
4017
  } catch {
4016
4018
  return null;
4017
4019
  }
4020
+ const address = ctx.walletAddress;
4018
4021
  await ctx.database.write(async () => {
4022
+ const key = await resolveMessageEmbeddingKey(address, message.content);
4023
+ const storedVector2 = await serializeMessageEmbedding(key, vector);
4019
4024
  await message.update((msg) => {
4020
- msg._setRaw("vector", JSON.stringify(vector));
4025
+ msg._setRaw("vector", storedVector2);
4021
4026
  if (msg.origin === "chunks_discarded" && vector.length > 0) {
4022
4027
  msg._setRaw("origin", "message");
4023
4028
  }
4024
4029
  msg._setRaw("embedding_model", embeddingModel);
4025
4030
  });
4026
4031
  });
4027
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
4032
+ return messageToStored(message, ctx.walletAddress);
4028
4033
  }
4029
4034
  async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
4030
4035
  let message;
@@ -4034,16 +4039,123 @@ async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
4034
4039
  return null;
4035
4040
  }
4036
4041
  const storedChunks = chunks3.map(({ text: _text, ...rest }) => rest);
4042
+ const address = ctx.walletAddress;
4037
4043
  await ctx.database.write(async () => {
4044
+ const key = await resolveMessageEmbeddingKey(address, message.content);
4045
+ const serializedChunks = await serializeMessageEmbedding(key, storedChunks);
4038
4046
  await message.update((msg) => {
4039
- msg._setRaw("chunks", JSON.stringify(storedChunks));
4047
+ msg._setRaw("chunks", serializedChunks);
4040
4048
  if (msg.origin === "chunks_discarded" && storedChunks.length > 0 && storedChunks.every((chunk) => chunk.vector.length > 0)) {
4041
4049
  msg._setRaw("origin", "message");
4042
4050
  }
4043
4051
  msg._setRaw("embedding_model", embeddingModel);
4044
4052
  });
4045
4053
  });
4046
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
4054
+ return messageToStored(message, ctx.walletAddress);
4055
+ }
4056
+ async function resolveMessageEmbeddingKey(address, content) {
4057
+ if (!address || !isEncrypted(content)) return null;
4058
+ const key = await getEncryptionKey(address, "v3");
4059
+ const contentKey = content.startsWith("enc:v2:") ? await getEncryptionKey(address, "v2") : key;
4060
+ try {
4061
+ await decryptDataWithKey(content.slice("enc:vN:".length), contentKey);
4062
+ } catch {
4063
+ throw new Error("Cannot decrypt the message with the cached wallet key");
4064
+ }
4065
+ return key;
4066
+ }
4067
+ async function serializeMessageEmbedding(key, value) {
4068
+ const json4 = JSON.stringify(value);
4069
+ return key ? `enc:v3:${await encryptDataWithKey(json4, key)}` : json4;
4070
+ }
4071
+ async function decryptMessageEmbeddingFields(raw, walletAddress) {
4072
+ const result = { ...raw };
4073
+ for (const column of ["vector", "chunks"]) {
4074
+ const value = raw[column];
4075
+ if (typeof value !== "string" || !value.startsWith("enc:")) continue;
4076
+ const decrypted = walletAddress ? await decryptField(value, walletAddress) : value;
4077
+ result[column] = decrypted.startsWith("enc:") ? void 0 : decrypted;
4078
+ }
4079
+ return result;
4080
+ }
4081
+ async function sealLegacyMessageEmbeddingsOp(ctx) {
4082
+ if (!ctx.walletAddress) return 0;
4083
+ const candidateIds = await ctx.messagesCollection.query(
4084
+ import_watermelondb2.Q.where("content", import_watermelondb2.Q.like("enc:%")),
4085
+ import_watermelondb2.Q.or(
4086
+ ...["vector", "chunks"].map(
4087
+ (column) => import_watermelondb2.Q.and(
4088
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq(null)),
4089
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq("")),
4090
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notLike("enc:%"))
4091
+ )
4092
+ )
4093
+ )
4094
+ ).fetchIds();
4095
+ let sealed = 0;
4096
+ let undecryptable = 0;
4097
+ for (let start = 0; start < candidateIds.length; start += 50) {
4098
+ const pageIds = candidateIds.slice(start, start + 50);
4099
+ await ctx.database.write(async () => {
4100
+ const pageMessages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).fetch();
4101
+ for (const message of pageMessages) {
4102
+ if (!isEncrypted(message.content)) continue;
4103
+ const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
4104
+ if (content.status === "key_missing") {
4105
+ throw new Error("Cannot decrypt the message with the cached wallet key");
4106
+ }
4107
+ if (content.status !== "ok") {
4108
+ undecryptable++;
4109
+ continue;
4110
+ }
4111
+ const plaintext = content.value;
4112
+ const key = await resolveMessageEmbeddingKey(ctx.walletAddress, message.content);
4113
+ const updates = {};
4114
+ for (const column of ["vector", "chunks"]) {
4115
+ const value = message._getRaw(column);
4116
+ if (typeof value !== "string" || value.startsWith("enc:") || !value) continue;
4117
+ let parsed;
4118
+ try {
4119
+ parsed = JSON.parse(value);
4120
+ } catch {
4121
+ updates[column] = null;
4122
+ continue;
4123
+ }
4124
+ if (!Array.isArray(parsed)) {
4125
+ updates[column] = null;
4126
+ continue;
4127
+ }
4128
+ if (column === "chunks") {
4129
+ const chunks3 = parsed;
4130
+ if (chunks3.some(
4131
+ (chunk) => !chunk || !Number.isInteger(chunk.startOffset) || !Number.isInteger(chunk.endOffset) || chunk.startOffset < 0 || chunk.endOffset <= chunk.startOffset || chunk.endOffset > plaintext.length
4132
+ )) {
4133
+ updates.chunks = null;
4134
+ updates.vector = null;
4135
+ updates.origin = message.origin === "tool_result" ? "tool_result" : "chunks_discarded";
4136
+ break;
4137
+ }
4138
+ parsed = chunks3.map(({ text: _text, ...rest }) => rest);
4139
+ }
4140
+ updates[column] = await serializeMessageEmbedding(key, parsed);
4141
+ }
4142
+ if (Object.keys(updates).length === 0) continue;
4143
+ const updatedAt = Number(message._getRaw("updated_at"));
4144
+ const discarded = updates.origin !== void 0;
4145
+ await message.update((msg) => {
4146
+ for (const [column, value] of Object.entries(updates)) msg._setRaw(column, value);
4147
+ msg._setRaw("updated_at", discarded ? Math.max(Date.now(), updatedAt + 1) : updatedAt);
4148
+ });
4149
+ sealed++;
4150
+ }
4151
+ });
4152
+ }
4153
+ if (undecryptable > 0) {
4154
+ getLogger().warn(
4155
+ `Skipped ${undecryptable} message embeddings that the cached wallet key cannot decrypt`
4156
+ );
4157
+ }
4158
+ return sealed;
4047
4159
  }
4048
4160
  var RAW_REPAIR_PAGE_SIZE = 100;
4049
4161
  function chunksWithoutText(raw) {
@@ -29980,6 +30092,7 @@ function useChatStorage(options) {
29980
30092
  createWebSearchPreProcessor,
29981
30093
  decodeChunkVector,
29982
30094
  decryptConversationTitle,
30095
+ decryptMessageEmbeddingFields,
29983
30096
  deleteAllVaultMemoriesForUserOp,
29984
30097
  deleteMessageOp,
29985
30098
  deleteVaultFolderOp,
@@ -30060,6 +30173,7 @@ function useChatStorage(options) {
30060
30173
  sdkMigrations,
30061
30174
  sdkModelClasses,
30062
30175
  sdkSchema,
30176
+ sealLegacyMessageEmbeddingsOp,
30063
30177
  searchVaultMemories,
30064
30178
  seedEncryptionKeys,
30065
30179
  setLogger,
@@ -4191,6 +4191,10 @@ declare function deleteMessageOp(ctx: StorageOperationsContext, uniqueId: string
4191
4191
  declare function upsertMessageOp(ctx: StorageOperationsContext, opts: CreateMessageOptions & {
4192
4192
  uniqueId: string;
4193
4193
  }): Promise<StoredMessage>;
4194
+ /** Decrypts raw message embedding columns with the cached wallet key. */
4195
+ declare function decryptMessageEmbeddingFields(raw: Record<string, unknown>, walletAddress?: string): Promise<Record<string, unknown>>;
4196
+ /** Seals legacy message embedding columns and discards chunks with invalid plaintext offsets. */
4197
+ declare function sealLegacyMessageEmbeddingsOp(ctx: StorageOperationsContext): Promise<number>;
4194
4198
  /**
4195
4199
  * Removes the plaintext `text` that rows chunked before sdk#889 still carry in
4196
4200
  * their `chunks` column. Since #889 `updateMessageChunksOp` never writes it, so
@@ -11525,4 +11529,4 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
11525
11529
  */
11526
11530
  declare function useChatStorage(options: UseChatStorageOptions): UseChatStorageResult;
11527
11531
 
11528
- export { type AutoExtractMessage, type AutoExtractor, type Budget, CHUNKS_DISCARDED_ORIGIN, type CachedChunkVectors, type CachedServerTools, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ChunkSearchStats, type ChunkVectorCache, type ChunkingOptions, type ConsolidationAction, type ConsolidationFallbackReason, type ConversationMemoryInput, ConversationMemory as ConversationMemoryModel, type ConversationMemoryOperationsContext, type CreateAutoExtractorOptions, type CreateConversationOptions, type CreateDecaySweeperOptions, type CreateMessageOptions, type CreateVaultFolderOptions, type CreateVaultMemoryOptions, type CryptoPriceClassification, type CryptoPricePreProcessorOptions, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_CHUNK_CACHE_SIZE, DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, DEFAULT_DECAY_POLICY, DEFAULT_MAX_CLASSIFIER_CALLS_PER_SWEEP, DEFAULT_MIN_CHUNK_SIZE, DEFAULT_PROFILE_FACETS, DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, DEFAULT_PROFILE_PROOF_ALPHA, DEFAULT_PROFILE_TREND_MULTIPLIERS, DEFAULT_VAULT_CACHE_SIZE, DatabaseManager, type DatabaseManagerLogger, type DatabaseManagerOptions, type DecayCandidateRaw, type DecayClassifier, type DecayInput, type DecayPolicy, type DecaySweepResult, type DecaySweeper, type DecayVerdict, type DurableAutoExtractorOptions, ENTITY_FANOUT, type EmbeddedWalletSignerFn, type EmbeddingRepairOptions, type EmbeddingRepairResult, EncryptionKeyMissingError, type ExtractFactsOptions, type ExtractOutcome, type ExtractedCandidate, type ExtractedEntity, type ExtractionCursorStore, type ExtractionFunnel, type ExtractionMessageSource, type ExtractionSourceMessage, type ExtractionSourceStatus, type ExtractionTimings, type FactType, type FileMetadata, type FileProcessingReason, type FileProcessingStatus, type FlushResult, type GetConversationsPageOptions, type GetMessagesPageOptions, type GraphTraversalOptions, HARD_DELETE_WINDOW_MS, INFERENCE_ID_HEADER, type InjectionClassifierOptions, type InjectionReason, type LazyStoredConversation, type LlmDecayClassifierOptions, type LlmNeighborRefinerOptions, type LocalMemoryStoreOptions, type Logger, LoggerProvider, type LoggerProviderProps, MAX_HOPS, MEDIUM_TTL_MS, MEMORY_KINDS, MEMORY_LEVELS, type ManualFactType, type MemoriesNeedingTopicExtraction, type MemoryContextItem, type MemoryContextLane, type MemoryContextOptions, type MemoryContextResult, type MemoryCreate, type MemoryDecay, type MemoryDecaySweeperOptions, type EmbeddingOptions as MemoryEngineEmbeddingOptions, type MemoryEngineResult, type MemoryEngineSearchOptions, type MemoryExtractedEvent, MemoryKeyError, type MemoryKeyRing, type MemoryKind, type MemoryLevel, MemoryLevelError, type MemoryListOptions, type MemoryMaintenance, type MemoryMigrationOptions, type MemoryMigrationProgress, type MemoryMigrationResult, type MemoryMigrationSkip, type MemoryQuarantinedEvent, type MemoryRecallOptions, type MemoryRetainOptions, type MemoryStore, type MemorySubscribeOptions, type MemoryToVerify, type MemoryTopic, type MemoryTopicBacklog, type MemoryTopicMaintenance, type MemoryUpdate, type MemoryVaultSearchOptions, type MemoryVaultToolOptions, type MemoryVerification, type MessageRedactionResult, type MessageSkeleton, NEVER_TTL_MS, NODE_BUDGET, NOTION_OAUTH_CONFIG, type NeighborRefiner, type NotionAuthUrlParams, type NotionClientRegistration, type NotionExchangeCodeParams, type NotionMcpCaller, type NotionOAuthEndpoints, type NotionPKCEChallenge, type NotionRefreshTokenParams, type NotionTokenResponse, type NowSource, type ObservationTrend, type ObservationTrendInput, PAST_EVENT_GRACE_MS, PII_PATTERNS, PROFILE_DOC_VERSION, type PhotoIngestResult, type PhotoMediaRef, type PiiCategory, type PiiMatch, type PiiPattern, PiiRedactor, type PiiRedactorOptions, type PlatformStorage, type PortalLlmAuth, type PortalLlmFailure, type PortalLlmFailureReason, type ProfileConfigFingerprint, type ProfileDoc, type ProfileFacet, type ProfileFacetKey, type ProfileSalienceInput, type ProfileSection, type PromptPreProcessor, type PromptPreProcessorContext, type PublishedPhotoMemory, type QuantizedEmbedding, type QuarantinedMemoryInfo, QueueManager, type QueueStatus, RECALL_MAX_LIMIT, RECALL_TOOL_NAME, type RankableVaultMemory, type RankedMemory, type RankedProfileCandidate, type RecallContext, type RecallDegradation, type RecallDiagnostics, type RecallEmptyReason, type RecallOptions, type RecallResult, type RecallTelemetryCallbacks, type RecallToolCallbacks, type RecallToolOptions, type RecallTruncation, type RecencyOptions, type RedactionResult, type ReflectOptions, type ReflectResult, type RemoteMemoryCandidateOptions, type RemoteMemoryDecodeFailure, RemoteMemoryError, type RemoteMemoryListOptions, type RemoteMemoryMetadataPage, type RemoteMemoryMetadataRecord, type RemoteMemoryPage, RemoteMemoryPartialCreateError, type RemoteMemoryPersistence, type RemoteMemoryPersistenceOptions, type RemoteMemoryPipeline, type RemoteMemoryPipelineOptions, type RemoteMemoryQueryOptions, type RemoteMemoryQueryPage, type RemoteMemoryReadFilters, type RemoteMemoryRecord, type RemoteMemoryRow, type RemoteMemoryStoreOptions, type RequestEncryptionKeyOptions, RerankerUnavailableError, type ReservationReceipt, type ResumeStreamOptions, type ResumeStreamResult, type ResumeStreamWithStorageResult, type RetainAction, type RetainContext, type RetainOptions, type RetainResult, type RetainSource, SDK_SCHEMA_VERSION, SHORT_TTL_MS, STREAM_RESUMABLE_HEADER, type ScoreBreakdown, type ScoreProfileSalienceOptions, type ScreenResult, type ScreenedCandidate, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageDetachedResult, type SendMessageWithStorageResult, type ServerToolsOptions, type ServerToolsResponse, type SignMessageFn, type StockPriceClassification, type StockPricePreProcessorOptions, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredConversationMemory, type StoredMessage, type StoredMessageWithSimilarity, type StoredTopic, type StoredVaultFolder, VaultFolder as StoredVaultFolderModel, type StoredVaultMemory, VaultMemory as StoredVaultMemoryModel, StreamExpiredError, type StreamMetaEvent, type StreamResumeHandle, type StreamSmoothingConfig, type SynthesizeProfileOptions, TOOL_RESULT_ORIGIN, TOPICS_EXTRACTION_VERSION, TOPIC_EXTRACTION_BATCH_SIZE, TOPIC_SALIENCE_WEIGHTS, TREND_RECENT_WINDOW_DAYS, TREND_STALE_WINDOW_DAYS, type TextChunk, type TopicExtractOptions, type TopicExtractionBatchDiagnostics, type TopicExtractionInput, type TopicExtractionRunResult, type TopicSalience, type TopicSkipReason, type TurnCompleteEvent, type TurnSkippedEvent, type UncheckedReason, type UnverifiableReason, type UpdateVaultFolderOptions, type UpdateVaultMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseCreditsOptions, type UseCreditsResult, type UseModelsOptions, type UseModelsResult, VAULT_SIZE_HOP_CAP, type VaultEmbeddingCache, type VaultEmbeddingExpectation, type VaultFolderOperationsContext, type VaultMemoryKind, type VaultMemoryOperationsContext, type VaultMemoryProjection, type VaultMemoryVisibility, type VaultMemoryWriter, type VaultSaveOperation, type VaultSearchResult, type VaultWriteAction, type VaultWriteInput, type VaultWriteOutcome, type VerificationSources, type VerifyMemoriesForPublishOptions, WalletPoller, type WeatherClassification, type WeatherPreProcessorOptions, type WebSearchClassification, type WebSearchPreProcessorOptions, type WriteFailureReason, addConversationMemoriesOp, archiveVaultMemoryOp, assembleMemoryContext, attachFileContextToLastUserMessage, backfillMemoryTopicsOp, buildAttachedFilesText, buildNotionAuthUrl, capHopsForDensity, chatStorageMigrations, chatStorageSchema, chunkAndEmbedAllMessages, chunkAndEmbedMessage, chunkText, classifyCryptoPrice, classifyCryptoPriceBatch, classifyDecay, classifyInjectionCandidates, classifyObservationTrend, classifyStockPrice, classifyStockPriceBatch, classifyWeather, classifyWeatherBatch, classifyWebSearch, classifyWebSearchBatch, clearAllEncryptionKeys, clearAllEncryptionState, clearConversationMemoriesOp, clearEncryptionKey, clearLazyTitleCache, clearModelsCache, clearServerToolsCache, consoleLogger, conversationMemoryToStored, cosineInt8, createAutoExtractor, createChunkVectorCache, createCryptoPricePreProcessor, createDecaySweeper, createDurableAutoExtractor, createLlmDecayClassifier, createLlmNeighborRefiner, createLocalMemoryStore, createMemoryEngineTool, createMemoryVaultSearchTool, createMemoryVaultTool, createMessageSourceResolver, createNotionProxyTools, createNotionTools, createPlatformCursorStore, createRecallTool, createRemoteMemoryPersistence, createRemoteMemoryPipeline, createRemoteMemoryStore, createStockPricePreProcessor, createStreamingDeAnonymizer, createVaultEmbeddingCache, createVaultFolderOp, createVaultMemoriesBatchOp, createVaultMemoryOp, createWeatherPreProcessor, createWebSearchPreProcessor, decodeChunkVector, decryptConversationTitle, deleteAllVaultMemoriesForUserOp, deleteMessageOp, deleteVaultFolderOp, deleteVaultMemoryOp, dequantizeEmbedding, deriveKeyFromSignatureBytes, deriveMemoryKeyRing, discoverNotionOAuthEndpoints, eagerEmbedContent, embedAllMessages, embedMessage, encodeChunkVector, encryptToolCallEventsOp, ensureDefaultFoldersOp, exchangeNotionCode, extractAndLinkEntitiesForMemoriesOp, extractAndRetain, extractEntitiesForMemories, extractFacts, extractReservationReceipts, formatFileProcessingNotes, generateConversationId, generateEmbedding, generateEmbeddings, generateNotionPKCE, getAllVaultFoldersOp, getAllVaultMemoriesOp, getAllVaultMemoryContentsOp, getCachedServerTools, getConversationMemoriesOp, getConversationsByProjectLazyOp, getConversationsLazyOp, getConversationsPageOp, getDecayCandidatesRawOp, getLogger, getMemoriesNeedingTopicExtractionOp, getServerTools, getUnfiledVaultMemoriesOp, getVaultFolderMemoryCountOp, getVaultMemoriesByIdsOp, getVaultMemoryOp, getVaultRankingProjectionsOp, hardDeleteDecayedOp, hasEncryptionKey, ingestPublishedPhotoMemoriesOp, injectionSignatureCatalog, isAttachedFilesText, isDegradedTopicSkip, isEncrypted, isPiiRedactor, isRerankerAvailable, maskScopedEmbeddingCache, memoryCipher, migrateMemoriesToRemote, moveMemoriesToFolderOp, noopLogger, onKeyAvailable, parseMedia, preEmbedVaultMemories, primaryTopic, quantizeEmbedding, queueManager, rankProfileCandidates, recall, reencryptMemoryField, reflect, refreshEncryptionKeyIfMatches, refreshNotionAccessToken, registerNotionClient, relinkMemoryTopicsOp, requestEncryptionKey, resolvePiiRedactor, restoreVaultMemoryOp, resumeStream, retain, scoreProfileSalience, screenCandidatesForInjection, sdkMigrations, sdkModelClasses, sdkSchema, searchVaultMemories, seedEncryptionKeys, setLogger, setMemoryVisibilityOp, shouldChunkMessage, shouldRecallMemory, stampTopicsExtractedAtOp, streamCancelPath, streamReplayPath, stripLegacyChunkTextOp, summarizeObservationTrends, supersedeVaultMemoryOp, synthesizeProfile, topicWeight, traverseGraphLane, ttlForType, updateVaultFolderContextOp, updateVaultFolderOp, updateVaultMemoryEmbeddingOp, updateVaultMemoryOp, upsertMessageOp, useChat, useChatStorage, useCredits, useEncryption, useModels, verifyMemoriesForPublish, xhrTransport };
11532
+ export { type AutoExtractMessage, type AutoExtractor, type Budget, CHUNKS_DISCARDED_ORIGIN, type CachedChunkVectors, type CachedServerTools, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ChunkSearchStats, type ChunkVectorCache, type ChunkingOptions, type ConsolidationAction, type ConsolidationFallbackReason, type ConversationMemoryInput, ConversationMemory as ConversationMemoryModel, type ConversationMemoryOperationsContext, type CreateAutoExtractorOptions, type CreateConversationOptions, type CreateDecaySweeperOptions, type CreateMessageOptions, type CreateVaultFolderOptions, type CreateVaultMemoryOptions, type CryptoPriceClassification, type CryptoPricePreProcessorOptions, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_CHUNK_CACHE_SIZE, DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, DEFAULT_DECAY_POLICY, DEFAULT_MAX_CLASSIFIER_CALLS_PER_SWEEP, DEFAULT_MIN_CHUNK_SIZE, DEFAULT_PROFILE_FACETS, DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, DEFAULT_PROFILE_PROOF_ALPHA, DEFAULT_PROFILE_TREND_MULTIPLIERS, DEFAULT_VAULT_CACHE_SIZE, DatabaseManager, type DatabaseManagerLogger, type DatabaseManagerOptions, type DecayCandidateRaw, type DecayClassifier, type DecayInput, type DecayPolicy, type DecaySweepResult, type DecaySweeper, type DecayVerdict, type DurableAutoExtractorOptions, ENTITY_FANOUT, type EmbeddedWalletSignerFn, type EmbeddingRepairOptions, type EmbeddingRepairResult, EncryptionKeyMissingError, type ExtractFactsOptions, type ExtractOutcome, type ExtractedCandidate, type ExtractedEntity, type ExtractionCursorStore, type ExtractionFunnel, type ExtractionMessageSource, type ExtractionSourceMessage, type ExtractionSourceStatus, type ExtractionTimings, type FactType, type FileMetadata, type FileProcessingReason, type FileProcessingStatus, type FlushResult, type GetConversationsPageOptions, type GetMessagesPageOptions, type GraphTraversalOptions, HARD_DELETE_WINDOW_MS, INFERENCE_ID_HEADER, type InjectionClassifierOptions, type InjectionReason, type LazyStoredConversation, type LlmDecayClassifierOptions, type LlmNeighborRefinerOptions, type LocalMemoryStoreOptions, type Logger, LoggerProvider, type LoggerProviderProps, MAX_HOPS, MEDIUM_TTL_MS, MEMORY_KINDS, MEMORY_LEVELS, type ManualFactType, type MemoriesNeedingTopicExtraction, type MemoryContextItem, type MemoryContextLane, type MemoryContextOptions, type MemoryContextResult, type MemoryCreate, type MemoryDecay, type MemoryDecaySweeperOptions, type EmbeddingOptions as MemoryEngineEmbeddingOptions, type MemoryEngineResult, type MemoryEngineSearchOptions, type MemoryExtractedEvent, MemoryKeyError, type MemoryKeyRing, type MemoryKind, type MemoryLevel, MemoryLevelError, type MemoryListOptions, type MemoryMaintenance, type MemoryMigrationOptions, type MemoryMigrationProgress, type MemoryMigrationResult, type MemoryMigrationSkip, type MemoryQuarantinedEvent, type MemoryRecallOptions, type MemoryRetainOptions, type MemoryStore, type MemorySubscribeOptions, type MemoryToVerify, type MemoryTopic, type MemoryTopicBacklog, type MemoryTopicMaintenance, type MemoryUpdate, type MemoryVaultSearchOptions, type MemoryVaultToolOptions, type MemoryVerification, type MessageRedactionResult, type MessageSkeleton, NEVER_TTL_MS, NODE_BUDGET, NOTION_OAUTH_CONFIG, type NeighborRefiner, type NotionAuthUrlParams, type NotionClientRegistration, type NotionExchangeCodeParams, type NotionMcpCaller, type NotionOAuthEndpoints, type NotionPKCEChallenge, type NotionRefreshTokenParams, type NotionTokenResponse, type NowSource, type ObservationTrend, type ObservationTrendInput, PAST_EVENT_GRACE_MS, PII_PATTERNS, PROFILE_DOC_VERSION, type PhotoIngestResult, type PhotoMediaRef, type PiiCategory, type PiiMatch, type PiiPattern, PiiRedactor, type PiiRedactorOptions, type PlatformStorage, type PortalLlmAuth, type PortalLlmFailure, type PortalLlmFailureReason, type ProfileConfigFingerprint, type ProfileDoc, type ProfileFacet, type ProfileFacetKey, type ProfileSalienceInput, type ProfileSection, type PromptPreProcessor, type PromptPreProcessorContext, type PublishedPhotoMemory, type QuantizedEmbedding, type QuarantinedMemoryInfo, QueueManager, type QueueStatus, RECALL_MAX_LIMIT, RECALL_TOOL_NAME, type RankableVaultMemory, type RankedMemory, type RankedProfileCandidate, type RecallContext, type RecallDegradation, type RecallDiagnostics, type RecallEmptyReason, type RecallOptions, type RecallResult, type RecallTelemetryCallbacks, type RecallToolCallbacks, type RecallToolOptions, type RecallTruncation, type RecencyOptions, type RedactionResult, type ReflectOptions, type ReflectResult, type RemoteMemoryCandidateOptions, type RemoteMemoryDecodeFailure, RemoteMemoryError, type RemoteMemoryListOptions, type RemoteMemoryMetadataPage, type RemoteMemoryMetadataRecord, type RemoteMemoryPage, RemoteMemoryPartialCreateError, type RemoteMemoryPersistence, type RemoteMemoryPersistenceOptions, type RemoteMemoryPipeline, type RemoteMemoryPipelineOptions, type RemoteMemoryQueryOptions, type RemoteMemoryQueryPage, type RemoteMemoryReadFilters, type RemoteMemoryRecord, type RemoteMemoryRow, type RemoteMemoryStoreOptions, type RequestEncryptionKeyOptions, RerankerUnavailableError, type ReservationReceipt, type ResumeStreamOptions, type ResumeStreamResult, type ResumeStreamWithStorageResult, type RetainAction, type RetainContext, type RetainOptions, type RetainResult, type RetainSource, SDK_SCHEMA_VERSION, SHORT_TTL_MS, STREAM_RESUMABLE_HEADER, type ScoreBreakdown, type ScoreProfileSalienceOptions, type ScreenResult, type ScreenedCandidate, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageDetachedResult, type SendMessageWithStorageResult, type ServerToolsOptions, type ServerToolsResponse, type SignMessageFn, type StockPriceClassification, type StockPricePreProcessorOptions, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredConversationMemory, type StoredMessage, type StoredMessageWithSimilarity, type StoredTopic, type StoredVaultFolder, VaultFolder as StoredVaultFolderModel, type StoredVaultMemory, VaultMemory as StoredVaultMemoryModel, StreamExpiredError, type StreamMetaEvent, type StreamResumeHandle, type StreamSmoothingConfig, type SynthesizeProfileOptions, TOOL_RESULT_ORIGIN, TOPICS_EXTRACTION_VERSION, TOPIC_EXTRACTION_BATCH_SIZE, TOPIC_SALIENCE_WEIGHTS, TREND_RECENT_WINDOW_DAYS, TREND_STALE_WINDOW_DAYS, type TextChunk, type TopicExtractOptions, type TopicExtractionBatchDiagnostics, type TopicExtractionInput, type TopicExtractionRunResult, type TopicSalience, type TopicSkipReason, type TurnCompleteEvent, type TurnSkippedEvent, type UncheckedReason, type UnverifiableReason, type UpdateVaultFolderOptions, type UpdateVaultMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseCreditsOptions, type UseCreditsResult, type UseModelsOptions, type UseModelsResult, VAULT_SIZE_HOP_CAP, type VaultEmbeddingCache, type VaultEmbeddingExpectation, type VaultFolderOperationsContext, type VaultMemoryKind, type VaultMemoryOperationsContext, type VaultMemoryProjection, type VaultMemoryVisibility, type VaultMemoryWriter, type VaultSaveOperation, type VaultSearchResult, type VaultWriteAction, type VaultWriteInput, type VaultWriteOutcome, type VerificationSources, type VerifyMemoriesForPublishOptions, WalletPoller, type WeatherClassification, type WeatherPreProcessorOptions, type WebSearchClassification, type WebSearchPreProcessorOptions, type WriteFailureReason, addConversationMemoriesOp, archiveVaultMemoryOp, assembleMemoryContext, attachFileContextToLastUserMessage, backfillMemoryTopicsOp, buildAttachedFilesText, buildNotionAuthUrl, capHopsForDensity, chatStorageMigrations, chatStorageSchema, chunkAndEmbedAllMessages, chunkAndEmbedMessage, chunkText, classifyCryptoPrice, classifyCryptoPriceBatch, classifyDecay, classifyInjectionCandidates, classifyObservationTrend, classifyStockPrice, classifyStockPriceBatch, classifyWeather, classifyWeatherBatch, classifyWebSearch, classifyWebSearchBatch, clearAllEncryptionKeys, clearAllEncryptionState, clearConversationMemoriesOp, clearEncryptionKey, clearLazyTitleCache, clearModelsCache, clearServerToolsCache, consoleLogger, conversationMemoryToStored, cosineInt8, createAutoExtractor, createChunkVectorCache, createCryptoPricePreProcessor, createDecaySweeper, createDurableAutoExtractor, createLlmDecayClassifier, createLlmNeighborRefiner, createLocalMemoryStore, createMemoryEngineTool, createMemoryVaultSearchTool, createMemoryVaultTool, createMessageSourceResolver, createNotionProxyTools, createNotionTools, createPlatformCursorStore, createRecallTool, createRemoteMemoryPersistence, createRemoteMemoryPipeline, createRemoteMemoryStore, createStockPricePreProcessor, createStreamingDeAnonymizer, createVaultEmbeddingCache, createVaultFolderOp, createVaultMemoriesBatchOp, createVaultMemoryOp, createWeatherPreProcessor, createWebSearchPreProcessor, decodeChunkVector, decryptConversationTitle, decryptMessageEmbeddingFields, deleteAllVaultMemoriesForUserOp, deleteMessageOp, deleteVaultFolderOp, deleteVaultMemoryOp, dequantizeEmbedding, deriveKeyFromSignatureBytes, deriveMemoryKeyRing, discoverNotionOAuthEndpoints, eagerEmbedContent, embedAllMessages, embedMessage, encodeChunkVector, encryptToolCallEventsOp, ensureDefaultFoldersOp, exchangeNotionCode, extractAndLinkEntitiesForMemoriesOp, extractAndRetain, extractEntitiesForMemories, extractFacts, extractReservationReceipts, formatFileProcessingNotes, generateConversationId, generateEmbedding, generateEmbeddings, generateNotionPKCE, getAllVaultFoldersOp, getAllVaultMemoriesOp, getAllVaultMemoryContentsOp, getCachedServerTools, getConversationMemoriesOp, getConversationsByProjectLazyOp, getConversationsLazyOp, getConversationsPageOp, getDecayCandidatesRawOp, getLogger, getMemoriesNeedingTopicExtractionOp, getServerTools, getUnfiledVaultMemoriesOp, getVaultFolderMemoryCountOp, getVaultMemoriesByIdsOp, getVaultMemoryOp, getVaultRankingProjectionsOp, hardDeleteDecayedOp, hasEncryptionKey, ingestPublishedPhotoMemoriesOp, injectionSignatureCatalog, isAttachedFilesText, isDegradedTopicSkip, isEncrypted, isPiiRedactor, isRerankerAvailable, maskScopedEmbeddingCache, memoryCipher, migrateMemoriesToRemote, moveMemoriesToFolderOp, noopLogger, onKeyAvailable, parseMedia, preEmbedVaultMemories, primaryTopic, quantizeEmbedding, queueManager, rankProfileCandidates, recall, reencryptMemoryField, reflect, refreshEncryptionKeyIfMatches, refreshNotionAccessToken, registerNotionClient, relinkMemoryTopicsOp, requestEncryptionKey, resolvePiiRedactor, restoreVaultMemoryOp, resumeStream, retain, scoreProfileSalience, screenCandidatesForInjection, sdkMigrations, sdkModelClasses, sdkSchema, sealLegacyMessageEmbeddingsOp, searchVaultMemories, seedEncryptionKeys, setLogger, setMemoryVisibilityOp, shouldChunkMessage, shouldRecallMemory, stampTopicsExtractedAtOp, streamCancelPath, streamReplayPath, stripLegacyChunkTextOp, summarizeObservationTrends, supersedeVaultMemoryOp, synthesizeProfile, topicWeight, traverseGraphLane, ttlForType, updateVaultFolderContextOp, updateVaultFolderOp, updateVaultMemoryEmbeddingOp, updateVaultMemoryOp, upsertMessageOp, useChat, useChatStorage, useCredits, useEncryption, useModels, verifyMemoriesForPublish, xhrTransport };
@@ -4191,6 +4191,10 @@ declare function deleteMessageOp(ctx: StorageOperationsContext, uniqueId: string
4191
4191
  declare function upsertMessageOp(ctx: StorageOperationsContext, opts: CreateMessageOptions & {
4192
4192
  uniqueId: string;
4193
4193
  }): Promise<StoredMessage>;
4194
+ /** Decrypts raw message embedding columns with the cached wallet key. */
4195
+ declare function decryptMessageEmbeddingFields(raw: Record<string, unknown>, walletAddress?: string): Promise<Record<string, unknown>>;
4196
+ /** Seals legacy message embedding columns and discards chunks with invalid plaintext offsets. */
4197
+ declare function sealLegacyMessageEmbeddingsOp(ctx: StorageOperationsContext): Promise<number>;
4194
4198
  /**
4195
4199
  * Removes the plaintext `text` that rows chunked before sdk#889 still carry in
4196
4200
  * their `chunks` column. Since #889 `updateMessageChunksOp` never writes it, so
@@ -11525,4 +11529,4 @@ interface UseChatStorageResult extends BaseUseChatStorageResult {
11525
11529
  */
11526
11530
  declare function useChatStorage(options: UseChatStorageOptions): UseChatStorageResult;
11527
11531
 
11528
- export { type AutoExtractMessage, type AutoExtractor, type Budget, CHUNKS_DISCARDED_ORIGIN, type CachedChunkVectors, type CachedServerTools, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ChunkSearchStats, type ChunkVectorCache, type ChunkingOptions, type ConsolidationAction, type ConsolidationFallbackReason, type ConversationMemoryInput, ConversationMemory as ConversationMemoryModel, type ConversationMemoryOperationsContext, type CreateAutoExtractorOptions, type CreateConversationOptions, type CreateDecaySweeperOptions, type CreateMessageOptions, type CreateVaultFolderOptions, type CreateVaultMemoryOptions, type CryptoPriceClassification, type CryptoPricePreProcessorOptions, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_CHUNK_CACHE_SIZE, DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, DEFAULT_DECAY_POLICY, DEFAULT_MAX_CLASSIFIER_CALLS_PER_SWEEP, DEFAULT_MIN_CHUNK_SIZE, DEFAULT_PROFILE_FACETS, DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, DEFAULT_PROFILE_PROOF_ALPHA, DEFAULT_PROFILE_TREND_MULTIPLIERS, DEFAULT_VAULT_CACHE_SIZE, DatabaseManager, type DatabaseManagerLogger, type DatabaseManagerOptions, type DecayCandidateRaw, type DecayClassifier, type DecayInput, type DecayPolicy, type DecaySweepResult, type DecaySweeper, type DecayVerdict, type DurableAutoExtractorOptions, ENTITY_FANOUT, type EmbeddedWalletSignerFn, type EmbeddingRepairOptions, type EmbeddingRepairResult, EncryptionKeyMissingError, type ExtractFactsOptions, type ExtractOutcome, type ExtractedCandidate, type ExtractedEntity, type ExtractionCursorStore, type ExtractionFunnel, type ExtractionMessageSource, type ExtractionSourceMessage, type ExtractionSourceStatus, type ExtractionTimings, type FactType, type FileMetadata, type FileProcessingReason, type FileProcessingStatus, type FlushResult, type GetConversationsPageOptions, type GetMessagesPageOptions, type GraphTraversalOptions, HARD_DELETE_WINDOW_MS, INFERENCE_ID_HEADER, type InjectionClassifierOptions, type InjectionReason, type LazyStoredConversation, type LlmDecayClassifierOptions, type LlmNeighborRefinerOptions, type LocalMemoryStoreOptions, type Logger, LoggerProvider, type LoggerProviderProps, MAX_HOPS, MEDIUM_TTL_MS, MEMORY_KINDS, MEMORY_LEVELS, type ManualFactType, type MemoriesNeedingTopicExtraction, type MemoryContextItem, type MemoryContextLane, type MemoryContextOptions, type MemoryContextResult, type MemoryCreate, type MemoryDecay, type MemoryDecaySweeperOptions, type EmbeddingOptions as MemoryEngineEmbeddingOptions, type MemoryEngineResult, type MemoryEngineSearchOptions, type MemoryExtractedEvent, MemoryKeyError, type MemoryKeyRing, type MemoryKind, type MemoryLevel, MemoryLevelError, type MemoryListOptions, type MemoryMaintenance, type MemoryMigrationOptions, type MemoryMigrationProgress, type MemoryMigrationResult, type MemoryMigrationSkip, type MemoryQuarantinedEvent, type MemoryRecallOptions, type MemoryRetainOptions, type MemoryStore, type MemorySubscribeOptions, type MemoryToVerify, type MemoryTopic, type MemoryTopicBacklog, type MemoryTopicMaintenance, type MemoryUpdate, type MemoryVaultSearchOptions, type MemoryVaultToolOptions, type MemoryVerification, type MessageRedactionResult, type MessageSkeleton, NEVER_TTL_MS, NODE_BUDGET, NOTION_OAUTH_CONFIG, type NeighborRefiner, type NotionAuthUrlParams, type NotionClientRegistration, type NotionExchangeCodeParams, type NotionMcpCaller, type NotionOAuthEndpoints, type NotionPKCEChallenge, type NotionRefreshTokenParams, type NotionTokenResponse, type NowSource, type ObservationTrend, type ObservationTrendInput, PAST_EVENT_GRACE_MS, PII_PATTERNS, PROFILE_DOC_VERSION, type PhotoIngestResult, type PhotoMediaRef, type PiiCategory, type PiiMatch, type PiiPattern, PiiRedactor, type PiiRedactorOptions, type PlatformStorage, type PortalLlmAuth, type PortalLlmFailure, type PortalLlmFailureReason, type ProfileConfigFingerprint, type ProfileDoc, type ProfileFacet, type ProfileFacetKey, type ProfileSalienceInput, type ProfileSection, type PromptPreProcessor, type PromptPreProcessorContext, type PublishedPhotoMemory, type QuantizedEmbedding, type QuarantinedMemoryInfo, QueueManager, type QueueStatus, RECALL_MAX_LIMIT, RECALL_TOOL_NAME, type RankableVaultMemory, type RankedMemory, type RankedProfileCandidate, type RecallContext, type RecallDegradation, type RecallDiagnostics, type RecallEmptyReason, type RecallOptions, type RecallResult, type RecallTelemetryCallbacks, type RecallToolCallbacks, type RecallToolOptions, type RecallTruncation, type RecencyOptions, type RedactionResult, type ReflectOptions, type ReflectResult, type RemoteMemoryCandidateOptions, type RemoteMemoryDecodeFailure, RemoteMemoryError, type RemoteMemoryListOptions, type RemoteMemoryMetadataPage, type RemoteMemoryMetadataRecord, type RemoteMemoryPage, RemoteMemoryPartialCreateError, type RemoteMemoryPersistence, type RemoteMemoryPersistenceOptions, type RemoteMemoryPipeline, type RemoteMemoryPipelineOptions, type RemoteMemoryQueryOptions, type RemoteMemoryQueryPage, type RemoteMemoryReadFilters, type RemoteMemoryRecord, type RemoteMemoryRow, type RemoteMemoryStoreOptions, type RequestEncryptionKeyOptions, RerankerUnavailableError, type ReservationReceipt, type ResumeStreamOptions, type ResumeStreamResult, type ResumeStreamWithStorageResult, type RetainAction, type RetainContext, type RetainOptions, type RetainResult, type RetainSource, SDK_SCHEMA_VERSION, SHORT_TTL_MS, STREAM_RESUMABLE_HEADER, type ScoreBreakdown, type ScoreProfileSalienceOptions, type ScreenResult, type ScreenedCandidate, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageDetachedResult, type SendMessageWithStorageResult, type ServerToolsOptions, type ServerToolsResponse, type SignMessageFn, type StockPriceClassification, type StockPricePreProcessorOptions, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredConversationMemory, type StoredMessage, type StoredMessageWithSimilarity, type StoredTopic, type StoredVaultFolder, VaultFolder as StoredVaultFolderModel, type StoredVaultMemory, VaultMemory as StoredVaultMemoryModel, StreamExpiredError, type StreamMetaEvent, type StreamResumeHandle, type StreamSmoothingConfig, type SynthesizeProfileOptions, TOOL_RESULT_ORIGIN, TOPICS_EXTRACTION_VERSION, TOPIC_EXTRACTION_BATCH_SIZE, TOPIC_SALIENCE_WEIGHTS, TREND_RECENT_WINDOW_DAYS, TREND_STALE_WINDOW_DAYS, type TextChunk, type TopicExtractOptions, type TopicExtractionBatchDiagnostics, type TopicExtractionInput, type TopicExtractionRunResult, type TopicSalience, type TopicSkipReason, type TurnCompleteEvent, type TurnSkippedEvent, type UncheckedReason, type UnverifiableReason, type UpdateVaultFolderOptions, type UpdateVaultMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseCreditsOptions, type UseCreditsResult, type UseModelsOptions, type UseModelsResult, VAULT_SIZE_HOP_CAP, type VaultEmbeddingCache, type VaultEmbeddingExpectation, type VaultFolderOperationsContext, type VaultMemoryKind, type VaultMemoryOperationsContext, type VaultMemoryProjection, type VaultMemoryVisibility, type VaultMemoryWriter, type VaultSaveOperation, type VaultSearchResult, type VaultWriteAction, type VaultWriteInput, type VaultWriteOutcome, type VerificationSources, type VerifyMemoriesForPublishOptions, WalletPoller, type WeatherClassification, type WeatherPreProcessorOptions, type WebSearchClassification, type WebSearchPreProcessorOptions, type WriteFailureReason, addConversationMemoriesOp, archiveVaultMemoryOp, assembleMemoryContext, attachFileContextToLastUserMessage, backfillMemoryTopicsOp, buildAttachedFilesText, buildNotionAuthUrl, capHopsForDensity, chatStorageMigrations, chatStorageSchema, chunkAndEmbedAllMessages, chunkAndEmbedMessage, chunkText, classifyCryptoPrice, classifyCryptoPriceBatch, classifyDecay, classifyInjectionCandidates, classifyObservationTrend, classifyStockPrice, classifyStockPriceBatch, classifyWeather, classifyWeatherBatch, classifyWebSearch, classifyWebSearchBatch, clearAllEncryptionKeys, clearAllEncryptionState, clearConversationMemoriesOp, clearEncryptionKey, clearLazyTitleCache, clearModelsCache, clearServerToolsCache, consoleLogger, conversationMemoryToStored, cosineInt8, createAutoExtractor, createChunkVectorCache, createCryptoPricePreProcessor, createDecaySweeper, createDurableAutoExtractor, createLlmDecayClassifier, createLlmNeighborRefiner, createLocalMemoryStore, createMemoryEngineTool, createMemoryVaultSearchTool, createMemoryVaultTool, createMessageSourceResolver, createNotionProxyTools, createNotionTools, createPlatformCursorStore, createRecallTool, createRemoteMemoryPersistence, createRemoteMemoryPipeline, createRemoteMemoryStore, createStockPricePreProcessor, createStreamingDeAnonymizer, createVaultEmbeddingCache, createVaultFolderOp, createVaultMemoriesBatchOp, createVaultMemoryOp, createWeatherPreProcessor, createWebSearchPreProcessor, decodeChunkVector, decryptConversationTitle, deleteAllVaultMemoriesForUserOp, deleteMessageOp, deleteVaultFolderOp, deleteVaultMemoryOp, dequantizeEmbedding, deriveKeyFromSignatureBytes, deriveMemoryKeyRing, discoverNotionOAuthEndpoints, eagerEmbedContent, embedAllMessages, embedMessage, encodeChunkVector, encryptToolCallEventsOp, ensureDefaultFoldersOp, exchangeNotionCode, extractAndLinkEntitiesForMemoriesOp, extractAndRetain, extractEntitiesForMemories, extractFacts, extractReservationReceipts, formatFileProcessingNotes, generateConversationId, generateEmbedding, generateEmbeddings, generateNotionPKCE, getAllVaultFoldersOp, getAllVaultMemoriesOp, getAllVaultMemoryContentsOp, getCachedServerTools, getConversationMemoriesOp, getConversationsByProjectLazyOp, getConversationsLazyOp, getConversationsPageOp, getDecayCandidatesRawOp, getLogger, getMemoriesNeedingTopicExtractionOp, getServerTools, getUnfiledVaultMemoriesOp, getVaultFolderMemoryCountOp, getVaultMemoriesByIdsOp, getVaultMemoryOp, getVaultRankingProjectionsOp, hardDeleteDecayedOp, hasEncryptionKey, ingestPublishedPhotoMemoriesOp, injectionSignatureCatalog, isAttachedFilesText, isDegradedTopicSkip, isEncrypted, isPiiRedactor, isRerankerAvailable, maskScopedEmbeddingCache, memoryCipher, migrateMemoriesToRemote, moveMemoriesToFolderOp, noopLogger, onKeyAvailable, parseMedia, preEmbedVaultMemories, primaryTopic, quantizeEmbedding, queueManager, rankProfileCandidates, recall, reencryptMemoryField, reflect, refreshEncryptionKeyIfMatches, refreshNotionAccessToken, registerNotionClient, relinkMemoryTopicsOp, requestEncryptionKey, resolvePiiRedactor, restoreVaultMemoryOp, resumeStream, retain, scoreProfileSalience, screenCandidatesForInjection, sdkMigrations, sdkModelClasses, sdkSchema, searchVaultMemories, seedEncryptionKeys, setLogger, setMemoryVisibilityOp, shouldChunkMessage, shouldRecallMemory, stampTopicsExtractedAtOp, streamCancelPath, streamReplayPath, stripLegacyChunkTextOp, summarizeObservationTrends, supersedeVaultMemoryOp, synthesizeProfile, topicWeight, traverseGraphLane, ttlForType, updateVaultFolderContextOp, updateVaultFolderOp, updateVaultMemoryEmbeddingOp, updateVaultMemoryOp, upsertMessageOp, useChat, useChatStorage, useCredits, useEncryption, useModels, verifyMemoriesForPublish, xhrTransport };
11532
+ export { type AutoExtractMessage, type AutoExtractor, type Budget, CHUNKS_DISCARDED_ORIGIN, type CachedChunkVectors, type CachedServerTools, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ChunkSearchStats, type ChunkVectorCache, type ChunkingOptions, type ConsolidationAction, type ConsolidationFallbackReason, type ConversationMemoryInput, ConversationMemory as ConversationMemoryModel, type ConversationMemoryOperationsContext, type CreateAutoExtractorOptions, type CreateConversationOptions, type CreateDecaySweeperOptions, type CreateMessageOptions, type CreateVaultFolderOptions, type CreateVaultMemoryOptions, type CryptoPriceClassification, type CryptoPricePreProcessorOptions, DEFAULT_CACHE_EXPIRATION_MS, DEFAULT_CHUNK_CACHE_SIZE, DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE, DEFAULT_DECAY_POLICY, DEFAULT_MAX_CLASSIFIER_CALLS_PER_SWEEP, DEFAULT_MIN_CHUNK_SIZE, DEFAULT_PROFILE_FACETS, DEFAULT_PROFILE_FACT_TYPE_WEIGHTS, DEFAULT_PROFILE_PROOF_ALPHA, DEFAULT_PROFILE_TREND_MULTIPLIERS, DEFAULT_VAULT_CACHE_SIZE, DatabaseManager, type DatabaseManagerLogger, type DatabaseManagerOptions, type DecayCandidateRaw, type DecayClassifier, type DecayInput, type DecayPolicy, type DecaySweepResult, type DecaySweeper, type DecayVerdict, type DurableAutoExtractorOptions, ENTITY_FANOUT, type EmbeddedWalletSignerFn, type EmbeddingRepairOptions, type EmbeddingRepairResult, EncryptionKeyMissingError, type ExtractFactsOptions, type ExtractOutcome, type ExtractedCandidate, type ExtractedEntity, type ExtractionCursorStore, type ExtractionFunnel, type ExtractionMessageSource, type ExtractionSourceMessage, type ExtractionSourceStatus, type ExtractionTimings, type FactType, type FileMetadata, type FileProcessingReason, type FileProcessingStatus, type FlushResult, type GetConversationsPageOptions, type GetMessagesPageOptions, type GraphTraversalOptions, HARD_DELETE_WINDOW_MS, INFERENCE_ID_HEADER, type InjectionClassifierOptions, type InjectionReason, type LazyStoredConversation, type LlmDecayClassifierOptions, type LlmNeighborRefinerOptions, type LocalMemoryStoreOptions, type Logger, LoggerProvider, type LoggerProviderProps, MAX_HOPS, MEDIUM_TTL_MS, MEMORY_KINDS, MEMORY_LEVELS, type ManualFactType, type MemoriesNeedingTopicExtraction, type MemoryContextItem, type MemoryContextLane, type MemoryContextOptions, type MemoryContextResult, type MemoryCreate, type MemoryDecay, type MemoryDecaySweeperOptions, type EmbeddingOptions as MemoryEngineEmbeddingOptions, type MemoryEngineResult, type MemoryEngineSearchOptions, type MemoryExtractedEvent, MemoryKeyError, type MemoryKeyRing, type MemoryKind, type MemoryLevel, MemoryLevelError, type MemoryListOptions, type MemoryMaintenance, type MemoryMigrationOptions, type MemoryMigrationProgress, type MemoryMigrationResult, type MemoryMigrationSkip, type MemoryQuarantinedEvent, type MemoryRecallOptions, type MemoryRetainOptions, type MemoryStore, type MemorySubscribeOptions, type MemoryToVerify, type MemoryTopic, type MemoryTopicBacklog, type MemoryTopicMaintenance, type MemoryUpdate, type MemoryVaultSearchOptions, type MemoryVaultToolOptions, type MemoryVerification, type MessageRedactionResult, type MessageSkeleton, NEVER_TTL_MS, NODE_BUDGET, NOTION_OAUTH_CONFIG, type NeighborRefiner, type NotionAuthUrlParams, type NotionClientRegistration, type NotionExchangeCodeParams, type NotionMcpCaller, type NotionOAuthEndpoints, type NotionPKCEChallenge, type NotionRefreshTokenParams, type NotionTokenResponse, type NowSource, type ObservationTrend, type ObservationTrendInput, PAST_EVENT_GRACE_MS, PII_PATTERNS, PROFILE_DOC_VERSION, type PhotoIngestResult, type PhotoMediaRef, type PiiCategory, type PiiMatch, type PiiPattern, PiiRedactor, type PiiRedactorOptions, type PlatformStorage, type PortalLlmAuth, type PortalLlmFailure, type PortalLlmFailureReason, type ProfileConfigFingerprint, type ProfileDoc, type ProfileFacet, type ProfileFacetKey, type ProfileSalienceInput, type ProfileSection, type PromptPreProcessor, type PromptPreProcessorContext, type PublishedPhotoMemory, type QuantizedEmbedding, type QuarantinedMemoryInfo, QueueManager, type QueueStatus, RECALL_MAX_LIMIT, RECALL_TOOL_NAME, type RankableVaultMemory, type RankedMemory, type RankedProfileCandidate, type RecallContext, type RecallDegradation, type RecallDiagnostics, type RecallEmptyReason, type RecallOptions, type RecallResult, type RecallTelemetryCallbacks, type RecallToolCallbacks, type RecallToolOptions, type RecallTruncation, type RecencyOptions, type RedactionResult, type ReflectOptions, type ReflectResult, type RemoteMemoryCandidateOptions, type RemoteMemoryDecodeFailure, RemoteMemoryError, type RemoteMemoryListOptions, type RemoteMemoryMetadataPage, type RemoteMemoryMetadataRecord, type RemoteMemoryPage, RemoteMemoryPartialCreateError, type RemoteMemoryPersistence, type RemoteMemoryPersistenceOptions, type RemoteMemoryPipeline, type RemoteMemoryPipelineOptions, type RemoteMemoryQueryOptions, type RemoteMemoryQueryPage, type RemoteMemoryReadFilters, type RemoteMemoryRecord, type RemoteMemoryRow, type RemoteMemoryStoreOptions, type RequestEncryptionKeyOptions, RerankerUnavailableError, type ReservationReceipt, type ResumeStreamOptions, type ResumeStreamResult, type ResumeStreamWithStorageResult, type RetainAction, type RetainContext, type RetainOptions, type RetainResult, type RetainSource, SDK_SCHEMA_VERSION, SHORT_TTL_MS, STREAM_RESUMABLE_HEADER, type ScoreBreakdown, type ScoreProfileSalienceOptions, type ScreenResult, type ScreenedCandidate, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageDetachedResult, type SendMessageWithStorageResult, type ServerToolsOptions, type ServerToolsResponse, type SignMessageFn, type StockPriceClassification, type StockPricePreProcessorOptions, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredConversationMemory, type StoredMessage, type StoredMessageWithSimilarity, type StoredTopic, type StoredVaultFolder, VaultFolder as StoredVaultFolderModel, type StoredVaultMemory, VaultMemory as StoredVaultMemoryModel, StreamExpiredError, type StreamMetaEvent, type StreamResumeHandle, type StreamSmoothingConfig, type SynthesizeProfileOptions, TOOL_RESULT_ORIGIN, TOPICS_EXTRACTION_VERSION, TOPIC_EXTRACTION_BATCH_SIZE, TOPIC_SALIENCE_WEIGHTS, TREND_RECENT_WINDOW_DAYS, TREND_STALE_WINDOW_DAYS, type TextChunk, type TopicExtractOptions, type TopicExtractionBatchDiagnostics, type TopicExtractionInput, type TopicExtractionRunResult, type TopicSalience, type TopicSkipReason, type TurnCompleteEvent, type TurnSkippedEvent, type UncheckedReason, type UnverifiableReason, type UpdateVaultFolderOptions, type UpdateVaultMemoryOptions, type UseChatStorageOptions, type UseChatStorageResult, type UseCreditsOptions, type UseCreditsResult, type UseModelsOptions, type UseModelsResult, VAULT_SIZE_HOP_CAP, type VaultEmbeddingCache, type VaultEmbeddingExpectation, type VaultFolderOperationsContext, type VaultMemoryKind, type VaultMemoryOperationsContext, type VaultMemoryProjection, type VaultMemoryVisibility, type VaultMemoryWriter, type VaultSaveOperation, type VaultSearchResult, type VaultWriteAction, type VaultWriteInput, type VaultWriteOutcome, type VerificationSources, type VerifyMemoriesForPublishOptions, WalletPoller, type WeatherClassification, type WeatherPreProcessorOptions, type WebSearchClassification, type WebSearchPreProcessorOptions, type WriteFailureReason, addConversationMemoriesOp, archiveVaultMemoryOp, assembleMemoryContext, attachFileContextToLastUserMessage, backfillMemoryTopicsOp, buildAttachedFilesText, buildNotionAuthUrl, capHopsForDensity, chatStorageMigrations, chatStorageSchema, chunkAndEmbedAllMessages, chunkAndEmbedMessage, chunkText, classifyCryptoPrice, classifyCryptoPriceBatch, classifyDecay, classifyInjectionCandidates, classifyObservationTrend, classifyStockPrice, classifyStockPriceBatch, classifyWeather, classifyWeatherBatch, classifyWebSearch, classifyWebSearchBatch, clearAllEncryptionKeys, clearAllEncryptionState, clearConversationMemoriesOp, clearEncryptionKey, clearLazyTitleCache, clearModelsCache, clearServerToolsCache, consoleLogger, conversationMemoryToStored, cosineInt8, createAutoExtractor, createChunkVectorCache, createCryptoPricePreProcessor, createDecaySweeper, createDurableAutoExtractor, createLlmDecayClassifier, createLlmNeighborRefiner, createLocalMemoryStore, createMemoryEngineTool, createMemoryVaultSearchTool, createMemoryVaultTool, createMessageSourceResolver, createNotionProxyTools, createNotionTools, createPlatformCursorStore, createRecallTool, createRemoteMemoryPersistence, createRemoteMemoryPipeline, createRemoteMemoryStore, createStockPricePreProcessor, createStreamingDeAnonymizer, createVaultEmbeddingCache, createVaultFolderOp, createVaultMemoriesBatchOp, createVaultMemoryOp, createWeatherPreProcessor, createWebSearchPreProcessor, decodeChunkVector, decryptConversationTitle, decryptMessageEmbeddingFields, deleteAllVaultMemoriesForUserOp, deleteMessageOp, deleteVaultFolderOp, deleteVaultMemoryOp, dequantizeEmbedding, deriveKeyFromSignatureBytes, deriveMemoryKeyRing, discoverNotionOAuthEndpoints, eagerEmbedContent, embedAllMessages, embedMessage, encodeChunkVector, encryptToolCallEventsOp, ensureDefaultFoldersOp, exchangeNotionCode, extractAndLinkEntitiesForMemoriesOp, extractAndRetain, extractEntitiesForMemories, extractFacts, extractReservationReceipts, formatFileProcessingNotes, generateConversationId, generateEmbedding, generateEmbeddings, generateNotionPKCE, getAllVaultFoldersOp, getAllVaultMemoriesOp, getAllVaultMemoryContentsOp, getCachedServerTools, getConversationMemoriesOp, getConversationsByProjectLazyOp, getConversationsLazyOp, getConversationsPageOp, getDecayCandidatesRawOp, getLogger, getMemoriesNeedingTopicExtractionOp, getServerTools, getUnfiledVaultMemoriesOp, getVaultFolderMemoryCountOp, getVaultMemoriesByIdsOp, getVaultMemoryOp, getVaultRankingProjectionsOp, hardDeleteDecayedOp, hasEncryptionKey, ingestPublishedPhotoMemoriesOp, injectionSignatureCatalog, isAttachedFilesText, isDegradedTopicSkip, isEncrypted, isPiiRedactor, isRerankerAvailable, maskScopedEmbeddingCache, memoryCipher, migrateMemoriesToRemote, moveMemoriesToFolderOp, noopLogger, onKeyAvailable, parseMedia, preEmbedVaultMemories, primaryTopic, quantizeEmbedding, queueManager, rankProfileCandidates, recall, reencryptMemoryField, reflect, refreshEncryptionKeyIfMatches, refreshNotionAccessToken, registerNotionClient, relinkMemoryTopicsOp, requestEncryptionKey, resolvePiiRedactor, restoreVaultMemoryOp, resumeStream, retain, scoreProfileSalience, screenCandidatesForInjection, sdkMigrations, sdkModelClasses, sdkSchema, sealLegacyMessageEmbeddingsOp, searchVaultMemories, seedEncryptionKeys, setLogger, setMemoryVisibilityOp, shouldChunkMessage, shouldRecallMemory, stampTopicsExtractedAtOp, streamCancelPath, streamReplayPath, stripLegacyChunkTextOp, summarizeObservationTrends, supersedeVaultMemoryOp, synthesizeProfile, topicWeight, traverseGraphLane, ttlForType, updateVaultFolderContextOp, updateVaultFolderOp, updateVaultMemoryEmbeddingOp, updateVaultMemoryOp, upsertMessageOp, useChat, useChatStorage, useCredits, useEncryption, useModels, verifyMemoriesForPublish, xhrTransport };
@@ -2420,16 +2420,19 @@ async function updateMessageEmbeddingOp(ctx, uniqueId, vector, embeddingModel) {
2420
2420
  } catch {
2421
2421
  return null;
2422
2422
  }
2423
+ const address = ctx.walletAddress;
2423
2424
  await ctx.database.write(async () => {
2425
+ const key = await resolveMessageEmbeddingKey(address, message.content);
2426
+ const storedVector2 = await serializeMessageEmbedding(key, vector);
2424
2427
  await message.update((msg) => {
2425
- msg._setRaw("vector", JSON.stringify(vector));
2428
+ msg._setRaw("vector", storedVector2);
2426
2429
  if (msg.origin === "chunks_discarded" && vector.length > 0) {
2427
2430
  msg._setRaw("origin", "message");
2428
2431
  }
2429
2432
  msg._setRaw("embedding_model", embeddingModel);
2430
2433
  });
2431
2434
  });
2432
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
2435
+ return messageToStored(message, ctx.walletAddress);
2433
2436
  }
2434
2437
  async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
2435
2438
  let message;
@@ -2439,16 +2442,123 @@ async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
2439
2442
  return null;
2440
2443
  }
2441
2444
  const storedChunks = chunks3.map(({ text: _text, ...rest }) => rest);
2445
+ const address = ctx.walletAddress;
2442
2446
  await ctx.database.write(async () => {
2447
+ const key = await resolveMessageEmbeddingKey(address, message.content);
2448
+ const serializedChunks = await serializeMessageEmbedding(key, storedChunks);
2443
2449
  await message.update((msg) => {
2444
- msg._setRaw("chunks", JSON.stringify(storedChunks));
2450
+ msg._setRaw("chunks", serializedChunks);
2445
2451
  if (msg.origin === "chunks_discarded" && storedChunks.length > 0 && storedChunks.every((chunk) => chunk.vector.length > 0)) {
2446
2452
  msg._setRaw("origin", "message");
2447
2453
  }
2448
2454
  msg._setRaw("embedding_model", embeddingModel);
2449
2455
  });
2450
2456
  });
2451
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
2457
+ return messageToStored(message, ctx.walletAddress);
2458
+ }
2459
+ async function resolveMessageEmbeddingKey(address, content) {
2460
+ if (!address || !isEncrypted(content)) return null;
2461
+ const key = await getEncryptionKey(address, "v3");
2462
+ const contentKey = content.startsWith("enc:v2:") ? await getEncryptionKey(address, "v2") : key;
2463
+ try {
2464
+ await decryptDataWithKey(content.slice("enc:vN:".length), contentKey);
2465
+ } catch {
2466
+ throw new Error("Cannot decrypt the message with the cached wallet key");
2467
+ }
2468
+ return key;
2469
+ }
2470
+ async function serializeMessageEmbedding(key, value) {
2471
+ const json4 = JSON.stringify(value);
2472
+ return key ? `enc:v3:${await encryptDataWithKey(json4, key)}` : json4;
2473
+ }
2474
+ async function decryptMessageEmbeddingFields(raw, walletAddress) {
2475
+ const result = { ...raw };
2476
+ for (const column of ["vector", "chunks"]) {
2477
+ const value = raw[column];
2478
+ if (typeof value !== "string" || !value.startsWith("enc:")) continue;
2479
+ const decrypted = walletAddress ? await decryptField(value, walletAddress) : value;
2480
+ result[column] = decrypted.startsWith("enc:") ? void 0 : decrypted;
2481
+ }
2482
+ return result;
2483
+ }
2484
+ async function sealLegacyMessageEmbeddingsOp(ctx) {
2485
+ if (!ctx.walletAddress) return 0;
2486
+ const candidateIds = await ctx.messagesCollection.query(
2487
+ Q.where("content", Q.like("enc:%")),
2488
+ Q.or(
2489
+ ...["vector", "chunks"].map(
2490
+ (column) => Q.and(
2491
+ Q.where(column, Q.notEq(null)),
2492
+ Q.where(column, Q.notEq("")),
2493
+ Q.where(column, Q.notLike("enc:%"))
2494
+ )
2495
+ )
2496
+ )
2497
+ ).fetchIds();
2498
+ let sealed = 0;
2499
+ let undecryptable = 0;
2500
+ for (let start = 0; start < candidateIds.length; start += 50) {
2501
+ const pageIds = candidateIds.slice(start, start + 50);
2502
+ await ctx.database.write(async () => {
2503
+ const pageMessages = await ctx.messagesCollection.query(Q.where("id", Q.oneOf(pageIds))).fetch();
2504
+ for (const message of pageMessages) {
2505
+ if (!isEncrypted(message.content)) continue;
2506
+ const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
2507
+ if (content.status === "key_missing") {
2508
+ throw new Error("Cannot decrypt the message with the cached wallet key");
2509
+ }
2510
+ if (content.status !== "ok") {
2511
+ undecryptable++;
2512
+ continue;
2513
+ }
2514
+ const plaintext = content.value;
2515
+ const key = await resolveMessageEmbeddingKey(ctx.walletAddress, message.content);
2516
+ const updates = {};
2517
+ for (const column of ["vector", "chunks"]) {
2518
+ const value = message._getRaw(column);
2519
+ if (typeof value !== "string" || value.startsWith("enc:") || !value) continue;
2520
+ let parsed;
2521
+ try {
2522
+ parsed = JSON.parse(value);
2523
+ } catch {
2524
+ updates[column] = null;
2525
+ continue;
2526
+ }
2527
+ if (!Array.isArray(parsed)) {
2528
+ updates[column] = null;
2529
+ continue;
2530
+ }
2531
+ if (column === "chunks") {
2532
+ const chunks3 = parsed;
2533
+ if (chunks3.some(
2534
+ (chunk) => !chunk || !Number.isInteger(chunk.startOffset) || !Number.isInteger(chunk.endOffset) || chunk.startOffset < 0 || chunk.endOffset <= chunk.startOffset || chunk.endOffset > plaintext.length
2535
+ )) {
2536
+ updates.chunks = null;
2537
+ updates.vector = null;
2538
+ updates.origin = message.origin === "tool_result" ? "tool_result" : "chunks_discarded";
2539
+ break;
2540
+ }
2541
+ parsed = chunks3.map(({ text: _text, ...rest }) => rest);
2542
+ }
2543
+ updates[column] = await serializeMessageEmbedding(key, parsed);
2544
+ }
2545
+ if (Object.keys(updates).length === 0) continue;
2546
+ const updatedAt = Number(message._getRaw("updated_at"));
2547
+ const discarded = updates.origin !== void 0;
2548
+ await message.update((msg) => {
2549
+ for (const [column, value] of Object.entries(updates)) msg._setRaw(column, value);
2550
+ msg._setRaw("updated_at", discarded ? Math.max(Date.now(), updatedAt + 1) : updatedAt);
2551
+ });
2552
+ sealed++;
2553
+ }
2554
+ });
2555
+ }
2556
+ if (undecryptable > 0) {
2557
+ getLogger().warn(
2558
+ `Skipped ${undecryptable} message embeddings that the cached wallet key cannot decrypt`
2559
+ );
2560
+ }
2561
+ return sealed;
2452
2562
  }
2453
2563
  var RAW_REPAIR_PAGE_SIZE = 100;
2454
2564
  function chunksWithoutText(raw) {
@@ -28289,6 +28399,7 @@ export {
28289
28399
  createWebSearchPreProcessor,
28290
28400
  decodeChunkVector,
28291
28401
  decryptConversationTitle,
28402
+ decryptMessageEmbeddingFields,
28292
28403
  deleteAllVaultMemoriesForUserOp,
28293
28404
  deleteMessageOp,
28294
28405
  deleteVaultFolderOp,
@@ -28369,6 +28480,7 @@ export {
28369
28480
  sdkMigrations,
28370
28481
  sdkModelClasses,
28371
28482
  sdkSchema,
28483
+ sealLegacyMessageEmbeddingsOp,
28372
28484
  searchVaultMemories,
28373
28485
  seedEncryptionKeys,
28374
28486
  setLogger,
@@ -1564,6 +1564,7 @@ __export(index_exports, {
1564
1564
  decryptDataBytes: () => decryptDataBytes,
1565
1565
  decryptDataBytesFromBytes: () => decryptDataBytesFromBytes,
1566
1566
  decryptDataWithKey: () => decryptDataWithKey,
1567
+ decryptMessageEmbeddingFields: () => decryptMessageEmbeddingFields,
1567
1568
  defaultServerToolsFilter: () => defaultServerToolsFilter,
1568
1569
  deleteAllAppFilesOp: () => deleteAllAppFilesOp,
1569
1570
  deleteAllVaultMemoriesForUserOp: () => deleteAllVaultMemoriesForUserOp,
@@ -1744,6 +1745,7 @@ __export(index_exports, {
1744
1745
  sdkMigrations: () => sdkMigrations,
1745
1746
  sdkModelClasses: () => sdkModelClasses,
1746
1747
  sdkSchema: () => sdkSchema,
1748
+ sealLegacyMessageEmbeddingsOp: () => sealLegacyMessageEmbeddingsOp,
1747
1749
  searchChunksOp: () => searchChunksOp,
1748
1750
  searchMediaOp: () => searchMediaOp,
1749
1751
  searchMessagesOp: () => searchMessagesOp,
@@ -4714,16 +4716,19 @@ async function updateMessageEmbeddingOp(ctx, uniqueId, vector, embeddingModel) {
4714
4716
  } catch {
4715
4717
  return null;
4716
4718
  }
4719
+ const address = ctx.walletAddress;
4717
4720
  await ctx.database.write(async () => {
4721
+ const key = await resolveMessageEmbeddingKey(address, message.content);
4722
+ const storedVector2 = await serializeMessageEmbedding(key, vector);
4718
4723
  await message.update((msg) => {
4719
- msg._setRaw("vector", JSON.stringify(vector));
4724
+ msg._setRaw("vector", storedVector2);
4720
4725
  if (msg.origin === "chunks_discarded" && vector.length > 0) {
4721
4726
  msg._setRaw("origin", "message");
4722
4727
  }
4723
4728
  msg._setRaw("embedding_model", embeddingModel);
4724
4729
  });
4725
4730
  });
4726
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
4731
+ return messageToStored(message, ctx.walletAddress);
4727
4732
  }
4728
4733
  async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
4729
4734
  let message;
@@ -4733,16 +4738,123 @@ async function updateMessageChunksOp(ctx, uniqueId, chunks3, embeddingModel) {
4733
4738
  return null;
4734
4739
  }
4735
4740
  const storedChunks = chunks3.map(({ text: _text, ...rest }) => rest);
4741
+ const address = ctx.walletAddress;
4736
4742
  await ctx.database.write(async () => {
4743
+ const key = await resolveMessageEmbeddingKey(address, message.content);
4744
+ const serializedChunks = await serializeMessageEmbedding(key, storedChunks);
4737
4745
  await message.update((msg) => {
4738
- msg._setRaw("chunks", JSON.stringify(storedChunks));
4746
+ msg._setRaw("chunks", serializedChunks);
4739
4747
  if (msg.origin === "chunks_discarded" && storedChunks.length > 0 && storedChunks.every((chunk) => chunk.vector.length > 0)) {
4740
4748
  msg._setRaw("origin", "message");
4741
4749
  }
4742
4750
  msg._setRaw("embedding_model", embeddingModel);
4743
4751
  });
4744
4752
  });
4745
- return messageToStored(message, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner);
4753
+ return messageToStored(message, ctx.walletAddress);
4754
+ }
4755
+ async function resolveMessageEmbeddingKey(address, content) {
4756
+ if (!address || !isEncrypted(content)) return null;
4757
+ const key = await getEncryptionKey(address, "v3");
4758
+ const contentKey = content.startsWith("enc:v2:") ? await getEncryptionKey(address, "v2") : key;
4759
+ try {
4760
+ await decryptDataWithKey(content.slice("enc:vN:".length), contentKey);
4761
+ } catch {
4762
+ throw new Error("Cannot decrypt the message with the cached wallet key");
4763
+ }
4764
+ return key;
4765
+ }
4766
+ async function serializeMessageEmbedding(key, value) {
4767
+ const json4 = JSON.stringify(value);
4768
+ return key ? `enc:v3:${await encryptDataWithKey(json4, key)}` : json4;
4769
+ }
4770
+ async function decryptMessageEmbeddingFields(raw, walletAddress) {
4771
+ const result = { ...raw };
4772
+ for (const column of ["vector", "chunks"]) {
4773
+ const value = raw[column];
4774
+ if (typeof value !== "string" || !value.startsWith("enc:")) continue;
4775
+ const decrypted = walletAddress ? await decryptField(value, walletAddress) : value;
4776
+ result[column] = decrypted.startsWith("enc:") ? void 0 : decrypted;
4777
+ }
4778
+ return result;
4779
+ }
4780
+ async function sealLegacyMessageEmbeddingsOp(ctx) {
4781
+ if (!ctx.walletAddress) return 0;
4782
+ const candidateIds = await ctx.messagesCollection.query(
4783
+ import_watermelondb2.Q.where("content", import_watermelondb2.Q.like("enc:%")),
4784
+ import_watermelondb2.Q.or(
4785
+ ...["vector", "chunks"].map(
4786
+ (column) => import_watermelondb2.Q.and(
4787
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq(null)),
4788
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notEq("")),
4789
+ import_watermelondb2.Q.where(column, import_watermelondb2.Q.notLike("enc:%"))
4790
+ )
4791
+ )
4792
+ )
4793
+ ).fetchIds();
4794
+ let sealed = 0;
4795
+ let undecryptable = 0;
4796
+ for (let start = 0; start < candidateIds.length; start += 50) {
4797
+ const pageIds = candidateIds.slice(start, start + 50);
4798
+ await ctx.database.write(async () => {
4799
+ const pageMessages = await ctx.messagesCollection.query(import_watermelondb2.Q.where("id", import_watermelondb2.Q.oneOf(pageIds))).fetch();
4800
+ for (const message of pageMessages) {
4801
+ if (!isEncrypted(message.content)) continue;
4802
+ const content = await decryptFieldDetailed(message.content, ctx.walletAddress);
4803
+ if (content.status === "key_missing") {
4804
+ throw new Error("Cannot decrypt the message with the cached wallet key");
4805
+ }
4806
+ if (content.status !== "ok") {
4807
+ undecryptable++;
4808
+ continue;
4809
+ }
4810
+ const plaintext = content.value;
4811
+ const key = await resolveMessageEmbeddingKey(ctx.walletAddress, message.content);
4812
+ const updates = {};
4813
+ for (const column of ["vector", "chunks"]) {
4814
+ const value = message._getRaw(column);
4815
+ if (typeof value !== "string" || value.startsWith("enc:") || !value) continue;
4816
+ let parsed;
4817
+ try {
4818
+ parsed = JSON.parse(value);
4819
+ } catch {
4820
+ updates[column] = null;
4821
+ continue;
4822
+ }
4823
+ if (!Array.isArray(parsed)) {
4824
+ updates[column] = null;
4825
+ continue;
4826
+ }
4827
+ if (column === "chunks") {
4828
+ const chunks3 = parsed;
4829
+ if (chunks3.some(
4830
+ (chunk) => !chunk || !Number.isInteger(chunk.startOffset) || !Number.isInteger(chunk.endOffset) || chunk.startOffset < 0 || chunk.endOffset <= chunk.startOffset || chunk.endOffset > plaintext.length
4831
+ )) {
4832
+ updates.chunks = null;
4833
+ updates.vector = null;
4834
+ updates.origin = message.origin === "tool_result" ? "tool_result" : "chunks_discarded";
4835
+ break;
4836
+ }
4837
+ parsed = chunks3.map(({ text: _text, ...rest }) => rest);
4838
+ }
4839
+ updates[column] = await serializeMessageEmbedding(key, parsed);
4840
+ }
4841
+ if (Object.keys(updates).length === 0) continue;
4842
+ const updatedAt = Number(message._getRaw("updated_at"));
4843
+ const discarded = updates.origin !== void 0;
4844
+ await message.update((msg) => {
4845
+ for (const [column, value] of Object.entries(updates)) msg._setRaw(column, value);
4846
+ msg._setRaw("updated_at", discarded ? Math.max(Date.now(), updatedAt + 1) : updatedAt);
4847
+ });
4848
+ sealed++;
4849
+ }
4850
+ });
4851
+ }
4852
+ if (undecryptable > 0) {
4853
+ getLogger().warn(
4854
+ `Skipped ${undecryptable} message embeddings that the cached wallet key cannot decrypt`
4855
+ );
4856
+ }
4857
+ return sealed;
4746
4858
  }
4747
4859
  var RAW_REPAIR_PAGE_SIZE = 100;
4748
4860
  function chunksWithoutText(raw) {
@@ -38196,6 +38308,7 @@ function useWalletBinding(options = {}) {
38196
38308
  decryptDataBytes,
38197
38309
  decryptDataBytesFromBytes,
38198
38310
  decryptDataWithKey,
38311
+ decryptMessageEmbeddingFields,
38199
38312
  defaultServerToolsFilter,
38200
38313
  deleteAllAppFilesOp,
38201
38314
  deleteAllVaultMemoriesForUserOp,
@@ -38376,6 +38489,7 @@ function useWalletBinding(options = {}) {
38376
38489
  sdkMigrations,
38377
38490
  sdkModelClasses,
38378
38491
  sdkSchema,
38492
+ sealLegacyMessageEmbeddingsOp,
38379
38493
  searchChunksOp,
38380
38494
  searchMediaOp,
38381
38495
  searchMessagesOp,