@anuma/sdk 6.32.0 → 6.33.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.
@@ -1595,6 +1595,7 @@ __export(index_exports, {
1595
1595
  createGitHubTools: () => createGitHubTools,
1596
1596
  createLlmDecayClassifier: () => createLlmDecayClassifier,
1597
1597
  createLlmNeighborRefiner: () => createLlmNeighborRefiner,
1598
+ createLocalMemoryStore: () => createLocalMemoryStore,
1598
1599
  createMediaBatchOp: () => createMediaBatchOp,
1599
1600
  createMediaOp: () => createMediaOp,
1600
1601
  createMemoryEngineTool: () => createMemoryEngineTool,
@@ -17202,7 +17203,10 @@ async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, mem
17202
17203
  if (memoryId) cacheRowVector(cache, memoryId, Float32Array.from(embedding), updatedAt, content);
17203
17204
  if (vaultCtx && memoryId) {
17204
17205
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
17205
- updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
17206
+ updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel, {
17207
+ content,
17208
+ ...updatedAt !== void 0 && { updatedAt: updatedAt.getTime() }
17209
+ }).catch(
17206
17210
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
17207
17211
  () => {
17208
17212
  }
@@ -20741,6 +20745,353 @@ function parseAnswer(body, base, parseSchema) {
20741
20745
  };
20742
20746
  }
20743
20747
 
20748
+ // src/lib/memory/store/local.ts
20749
+ var import_watermelondb13 = require("@nozbe/watermelondb");
20750
+ init_logger();
20751
+
20752
+ // src/lib/memory/topicExtract.ts
20753
+ init_logger();
20754
+ init_redactor();
20755
+ init_portalLlm();
20756
+ var TOPIC_EXTRACTION_BATCH_SIZE = 10;
20757
+ var MAX_CHARS_PER_MEMORY = 300;
20758
+ var MAX_VOCABULARY_NAMES = 100;
20759
+ var MAX_COMPLETION_TOKENS = 8192;
20760
+ var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
20761
+
20762
+ Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
20763
+
20764
+ Include only NAMED entities, skip generic/common nouns. A topic must identify a specific thing the user could recognize by name; if it would be equally true of thousands of unrelated memories, leave it out:
20765
+ - SKIP bare generic nouns even when the memory capitalizes them or a calendar entry is titled that way \u2014 "Home", "Work", "Meeting", "Lunch", "Birthday", "Appointment", "Trip", "Today", "Friday", "March" are NOT topics.
20766
+ - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
20767
+ - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
20768
+ ${ENTITY_KIND_GUIDELINES}
20769
+
20770
+ Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
20771
+ - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
20772
+ - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
20773
+ No prose.`;
20774
+ async function extractEntitiesForMemories(memories, options) {
20775
+ const out = /* @__PURE__ */ new Map();
20776
+ if (memories.length === 0) return out;
20777
+ const redactor = resolvePiiRedactor(options.piiRedaction);
20778
+ const vocabulary = [];
20779
+ for (const name of (options.existingEntityNames ?? []).filter((n) => n.trim().length > 0).slice(0, MAX_VOCABULARY_NAMES)) {
20780
+ vocabulary.push(redactor ? (await redactor.redactTextAsync(name)).text : name);
20781
+ }
20782
+ const vocabularyNote = vocabulary.length > 0 ? `The user's existing topics: ${vocabulary.join(", ")}.
20783
+ When a memory refers to one of these, reuse the EXACT existing name (same spelling, casing, spacing and punctuation) instead of a variant \u2014 if "Foo.ai" is listed, never emit "Foo ai" or "Foo AI", and if "Jane Roe" is listed, emit that rather than a bare "Jane".
20784
+
20785
+ ` : "";
20786
+ for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
20787
+ const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
20788
+ const rows = [];
20789
+ for (const m of batch) {
20790
+ const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
20791
+ rows.push(`${m.id}: ${redactor ? (await redactor.redactTextAsync(content)).text : content}`);
20792
+ }
20793
+ const listing = rows.join("\n");
20794
+ const parsed = await callPortalJsonCompletion({
20795
+ ...options.apiKey !== void 0 && { apiKey: options.apiKey },
20796
+ ...options.getToken !== void 0 && { getToken: options.getToken },
20797
+ ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
20798
+ taskType: "memory_topic",
20799
+ ...options.endpointOverride !== void 0 && {
20800
+ endpointOverride: options.endpointOverride
20801
+ },
20802
+ model: options.model ?? DEFAULT_EXTRACTION_MODEL,
20803
+ systemPrompt: SYSTEM_PROMPT6,
20804
+ userMessage: `${vocabularyNote}Memories:
20805
+ ${listing}
20806
+
20807
+ List each memory's named entities.`,
20808
+ tag: "memory/topics",
20809
+ extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
20810
+ ...options.fetchFn && { fetchFn: options.fetchFn },
20811
+ ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
20812
+ ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
20813
+ ...options.totalTimeoutMs !== void 0 && { totalTimeoutMs: options.totalTimeoutMs },
20814
+ ...options.backoffMs && { backoffMs: options.backoffMs }
20815
+ });
20816
+ if (parsed === null) {
20817
+ getLogger().warn(
20818
+ `[memory/topics] batch of ${batch.length} failed after retries \u2014 will retry next sweep`
20819
+ );
20820
+ continue;
20821
+ }
20822
+ const validIds = new Set(batch.map((m) => m.id));
20823
+ const byId = parseTopicResponse(parsed, validIds);
20824
+ if (byId === null) {
20825
+ getLogger().warn(
20826
+ `[memory/topics] batch of ${batch.length} returned an unrecognized shape \u2014 will retry next sweep`
20827
+ );
20828
+ continue;
20829
+ }
20830
+ for (const m of batch) {
20831
+ const entities = byId.get(m.id);
20832
+ if (entities === void 0) {
20833
+ continue;
20834
+ }
20835
+ out.set(m.id, redactor ? restoreEntities(entities, redactor) : entities);
20836
+ }
20837
+ }
20838
+ return out;
20839
+ }
20840
+ function restoreEntities(entities, redactor) {
20841
+ return entities.map((e) => ({ kind: e.kind, restored: redactor.restoreForStorage(e.name) })).filter((e) => !e.restored.unresolved).map(
20842
+ (e) => e.kind !== void 0 ? { name: e.restored.text, kind: e.kind } : { name: e.restored.text }
20843
+ );
20844
+ }
20845
+ function parseTopicResponse(parsed, validIds) {
20846
+ if (typeof parsed !== "object" || parsed === null) return null;
20847
+ const list = parsed.memories;
20848
+ if (!Array.isArray(list)) return null;
20849
+ const out = /* @__PURE__ */ new Map();
20850
+ for (const raw of list) {
20851
+ if (typeof raw !== "object" || raw === null) continue;
20852
+ const obj = raw;
20853
+ if (typeof obj.id !== "string") continue;
20854
+ const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
20855
+ if (!validIds.has(id) || out.has(id)) continue;
20856
+ const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
20857
+ out.set(id, entities);
20858
+ }
20859
+ return out;
20860
+ }
20861
+ var DEGRADED_TOPIC_SKIP = {
20862
+ excluded: false,
20863
+ "link-declined": false,
20864
+ "stamp-declined": false,
20865
+ "llm-unanswered": true,
20866
+ unreadable: true,
20867
+ "not-found": true,
20868
+ "link-failed": true
20869
+ };
20870
+ function isDegradedTopicSkip(reason) {
20871
+ return DEGRADED_TOPIC_SKIP[reason] === true;
20872
+ }
20873
+ async function extractAndLinkEntitiesForMemoriesOp(ctx, memoryIds, options) {
20874
+ const entityCtx = ctx.entityCtx;
20875
+ if (!entityCtx) {
20876
+ throw new Error("extractAndLinkEntitiesForMemoriesOp requires ctx.entityCtx");
20877
+ }
20878
+ const log = getLogger();
20879
+ const extractedAt = options.now ?? Date.now();
20880
+ const skippedIds = [];
20881
+ const skippedReasons = /* @__PURE__ */ new Map();
20882
+ const skip = (id, reason) => {
20883
+ if (skippedReasons.has(id)) return;
20884
+ skippedIds.push(id);
20885
+ skippedReasons.set(id, reason);
20886
+ };
20887
+ const inputs = [];
20888
+ for (const id of new Set(memoryIds)) {
20889
+ let record;
20890
+ try {
20891
+ record = await ctx.vaultMemoryCollection.find(id);
20892
+ } catch (err) {
20893
+ log.warn("[memory/topics] vault lookup failed for extraction", err);
20894
+ skip(id, "not-found");
20895
+ continue;
20896
+ }
20897
+ if (record.isDeleted || ctx.userId !== void 0 && record.userId !== ctx.userId || record.topicsUserManaged) {
20898
+ skip(id, "excluded");
20899
+ continue;
20900
+ }
20901
+ try {
20902
+ const stored = await vaultMemoryToStored(
20903
+ record,
20904
+ ctx.walletAddress,
20905
+ ctx.signMessage,
20906
+ ctx.embeddedWalletSigner
20907
+ );
20908
+ inputs.push({ id, content: stored.content });
20909
+ } catch (err) {
20910
+ log.warn("[memory/topics] failed to load memory for extraction", err);
20911
+ skip(id, "unreadable");
20912
+ }
20913
+ }
20914
+ const entitiesByMemory = await extractEntitiesForMemories(inputs, options);
20915
+ const toStamp = [];
20916
+ for (const input of inputs) {
20917
+ const entities = entitiesByMemory.get(input.id);
20918
+ if (entities === void 0) {
20919
+ skip(input.id, "llm-unanswered");
20920
+ continue;
20921
+ }
20922
+ try {
20923
+ const linked = await replaceMemoryEntitiesGuardedOp(entityCtx, input.id, entities);
20924
+ if (linked === null) {
20925
+ skip(input.id, "link-declined");
20926
+ entitiesByMemory.delete(input.id);
20927
+ continue;
20928
+ }
20929
+ } catch (err) {
20930
+ log.warn("[memory/topics] replaceMemoryEntitiesGuardedOp failed", err);
20931
+ skip(input.id, "link-failed");
20932
+ entitiesByMemory.delete(input.id);
20933
+ continue;
20934
+ }
20935
+ toStamp.push(input.id);
20936
+ }
20937
+ const stampedIds = await stampTopicsExtractedAtOp(ctx, toStamp, extractedAt);
20938
+ const stampedSet = new Set(stampedIds);
20939
+ for (const id of toStamp) {
20940
+ if (!stampedSet.has(id)) {
20941
+ skip(id, "stamp-declined");
20942
+ entitiesByMemory.delete(id);
20943
+ }
20944
+ }
20945
+ return { entitiesByMemory, stampedIds, skippedIds, skippedReasons };
20946
+ }
20947
+
20948
+ // src/lib/memory/store/local.ts
20949
+ function createLocalMemoryStore(options) {
20950
+ const { database, userId } = options;
20951
+ const entityCtx = {
20952
+ database,
20953
+ entityCollection: database.get("entity"),
20954
+ memoryEntityCollection: database.get("memory_entity"),
20955
+ ...userId !== void 0 && { userId },
20956
+ ...options.allowUnscopedRows !== void 0 && {
20957
+ allowUnscopedRows: options.allowUnscopedRows
20958
+ }
20959
+ };
20960
+ const vaultCtx = {
20961
+ database,
20962
+ vaultMemoryCollection: database.get("memory_vault"),
20963
+ walletAddress: options.walletAddress,
20964
+ signMessage: options.signMessage,
20965
+ embeddedWalletSigner: options.embeddedWalletSigner,
20966
+ ...userId !== void 0 && { userId },
20967
+ ...options.singleTenant !== void 0 && { singleTenant: options.singleTenant },
20968
+ // Deletes cascade to memory_entity, so the graph lane never serves a
20969
+ // deleted memory's id.
20970
+ entityCtx
20971
+ };
20972
+ const vaultCache = options.vaultCache ?? createVaultEmbeddingCache();
20973
+ const ownedBy = userId !== void 0 ? [import_watermelondb13.Q.where("user_id", userId)] : [];
20974
+ const watchedColumns = [
20975
+ "content",
20976
+ "scope",
20977
+ "updated_at",
20978
+ "fact_type",
20979
+ "event_time_start",
20980
+ "event_time_end",
20981
+ "event_time_kind",
20982
+ "archived_at",
20983
+ "trust_tier",
20984
+ "superseded_by",
20985
+ "visibility",
20986
+ "published_at",
20987
+ "geohash",
20988
+ "topics",
20989
+ "topics_user_managed",
20990
+ "media",
20991
+ "source"
20992
+ ];
20993
+ const embedInBackground = (memory) => {
20994
+ eagerEmbedContent(
20995
+ memory.content,
20996
+ options.embeddingOptions,
20997
+ vaultCache,
20998
+ vaultCtx,
20999
+ memory.uniqueId,
21000
+ memory.updatedAt
21001
+ ).catch((err) => {
21002
+ getLogger().warn("[memory/store] Failed to embed memory:", err);
21003
+ });
21004
+ };
21005
+ return {
21006
+ list: (listOptions) => getAllVaultMemoriesOp(vaultCtx, listOptions),
21007
+ get: (id) => getVaultMemoryOp(vaultCtx, id),
21008
+ listArchived: async () => {
21009
+ const ids = await vaultCtx.vaultMemoryCollection.query(import_watermelondb13.Q.where("is_deleted", false), import_watermelondb13.Q.where("archived_at", import_watermelondb13.Q.notEq(null)), ...ownedBy).fetchIds();
21010
+ if (ids.length === 0) return [];
21011
+ const rows = await getAllVaultMemoriesOp(vaultCtx, { memoryIds: ids, includeArchived: true });
21012
+ return rows.sort((a, b) => (b.archivedAt ?? 0) - (a.archivedAt ?? 0));
21013
+ },
21014
+ memoriesByTopics: (names) => getMemoriesByEntityNamesOp(entityCtx, names),
21015
+ topicsByMemories: (memoryIds) => getEntitiesByMemoryIdsOp(entityCtx, memoryIds),
21016
+ create: async (input) => {
21017
+ const created = await createVaultMemoryOp(vaultCtx, input);
21018
+ if (input.embedding === void 0) embedInBackground(created);
21019
+ return created;
21020
+ },
21021
+ createMany: async (inputs) => {
21022
+ const created = await createVaultMemoriesBatchOp(vaultCtx, inputs);
21023
+ created.forEach((memory, i) => {
21024
+ if (inputs[i].embedding === void 0) embedInBackground(memory);
21025
+ });
21026
+ return created;
21027
+ },
21028
+ update: async (id, patch) => {
21029
+ const reembed = patch.embedding === void 0;
21030
+ const updated = await updateVaultMemoryOp(
21031
+ vaultCtx,
21032
+ id,
21033
+ reembed ? { ...patch, embedding: null } : patch
21034
+ );
21035
+ if (!updated) return null;
21036
+ vaultCache.delete(id);
21037
+ if (reembed) embedInBackground(updated);
21038
+ return updated;
21039
+ },
21040
+ delete: async (id) => {
21041
+ const deleted = await deleteVaultMemoryOp(vaultCtx, id);
21042
+ if (deleted) vaultCache.delete(id);
21043
+ return deleted;
21044
+ },
21045
+ supersede: (id, supersededById) => supersedeVaultMemoryOp(vaultCtx, id, supersededById),
21046
+ archive: (id) => archiveVaultMemoryOp(vaultCtx, id),
21047
+ restore: (id) => restoreVaultMemoryOp(vaultCtx, id),
21048
+ setTopics: (memoryId, topics) => setMemoryEntitiesOp(vaultCtx, memoryId, topics),
21049
+ addTopics: (memoryId, topics) => database.write(async (writer) => {
21050
+ const owned = await vaultCtx.vaultMemoryCollection.query(import_watermelondb13.Q.where("id", memoryId), import_watermelondb13.Q.where("is_deleted", false), ...ownedBy).fetchCount();
21051
+ return owned > 0 ? writer.callWriter(() => linkMemoryEntitiesOp(entityCtx, memoryId, topics)) : [];
21052
+ }),
21053
+ setVisibility: (id, visibility, visibilityOptions) => setMemoryVisibilityOp(vaultCtx, id, { visibility, ...visibilityOptions }),
21054
+ recall: (query, recallOptions) => recall(
21055
+ query,
21056
+ { vaultCtx, entityCtx, embeddingOptions: options.embeddingOptions, vaultCache },
21057
+ { ...recallOptions, types: ["fact"] }
21058
+ ),
21059
+ retain: (content, retainOptions) => retain(
21060
+ content,
21061
+ { vaultCtx, embeddingOptions: options.embeddingOptions, vaultCache },
21062
+ retainOptions
21063
+ ),
21064
+ subscribe: (onChange, subscribeOptions) => {
21065
+ const afterFirst = () => {
21066
+ let first = true;
21067
+ return () => {
21068
+ if (first) first = false;
21069
+ else onChange();
21070
+ };
21071
+ };
21072
+ const memories = subscribeOptions?.includeDeleted ? vaultCtx.vaultMemoryCollection.query(...ownedBy).observe() : vaultCtx.vaultMemoryCollection.query(import_watermelondb13.Q.where("is_deleted", false), ...ownedBy).observeWithColumns(
21073
+ subscribeOptions?.embeddings ? [...watchedColumns, "embedding", "embedding_model"] : watchedColumns
21074
+ );
21075
+ const subscriptions = [memories.subscribe(afterFirst())];
21076
+ if (subscribeOptions?.topics) {
21077
+ const linksOwnedBy = userId === void 0 ? [] : options.allowUnscopedRows ? [import_watermelondb13.Q.or(import_watermelondb13.Q.where("user_id", userId), import_watermelondb13.Q.where("user_id", null))] : [import_watermelondb13.Q.where("user_id", userId)];
21078
+ subscriptions.push(
21079
+ entityCtx.memoryEntityCollection.query(...linksOwnedBy).observe().subscribe(afterFirst())
21080
+ );
21081
+ }
21082
+ return () => subscriptions.forEach((s) => s.unsubscribe());
21083
+ },
21084
+ maintenance: {
21085
+ createDecaySweeper: (sweeperOptions) => createDecaySweeper({ ...sweeperOptions, vaultCtx }),
21086
+ getTopicBacklog: (backlogOptions) => getMemoriesNeedingTopicExtractionOp(vaultCtx, backlogOptions),
21087
+ extractTopics: (memoryIds, extractOptions) => extractAndLinkEntitiesForMemoriesOp(vaultCtx, memoryIds, extractOptions),
21088
+ stampTopicsExtracted: (memoryIds, extractedAt, version) => stampTopicsExtractedAtOp(vaultCtx, memoryIds, extractedAt, version),
21089
+ relinkTopics: (memoryIds) => relinkMemoryTopicsOp(vaultCtx, memoryIds),
21090
+ backfillTopics: (memoryIds) => backfillMemoryTopicsOp(vaultCtx, memoryIds)
21091
+ }
21092
+ };
21093
+ }
21094
+
20744
21095
  // src/lib/memory/synthesizeProfile.ts
20745
21096
  init_internalFlowMarker();
20746
21097
  init_logger();
@@ -21270,202 +21621,6 @@ function normalizeInterests(values) {
21270
21621
  return out.length > 0 ? out : void 0;
21271
21622
  }
21272
21623
 
21273
- // src/lib/memory/topicExtract.ts
21274
- init_logger();
21275
- init_redactor();
21276
- init_portalLlm();
21277
- var TOPIC_EXTRACTION_BATCH_SIZE = 10;
21278
- var MAX_CHARS_PER_MEMORY = 300;
21279
- var MAX_VOCABULARY_NAMES = 100;
21280
- var MAX_COMPLETION_TOKENS = 8192;
21281
- var SYSTEM_PROMPT6 = `You assign topics to saved memories for a personal memory system.
21282
-
21283
- Each memory is a short statement about the user. For each memory, list the NAMED entities it mentions \u2014 these become the memory's topics, used to connect related memories in a knowledge graph.
21284
-
21285
- Include only NAMED entities, skip generic/common nouns. A topic must identify a specific thing the user could recognize by name; if it would be equally true of thousands of unrelated memories, leave it out:
21286
- - SKIP bare generic nouns even when the memory capitalizes them or a calendar entry is titled that way \u2014 "Home", "Work", "Meeting", "Lunch", "Birthday", "Appointment", "Trip", "Today", "Friday", "March" are NOT topics.
21287
- - KEEP the specific thing instead, when the memory names one: "Blue Bottle on Valencia" over "cafe", "Chicago Marathon" over "event", "Hollowpoint Labs" over "work".
21288
- - Prefer 0 entities over a weak one. A memory whose only candidate is a generic noun has NO entities.
21289
- ${ENTITY_KIND_GUIDELINES}
21290
-
21291
- Each memory below is written as "<id>: <text>". Output strict JSON: {"memories": [{"id": string, "entities": [{"name": string, "kind": string}]}]}
21292
- - exactly one element per input memory; copy its id EXACTLY as written (the token before the first ": "), with no brackets, quotes, or extra characters
21293
- - "entities" may be empty when a memory mentions no named entities \u2014 most short memories have 0-3
21294
- No prose.`;
21295
- async function extractEntitiesForMemories(memories, options) {
21296
- const out = /* @__PURE__ */ new Map();
21297
- if (memories.length === 0) return out;
21298
- const redactor = resolvePiiRedactor(options.piiRedaction);
21299
- const vocabulary = [];
21300
- for (const name of (options.existingEntityNames ?? []).filter((n) => n.trim().length > 0).slice(0, MAX_VOCABULARY_NAMES)) {
21301
- vocabulary.push(redactor ? (await redactor.redactTextAsync(name)).text : name);
21302
- }
21303
- const vocabularyNote = vocabulary.length > 0 ? `The user's existing topics: ${vocabulary.join(", ")}.
21304
- When a memory refers to one of these, reuse the EXACT existing name (same spelling, casing, spacing and punctuation) instead of a variant \u2014 if "Foo.ai" is listed, never emit "Foo ai" or "Foo AI", and if "Jane Roe" is listed, emit that rather than a bare "Jane".
21305
-
21306
- ` : "";
21307
- for (let i = 0; i < memories.length; i += TOPIC_EXTRACTION_BATCH_SIZE) {
21308
- const batch = memories.slice(i, i + TOPIC_EXTRACTION_BATCH_SIZE);
21309
- const rows = [];
21310
- for (const m of batch) {
21311
- const content = m.content.slice(0, MAX_CHARS_PER_MEMORY).replace(/\s+/g, " ").trim();
21312
- rows.push(`${m.id}: ${redactor ? (await redactor.redactTextAsync(content)).text : content}`);
21313
- }
21314
- const listing = rows.join("\n");
21315
- const parsed = await callPortalJsonCompletion({
21316
- ...options.apiKey !== void 0 && { apiKey: options.apiKey },
21317
- ...options.getToken !== void 0 && { getToken: options.getToken },
21318
- ...options.baseUrl !== void 0 && { baseUrl: options.baseUrl },
21319
- taskType: "memory_topic",
21320
- ...options.endpointOverride !== void 0 && {
21321
- endpointOverride: options.endpointOverride
21322
- },
21323
- model: options.model ?? DEFAULT_EXTRACTION_MODEL,
21324
- systemPrompt: SYSTEM_PROMPT6,
21325
- userMessage: `${vocabularyNote}Memories:
21326
- ${listing}
21327
-
21328
- List each memory's named entities.`,
21329
- tag: "memory/topics",
21330
- extra: { max_completion_tokens: MAX_COMPLETION_TOKENS },
21331
- ...options.fetchFn && { fetchFn: options.fetchFn },
21332
- ...options.maxAttempts !== void 0 && { maxAttempts: options.maxAttempts },
21333
- ...options.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
21334
- ...options.totalTimeoutMs !== void 0 && { totalTimeoutMs: options.totalTimeoutMs },
21335
- ...options.backoffMs && { backoffMs: options.backoffMs }
21336
- });
21337
- if (parsed === null) {
21338
- getLogger().warn(
21339
- `[memory/topics] batch of ${batch.length} failed after retries \u2014 will retry next sweep`
21340
- );
21341
- continue;
21342
- }
21343
- const validIds = new Set(batch.map((m) => m.id));
21344
- const byId = parseTopicResponse(parsed, validIds);
21345
- if (byId === null) {
21346
- getLogger().warn(
21347
- `[memory/topics] batch of ${batch.length} returned an unrecognized shape \u2014 will retry next sweep`
21348
- );
21349
- continue;
21350
- }
21351
- for (const m of batch) {
21352
- const entities = byId.get(m.id);
21353
- if (entities === void 0) {
21354
- continue;
21355
- }
21356
- out.set(m.id, redactor ? restoreEntities(entities, redactor) : entities);
21357
- }
21358
- }
21359
- return out;
21360
- }
21361
- function restoreEntities(entities, redactor) {
21362
- return entities.map((e) => ({ kind: e.kind, restored: redactor.restoreForStorage(e.name) })).filter((e) => !e.restored.unresolved).map(
21363
- (e) => e.kind !== void 0 ? { name: e.restored.text, kind: e.kind } : { name: e.restored.text }
21364
- );
21365
- }
21366
- function parseTopicResponse(parsed, validIds) {
21367
- if (typeof parsed !== "object" || parsed === null) return null;
21368
- const list = parsed.memories;
21369
- if (!Array.isArray(list)) return null;
21370
- const out = /* @__PURE__ */ new Map();
21371
- for (const raw of list) {
21372
- if (typeof raw !== "object" || raw === null) continue;
21373
- const obj = raw;
21374
- if (typeof obj.id !== "string") continue;
21375
- const id = obj.id.trim().replace(/:$/, "").replace(/^\[([\s\S]*)\]$/, "$1").trim();
21376
- if (!validIds.has(id) || out.has(id)) continue;
21377
- const entities = Array.isArray(obj.entities) ? parseEntities(obj.entities) : [];
21378
- out.set(id, entities);
21379
- }
21380
- return out;
21381
- }
21382
- var DEGRADED_TOPIC_SKIP = {
21383
- excluded: false,
21384
- "link-declined": false,
21385
- "stamp-declined": false,
21386
- "llm-unanswered": true,
21387
- unreadable: true,
21388
- "not-found": true,
21389
- "link-failed": true
21390
- };
21391
- function isDegradedTopicSkip(reason) {
21392
- return DEGRADED_TOPIC_SKIP[reason] === true;
21393
- }
21394
- async function extractAndLinkEntitiesForMemoriesOp(ctx, memoryIds, options) {
21395
- const entityCtx = ctx.entityCtx;
21396
- if (!entityCtx) {
21397
- throw new Error("extractAndLinkEntitiesForMemoriesOp requires ctx.entityCtx");
21398
- }
21399
- const log = getLogger();
21400
- const extractedAt = options.now ?? Date.now();
21401
- const skippedIds = [];
21402
- const skippedReasons = /* @__PURE__ */ new Map();
21403
- const skip = (id, reason) => {
21404
- if (skippedReasons.has(id)) return;
21405
- skippedIds.push(id);
21406
- skippedReasons.set(id, reason);
21407
- };
21408
- const inputs = [];
21409
- for (const id of new Set(memoryIds)) {
21410
- let record;
21411
- try {
21412
- record = await ctx.vaultMemoryCollection.find(id);
21413
- } catch (err) {
21414
- log.warn("[memory/topics] vault lookup failed for extraction", err);
21415
- skip(id, "not-found");
21416
- continue;
21417
- }
21418
- if (record.isDeleted || ctx.userId !== void 0 && record.userId !== ctx.userId || record.topicsUserManaged) {
21419
- skip(id, "excluded");
21420
- continue;
21421
- }
21422
- try {
21423
- const stored = await vaultMemoryToStored(
21424
- record,
21425
- ctx.walletAddress,
21426
- ctx.signMessage,
21427
- ctx.embeddedWalletSigner
21428
- );
21429
- inputs.push({ id, content: stored.content });
21430
- } catch (err) {
21431
- log.warn("[memory/topics] failed to load memory for extraction", err);
21432
- skip(id, "unreadable");
21433
- }
21434
- }
21435
- const entitiesByMemory = await extractEntitiesForMemories(inputs, options);
21436
- const toStamp = [];
21437
- for (const input of inputs) {
21438
- const entities = entitiesByMemory.get(input.id);
21439
- if (entities === void 0) {
21440
- skip(input.id, "llm-unanswered");
21441
- continue;
21442
- }
21443
- try {
21444
- const linked = await replaceMemoryEntitiesGuardedOp(entityCtx, input.id, entities);
21445
- if (linked === null) {
21446
- skip(input.id, "link-declined");
21447
- entitiesByMemory.delete(input.id);
21448
- continue;
21449
- }
21450
- } catch (err) {
21451
- log.warn("[memory/topics] replaceMemoryEntitiesGuardedOp failed", err);
21452
- skip(input.id, "link-failed");
21453
- entitiesByMemory.delete(input.id);
21454
- continue;
21455
- }
21456
- toStamp.push(input.id);
21457
- }
21458
- const stampedIds = await stampTopicsExtractedAtOp(ctx, toStamp, extractedAt);
21459
- const stampedSet = new Set(stampedIds);
21460
- for (const id of toStamp) {
21461
- if (!stampedSet.has(id)) {
21462
- skip(id, "stamp-declined");
21463
- entitiesByMemory.delete(id);
21464
- }
21465
- }
21466
- return { entitiesByMemory, stampedIds, skippedIds, skippedReasons };
21467
- }
21468
-
21469
21624
  // src/lib/memory/verifySupport.ts
21470
21625
  init_logger();
21471
21626
  init_redactor();
@@ -21859,7 +22014,7 @@ async function assembleMemoryContext(options) {
21859
22014
  }
21860
22015
 
21861
22016
  // src/lib/memory/durableExtraction.ts
21862
- var import_watermelondb13 = require("@nozbe/watermelondb");
22017
+ var import_watermelondb14 = require("@nozbe/watermelondb");
21863
22018
  var MAX_JOBS_PER_PASS = 3;
21864
22019
  var MAX_ATTEMPTS = 3;
21865
22020
  var MAX_FAILED_SESSIONS = 3;
@@ -22006,7 +22161,7 @@ function createDurableAutoExtractor(options) {
22006
22161
  ...options.retainCtx,
22007
22162
  vaultCtx: {
22008
22163
  ...vault,
22009
- canWrite: async () => !disposed && !cancelled && await storage.conversationsCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("id", import_watermelondb13.Q.oneOf(ids))).fetchCount() === ids.length && (!vault.canWrite || await vault.canWrite()) && !disposed && !cancelled
22164
+ canWrite: async () => !disposed && !cancelled && await storage.conversationsCollection.query(import_watermelondb14.Q.where("conversation_id", conversationId), import_watermelondb14.Q.where("is_deleted", false)).fetchCount() > 0 && await storage.messagesCollection.query(import_watermelondb14.Q.where("conversation_id", conversationId), import_watermelondb14.Q.where("id", import_watermelondb14.Q.oneOf(ids))).fetchCount() === ids.length && (!vault.canWrite || await vault.canWrite()) && !disposed && !cancelled
22010
22165
  }
22011
22166
  },
22012
22167
  // The model follows the job's scope, not the mode alive at drain time.
@@ -22148,7 +22303,7 @@ function createDurableAutoExtractor(options) {
22148
22303
  let scheduleAfterSuccess = false;
22149
22304
  try {
22150
22305
  await writes;
22151
- const pending = await jobs.query(import_watermelondb13.Q.where("owner_key", owner), import_watermelondb13.Q.where("message_ids", import_watermelondb13.Q.notEq("[]"))).fetch();
22306
+ const pending = await jobs.query(import_watermelondb14.Q.where("owner_key", owner), import_watermelondb14.Q.where("message_ids", import_watermelondb14.Q.notEq("[]"))).fetch();
22152
22307
  storeFailures = 0;
22153
22308
  let processed = 0;
22154
22309
  for (const job of pending) {
@@ -22164,7 +22319,7 @@ function createDurableAutoExtractor(options) {
22164
22319
  let ids = [];
22165
22320
  let loaded = [];
22166
22321
  try {
22167
- const conversations = await storage.conversationsCollection.query(import_watermelondb13.Q.where("conversation_id", conversationId), import_watermelondb13.Q.where("is_deleted", false)).fetchCount();
22322
+ const conversations = await storage.conversationsCollection.query(import_watermelondb14.Q.where("conversation_id", conversationId), import_watermelondb14.Q.where("is_deleted", false)).fetchCount();
22168
22323
  if (!conversations) {
22169
22324
  await database.write(() => job.destroyPermanently());
22170
22325
  continue;
@@ -22281,12 +22436,12 @@ function createDurableAutoExtractor(options) {
22281
22436
  const scope = currentScope();
22282
22437
  writes = writes.then(
22283
22438
  () => database.write(async () => {
22284
- const existing = await jobs.query(import_watermelondb13.Q.where("owner_key", owner), import_watermelondb13.Q.where("conversation_id", conversationId)).fetch();
22439
+ const existing = await jobs.query(import_watermelondb14.Q.where("owner_key", owner), import_watermelondb14.Q.where("conversation_id", conversationId)).fetch();
22285
22440
  const job = existing.find(
22286
22441
  (candidate) => candidate._getRaw("scope") === scope && (candidate._getRaw("folder_id") ?? null) === folderId
22287
22442
  );
22288
22443
  const positions = new Map(ids.map((id, index) => [id, index]));
22289
- const rows = await storage.messagesCollection.query(import_watermelondb13.Q.where("id", import_watermelondb13.Q.oneOf(ids))).fetch();
22444
+ const rows = await storage.messagesCollection.query(import_watermelondb14.Q.where("id", import_watermelondb14.Q.oneOf(ids))).fetch();
22290
22445
  const sequences = /* @__PURE__ */ new Map();
22291
22446
  for (const row of rows) {
22292
22447
  const sequence = Number(row._getRaw("message_id"));
@@ -26480,13 +26635,13 @@ function useChatStorage(options) {
26480
26635
  }
26481
26636
 
26482
26637
  // src/lib/db/schema.ts
26483
- var import_watermelondb22 = require("@nozbe/watermelondb");
26638
+ var import_watermelondb23 = require("@nozbe/watermelondb");
26484
26639
  var import_migrations2 = require("@nozbe/watermelondb/Schema/migrations");
26485
26640
 
26486
26641
  // src/lib/db/appFiles/models.ts
26487
- var import_watermelondb14 = require("@nozbe/watermelondb");
26642
+ var import_watermelondb15 = require("@nozbe/watermelondb");
26488
26643
  var import_decorators4 = require("@nozbe/watermelondb/decorators");
26489
- var AppFile = class extends import_watermelondb14.Model {
26644
+ var AppFile = class extends import_watermelondb15.Model {
26490
26645
  };
26491
26646
  AppFile.table = "app_files";
26492
26647
  AppFile.associations = {};
@@ -26508,9 +26663,9 @@ __decorateClass([
26508
26663
  ], AppFile.prototype, "updatedAt", 2);
26509
26664
 
26510
26665
  // src/lib/db/conversationMemory/models.ts
26511
- var import_watermelondb15 = require("@nozbe/watermelondb");
26666
+ var import_watermelondb16 = require("@nozbe/watermelondb");
26512
26667
  var import_decorators5 = require("@nozbe/watermelondb/decorators");
26513
- var ConversationMemory = class extends import_watermelondb15.Model {
26668
+ var ConversationMemory = class extends import_watermelondb16.Model {
26514
26669
  };
26515
26670
  ConversationMemory.table = "conversation_memory";
26516
26671
  ConversationMemory.associations = {};
@@ -26529,9 +26684,9 @@ __decorateClass([
26529
26684
  ], ConversationMemory.prototype, "createdAt", 2);
26530
26685
 
26531
26686
  // src/lib/db/entities/models.ts
26532
- var import_watermelondb16 = require("@nozbe/watermelondb");
26687
+ var import_watermelondb17 = require("@nozbe/watermelondb");
26533
26688
  var import_decorators6 = require("@nozbe/watermelondb/decorators");
26534
- var Entity = class extends import_watermelondb16.Model {
26689
+ var Entity = class extends import_watermelondb17.Model {
26535
26690
  };
26536
26691
  Entity.table = "entity";
26537
26692
  __decorateClass([
@@ -26547,7 +26702,7 @@ __decorateClass([
26547
26702
  __decorateClass([
26548
26703
  (0, import_decorators6.date)("updated_at")
26549
26704
  ], Entity.prototype, "updatedAt", 2);
26550
- var MemoryEntity = class extends import_watermelondb16.Model {
26705
+ var MemoryEntity = class extends import_watermelondb17.Model {
26551
26706
  };
26552
26707
  MemoryEntity.table = "memory_entity";
26553
26708
  __decorateClass([
@@ -26565,9 +26720,9 @@ __decorateClass([
26565
26720
  ], MemoryEntity.prototype, "createdAt", 2);
26566
26721
 
26567
26722
  // src/lib/db/project/models.ts
26568
- var import_watermelondb17 = require("@nozbe/watermelondb");
26723
+ var import_watermelondb18 = require("@nozbe/watermelondb");
26569
26724
  var import_decorators7 = require("@nozbe/watermelondb/decorators");
26570
- var Project = class extends import_watermelondb17.Model {
26725
+ var Project = class extends import_watermelondb18.Model {
26571
26726
  };
26572
26727
  Project.table = "projects";
26573
26728
  Project.associations = {
@@ -26590,10 +26745,10 @@ __decorateClass([
26590
26745
  ], Project.prototype, "isDeleted", 2);
26591
26746
 
26592
26747
  // src/lib/db/savedTools/models.ts
26593
- var import_watermelondb18 = require("@nozbe/watermelondb");
26748
+ var import_watermelondb19 = require("@nozbe/watermelondb");
26594
26749
  var import_decorators8 = require("@nozbe/watermelondb/decorators");
26595
26750
  var sanitizeParameters = (raw) => raw ?? {};
26596
- var SavedTool = class extends import_watermelondb18.Model {
26751
+ var SavedTool = class extends import_watermelondb19.Model {
26597
26752
  };
26598
26753
  SavedTool.table = "saved_tools";
26599
26754
  SavedTool.associations = {};
@@ -26627,9 +26782,9 @@ __decorateClass([
26627
26782
  ], SavedTool.prototype, "isDeleted", 2);
26628
26783
 
26629
26784
  // src/lib/db/settings/models.ts
26630
- var import_watermelondb19 = require("@nozbe/watermelondb");
26785
+ var import_watermelondb20 = require("@nozbe/watermelondb");
26631
26786
  var import_decorators9 = require("@nozbe/watermelondb/decorators");
26632
- var ModelPreference = class extends import_watermelondb19.Model {
26787
+ var ModelPreference = class extends import_watermelondb20.Model {
26633
26788
  };
26634
26789
  ModelPreference.table = "modelPreferences";
26635
26790
  __decorateClass([
@@ -26640,9 +26795,9 @@ __decorateClass([
26640
26795
  ], ModelPreference.prototype, "models", 2);
26641
26796
 
26642
26797
  // src/lib/db/userPreferences/models.ts
26643
- var import_watermelondb20 = require("@nozbe/watermelondb");
26798
+ var import_watermelondb21 = require("@nozbe/watermelondb");
26644
26799
  var import_decorators10 = require("@nozbe/watermelondb/decorators");
26645
- var UserPreference = class extends import_watermelondb20.Model {
26800
+ var UserPreference = class extends import_watermelondb21.Model {
26646
26801
  };
26647
26802
  UserPreference.table = "userPreferences";
26648
26803
  __decorateClass([
@@ -26671,9 +26826,9 @@ __decorateClass([
26671
26826
  ], UserPreference.prototype, "updatedAt", 2);
26672
26827
 
26673
26828
  // src/lib/db/vaultFolders/models.ts
26674
- var import_watermelondb21 = require("@nozbe/watermelondb");
26829
+ var import_watermelondb22 = require("@nozbe/watermelondb");
26675
26830
  var import_decorators11 = require("@nozbe/watermelondb/decorators");
26676
- var VaultFolder = class extends import_watermelondb21.Model {
26831
+ var VaultFolder = class extends import_watermelondb22.Model {
26677
26832
  };
26678
26833
  VaultFolder.table = "vault_folders";
26679
26834
  __decorateClass([
@@ -26701,10 +26856,10 @@ __decorateClass([
26701
26856
 
26702
26857
  // src/lib/db/schema.ts
26703
26858
  var SDK_SCHEMA_VERSION = 47;
26704
- var sdkSchema = (0, import_watermelondb22.appSchema)({
26859
+ var sdkSchema = (0, import_watermelondb23.appSchema)({
26705
26860
  version: SDK_SCHEMA_VERSION,
26706
26861
  tables: [
26707
- (0, import_watermelondb22.tableSchema)({
26862
+ (0, import_watermelondb23.tableSchema)({
26708
26863
  name: "memory_extraction_jobs",
26709
26864
  columns: [
26710
26865
  { name: "owner_key", type: "string", isIndexed: true },
@@ -26724,7 +26879,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26724
26879
  ]
26725
26880
  }),
26726
26881
  // Chat storage tables
26727
- (0, import_watermelondb22.tableSchema)({
26882
+ (0, import_watermelondb23.tableSchema)({
26728
26883
  name: "history",
26729
26884
  columns: [
26730
26885
  { name: "message_id", type: "number" },
@@ -26763,7 +26918,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26763
26918
  // MessageOrigin — provenance, NOT encrypted (see v44)
26764
26919
  ]
26765
26920
  }),
26766
- (0, import_watermelondb22.tableSchema)({
26921
+ (0, import_watermelondb23.tableSchema)({
26767
26922
  name: "conversations",
26768
26923
  columns: [
26769
26924
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -26785,7 +26940,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26785
26940
  ]
26786
26941
  }),
26787
26942
  // Project storage table
26788
- (0, import_watermelondb22.tableSchema)({
26943
+ (0, import_watermelondb23.tableSchema)({
26789
26944
  name: "projects",
26790
26945
  columns: [
26791
26946
  { name: "project_id", type: "string", isIndexed: true },
@@ -26796,7 +26951,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26796
26951
  ]
26797
26952
  }),
26798
26953
  // Settings storage tables (deprecated - use userPreferences)
26799
- (0, import_watermelondb22.tableSchema)({
26954
+ (0, import_watermelondb23.tableSchema)({
26800
26955
  name: "modelPreferences",
26801
26956
  columns: [
26802
26957
  { name: "wallet_address", type: "string", isIndexed: true },
@@ -26804,7 +26959,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26804
26959
  ]
26805
26960
  }),
26806
26961
  // Unified user preferences storage
26807
- (0, import_watermelondb22.tableSchema)({
26962
+ (0, import_watermelondb23.tableSchema)({
26808
26963
  name: "userPreferences",
26809
26964
  columns: [
26810
26965
  // Identity
@@ -26823,7 +26978,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26823
26978
  ]
26824
26979
  }),
26825
26980
  // Memory vault storage
26826
- (0, import_watermelondb22.tableSchema)({
26981
+ (0, import_watermelondb23.tableSchema)({
26827
26982
  name: "memory_vault",
26828
26983
  columns: [
26829
26984
  { name: "content", type: "string" },
@@ -26951,7 +27106,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26951
27106
  ]
26952
27107
  }),
26953
27108
  // Entity table — canonical names extracted from auto-extraction (W5).
26954
- (0, import_watermelondb22.tableSchema)({
27109
+ (0, import_watermelondb23.tableSchema)({
26955
27110
  name: "entity",
26956
27111
  columns: [
26957
27112
  { name: "canonical_name", type: "string", isIndexed: true },
@@ -26961,7 +27116,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26961
27116
  ]
26962
27117
  }),
26963
27118
  // Many-to-many join: which memories reference which entities.
26964
- (0, import_watermelondb22.tableSchema)({
27119
+ (0, import_watermelondb23.tableSchema)({
26965
27120
  name: "memory_entity",
26966
27121
  columns: [
26967
27122
  { name: "memory_id", type: "string", isIndexed: true },
@@ -26971,7 +27126,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26971
27126
  ]
26972
27127
  }),
26973
27128
  // Vault folder organization
26974
- (0, import_watermelondb22.tableSchema)({
27129
+ (0, import_watermelondb23.tableSchema)({
26975
27130
  name: "vault_folders",
26976
27131
  columns: [
26977
27132
  { name: "name", type: "string" },
@@ -26984,7 +27139,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26984
27139
  ]
26985
27140
  }),
26986
27141
  // Conversation summary cache for progressive history summarization
26987
- (0, import_watermelondb22.tableSchema)({
27142
+ (0, import_watermelondb23.tableSchema)({
26988
27143
  name: "conversation_summaries",
26989
27144
  columns: [
26990
27145
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -26997,7 +27152,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
26997
27152
  ]
26998
27153
  }),
26999
27154
  // Media library storage (images, videos, audio, documents)
27000
- (0, import_watermelondb22.tableSchema)({
27155
+ (0, import_watermelondb23.tableSchema)({
27001
27156
  name: "media",
27002
27157
  columns: [
27003
27158
  // Identity
@@ -27033,7 +27188,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
27033
27188
  ]
27034
27189
  }),
27035
27190
  // ── App files ─────────────────────────────────────────────────────────
27036
- (0, import_watermelondb22.tableSchema)({
27191
+ (0, import_watermelondb23.tableSchema)({
27037
27192
  name: "app_files",
27038
27193
  columns: [
27039
27194
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -27044,7 +27199,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
27044
27199
  ]
27045
27200
  }),
27046
27201
  // ── Saved tools ──────────────────────────────────────────────────────
27047
- (0, import_watermelondb22.tableSchema)({
27202
+ (0, import_watermelondb23.tableSchema)({
27048
27203
  name: "saved_tools",
27049
27204
  columns: [
27050
27205
  { name: "name", type: "string" },
@@ -27060,7 +27215,7 @@ var sdkSchema = (0, import_watermelondb22.appSchema)({
27060
27215
  ]
27061
27216
  }),
27062
27217
  // ── Conversation memories (panel persistence) ────────────────────────
27063
- (0, import_watermelondb22.tableSchema)({
27218
+ (0, import_watermelondb23.tableSchema)({
27064
27219
  name: "conversation_memory",
27065
27220
  columns: [
27066
27221
  { name: "conversation_id", type: "string", isIndexed: true },
@@ -27782,7 +27937,7 @@ var sdkModelClasses = [
27782
27937
  ];
27783
27938
 
27784
27939
  // src/lib/db/manager.ts
27785
- var import_watermelondb23 = require("@nozbe/watermelondb");
27940
+ var import_watermelondb24 = require("@nozbe/watermelondb");
27786
27941
  var DESTRUCTIVE_MIGRATION_VERSION = 8;
27787
27942
  var webPlatformStorage = {
27788
27943
  getItem: (key) => localStorage.getItem(key),
@@ -27863,7 +28018,7 @@ var DatabaseManager = class {
27863
28018
  walletAddress
27864
28019
  });
27865
28020
  const adapter = this.createAdapter(dbName, sdkSchema, sdkMigrations);
27866
- const database = new import_watermelondb23.Database({
28021
+ const database = new import_watermelondb24.Database({
27867
28022
  adapter,
27868
28023
  modelClasses: sdkModelClasses
27869
28024
  });
@@ -27948,7 +28103,7 @@ function useDatabaseManager(walletAddress, manager) {
27948
28103
  }
27949
28104
 
27950
28105
  // src/lib/db/project/operations.ts
27951
- var import_watermelondb24 = require("@nozbe/watermelondb");
28106
+ var import_watermelondb25 = require("@nozbe/watermelondb");
27952
28107
 
27953
28108
  // src/lib/db/project/types.ts
27954
28109
  function generateProjectId() {
@@ -27979,15 +28134,15 @@ async function createProjectOp(ctx, opts, defaultName = "New Project") {
27979
28134
  return projectToStored(created);
27980
28135
  }
27981
28136
  async function getProjectOp(ctx, id) {
27982
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
28137
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
27983
28138
  return results.length > 0 ? projectToStored(results[0]) : null;
27984
28139
  }
27985
28140
  async function getProjectsOp(ctx) {
27986
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("is_deleted", false), import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)).fetch();
28141
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("is_deleted", false), import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)).fetch();
27987
28142
  return results.map(projectToStored);
27988
28143
  }
27989
28144
  async function updateProjectNameOp(ctx, id, name) {
27990
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
28145
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
27991
28146
  if (results.length > 0) {
27992
28147
  await ctx.database.write(async () => {
27993
28148
  await results[0].update((proj) => {
@@ -27999,7 +28154,7 @@ async function updateProjectNameOp(ctx, id, name) {
27999
28154
  return false;
28000
28155
  }
28001
28156
  async function updateProjectOp(ctx, id, opts) {
28002
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
28157
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
28003
28158
  if (results.length > 0) {
28004
28159
  await ctx.database.write(async () => {
28005
28160
  await results[0].update((proj) => {
@@ -28011,7 +28166,7 @@ async function updateProjectOp(ctx, id, opts) {
28011
28166
  return false;
28012
28167
  }
28013
28168
  async function deleteProjectOp(ctx, id) {
28014
- const results = await ctx.projectsCollection.query(import_watermelondb24.Q.where("project_id", id), import_watermelondb24.Q.where("is_deleted", false)).fetch();
28169
+ const results = await ctx.projectsCollection.query(import_watermelondb25.Q.where("project_id", id), import_watermelondb25.Q.where("is_deleted", false)).fetch();
28015
28170
  if (results.length > 0) {
28016
28171
  await ctx.database.write(async () => {
28017
28172
  await results[0].update((proj) => {
@@ -28024,18 +28179,18 @@ async function deleteProjectOp(ctx, id) {
28024
28179
  }
28025
28180
  async function getProjectConversationsOp(ctx, projectId) {
28026
28181
  const results = await ctx.conversationsCollection.query(
28027
- import_watermelondb24.Q.where("project_id", projectId),
28028
- import_watermelondb24.Q.where("is_deleted", false),
28029
- import_watermelondb24.Q.sortBy("created_at", import_watermelondb24.Q.desc)
28182
+ import_watermelondb25.Q.where("project_id", projectId),
28183
+ import_watermelondb25.Q.where("is_deleted", false),
28184
+ import_watermelondb25.Q.sortBy("created_at", import_watermelondb25.Q.desc)
28030
28185
  ).fetch();
28031
28186
  return results.map(conversationToStoredRaw);
28032
28187
  }
28033
28188
  async function getProjectConversationCountOp(ctx, projectId) {
28034
- return await ctx.conversationsCollection.query(import_watermelondb24.Q.where("project_id", projectId), import_watermelondb24.Q.where("is_deleted", false)).fetchCount();
28189
+ return await ctx.conversationsCollection.query(import_watermelondb25.Q.where("project_id", projectId), import_watermelondb25.Q.where("is_deleted", false)).fetchCount();
28035
28190
  }
28036
28191
 
28037
28192
  // src/react/useFiles.ts
28038
- var import_watermelondb25 = require("@nozbe/watermelondb");
28193
+ var import_watermelondb26 = require("@nozbe/watermelondb");
28039
28194
  var import_react7 = require("react");
28040
28195
  init_logger();
28041
28196
  function useFiles(options) {
@@ -28054,7 +28209,7 @@ function useFiles(options) {
28054
28209
  setIsLoading(true);
28055
28210
  try {
28056
28211
  const coll = database.get("media");
28057
- await coll.query(import_watermelondb25.Q.take(1)).fetch();
28212
+ await coll.query(import_watermelondb26.Q.take(1)).fetch();
28058
28213
  setMediaCollection(coll);
28059
28214
  setIsReady(true);
28060
28215
  } catch (error) {
@@ -28462,7 +28617,7 @@ function useFiles(options) {
28462
28617
  }
28463
28618
 
28464
28619
  // src/react/useProjects.ts
28465
- var import_watermelondb26 = require("@nozbe/watermelondb");
28620
+ var import_watermelondb27 = require("@nozbe/watermelondb");
28466
28621
  var import_react8 = require("react");
28467
28622
  init_logger();
28468
28623
  function useProjects(options) {
@@ -28485,7 +28640,7 @@ function useProjects(options) {
28485
28640
  conversations: convColl?.table
28486
28641
  });
28487
28642
  getLogger().debug("[useProjects] Running test query on projects table...");
28488
- const testResult = await projColl.query(import_watermelondb26.Q.take(1)).fetch();
28643
+ const testResult = await projColl.query(import_watermelondb27.Q.take(1)).fetch();
28489
28644
  getLogger().debug(
28490
28645
  "[useProjects] Test query succeeded, found",
28491
28646
  testResult.length,
@@ -28572,7 +28727,7 @@ function useProjects(options) {
28572
28727
  if (!projectsCollection) {
28573
28728
  return;
28574
28729
  }
28575
- const subscription = projectsCollection.query(import_watermelondb26.Q.where("is_deleted", false)).observe().subscribe((records) => {
28730
+ const subscription = projectsCollection.query(import_watermelondb27.Q.where("is_deleted", false)).observe().subscribe((records) => {
28576
28731
  setProjects(records.map(projectToStored));
28577
28732
  });
28578
28733
  return () => subscription.unsubscribe();
@@ -28695,7 +28850,7 @@ function useProjects(options) {
28695
28850
  }
28696
28851
 
28697
28852
  // src/lib/db/settings/operations.ts
28698
- var import_watermelondb27 = require("@nozbe/watermelondb");
28853
+ var import_watermelondb28 = require("@nozbe/watermelondb");
28699
28854
  function modelPreferenceToStored(preference) {
28700
28855
  return {
28701
28856
  uniqueId: preference.id,
@@ -28704,12 +28859,12 @@ function modelPreferenceToStored(preference) {
28704
28859
  };
28705
28860
  }
28706
28861
  async function getModelPreferenceOp(ctx, walletAddress) {
28707
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
28862
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
28708
28863
  return results.length > 0 ? modelPreferenceToStored(results[0]) : null;
28709
28864
  }
28710
28865
  async function setModelPreferenceOp(ctx, walletAddress, models) {
28711
28866
  const result = await ctx.database.write(async () => {
28712
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
28867
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
28713
28868
  if (results.length > 0) {
28714
28869
  const preference = results[0];
28715
28870
  await preference.update((pref) => {
@@ -28727,7 +28882,7 @@ async function setModelPreferenceOp(ctx, walletAddress, models) {
28727
28882
  return modelPreferenceToStored(result);
28728
28883
  }
28729
28884
  async function deleteModelPreferenceOp(ctx, walletAddress) {
28730
- const results = await ctx.modelPreferencesCollection.query(import_watermelondb27.Q.where("wallet_address", walletAddress)).fetch();
28885
+ const results = await ctx.modelPreferencesCollection.query(import_watermelondb28.Q.where("wallet_address", walletAddress)).fetch();
28731
28886
  if (results.length === 0) return false;
28732
28887
  await ctx.database.write(async () => {
28733
28888
  await results[0].destroyPermanently();
@@ -28736,11 +28891,11 @@ async function deleteModelPreferenceOp(ctx, walletAddress) {
28736
28891
  }
28737
28892
 
28738
28893
  // src/lib/db/settings/schema.ts
28739
- var import_watermelondb28 = require("@nozbe/watermelondb");
28740
- var settingsStorageSchema = (0, import_watermelondb28.appSchema)({
28894
+ var import_watermelondb29 = require("@nozbe/watermelondb");
28895
+ var settingsStorageSchema = (0, import_watermelondb29.appSchema)({
28741
28896
  version: 1,
28742
28897
  tables: [
28743
- (0, import_watermelondb28.tableSchema)({
28898
+ (0, import_watermelondb29.tableSchema)({
28744
28899
  name: "modelPreferences",
28745
28900
  columns: [
28746
28901
  { name: "wallet_address", type: "string", isIndexed: true },
@@ -28751,7 +28906,7 @@ var settingsStorageSchema = (0, import_watermelondb28.appSchema)({
28751
28906
  });
28752
28907
 
28753
28908
  // src/lib/db/vaultFolders/operations.ts
28754
- var import_watermelondb29 = require("@nozbe/watermelondb");
28909
+ var import_watermelondb30 = require("@nozbe/watermelondb");
28755
28910
  function folderToStored(folder) {
28756
28911
  return {
28757
28912
  uniqueId: folder.id,
@@ -28776,7 +28931,7 @@ async function createVaultFolderOp(ctx, opts) {
28776
28931
  return folderToStored(created);
28777
28932
  }
28778
28933
  async function getAllVaultFoldersOp(ctx) {
28779
- const results = await ctx.vaultFolderCollection.query(import_watermelondb29.Q.where("is_deleted", false), import_watermelondb29.Q.sortBy("created_at", import_watermelondb29.Q.desc)).fetch();
28934
+ const results = await ctx.vaultFolderCollection.query(import_watermelondb30.Q.where("is_deleted", false), import_watermelondb30.Q.sortBy("created_at", import_watermelondb30.Q.desc)).fetch();
28780
28935
  return results.map(folderToStored);
28781
28936
  }
28782
28937
  async function updateVaultFolderOp(ctx, id, opts) {
@@ -28785,7 +28940,7 @@ async function updateVaultFolderOp(ctx, id, opts) {
28785
28940
  if (record.isDeleted) return null;
28786
28941
  const scopeChanged = opts.scope !== void 0 && opts.scope !== record.scope;
28787
28942
  const updated = await ctx.database.write(async () => {
28788
- const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", id), import_watermelondb29.Q.where("is_deleted", false)).fetch() : [];
28943
+ const memories = scopeChanged ? await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", id), import_watermelondb30.Q.where("is_deleted", false)).fetch() : [];
28789
28944
  const updates = [];
28790
28945
  updates.push(
28791
28946
  record.prepareUpdate((r) => {
@@ -28813,7 +28968,7 @@ async function deleteVaultFolderOp(ctx, id) {
28813
28968
  const record = await ctx.vaultFolderCollection.find(id);
28814
28969
  if (record.isDeleted) return false;
28815
28970
  await ctx.database.write(async () => {
28816
- const memories = await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", id), import_watermelondb29.Q.where("is_deleted", false)).fetch();
28971
+ const memories = await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", id), import_watermelondb30.Q.where("is_deleted", false)).fetch();
28817
28972
  const preparedMemories = memories.map(
28818
28973
  (memory) => memory.prepareUpdate((r) => {
28819
28974
  r._setRaw("folder_id", null);
@@ -28882,7 +29037,7 @@ async function updateVaultFolderContextOp(ctx, id, context) {
28882
29037
  }
28883
29038
  }
28884
29039
  async function getVaultFolderMemoryCountOp(ctx, folderId) {
28885
- return await ctx.vaultMemoryCollection.query(import_watermelondb29.Q.where("folder_id", folderId), import_watermelondb29.Q.where("is_deleted", false)).fetchCount();
29040
+ return await ctx.vaultMemoryCollection.query(import_watermelondb30.Q.where("folder_id", folderId), import_watermelondb30.Q.where("is_deleted", false)).fetchCount();
28886
29041
  }
28887
29042
 
28888
29043
  // src/lib/db/vaultFolders/defaults.ts
@@ -28928,7 +29083,7 @@ async function _ensureDefaultFoldersImpl(ctx) {
28928
29083
  var import_react9 = require("react");
28929
29084
 
28930
29085
  // src/lib/db/userPreferences/operations.ts
28931
- var import_watermelondb30 = require("@nozbe/watermelondb");
29086
+ var import_watermelondb31 = require("@nozbe/watermelondb");
28932
29087
  function userPreferenceToStored(preference) {
28933
29088
  return {
28934
29089
  uniqueId: preference.id,
@@ -28943,7 +29098,7 @@ function userPreferenceToStored(preference) {
28943
29098
  };
28944
29099
  }
28945
29100
  async function getUserPreferenceOp(ctx, walletAddress) {
28946
- const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
29101
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", walletAddress)).fetch();
28947
29102
  return results.length > 0 ? userPreferenceToStored(results[0]) : null;
28948
29103
  }
28949
29104
  async function createUserPreferenceOp(ctx, opts) {
@@ -28963,7 +29118,7 @@ async function createUserPreferenceOp(ctx, opts) {
28963
29118
  return userPreferenceToStored(created);
28964
29119
  }
28965
29120
  async function updateUserPreferenceOp(ctx, walletAddress, opts) {
28966
- const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
29121
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", walletAddress)).fetch();
28967
29122
  if (results.length === 0) return null;
28968
29123
  const preference = results[0];
28969
29124
  await ctx.database.write(async () => {
@@ -28991,7 +29146,7 @@ async function updateUserPreferenceOp(ctx, walletAddress, opts) {
28991
29146
  async function setUserPreferenceOp(ctx, walletAddress, opts) {
28992
29147
  const now = Date.now();
28993
29148
  const result = await ctx.database.write(async () => {
28994
- const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
29149
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", walletAddress)).fetch();
28995
29150
  if (results.length > 0) {
28996
29151
  const preference = results[0];
28997
29152
  await preference.update((pref) => {
@@ -29039,7 +29194,7 @@ async function updateModelsOp(ctx, walletAddress, models) {
29039
29194
  return updateUserPreferenceOp(ctx, walletAddress, { models });
29040
29195
  }
29041
29196
  async function deleteUserPreferenceOp(ctx, walletAddress) {
29042
- const results = await ctx.userPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
29197
+ const results = await ctx.userPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", walletAddress)).fetch();
29043
29198
  if (results.length === 0) return false;
29044
29199
  await ctx.database.write(async () => {
29045
29200
  await results[0].destroyPermanently();
@@ -29054,9 +29209,9 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
29054
29209
  if (existing) {
29055
29210
  return existing;
29056
29211
  }
29057
- const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", walletAddress)).fetch();
29212
+ const modelResults = await ctx.modelPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", walletAddress)).fetch();
29058
29213
  const personalityKey = `${walletAddress}_personality_settings`;
29059
- const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb30.Q.where("wallet_address", personalityKey)).fetch();
29214
+ const personalityResults = await ctx.modelPreferencesCollection.query(import_watermelondb31.Q.where("wallet_address", personalityKey)).fetch();
29060
29215
  if (modelResults.length === 0 && personalityResults.length === 0) {
29061
29216
  return null;
29062
29217
  }
@@ -29098,11 +29253,11 @@ async function migrateFromModelPreferencesOp(ctx, walletAddress) {
29098
29253
  }
29099
29254
 
29100
29255
  // src/lib/db/userPreferences/schema.ts
29101
- var import_watermelondb31 = require("@nozbe/watermelondb");
29102
- var userPreferencesStorageSchema = (0, import_watermelondb31.appSchema)({
29256
+ var import_watermelondb32 = require("@nozbe/watermelondb");
29257
+ var userPreferencesStorageSchema = (0, import_watermelondb32.appSchema)({
29103
29258
  version: 1,
29104
29259
  tables: [
29105
- (0, import_watermelondb31.tableSchema)({
29260
+ (0, import_watermelondb32.tableSchema)({
29106
29261
  name: "userPreferences",
29107
29262
  columns: [
29108
29263
  // Identity
@@ -29162,7 +29317,7 @@ var SLIDER_CONFIG = [
29162
29317
  ];
29163
29318
 
29164
29319
  // src/react/userSettingsStore.ts
29165
- var import_watermelondb32 = require("@nozbe/watermelondb");
29320
+ var import_watermelondb33 = require("@nozbe/watermelondb");
29166
29321
  var EMPTY_SNAPSHOT = Object.freeze({
29167
29322
  modelPreference: null,
29168
29323
  userPreference: null,
@@ -29224,7 +29379,7 @@ async function startLoad(entry, walletAddress) {
29224
29379
  }
29225
29380
  function startObserve(entry, walletAddress) {
29226
29381
  let isInitialEmission = true;
29227
- entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb32.Q.where("wallet_address", walletAddress)).observeWithColumns([
29382
+ entry.observeSub = entry.storageCtx.userPreferencesCollection.query(import_watermelondb33.Q.where("wallet_address", walletAddress)).observeWithColumns([
29228
29383
  "nickname",
29229
29384
  "occupation",
29230
29385
  "description",
@@ -29488,7 +29643,7 @@ function useSettings(options) {
29488
29643
  }
29489
29644
 
29490
29645
  // src/lib/db/appFiles/operations.ts
29491
- var import_watermelondb33 = require("@nozbe/watermelondb");
29646
+ var import_watermelondb34 = require("@nozbe/watermelondb");
29492
29647
 
29493
29648
  // src/utils/paths.ts
29494
29649
  function normalizePath(p) {
@@ -29514,7 +29669,7 @@ async function putAppFileOp(ctx, conversationId, path, content) {
29514
29669
  const normalized = normalizePath(path);
29515
29670
  const now = Date.now();
29516
29671
  const result = await ctx.database.write(async () => {
29517
- const existing = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
29672
+ const existing = await ctx.appFilesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("path", normalized)).fetch();
29518
29673
  if (existing.length > 0) {
29519
29674
  await existing[0].update((f) => {
29520
29675
  f._setRaw("content", content);
@@ -29534,11 +29689,11 @@ async function putAppFileOp(ctx, conversationId, path, content) {
29534
29689
  }
29535
29690
  async function getAppFileOp(ctx, conversationId, path) {
29536
29691
  const normalized = normalizePath(path);
29537
- const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
29692
+ const results = await ctx.appFilesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("path", normalized)).fetch();
29538
29693
  return results.length > 0 ? appFileToStored(results[0]) : null;
29539
29694
  }
29540
29695
  async function getAppFilesOp(ctx, conversationId) {
29541
- const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId)).fetch();
29696
+ const results = await ctx.appFilesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
29542
29697
  return results.map(appFileToStored);
29543
29698
  }
29544
29699
  async function getAppFileMapOp(ctx, conversationId) {
@@ -29549,7 +29704,7 @@ async function getAppFileMapOp(ctx, conversationId) {
29549
29704
  }
29550
29705
  async function deleteAppFileOp(ctx, conversationId, path) {
29551
29706
  const normalized = normalizePath(path);
29552
- const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId), import_watermelondb33.Q.where("path", normalized)).fetch();
29707
+ const results = await ctx.appFilesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.where("path", normalized)).fetch();
29553
29708
  if (results.length === 0) return false;
29554
29709
  await ctx.database.write(async () => {
29555
29710
  await results[0].destroyPermanently();
@@ -29557,7 +29712,7 @@ async function deleteAppFileOp(ctx, conversationId, path) {
29557
29712
  return true;
29558
29713
  }
29559
29714
  async function deleteAllAppFilesOp(ctx, conversationId) {
29560
- const results = await ctx.appFilesCollection.query(import_watermelondb33.Q.where("conversation_id", conversationId)).fetch();
29715
+ const results = await ctx.appFilesCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
29561
29716
  if (results.length === 0) return;
29562
29717
  await ctx.database.write(async () => {
29563
29718
  const batch = results.map((file) => file.prepareDestroyPermanently());
@@ -29566,7 +29721,7 @@ async function deleteAllAppFilesOp(ctx, conversationId) {
29566
29721
  }
29567
29722
 
29568
29723
  // src/lib/db/conversationMemory/operations.ts
29569
- var import_watermelondb34 = require("@nozbe/watermelondb");
29724
+ var import_watermelondb35 = require("@nozbe/watermelondb");
29570
29725
  var MAX_PER_CONVERSATION = 200;
29571
29726
  function conversationMemoryToStored(row) {
29572
29727
  return {
@@ -29581,7 +29736,7 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
29581
29736
  if (!conversationId || items.length === 0) return;
29582
29737
  const now = Date.now();
29583
29738
  await ctx.database.write(async () => {
29584
- const existing = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.sortBy("created_at", import_watermelondb34.Q.asc)).fetch();
29739
+ const existing = await ctx.conversationMemoryCollection.query(import_watermelondb35.Q.where("conversation_id", conversationId), import_watermelondb35.Q.sortBy("created_at", import_watermelondb35.Q.asc)).fetch();
29585
29740
  const seen = new Set(existing.map((r) => r.memoryId));
29586
29741
  const batchSeen = /* @__PURE__ */ new Set();
29587
29742
  const deduped = [];
@@ -29616,20 +29771,20 @@ async function addConversationMemoriesOp(ctx, conversationId, items) {
29616
29771
  }
29617
29772
  async function getConversationMemoriesOp(ctx, conversationId) {
29618
29773
  if (!conversationId) return [];
29619
- const rows = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId), import_watermelondb34.Q.sortBy("created_at", import_watermelondb34.Q.asc)).fetch();
29774
+ const rows = await ctx.conversationMemoryCollection.query(import_watermelondb35.Q.where("conversation_id", conversationId), import_watermelondb35.Q.sortBy("created_at", import_watermelondb35.Q.asc)).fetch();
29620
29775
  return rows.map(conversationMemoryToStored);
29621
29776
  }
29622
29777
  async function clearConversationMemoriesOp(ctx, conversationId) {
29623
29778
  if (!conversationId) return;
29624
29779
  await ctx.database.write(async () => {
29625
- const rows = await ctx.conversationMemoryCollection.query(import_watermelondb34.Q.where("conversation_id", conversationId)).fetch();
29780
+ const rows = await ctx.conversationMemoryCollection.query(import_watermelondb35.Q.where("conversation_id", conversationId)).fetch();
29626
29781
  if (rows.length === 0) return;
29627
29782
  await ctx.database.batch(...rows.map((r) => r.prepareDestroyPermanently()));
29628
29783
  });
29629
29784
  }
29630
29785
 
29631
29786
  // src/lib/db/savedTools/operations.ts
29632
- var import_watermelondb35 = require("@nozbe/watermelondb");
29787
+ var import_watermelondb36 = require("@nozbe/watermelondb");
29633
29788
  function savedToolToStored(tool) {
29634
29789
  return {
29635
29790
  uniqueId: tool.id,
@@ -29662,7 +29817,7 @@ async function createSavedToolOp(ctx, opts) {
29662
29817
  return savedToolToStored(created);
29663
29818
  }
29664
29819
  async function getAllSavedToolsOp(ctx) {
29665
- const results = await ctx.savedToolsCollection.query(import_watermelondb35.Q.where("is_deleted", false), import_watermelondb35.Q.sortBy("created_at", import_watermelondb35.Q.desc)).fetch();
29820
+ const results = await ctx.savedToolsCollection.query(import_watermelondb36.Q.where("is_deleted", false), import_watermelondb36.Q.sortBy("created_at", import_watermelondb36.Q.desc)).fetch();
29666
29821
  return results.map(savedToolToStored);
29667
29822
  }
29668
29823
  async function getSavedToolByIdOp(ctx, uniqueId) {
@@ -32323,8 +32478,8 @@ function createDropboxFileIndex(backupFolder) {
32323
32478
  };
32324
32479
  }
32325
32480
  async function readLocalUpdatedAt(database, conversationId) {
32326
- const { Q: Q19 } = await import("@nozbe/watermelondb");
32327
- const records = await database.get("conversations").query(Q19.where("conversation_id", conversationId)).fetch();
32481
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
32482
+ const records = await database.get("conversations").query(Q20.where("conversation_id", conversationId)).fetch();
32328
32483
  const match = records.map(conversationToStoredRaw).find((c) => c.conversationId === conversationId);
32329
32484
  return match ? match.updatedAt : null;
32330
32485
  }
@@ -32380,9 +32535,9 @@ async function pushConversationToDropbox(database, conversationId, userAddress,
32380
32535
  }
32381
32536
  async function performDropboxExport(database, userAddress, token, deps, onProgress, backupFolder = DEFAULT_BACKUP_FOLDER) {
32382
32537
  await deps.requestEncryptionKey(userAddress);
32383
- const { Q: Q19 } = await import("@nozbe/watermelondb");
32538
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
32384
32539
  const conversationsCollection = database.get("conversations");
32385
- const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
32540
+ const records = await conversationsCollection.query(Q20.where("is_deleted", false)).fetch();
32386
32541
  const conversations = records.map(conversationToStoredRaw);
32387
32542
  const total = conversations.length;
32388
32543
  if (total === 0) {
@@ -33059,8 +33214,8 @@ function createDriveFileIndex(folderId) {
33059
33214
  };
33060
33215
  }
33061
33216
  async function readLocalUpdatedAt2(database, conversationId) {
33062
- const { Q: Q19 } = await import("@nozbe/watermelondb");
33063
- const records = await database.get("conversations").query(Q19.where("conversation_id", conversationId)).fetch();
33217
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
33218
+ const records = await database.get("conversations").query(Q20.where("conversation_id", conversationId)).fetch();
33064
33219
  const match = records.map(conversationToStoredRaw).find((c) => c.conversationId === conversationId);
33065
33220
  return match ? match.updatedAt : null;
33066
33221
  }
@@ -33140,9 +33295,9 @@ async function performGoogleDriveExport(database, userAddress, token, deps, onPr
33140
33295
  }
33141
33296
  const { folderId, token: activeToken } = folderResult;
33142
33297
  const fileIndex = createDriveFileIndex(folderId);
33143
- const { Q: Q19 } = await import("@nozbe/watermelondb");
33298
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
33144
33299
  const conversationsCollection = database.get("conversations");
33145
- const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
33300
+ const records = await conversationsCollection.query(Q20.where("is_deleted", false)).fetch();
33146
33301
  const conversations = records.map(conversationToStoredRaw);
33147
33302
  const total = conversations.length;
33148
33303
  if (total === 0) {
@@ -33722,9 +33877,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
33722
33877
  const filename = `${conversationId}.json`;
33723
33878
  const existingFile = await findICloudFile(filename);
33724
33879
  if (existingFile) {
33725
- const { Q: Q19 } = await import("@nozbe/watermelondb");
33880
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
33726
33881
  const conversationsCollection = database.get("conversations");
33727
- const records = await conversationsCollection.query(Q19.where("conversation_id", conversationId)).fetch();
33882
+ const records = await conversationsCollection.query(Q20.where("conversation_id", conversationId)).fetch();
33728
33883
  if (records.length > 0) {
33729
33884
  const conversation = conversationToStoredRaw(records[0]);
33730
33885
  const localUpdated = conversation.updatedAt.getTime();
@@ -33754,9 +33909,9 @@ async function pushConversationToICloud(database, conversationId, userAddress, d
33754
33909
  }
33755
33910
  async function performICloudExport(database, userAddress, deps, onProgress) {
33756
33911
  await deps.requestEncryptionKey(userAddress);
33757
- const { Q: Q19 } = await import("@nozbe/watermelondb");
33912
+ const { Q: Q20 } = await import("@nozbe/watermelondb");
33758
33913
  const conversationsCollection = database.get("conversations");
33759
- const records = await conversationsCollection.query(Q19.where("is_deleted", false)).fetch();
33914
+ const records = await conversationsCollection.query(Q20.where("is_deleted", false)).fetch();
33760
33915
  const conversations = records.map(conversationToStoredRaw);
33761
33916
  const total = conversations.length;
33762
33917
  if (total === 0) {
@@ -37731,6 +37886,7 @@ function renderAnumaJsx(jsx3) {
37731
37886
  createGitHubTools,
37732
37887
  createLlmDecayClassifier,
37733
37888
  createLlmNeighborRefiner,
37889
+ createLocalMemoryStore,
37734
37890
  createMediaBatchOp,
37735
37891
  createMediaOp,
37736
37892
  createMemoryEngineTool,