@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.
@@ -73,6 +73,7 @@ import {
73
73
  getConversationsByProjectOp,
74
74
  getConversationsLazyOp,
75
75
  getConversationsOp,
76
+ getConversationsPageOp,
76
77
  getEncryptionKey,
77
78
  getImageModel,
78
79
  getMemoriesByEntityNamesOp,
@@ -131,7 +132,7 @@ import {
131
132
  updateVaultMemoryOp,
132
133
  useEncryption,
133
134
  vaultMemoryToStored
134
- } from "./chunk-ZXS3KOY4.mjs";
135
+ } from "./chunk-OSDVRDLI.mjs";
135
136
  import {
136
137
  PiiRedactor,
137
138
  createStreamingDeAnonymizer,
@@ -8274,6 +8275,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
8274
8275
  }
8275
8276
 
8276
8277
  // src/lib/processors/encoding.ts
8278
+ var B64_ENCODE_CHUNK = 32768 * 3;
8277
8279
  async function dataUrlToArrayBuffer(dataUrl) {
8278
8280
  if (dataUrl.startsWith("blob:") || dataUrl.startsWith("http://") || dataUrl.startsWith("https://")) {
8279
8281
  const response = await fetch(dataUrl);
@@ -8296,11 +8298,28 @@ function uint8ArrayToBase64(data) {
8296
8298
  if (typeof Buffer !== "undefined") {
8297
8299
  return Buffer.from(data).toString("base64");
8298
8300
  }
8299
- let binary = "";
8300
- for (let i = 0; i < data.length; i++) {
8301
- binary += String.fromCharCode(data[i]);
8301
+ let base64 = "";
8302
+ for (let i = 0; i < data.length; i += B64_ENCODE_CHUNK) {
8303
+ const slice = data.subarray(i, i + B64_ENCODE_CHUNK);
8304
+ let binary = "";
8305
+ for (let j = 0; j < slice.length; j++) {
8306
+ binary += String.fromCharCode(slice[j]);
8307
+ }
8308
+ base64 += btoa(binary);
8309
+ }
8310
+ return base64;
8311
+ }
8312
+ function base64ToUint8Array(base64) {
8313
+ if (typeof Buffer !== "undefined") {
8314
+ const buf = Buffer.from(base64, "base64");
8315
+ return new Uint8Array(buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength));
8302
8316
  }
8303
- return btoa(binary);
8317
+ const binary = atob(base64);
8318
+ const bytes = new Uint8Array(binary.length);
8319
+ for (let i = 0; i < binary.length; i++) {
8320
+ bytes[i] = binary.charCodeAt(i);
8321
+ }
8322
+ return bytes;
8304
8323
  }
8305
8324
 
8306
8325
  // src/lib/processors/ExcelProcessor.ts
@@ -18590,7 +18609,7 @@ async function uploadFileToICloud(filename, content) {
18590
18609
  const database = container.privateCloudDatabase;
18591
18610
  const recordName = `backup_${filename.replace(/[^a-zA-Z0-9]/g, "_")}`;
18592
18611
  const arrayBuffer = await content.arrayBuffer();
18593
- const base64Data = btoa(String.fromCharCode(...new Uint8Array(arrayBuffer)));
18612
+ const base64Data = uint8ArrayToBase64(new Uint8Array(arrayBuffer));
18594
18613
  const record = {
18595
18614
  recordType: RECORD_TYPE,
18596
18615
  recordName,
@@ -18652,11 +18671,7 @@ async function downloadICloudFile(recordName) {
18652
18671
  throw new Error("No data in record");
18653
18672
  }
18654
18673
  if (typeof dataField === "string") {
18655
- const binaryString = atob(dataField);
18656
- const bytes = new Uint8Array(binaryString.length);
18657
- for (let i = 0; i < binaryString.length; i++) {
18658
- bytes[i] = binaryString.charCodeAt(i);
18659
- }
18674
+ const bytes = base64ToUint8Array(dataField);
18660
18675
  return new Blob([bytes], { type: "application/json" });
18661
18676
  }
18662
18677
  if (typeof dataField === "object" && "downloadURL" in dataField) {
@@ -22831,6 +22846,7 @@ export {
22831
22846
  getConversationsByProjectLazyOp,
22832
22847
  getConversationsByProjectOp,
22833
22848
  getConversationsLazyOp,
22849
+ getConversationsPageOp,
22834
22850
  getDocumentsOp,
22835
22851
  getDriveAccessToken,
22836
22852
  getEncryptionKey,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-ZXS3KOY4.mjs";
3
+ } from "./chunk-OSDVRDLI.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -14553,6 +14553,15 @@ async function encryptData(plaintext, address) {
14553
14553
  const key = await getEncryptionKey(address);
14554
14554
  return encryptDataWithKey(plaintext, key);
14555
14555
  }
14556
+ async function encryptDataBytes(plaintext, address) {
14557
+ if (!isValidWalletAddress(address)) {
14558
+ throw new Error(
14559
+ `Invalid wallet address: ${address}. Address must start with 0x and be 42 characters (0x + 40 hex characters).`
14560
+ );
14561
+ }
14562
+ const key = await getEncryptionKey(address);
14563
+ return encryptBytesWithKey(plaintext, key);
14564
+ }
14556
14565
  async function decryptData(encryptedHex, address, version = "v3") {
14557
14566
  const key = await getEncryptionKey(address, version);
14558
14567
  return decryptDataWithKey(encryptedHex, key);
@@ -14572,6 +14581,20 @@ async function decryptDataBytes(encryptedHex, address, version = "v3") {
14572
14581
  );
14573
14582
  return new Uint8Array(decryptedData);
14574
14583
  }
14584
+ async function decryptDataBytesFromBytes(encrypted, address, version = "v3") {
14585
+ const key = await getEncryptionKey(address, version);
14586
+ const iv = encrypted.subarray(0, 12);
14587
+ const encryptedData = encrypted.subarray(12);
14588
+ const decryptedData = await crypto.subtle.decrypt(
14589
+ {
14590
+ name: "AES-GCM",
14591
+ iv
14592
+ },
14593
+ key,
14594
+ encryptedData
14595
+ );
14596
+ return new Uint8Array(decryptedData);
14597
+ }
14575
14598
  function hasEncryptionKey(address) {
14576
14599
  return getStoredKey(address) !== null;
14577
14600
  }
@@ -15209,6 +15232,67 @@ async function messageToStored(message, walletAddress, signMessage, embeddedWall
15209
15232
  }
15210
15233
  return baseMessage;
15211
15234
  }
15235
+ function rawDate(value) {
15236
+ return new Date(typeof value === "number" ? value : 0);
15237
+ }
15238
+ function messageRawToStoredRaw(raw, projection) {
15239
+ const parseJsonField = (rawValue) => {
15240
+ if (!rawValue) return void 0;
15241
+ if (typeof rawValue === "string") {
15242
+ if (rawValue.startsWith("enc:")) return rawValue;
15243
+ try {
15244
+ return JSON.parse(rawValue);
15245
+ } catch {
15246
+ return void 0;
15247
+ }
15248
+ }
15249
+ return rawValue;
15250
+ };
15251
+ const skipEmbeddings = projection?.skipEmbeddings === true;
15252
+ const vectorRaw = skipEmbeddings ? null : raw.vector;
15253
+ const chunksRaw = skipEmbeddings ? null : raw.chunks;
15254
+ return {
15255
+ uniqueId: raw.id,
15256
+ messageId: raw.message_id,
15257
+ conversationId: raw.conversation_id ?? "",
15258
+ role: raw.role ?? "",
15259
+ content: raw.content ?? "",
15260
+ model: raw.model,
15261
+ imageModel: raw.image_model,
15262
+ files: parseJsonField(raw.files),
15263
+ fileIds: parseJsonField(raw.file_ids),
15264
+ createdAt: rawDate(raw.created_at),
15265
+ updatedAt: rawDate(raw.updated_at),
15266
+ vector: skipEmbeddings ? void 0 : parseJsonField(vectorRaw),
15267
+ embeddingModel: raw.embedding_model,
15268
+ chunks: skipEmbeddings ? void 0 : parseJsonField(chunksRaw),
15269
+ usage: parseJsonField(raw.usage),
15270
+ sources: parseJsonField(raw.sources),
15271
+ responseDuration: raw.response_duration,
15272
+ // `was_stopped` is an OPTIONAL boolean: an unset row sanitizes to null, and the Model path
15273
+ // (message.wasStopped) returns that null verbatim. Preserve it (don't collapse to false) so the
15274
+ // raw path is byte-identical. When set, coerce SQLite 0/1 and LokiJS true/false alike.
15275
+ wasStopped: raw.was_stopped === null || raw.was_stopped === void 0 ? raw.was_stopped : raw.was_stopped === true || raw.was_stopped === 1,
15276
+ error: raw.error,
15277
+ thoughtProcess: parseJsonField(raw.thought_process),
15278
+ thinking: raw.thinking,
15279
+ parentMessageId: raw.parent_message_id,
15280
+ feedback: raw.feedback || null,
15281
+ toolCallEvents: parseJsonField(raw.tool_call_events)
15282
+ };
15283
+ }
15284
+ async function messageRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner, projection) {
15285
+ const baseMessage = messageRawToStoredRaw(raw, projection);
15286
+ if (walletAddress) {
15287
+ return await decryptMessageFields(
15288
+ baseMessage,
15289
+ walletAddress,
15290
+ signMessage,
15291
+ embeddedWalletSigner
15292
+ );
15293
+ }
15294
+ return baseMessage;
15295
+ }
15212
15296
  function conversationToStoredRaw(conversation) {
15213
15297
  return {
15214
15298
  uniqueId: conversation.id,
@@ -15233,6 +15317,33 @@ async function conversationToStored(conversation, walletAddress, signMessage, em
15233
15317
  }
15234
15318
  return baseConversation;
15235
15319
  }
15320
+ function conversationRawToStoredRaw(raw) {
15321
+ const pinnedAt = raw.pinned_at;
15322
+ return {
15323
+ uniqueId: raw.id,
15324
+ conversationId: raw.conversation_id ?? "",
15325
+ title: raw.title ?? "",
15326
+ projectId: raw.project_id,
15327
+ createdAt: rawDate(raw.created_at),
15328
+ updatedAt: rawDate(raw.updated_at),
15329
+ // SQLite stores booleans as 0/1, LokiJS as true/false — coerce both.
15330
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
15331
+ // @date maps a non-number raw column (incl. an explicit unpin null) to null; a number → Date.
15332
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
15333
+ };
15334
+ }
15335
+ async function conversationRawToStored(raw, walletAddress, signMessage, embeddedWalletSigner) {
15336
+ const baseConversation = conversationRawToStoredRaw(raw);
15337
+ if (walletAddress) {
15338
+ return await decryptConversationFields(
15339
+ baseConversation,
15340
+ walletAddress,
15341
+ signMessage,
15342
+ embeddedWalletSigner
15343
+ );
15344
+ }
15345
+ return baseConversation;
15346
+ }
15236
15347
  async function createConversationOp(ctx, opts, defaultTitle = "New Conversation") {
15237
15348
  const convId = opts?.conversationId || generateConversationId();
15238
15349
  const title = opts?.title || defaultTitle;
@@ -15272,36 +15383,51 @@ async function getConversationOp(ctx, id) {
15272
15383
  ) : null;
15273
15384
  }
15274
15385
  async function getConversationsOp(ctx) {
15275
- const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).fetch();
15386
+ const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).unsafeFetchRaw();
15276
15387
  return Promise.all(
15277
15388
  results.map(
15278
- (conv) => conversationToStored(conv, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15389
+ (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15279
15390
  )
15280
15391
  );
15281
15392
  }
15282
- function conversationToLazyStored(conversation) {
15393
+ function conversationRawToLazyStored(raw) {
15394
+ const pinnedAt = raw.pinned_at;
15283
15395
  return {
15284
- uniqueId: conversation.id,
15285
- conversationId: conversation.conversationId,
15286
- encryptedTitle: conversation.title,
15287
- projectId: conversation.projectId,
15288
- createdAt: conversation.createdAt,
15289
- updatedAt: conversation.updatedAt,
15290
- isDeleted: conversation.isDeleted,
15291
- pinnedAt: conversation.pinnedAt
15396
+ uniqueId: raw.id,
15397
+ conversationId: raw.conversation_id ?? "",
15398
+ encryptedTitle: raw.title ?? "",
15399
+ projectId: raw.project_id,
15400
+ createdAt: rawDate(raw.created_at),
15401
+ updatedAt: rawDate(raw.updated_at),
15402
+ isDeleted: raw.is_deleted === true || raw.is_deleted === 1,
15403
+ pinnedAt: typeof pinnedAt === "number" ? new Date(pinnedAt) : null
15292
15404
  };
15293
15405
  }
15294
15406
  async function getConversationsLazyOp(ctx) {
15295
- const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).fetch();
15296
- return results.map(conversationToLazyStored);
15407
+ const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("is_deleted", false), import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)).unsafeFetchRaw();
15408
+ return results.map(conversationRawToLazyStored);
15409
+ }
15410
+ async function getConversationsPageOp(ctx, options) {
15411
+ const limit = Math.floor(options?.limit ?? 200);
15412
+ if (!Number.isFinite(limit) || limit < 1) return [];
15413
+ const exclude = new Set(options?.boundaryExcludeUniqueIds ?? []);
15414
+ const clauses = [import_watermelondb.Q.where("is_deleted", false)];
15415
+ if (options?.before !== void 0) {
15416
+ clauses.push(
15417
+ 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))
15418
+ );
15419
+ }
15420
+ 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();
15421
+ const results = exclude.size > 0 ? fetched.filter((raw) => !exclude.has(raw.id)) : fetched;
15422
+ return results.slice(0, limit).map(conversationRawToLazyStored);
15297
15423
  }
15298
15424
  async function getConversationsByProjectLazyOp(ctx, projectId) {
15299
15425
  const results = await ctx.conversationsCollection.query(
15300
15426
  import_watermelondb.Q.where("project_id", projectId === null ? "" : projectId),
15301
15427
  import_watermelondb.Q.where("is_deleted", false),
15302
15428
  import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)
15303
- ).fetch();
15304
- return results.map(conversationToLazyStored);
15429
+ ).unsafeFetchRaw();
15430
+ return results.map(conversationRawToLazyStored);
15305
15431
  }
15306
15432
  async function updateConversationTitleOp(ctx, id, title) {
15307
15433
  const results = await ctx.conversationsCollection.query(import_watermelondb.Q.where("conversation_id", id), import_watermelondb.Q.where("is_deleted", false)).fetch();
@@ -15351,18 +15477,18 @@ async function getConversationsByProjectOp(ctx, projectId) {
15351
15477
  import_watermelondb.Q.where("project_id", projectId === null ? "" : projectId),
15352
15478
  import_watermelondb.Q.where("is_deleted", false),
15353
15479
  import_watermelondb.Q.sortBy("created_at", import_watermelondb.Q.desc)
15354
- ).fetch();
15480
+ ).unsafeFetchRaw();
15355
15481
  return Promise.all(
15356
15482
  results.map(
15357
- (conv) => conversationToStored(conv, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15483
+ (raw) => conversationRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15358
15484
  )
15359
15485
  );
15360
15486
  }
15361
15487
  async function getMessagesOp(ctx, convId) {
15362
- const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).fetch();
15488
+ const results = await ctx.messagesCollection.query(import_watermelondb.Q.where("conversation_id", convId), import_watermelondb.Q.sortBy("message_id", import_watermelondb.Q.asc)).unsafeFetchRaw();
15363
15489
  return Promise.all(
15364
15490
  results.map(
15365
- (msg) => messageToStored(msg, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15491
+ (raw) => messageRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
15366
15492
  )
15367
15493
  );
15368
15494
  }
@@ -17640,7 +17766,7 @@ async function generateEmbedding(text, options) {
17640
17766
  const { baseUrl = BASE_URL, getToken, apiKey, model, cache } = options;
17641
17767
  if (cache) {
17642
17768
  const cached = cache.get(text);
17643
- if (cached) return cached;
17769
+ if (cached) return Array.from(cached);
17644
17770
  }
17645
17771
  let headers;
17646
17772
  if (apiKey) {
@@ -17679,10 +17805,11 @@ async function generateEmbedding(text, options) {
17679
17805
  totalTokens: response.data.usage.total_tokens ?? 0
17680
17806
  });
17681
17807
  }
17808
+ const f32Embedding = Float32Array.from(embedding);
17682
17809
  if (cache) {
17683
- cache.set(text, embedding);
17810
+ cache.set(text, f32Embedding);
17684
17811
  }
17685
- return embedding;
17812
+ return Array.from(f32Embedding);
17686
17813
  }
17687
17814
  var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
17688
17815
  var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
@@ -17720,7 +17847,7 @@ async function generateEmbeddings(texts, options) {
17720
17847
  if (cache) {
17721
17848
  const cached = cache.get(texts[i]);
17722
17849
  if (cached) {
17723
- results[i] = cached;
17850
+ results[i] = Array.from(cached);
17724
17851
  continue;
17725
17852
  }
17726
17853
  }
@@ -17781,9 +17908,10 @@ async function generateEmbeddings(texts, options) {
17781
17908
  newEmbeddings = allEmbeddings.flat();
17782
17909
  }
17783
17910
  for (let i = 0; i < uncachedIndices.length; i++) {
17784
- results[uncachedIndices[i]] = newEmbeddings[i];
17911
+ const f32Embedding = Float32Array.from(newEmbeddings[i]);
17912
+ results[uncachedIndices[i]] = Array.from(f32Embedding);
17785
17913
  if (cache) {
17786
- cache.set(uncachedTexts[i], newEmbeddings[i]);
17914
+ cache.set(uncachedTexts[i], f32Embedding);
17787
17915
  }
17788
17916
  }
17789
17917
  return results;
@@ -19207,7 +19335,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
19207
19335
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
19208
19336
  );
19209
19337
  }
19210
- const { recall: recall2 } = await import("./recall-CQT24XLH.mjs");
19338
+ const { recall: recall2 } = await import("./recall-6QLUEYB7.mjs");
19211
19339
  const result = await recall2(
19212
19340
  query,
19213
19341
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -19847,8 +19975,10 @@ export {
19847
19975
  clearAllEncryptionKeys,
19848
19976
  getEncryptionKey,
19849
19977
  encryptData,
19978
+ encryptDataBytes,
19850
19979
  decryptData,
19851
19980
  decryptDataBytes,
19981
+ decryptDataBytesFromBytes,
19852
19982
  hasEncryptionKey,
19853
19983
  encryptDataWithKey,
19854
19984
  decryptDataWithKey,
@@ -19873,6 +20003,7 @@ export {
19873
20003
  getConversationOp,
19874
20004
  getConversationsOp,
19875
20005
  getConversationsLazyOp,
20006
+ getConversationsPageOp,
19876
20007
  getConversationsByProjectLazyOp,
19877
20008
  updateConversationTitleOp,
19878
20009
  deleteConversationOp,