@anuma/sdk 2.7.0 → 3.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.
@@ -1041,6 +1041,67 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
1041
1041
  }
1042
1042
  return baseMessage;
1043
1043
  }
1044
+ function rawDate(value) {
1045
+ return new Date(typeof value === "number" ? value : 0);
1046
+ }
1047
+ function messageRawToStoredRaw(raw, projection) {
1048
+ const parseJsonField = (rawValue) => {
1049
+ if (!rawValue) return void 0;
1050
+ if (typeof rawValue === "string") {
1051
+ if (rawValue.startsWith("enc:")) return rawValue;
1052
+ try {
1053
+ return JSON.parse(rawValue);
1054
+ } catch {
1055
+ return void 0;
1056
+ }
1057
+ }
1058
+ return rawValue;
1059
+ };
1060
+ const skipEmbeddings = projection?.skipEmbeddings === true;
1061
+ const vectorRaw = skipEmbeddings ? null : raw.vector;
1062
+ const chunksRaw = skipEmbeddings ? null : raw.chunks;
1063
+ return {
1064
+ uniqueId: raw.id,
1065
+ messageId: raw.message_id,
1066
+ conversationId: raw.conversation_id ?? "",
1067
+ role: raw.role ?? "",
1068
+ content: raw.content ?? "",
1069
+ model: raw.model,
1070
+ imageModel: raw.image_model,
1071
+ files: parseJsonField(raw.files),
1072
+ fileIds: parseJsonField(raw.file_ids),
1073
+ createdAt: rawDate(raw.created_at),
1074
+ updatedAt: rawDate(raw.updated_at),
1075
+ vector: skipEmbeddings ? void 0 : parseJsonField(vectorRaw),
1076
+ embeddingModel: raw.embedding_model,
1077
+ chunks: skipEmbeddings ? void 0 : parseJsonField(chunksRaw),
1078
+ usage: parseJsonField(raw.usage),
1079
+ sources: parseJsonField(raw.sources),
1080
+ responseDuration: raw.response_duration,
1081
+ // `was_stopped` is an OPTIONAL boolean: an unset row sanitizes to null, and the Model path
1082
+ // (message.wasStopped) returns that null verbatim. Preserve it (don't collapse to false) so the
1083
+ // raw path is byte-identical. When set, coerce SQLite 0/1 and LokiJS true/false alike.
1084
+ wasStopped: raw.was_stopped === null || raw.was_stopped === void 0 ? raw.was_stopped : raw.was_stopped === true || raw.was_stopped === 1,
1085
+ error: raw.error,
1086
+ thoughtProcess: parseJsonField(raw.thought_process),
1087
+ thinking: raw.thinking,
1088
+ parentMessageId: raw.parent_message_id,
1089
+ feedback: raw.feedback || null,
1090
+ toolCallEvents: parseJsonField(raw.tool_call_events)
1091
+ };
1092
+ }
1093
+ async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
1094
+ const baseMessage = messageRawToStoredRaw(raw, projection);
1095
+ if (walletAddress) {
1096
+ return await decryptMessageFields(
1097
+ baseMessage,
1098
+ walletAddress,
1099
+ signMessage,
1100
+ embeddedWalletSigner
1101
+ );
1102
+ }
1103
+ return baseMessage;
1104
+ }
1044
1105
  function conversationToStoredRaw(conversation) {
1045
1106
  return {
1046
1107
  uniqueId: conversation.id,
@@ -1065,6 +1126,33 @@ async function conversationToStored(conversation, walletAddress, signMessage, em
1065
1126
  }
1066
1127
  return baseConversation;
1067
1128
  }
1129
+ function conversationRawToStoredRaw(raw) {
1130
+ const pinnedAt = raw.pinned_at;
1131
+ return {
1132
+ uniqueId: raw.id,
1133
+ conversationId: raw.conversation_id ?? "",
1134
+ title: raw.title ?? "",
1135
+ projectId: raw.project_id,
1136
+ createdAt: rawDate(raw.created_at),
1137
+ updatedAt: rawDate(raw.updated_at),
1138
+ // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
1139
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
1140
+ // @date maps a non-number raw column (incl. an explicit unpin null) to null; a number → Date.
1141
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
1142
+ };
1143
+ }
1144
+ async function conversationRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner) {
1145
+ const baseConversation = conversationRawToStoredRaw(raw);
1146
+ if (walletAddress) {
1147
+ return await decryptConversationFields(
1148
+ baseConversation,
1149
+ walletAddress,
1150
+ signMessage,
1151
+ embeddedWalletSigner
1152
+ );
1153
+ }
1154
+ return baseConversation;
1155
+ }
1068
1156
  async function createConversationOp(ctx, opts, defaultTitle = "New Conversation") {
1069
1157
  const convId = opts?.conversationId || generateConversationId();
1070
1158
  const title = opts?.title || defaultTitle;
@@ -1104,36 +1192,51 @@ async function getConversationOp(ctx, id) {
1104
1192
  ) : null;
1105
1193
  }
1106
1194
  async function getConversationsOp(ctx) {
1107
- const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).fetch();
1195
+ const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).unsafeFetchRaw();
1108
1196
  return Promise.all(
1109
1197
  results.map(
1110
- (conv) => conversationToStored(conv, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
1198
+ (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
1111
1199
  )
1112
1200
  );
1113
1201
  }
1114
- function conversationToLazyStored(conversation) {
1202
+ function conversationRawToLazyStored(raw) {
1203
+ const pinnedAt = raw.pinned_at;
1115
1204
  return {
1116
- uniqueId: conversation.id,
1117
- conversationId: conversation.conversationId,
1118
- encryptedTitle: conversation.title,
1119
- projectId: conversation.projectId,
1120
- createdAt: conversation.createdAt,
1121
- updatedAt: conversation.updatedAt,
1122
- isDeleted: conversation.isDeleted,
1123
- pinnedAt: conversation.pinnedAt
1205
+ uniqueId: raw.id,
1206
+ conversationId: raw.conversation_id ?? "",
1207
+ encryptedTitle: raw.title ?? "",
1208
+ projectId: raw.project_id,
1209
+ createdAt: rawDate(raw.created_at),
1210
+ updatedAt: rawDate(raw.updated_at),
1211
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
1212
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
1124
1213
  };
1125
1214
  }
1126
1215
  async function getConversationsLazyOp(ctx) {
1127
- const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).fetch();
1128
- return results.map(conversationToLazyStored);
1216
+ const results = await ctx.conversationsCollection.query(Q.where("is_deleted", false), Q.sortBy("created_at", Q.desc)).unsafeFetchRaw();
1217
+ return results.map(conversationRawToLazyStored);
1218
+ }
1219
+ async function getConversationsPageOp(ctx, options) {
1220
+ const limit = Math.floor(options?.limit ?? 200);
1221
+ if (!Number.isFinite(limit) || limit < 1) return [];
1222
+ const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
1223
+ const clauses = [Q.where("is_deleted", false)];
1224
+ if (options?.before !== void 0) {
1225
+ clauses.push(
1226
+ exclude.size > 0 ? Q.where("created_at", Q.lte(options.before)) : Q.where("created_at", Q.lt(options.before))
1227
+ );
1228
+ }
1229
+ const fetched = await ctx.conversationsCollection.query(...clauses, Q.sortBy("created_at", Q.desc), Q.take(limit + exclude.size)).unsafeFetchRaw();
1230
+ const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
1231
+ return results.slice(0, limit).map(conversationRawToLazyStored);
1129
1232
  }
1130
1233
  async function getConversationsByProjectLazyOp(ctx, projectId) {
1131
1234
  const results = await ctx.conversationsCollection.query(
1132
1235
  Q.where("project_id", projectId === null ? "" : projectId),
1133
1236
  Q.where("is_deleted", false),
1134
1237
  Q.sortBy("created_at", Q.desc)
1135
- ).fetch();
1136
- return results.map(conversationToLazyStored);
1238
+ ).unsafeFetchRaw();
1239
+ return results.map(conversationRawToLazyStored);
1137
1240
  }
1138
1241
  async function updateConversationTitleOp(ctx, id, title) {
1139
1242
  const results = await ctx.conversationsCollection.query(Q.where("conversation_id", id), Q.where("is_deleted", false)).fetch();
@@ -1179,10 +1282,10 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
1179
1282
  return false;
1180
1283
  }
1181
1284
  async function getMessagesOp(ctx, convId) {
1182
- const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).fetch();
1285
+ const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).unsafeFetchRaw();
1183
1286
  return Promise.all(
1184
1287
  results.map(
1185
- (msg) => messageToStored(msg, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
1288
+ (raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
1186
1289
  )
1187
1290
  );
1188
1291
  }
@@ -1199,39 +1302,40 @@ async function getMessagesPageOp(ctx, convId, opts) {
1199
1302
  exclude.size > 0 ? Q.where("message_id", Q.lte(opts.beforeMessageId)) : Q.where("message_id", Q.lt(opts.beforeMessageId))
1200
1303
  );
1201
1304
  }
1202
- const fetched = await ctx.messagesCollection.query(...clauses, Q.sortBy("message_id", Q.desc), Q.take(limit + exclude.size)).fetch();
1203
- const results = (exclude.size > 0 ? fetched.filter((msg) => !exclude.has(msg.id)) : fetched).slice(0, limit);
1305
+ const fetched = await ctx.messagesCollection.query(...clauses, Q.sortBy("message_id", Q.desc), Q.take(limit + exclude.size)).unsafeFetchRaw();
1306
+ const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
1204
1307
  results.reverse();
1205
1308
  return Promise.all(
1206
1309
  results.map(
1207
- (msg) => messageToStored(msg, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner, {
1310
+ (raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner, {
1208
1311
  skipEmbeddings: true
1209
1312
  })
1210
1313
  )
1211
1314
  );
1212
1315
  }
1213
1316
  async function getMessageSkeletonsOp(ctx, convId) {
1214
- const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).fetch();
1317
+ const results = await ctx.messagesCollection.query(Q.where("conversation_id", convId), Q.sortBy("message_id", Q.asc)).unsafeFetchRaw();
1215
1318
  const roleById = /* @__PURE__ */ new Map();
1216
- for (const msg of results) {
1217
- roleById.set(msg.id, msg.role);
1218
- }
1219
- const skeletons = results.map((msg) => ({
1220
- uniqueId: msg.id,
1221
- messageId: msg.messageId,
1222
- conversationId: String(msg._getRaw("conversation_id")),
1223
- role: msg.role,
1224
- createdAt: msg.createdAt,
1319
+ for (const raw of results) {
1320
+ roleById.set(raw.id, raw.role);
1321
+ }
1322
+ const skeletons = results.map((raw) => ({
1323
+ uniqueId: raw.id,
1324
+ messageId: raw.message_id,
1325
+ conversationId: raw.conversation_id ?? "",
1326
+ role: raw.role ?? "",
1327
+ createdAt: rawDate(raw.created_at),
1225
1328
  // WatermelonDB surfaces unset text columns as null at runtime — normalize
1226
1329
  // to undefined so `parentMessageId ?? undefined` keying works everywhere.
1227
- parentMessageId: msg.parentMessageId ?? void 0,
1228
- model: msg.model ?? void 0
1330
+ parentMessageId: raw.parent_message_id ?? void 0,
1331
+ model: raw.model ?? void 0
1229
1332
  }));
1230
1333
  const artifactIndices = [];
1231
1334
  for (let i = 0; i < results.length; i++) {
1232
- const msg = results[i];
1233
- if (msg.role !== "user" || !msg.parentMessageId) continue;
1234
- if (roleById.get(msg.parentMessageId) === "user") {
1335
+ const raw = results[i];
1336
+ const parentMessageId = raw.parent_message_id;
1337
+ if (raw.role !== "user" || !parentMessageId) continue;
1338
+ if (roleById.get(parentMessageId) === "user") {
1235
1339
  artifactIndices.push(i);
1236
1340
  }
1237
1341
  }
@@ -3482,7 +3586,7 @@ async function generateEmbedding(text, options) {
3482
3586
  const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
3483
3587
  if (cache) {
3484
3588
  const cached = cache.get(text);
3485
- if (cached) return cached;
3589
+ if (cached) return Array.from(cached);
3486
3590
  }
3487
3591
  let headers;
3488
3592
  if (apiKey) {
@@ -3521,10 +3625,11 @@ async function generateEmbedding(text, options) {
3521
3625
  totalTokens: response.data.usage.total_tokens ?? 0
3522
3626
  });
3523
3627
  }
3628
+ const f32Embedding = Float32Array.from(embedding);
3524
3629
  if (cache) {
3525
- cache.set(text, embedding);
3630
+ cache.set(text, f32Embedding);
3526
3631
  }
3527
- return embedding;
3632
+ return Array.from(f32Embedding);
3528
3633
  }
3529
3634
  var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
3530
3635
  var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
@@ -3562,7 +3667,7 @@ async function generateEmbeddings(texts, options) {
3562
3667
  if (cache) {
3563
3668
  const cached = cache.get(texts[i]);
3564
3669
  if (cached) {
3565
- results[i] = cached;
3670
+ results[i] = Array.from(cached);
3566
3671
  continue;
3567
3672
  }
3568
3673
  }
@@ -3623,9 +3728,10 @@ async function generateEmbeddings(texts, options) {
3623
3728
  newEmbeddings = allEmbeddings.flat();
3624
3729
  }
3625
3730
  for (let i = 0; i < uncachedIndices.length; i++) {
3626
- results[uncachedIndices[i]] = newEmbeddings[i];
3731
+ const f32Embedding = Float32Array.from(newEmbeddings[i]);
3732
+ results[uncachedIndices[i]] = Array.from(f32Embedding);
3627
3733
  if (cache) {
3628
- cache.set(uncachedTexts[i], newEmbeddings[i]);
3734
+ cache.set(uncachedTexts[i], f32Embedding);
3629
3735
  }
3630
3736
  }
3631
3737
  return results;
@@ -5049,7 +5155,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5049
5155
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5050
5156
  );
5051
5157
  }
5052
- const { recall: recall2 } = await import("./recall-FQU3NUTL.mjs");
5158
+ const { recall: recall2 } = await import("./recall-DJ5LD5WJ.mjs");
5053
5159
  const result = await recall2(
5054
5160
  query,
5055
5161
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -5701,6 +5807,7 @@ export {
5701
5807
  getConversationOp,
5702
5808
  getConversationsOp,
5703
5809
  getConversationsLazyOp,
5810
+ getConversationsPageOp,
5704
5811
  getConversationsByProjectLazyOp,
5705
5812
  updateConversationTitleOp,
5706
5813
  deleteConversationOp,
@@ -2101,6 +2101,67 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
2101
2101
  }
2102
2102
  return baseMessage;
2103
2103
  }
2104
+ function rawDate(value) {
2105
+ return new Date(typeof value === "number" ? value : 0);
2106
+ }
2107
+ function messageRawToStoredRaw(raw, projection) {
2108
+ const parseJsonField = (rawValue) => {
2109
+ if (!rawValue) return void 0;
2110
+ if (typeof rawValue === "string") {
2111
+ if (rawValue.startsWith("enc:")) return rawValue;
2112
+ try {
2113
+ return JSON.parse(rawValue);
2114
+ } catch {
2115
+ return void 0;
2116
+ }
2117
+ }
2118
+ return rawValue;
2119
+ };
2120
+ const skipEmbeddings = projection?.skipEmbeddings === true;
2121
+ const vectorRaw = skipEmbeddings ? null : raw.vector;
2122
+ const chunksRaw = skipEmbeddings ? null : raw.chunks;
2123
+ return {
2124
+ uniqueId: raw.id,
2125
+ messageId: raw.message_id,
2126
+ conversationId: raw.conversation_id ?? "",
2127
+ role: raw.role ?? "",
2128
+ content: raw.content ?? "",
2129
+ model: raw.model,
2130
+ imageModel: raw.image_model,
2131
+ files: parseJsonField(raw.files),
2132
+ fileIds: parseJsonField(raw.file_ids),
2133
+ createdAt: rawDate(raw.created_at),
2134
+ updatedAt: rawDate(raw.updated_at),
2135
+ vector: skipEmbeddings ? void 0 : parseJsonField(vectorRaw),
2136
+ embeddingModel: raw.embedding_model,
2137
+ chunks: skipEmbeddings ? void 0 : parseJsonField(chunksRaw),
2138
+ usage: parseJsonField(raw.usage),
2139
+ sources: parseJsonField(raw.sources),
2140
+ responseDuration: raw.response_duration,
2141
+ // `was_stopped` is an OPTIONAL boolean: an unset row sanitizes to null, and the Model path
2142
+ // (message.wasStopped) returns that null verbatim. Preserve it (don't collapse to false) so the
2143
+ // raw path is byte-identical. When set, coerce SQLite 0/1 and LokiJS true/false alike.
2144
+ wasStopped: raw.was_stopped === null || raw.was_stopped === void 0 ? raw.was_stopped : raw.was_stopped === true || raw.was_stopped === 1,
2145
+ error: raw.error,
2146
+ thoughtProcess: parseJsonField(raw.thought_process),
2147
+ thinking: raw.thinking,
2148
+ parentMessageId: raw.parent_message_id,
2149
+ feedback: raw.feedback || null,
2150
+ toolCallEvents: parseJsonField(raw.tool_call_events)
2151
+ };
2152
+ }
2153
+ async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
2154
+ const baseMessage = messageRawToStoredRaw(raw, projection);
2155
+ if (walletAddress) {
2156
+ return await decryptMessageFields(
2157
+ baseMessage,
2158
+ walletAddress,
2159
+ signMessage,
2160
+ embeddedWalletSigner
2161
+ );
2162
+ }
2163
+ return baseMessage;
2164
+ }
2104
2165
  function conversationToStoredRaw(conversation) {
2105
2166
  return {
2106
2167
  uniqueId: conversation.id,
@@ -2125,6 +2186,33 @@ async function conversationToStored(conversation, walletAddress, signMessage, em
2125
2186
  }
2126
2187
  return baseConversation;
2127
2188
  }
2189
+ function conversationRawToStoredRaw(raw) {
2190
+ const pinnedAt = raw.pinned_at;
2191
+ return {
2192
+ uniqueId: raw.id,
2193
+ conversationId: raw.conversation_id ?? "",
2194
+ title: raw.title ?? "",
2195
+ projectId: raw.project_id,
2196
+ createdAt: rawDate(raw.created_at),
2197
+ updatedAt: rawDate(raw.updated_at),
2198
+ // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
2199
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
2200
+ // @date maps a non-number raw column (incl. an explicit unpin null) to null; a number → Date.
2201
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
2202
+ };
2203
+ }
2204
+ async function conversationRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner) {
2205
+ const baseConversation = conversationRawToStoredRaw(raw);
2206
+ if (walletAddress) {
2207
+ return await decryptConversationFields(
2208
+ baseConversation,
2209
+ walletAddress,
2210
+ signMessage,
2211
+ embeddedWalletSigner
2212
+ );
2213
+ }
2214
+ return baseConversation;
2215
+ }
2128
2216
  async function createConversationOp(ctx, opts, defaultTitle = "New Conversation") {
2129
2217
  const convId = opts?.conversationId || generateConversationId();
2130
2218
  const title = opts?.title || defaultTitle;
@@ -2164,36 +2252,51 @@ async function getConversationOp(ctx, id) {
2164
2252
  ) : null;
2165
2253
  }
2166
2254
  async function getConversationsOp(ctx) {
2167
- const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).fetch();
2255
+ const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).unsafeFetchRaw();
2168
2256
  return Promise.all(
2169
2257
  results.map(
2170
- (conv) => conversationToStored(conv, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2258
+ (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2171
2259
  )
2172
2260
  );
2173
2261
  }
2174
- function conversationToLazyStored(conversation) {
2262
+ function conversationRawToLazyStored(raw) {
2263
+ const pinnedAt = raw.pinned_at;
2175
2264
  return {
2176
- uniqueId: conversation.id,
2177
- conversationId: conversation.conversationId,
2178
- encryptedTitle: conversation.title,
2179
- projectId: conversation.projectId,
2180
- createdAt: conversation.createdAt,
2181
- updatedAt: conversation.updatedAt,
2182
- isDeleted: conversation.isDeleted,
2183
- pinnedAt: conversation.pinnedAt
2265
+ uniqueId: raw.id,
2266
+ conversationId: raw.conversation_id ?? "",
2267
+ encryptedTitle: raw.title ?? "",
2268
+ projectId: raw.project_id,
2269
+ createdAt: rawDate(raw.created_at),
2270
+ updatedAt: rawDate(raw.updated_at),
2271
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
2272
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
2184
2273
  };
2185
2274
  }
2186
2275
  async function getConversationsLazyOp(ctx) {
2187
- const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).fetch();
2188
- return results.map(conversationToLazyStored);
2276
+ const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).unsafeFetchRaw();
2277
+ return results.map(conversationRawToLazyStored);
2278
+ }
2279
+ async function getConversationsPageOp(ctx, options) {
2280
+ const limit = Math.floor(options?.limit ?? 200);
2281
+ if (!Number.isFinite(limit) || limit < 1) return [];
2282
+ const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
2283
+ const clauses = [import_watermelondb.Q.where("is_deleted", false)];
2284
+ if (options?.before !== void 0) {
2285
+ clauses.push(
2286
+ exclude.size > 0 ? import_watermelondb.Q.where("created_at", import_watermelondb.Q.lte(options.before)) : import_watermelondb.Q.where("created_at", import_watermelondb.Q.lt(options.before))
2287
+ );
2288
+ }
2289
+ const fetched = await ctx.conversationsCollection.query(...clauses, import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc), import_watermelondb.Q.take(limit + exclude.size)).unsafeFetchRaw();
2290
+ const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
2291
+ return results.slice(0, limit).map(conversationRawToLazyStored);
2189
2292
  }
2190
2293
  async function getConversationsByProjectLazyOp(ctx, projectId) {
2191
2294
  const results = await ctx.conversationsCollection.query(
2192
2295
  import_watermelondb.Q.where("project_id", projectId === null ? "" : projectId),
2193
2296
  import_watermelondb.Q.where("is_deleted", false),
2194
2297
  import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)
2195
- ).fetch();
2196
- return results.map(conversationToLazyStored);
2298
+ ).unsafeFetchRaw();
2299
+ return results.map(conversationRawToLazyStored);
2197
2300
  }
2198
2301
  async function updateConversationTitleOp(ctx, id, title) {
2199
2302
  const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("conversation_id", id), import_watermelondb.Q.where("is_deleted", false)).fetch();
@@ -2239,10 +2342,10 @@ async function updateConversationPinnedOp(ctx, id, pinned) {
2239
2342
  return false;
2240
2343
  }
2241
2344
  async function getMessagesOp(ctx, convId) {
2242
- const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).fetch();
2345
+ const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).unsafeFetchRaw();
2243
2346
  return Promise.all(
2244
2347
  results.map(
2245
- (msg) => messageToStored(msg, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2348
+ (raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
2246
2349
  )
2247
2350
  );
2248
2351
  }
@@ -2259,39 +2362,40 @@ async function getMessagesPageOp(ctx, convId, opts) {
2259
2362
  exclude.size > 0 ? import_watermelondb.Q.where("message_id", import_watermelondb.Q.lte(opts.beforeMessageId)) : import_watermelondb.Q.where("message_id", import_watermelondb.Q.lt(opts.beforeMessageId))
2260
2363
  );
2261
2364
  }
2262
- const fetched = await ctx.messagesCollection.query(...clauses, import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.desc), import_watermelondb.Q.take(limit + exclude.size)).fetch();
2263
- const results = (exclude.size > 0 ? fetched.filter((msg) => !exclude.has(msg.id)) : fetched).slice(0, limit);
2365
+ const fetched = await ctx.messagesCollection.query(...clauses, import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.desc), import_watermelondb.Q.take(limit + exclude.size)).unsafeFetchRaw();
2366
+ const results = (exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched).slice(0, limit);
2264
2367
  results.reverse();
2265
2368
  return Promise.all(
2266
2369
  results.map(
2267
- (msg) => messageToStored(msg, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner, {
2370
+ (raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner, {
2268
2371
  skipEmbeddings: true
2269
2372
  })
2270
2373
  )
2271
2374
  );
2272
2375
  }
2273
2376
  async function getMessageSkeletonsOp(ctx, convId) {
2274
- const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).fetch();
2377
+ const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).unsafeFetchRaw();
2275
2378
  const roleById = /* @__PURE__ */ new Map();
2276
- for (const msg of results) {
2277
- roleById.set(msg.id, msg.role);
2278
- }
2279
- const skeletons = results.map((msg) => ({
2280
- uniqueId: msg.id,
2281
- messageId: msg.messageId,
2282
- conversationId: String(msg._getRaw("conversation_id")),
2283
- role: msg.role,
2284
- createdAt: msg.createdAt,
2379
+ for (const raw of results) {
2380
+ roleById.set(raw.id, raw.role);
2381
+ }
2382
+ const skeletons = results.map((raw) => ({
2383
+ uniqueId: raw.id,
2384
+ messageId: raw.message_id,
2385
+ conversationId: raw.conversation_id ?? "",
2386
+ role: raw.role ?? "",
2387
+ createdAt: rawDate(raw.created_at),
2285
2388
  // WatermelonDB surfaces unset text columns as null at runtime — normalize
2286
2389
  // to undefined so `parentMessageId ?? undefined` keying works everywhere.
2287
- parentMessageId: msg.parentMessageId ?? void 0,
2288
- model: msg.model ?? void 0
2390
+ parentMessageId: raw.parent_message_id ?? void 0,
2391
+ model: raw.model ?? void 0
2289
2392
  }));
2290
2393
  const artifactIndices = [];
2291
2394
  for (let i = 0; i < results.length; i++) {
2292
- const msg = results[i];
2293
- if (msg.role !== "user" || !msg.parentMessageId) continue;
2294
- if (roleById.get(msg.parentMessageId) === "user") {
2395
+ const raw = results[i];
2396
+ const parentMessageId = raw.parent_message_id;
2397
+ if (raw.role !== "user" || !parentMessageId) continue;
2398
+ if (roleById.get(parentMessageId) === "user") {
2295
2399
  artifactIndices.push(i);
2296
2400
  }
2297
2401
  }
@@ -2912,7 +3016,7 @@ async function generateEmbedding(text12, options) {
2912
3016
  const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
2913
3017
  if (cache) {
2914
3018
  const cached = cache.get(text12);
2915
- if (cached) return cached;
3019
+ if (cached) return Array.from(cached);
2916
3020
  }
2917
3021
  let headers;
2918
3022
  if (apiKey) {
@@ -2951,10 +3055,11 @@ async function generateEmbedding(text12, options) {
2951
3055
  totalTokens: response.data.usage.total_tokens ?? 0
2952
3056
  });
2953
3057
  }
3058
+ const f32Embedding = Float32Array.from(embedding);
2954
3059
  if (cache) {
2955
- cache.set(text12, embedding);
3060
+ cache.set(text12, f32Embedding);
2956
3061
  }
2957
- return embedding;
3062
+ return Array.from(f32Embedding);
2958
3063
  }
2959
3064
  async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput) {
2960
3065
  const response = await withEmbeddingRetry(
@@ -2990,7 +3095,7 @@ async function generateEmbeddings(texts, options) {
2990
3095
  if (cache) {
2991
3096
  const cached = cache.get(texts[i]);
2992
3097
  if (cached) {
2993
- results[i] = cached;
3098
+ results[i] = Array.from(cached);
2994
3099
  continue;
2995
3100
  }
2996
3101
  }
@@ -3051,9 +3156,10 @@ async function generateEmbeddings(texts, options) {
3051
3156
  newEmbeddings = allEmbeddings.flat();
3052
3157
  }
3053
3158
  for (let i = 0; i < uncachedIndices.length; i++) {
3054
- results[uncachedIndices[i]] = newEmbeddings[i];
3159
+ const f32Embedding = Float32Array.from(newEmbeddings[i]);
3160
+ results[uncachedIndices[i]] = Array.from(f32Embedding);
3055
3161
  if (cache) {
3056
- cache.set(uncachedTexts[i], newEmbeddings[i]);
3162
+ cache.set(uncachedTexts[i], f32Embedding);
3057
3163
  }
3058
3164
  }
3059
3165
  return results;
@@ -7153,6 +7259,7 @@ __export(index_exports, {
7153
7259
  getConversationMemoriesOp: () => getConversationMemoriesOp,
7154
7260
  getConversationsByProjectLazyOp: () => getConversationsByProjectLazyOp,
7155
7261
  getConversationsLazyOp: () => getConversationsLazyOp,
7262
+ getConversationsPageOp: () => getConversationsPageOp,
7156
7263
  getLogger: () => getLogger,
7157
7264
  getMemoriesNeedingTopicExtractionOp: () => getMemoriesNeedingTopicExtractionOp,
7158
7265
  getServerTools: () => getServerTools,
@@ -19019,6 +19126,7 @@ function createNotionTools(getAccessToken, requestNotionAccess) {
19019
19126
  getConversationMemoriesOp,
19020
19127
  getConversationsByProjectLazyOp,
19021
19128
  getConversationsLazyOp,
19129
+ getConversationsPageOp,
19022
19130
  getLogger,
19023
19131
  getMemoriesNeedingTopicExtractionOp,
19024
19132
  getServerTools,