bedrock-ts-sdk 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -188,24 +188,27 @@ var FileMetaEncryptedSchema = import_zod.z.object({
188
188
  // Encrypted filename
189
189
  path: import_zod.z.string(),
190
190
  // Encrypted path
191
- key: HexString64Schema,
192
- // Encrypted AES key
193
- iv: HexString32Schema,
194
- // Encrypted IV
195
- store_hash: HexString64Schema,
196
- // Aleph STORE hash
191
+ key: import_zod.z.string(),
192
+ // Encrypted AES key (ECIES encrypted)
193
+ iv: import_zod.z.string(),
194
+ // Encrypted IV (ECIES encrypted)
195
+ store_hash: import_zod.z.string(),
196
+ // Encrypted Aleph STORE hash
197
197
  size: import_zod.z.string(),
198
198
  // Encrypted size
199
199
  created_at: import_zod.z.string(),
200
200
  // Encrypted datetime
201
201
  deleted_at: import_zod.z.string().nullable(),
202
202
  // Encrypted datetime or null
203
- shared_keys: import_zod.z.record(import_zod.z.string(), import_zod.z.object({
204
- key: import_zod.z.string(),
205
- // Encrypted key for recipient
206
- iv: import_zod.z.string()
207
- // Encrypted IV for recipient
208
- })).default({})
203
+ shared_keys: import_zod.z.record(
204
+ import_zod.z.string(),
205
+ import_zod.z.object({
206
+ key: import_zod.z.string(),
207
+ // Encrypted key for recipient
208
+ iv: import_zod.z.string()
209
+ // Encrypted IV for recipient
210
+ })
211
+ ).default({})
209
212
  });
210
213
  var FileMetaSchema = import_zod.z.object({
211
214
  name: import_zod.z.string(),
@@ -216,10 +219,13 @@ var FileMetaSchema = import_zod.z.object({
216
219
  size: import_zod.z.number(),
217
220
  created_at: DatetimeSchema,
218
221
  deleted_at: DatetimeSchema.nullable(),
219
- shared_keys: import_zod.z.record(import_zod.z.string(), import_zod.z.object({
220
- key: HexString64Schema,
221
- iv: HexString32Schema
222
- })).default({})
222
+ shared_keys: import_zod.z.record(
223
+ import_zod.z.string(),
224
+ import_zod.z.object({
225
+ key: HexString64Schema,
226
+ iv: HexString32Schema
227
+ })
228
+ ).default({})
223
229
  });
224
230
  var PublicFileMetaSchema = import_zod.z.object({
225
231
  name: import_zod.z.string(),
@@ -264,13 +270,15 @@ var FileEntriesAggregateSchema = import_zod.z.object({
264
270
  files: import_zod.z.array(FileEntrySchema).default([])
265
271
  });
266
272
  var SecurityAggregateSchema = import_zod.z.object({
267
- authorizations: import_zod.z.array(import_zod.z.object({
268
- address: AddressSchema,
269
- chain: import_zod.z.string(),
270
- channels: import_zod.z.array(import_zod.z.string()).optional(),
271
- post_types: import_zod.z.array(import_zod.z.string()).optional(),
272
- aggregate_keys: import_zod.z.array(import_zod.z.string()).optional()
273
- }))
273
+ authorizations: import_zod.z.array(
274
+ import_zod.z.object({
275
+ address: AddressSchema,
276
+ chain: import_zod.z.string(),
277
+ channels: import_zod.z.array(import_zod.z.string()).optional(),
278
+ post_types: import_zod.z.array(import_zod.z.string()).optional(),
279
+ aggregate_keys: import_zod.z.array(import_zod.z.string()).optional()
280
+ })
281
+ )
274
282
  });
275
283
 
276
284
  // src/client/aleph-service.ts
@@ -883,68 +891,28 @@ var EncryptionService = class {
883
891
  // ============================================================================
884
892
  static async encryptBrowser(data, key, iv) {
885
893
  const crypto = CryptoUtils.getCrypto();
886
- const cryptoKey = await crypto.subtle.importKey(
887
- "raw",
888
- key,
889
- { name: "AES-CBC" },
890
- false,
891
- ["encrypt"]
892
- );
894
+ const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
893
895
  const dataBuffer = Buffer.from(data, "utf-8");
894
- const encrypted = await crypto.subtle.encrypt(
895
- { name: "AES-CBC", iv },
896
- cryptoKey,
897
- dataBuffer
898
- );
896
+ const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, dataBuffer);
899
897
  return CryptoUtils.bufferToHex(Buffer.from(encrypted));
900
898
  }
901
899
  static async decryptBrowser(encryptedData, key, iv) {
902
900
  const crypto = CryptoUtils.getCrypto();
903
- const cryptoKey = await crypto.subtle.importKey(
904
- "raw",
905
- key,
906
- { name: "AES-CBC" },
907
- false,
908
- ["decrypt"]
909
- );
901
+ const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
910
902
  const encryptedBuffer = CryptoUtils.hexToBuffer(encryptedData);
911
- const decrypted = await crypto.subtle.decrypt(
912
- { name: "AES-CBC", iv },
913
- cryptoKey,
914
- encryptedBuffer
915
- );
903
+ const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, encryptedBuffer);
916
904
  return Buffer.from(decrypted).toString("utf-8");
917
905
  }
918
906
  static async encryptFileBrowser(buffer, key, iv) {
919
907
  const crypto = CryptoUtils.getCrypto();
920
- const cryptoKey = await crypto.subtle.importKey(
921
- "raw",
922
- key,
923
- { name: "AES-CBC" },
924
- false,
925
- ["encrypt"]
926
- );
927
- const encrypted = await crypto.subtle.encrypt(
928
- { name: "AES-CBC", iv },
929
- cryptoKey,
930
- buffer
931
- );
908
+ const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["encrypt"]);
909
+ const encrypted = await crypto.subtle.encrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
932
910
  return Buffer.from(encrypted);
933
911
  }
934
912
  static async decryptFileBrowser(buffer, key, iv) {
935
913
  const crypto = CryptoUtils.getCrypto();
936
- const cryptoKey = await crypto.subtle.importKey(
937
- "raw",
938
- key,
939
- { name: "AES-CBC" },
940
- false,
941
- ["decrypt"]
942
- );
943
- const decrypted = await crypto.subtle.decrypt(
944
- { name: "AES-CBC", iv },
945
- cryptoKey,
946
- buffer
947
- );
914
+ const cryptoKey = await crypto.subtle.importKey("raw", key, { name: "AES-CBC" }, false, ["decrypt"]);
915
+ const decrypted = await crypto.subtle.decrypt({ name: "AES-CBC", iv }, cryptoKey, buffer);
948
916
  return Buffer.from(decrypted);
949
917
  }
950
918
  };
@@ -960,10 +928,7 @@ var FileService = class {
960
928
  async setup() {
961
929
  const aleph = this.core.getAlephService();
962
930
  try {
963
- await aleph.fetchAggregate(
964
- AGGREGATE_KEYS.FILE_ENTRIES,
965
- FileEntriesAggregateSchema
966
- );
931
+ await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
967
932
  } catch {
968
933
  await aleph.createAggregate(AGGREGATE_KEYS.FILE_ENTRIES, { files: [] });
969
934
  }
@@ -1044,10 +1009,7 @@ var FileService = class {
1044
1009
  const aleph = this.core.getAlephService();
1045
1010
  const privateKey = this.core.getSubAccountPrivateKey();
1046
1011
  try {
1047
- const aggregate = await aleph.fetchAggregate(
1048
- AGGREGATE_KEYS.FILE_ENTRIES,
1049
- FileEntriesAggregateSchema
1050
- );
1012
+ const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema);
1051
1013
  return aggregate.files.map(({ post_hash, path, shared_with }) => ({
1052
1014
  post_hash,
1053
1015
  path: EncryptionService.decryptEcies(path, privateKey),
@@ -1174,15 +1136,9 @@ var FileService = class {
1174
1136
  const aleph = this.core.getAlephService();
1175
1137
  try {
1176
1138
  const files = await Promise.all(filePaths.map((path) => this.getFile(path)));
1177
- await aleph.updateAggregate(
1178
- AGGREGATE_KEYS.FILE_ENTRIES,
1179
- FileEntriesAggregateSchema,
1180
- async (aggregate) => ({
1181
- files: aggregate.files.filter(
1182
- (entry) => !files.some((f) => f.post_hash === entry.post_hash)
1183
- )
1184
- })
1185
- );
1139
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
1140
+ files: aggregate.files.filter((entry) => !files.some((f) => f.post_hash === entry.post_hash))
1141
+ }));
1186
1142
  const hashesToForget = files.flatMap((f) => [f.store_hash, f.post_hash]);
1187
1143
  await aleph.deleteFiles(hashesToForget);
1188
1144
  } catch (error) {
@@ -1212,15 +1168,11 @@ var FileService = class {
1212
1168
  }
1213
1169
  );
1214
1170
  const newEncryptedPath = EncryptionService.encryptEcies(newPath, publicKey);
1215
- await aleph.updateAggregate(
1216
- AGGREGATE_KEYS.FILE_ENTRIES,
1217
- FileEntriesAggregateSchema,
1218
- async (aggregate) => ({
1219
- files: aggregate.files.map(
1220
- (entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
1221
- )
1222
- })
1223
- );
1171
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
1172
+ files: aggregate.files.map(
1173
+ (entry) => entry.post_hash === file.post_hash ? { ...entry, path: newEncryptedPath } : entry
1174
+ )
1175
+ }));
1224
1176
  }
1225
1177
  } catch (error) {
1226
1178
  throw new FileError(`Failed to move files: ${error.message}`);
@@ -1235,11 +1187,13 @@ var FileService = class {
1235
1187
  try {
1236
1188
  const sourceFile = await this.getFile(sourcePath);
1237
1189
  const content = await this.downloadFile(sourceFile);
1238
- const [newFile] = await this.uploadFiles([{
1239
- name: newPath.split("/").pop() || newPath,
1240
- path: newPath,
1241
- content
1242
- }]);
1190
+ const [newFile] = await this.uploadFiles([
1191
+ {
1192
+ name: newPath.split("/").pop() || newPath,
1193
+ path: newPath,
1194
+ content
1195
+ }
1196
+ ]);
1243
1197
  return newFile;
1244
1198
  } catch (error) {
1245
1199
  throw new FileError(`Failed to duplicate file: ${error.message}`);
@@ -1270,15 +1224,11 @@ var FileService = class {
1270
1224
  return await this.encryptFileMeta(decryptedMeta);
1271
1225
  }
1272
1226
  );
1273
- await aleph.updateAggregate(
1274
- AGGREGATE_KEYS.FILE_ENTRIES,
1275
- FileEntriesAggregateSchema,
1276
- async (aggregate) => ({
1277
- files: aggregate.files.map(
1278
- (entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
1279
- )
1280
- })
1281
- );
1227
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
1228
+ files: aggregate.files.map(
1229
+ (entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: [.../* @__PURE__ */ new Set([...entry.shared_with, contactPublicKey])] } : entry
1230
+ )
1231
+ }));
1282
1232
  } catch (error) {
1283
1233
  throw new FileError(`Failed to share file: ${error.message}`);
1284
1234
  }
@@ -1303,15 +1253,11 @@ var FileService = class {
1303
1253
  return await this.encryptFileMeta(decryptedMeta);
1304
1254
  }
1305
1255
  );
1306
- await aleph.updateAggregate(
1307
- AGGREGATE_KEYS.FILE_ENTRIES,
1308
- FileEntriesAggregateSchema,
1309
- async (aggregate) => ({
1310
- files: aggregate.files.map(
1311
- (entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
1312
- )
1313
- })
1314
- );
1256
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => ({
1257
+ files: aggregate.files.map(
1258
+ (entry) => entry.post_hash === file.post_hash ? { ...entry, shared_with: entry.shared_with.filter((pk) => pk !== contactPublicKey) } : entry
1259
+ )
1260
+ }));
1315
1261
  } catch (error) {
1316
1262
  throw new FileError(`Failed to unshare file: ${error.message}`);
1317
1263
  }
@@ -1377,40 +1323,32 @@ var FileService = class {
1377
1323
  async saveFileEntries(files) {
1378
1324
  const aleph = this.core.getAlephService();
1379
1325
  const publicKey = this.core.getPublicKey();
1380
- await aleph.updateAggregate(
1381
- AGGREGATE_KEYS.FILE_ENTRIES,
1382
- FileEntriesAggregateSchema,
1383
- async (aggregate) => {
1384
- const newEntries = files.map((f) => ({
1385
- path: EncryptionService.encryptEcies(f.path, publicKey),
1386
- post_hash: f.post_hash,
1387
- shared_with: f.shared_with || []
1388
- }));
1389
- return { files: [...aggregate.files, ...newEntries] };
1390
- }
1391
- );
1326
+ await aleph.updateAggregate(AGGREGATE_KEYS.FILE_ENTRIES, FileEntriesAggregateSchema, async (aggregate) => {
1327
+ const newEntries = files.map((f) => ({
1328
+ path: EncryptionService.encryptEcies(f.path, publicKey),
1329
+ post_hash: f.post_hash,
1330
+ shared_with: f.shared_with || []
1331
+ }));
1332
+ return { files: [...aggregate.files, ...newEntries] };
1333
+ });
1392
1334
  }
1393
1335
  async encryptFileMeta(meta) {
1394
- const key = this.core.getEncryptionKey();
1395
- const iv = EncryptionService.generateIv();
1396
1336
  const publicKey = this.core.getPublicKey();
1397
1337
  const fileKey = Buffer.from(meta.key, "hex");
1398
1338
  const fileIv = Buffer.from(meta.iv, "hex");
1399
1339
  return {
1400
- name: await EncryptionService.encrypt(meta.name, key, iv),
1340
+ name: await EncryptionService.encrypt(meta.name, fileKey, fileIv),
1401
1341
  path: await EncryptionService.encrypt(meta.path, fileKey, fileIv),
1402
1342
  key: EncryptionService.encryptEcies(meta.key, publicKey),
1403
1343
  iv: EncryptionService.encryptEcies(meta.iv, publicKey),
1404
1344
  store_hash: await EncryptionService.encrypt(meta.store_hash, fileKey, fileIv),
1405
- size: await EncryptionService.encrypt(meta.size.toString(), key, iv),
1406
- created_at: await EncryptionService.encrypt(meta.created_at, key, iv),
1345
+ size: await EncryptionService.encrypt(meta.size.toString(), fileKey, fileIv),
1346
+ created_at: await EncryptionService.encrypt(meta.created_at, fileKey, fileIv),
1407
1347
  deleted_at: await EncryptionService.encrypt(meta.deleted_at ?? "null", fileKey, fileIv),
1408
1348
  shared_keys: meta.shared_keys
1409
1349
  };
1410
1350
  }
1411
1351
  async decryptFileMeta(encryptedMeta, privateKey) {
1412
- const key = this.core.getEncryptionKey();
1413
- const iv = EncryptionService.generateIv();
1414
1352
  const privKey = privateKey || this.core.getSubAccountPrivateKey();
1415
1353
  if (!privKey) {
1416
1354
  throw new EncryptionError("Private key not available");
@@ -1421,13 +1359,13 @@ var FileService = class {
1421
1359
  const fileIv = Buffer.from(decryptedIv, "hex");
1422
1360
  const decryptedDeletedAt = await EncryptionService.decrypt(encryptedMeta.deleted_at, fileKey, fileIv);
1423
1361
  return {
1424
- name: await EncryptionService.decrypt(encryptedMeta.name, key, iv),
1362
+ name: await EncryptionService.decrypt(encryptedMeta.name, fileKey, fileIv),
1425
1363
  path: await EncryptionService.decrypt(encryptedMeta.path, fileKey, fileIv),
1426
1364
  key: decryptedKey,
1427
1365
  iv: decryptedIv,
1428
1366
  store_hash: await EncryptionService.decrypt(encryptedMeta.store_hash, fileKey, fileIv),
1429
- size: parseInt(await EncryptionService.decrypt(encryptedMeta.size, key, iv)),
1430
- created_at: await EncryptionService.decrypt(encryptedMeta.created_at, key, iv),
1367
+ size: Number.parseInt(await EncryptionService.decrypt(encryptedMeta.size, fileKey, fileIv)),
1368
+ created_at: await EncryptionService.decrypt(encryptedMeta.created_at, fileKey, fileIv),
1431
1369
  deleted_at: decryptedDeletedAt === "null" ? null : decryptedDeletedAt,
1432
1370
  shared_keys: encryptedMeta.shared_keys || {}
1433
1371
  };
@@ -1446,10 +1384,7 @@ var ContactService = class {
1446
1384
  async setup() {
1447
1385
  const aleph = this.core.getAlephService();
1448
1386
  try {
1449
- await aleph.fetchAggregate(
1450
- AGGREGATE_KEYS.CONTACTS,
1451
- ContactsAggregateSchema
1452
- );
1387
+ await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
1453
1388
  } catch {
1454
1389
  await aleph.createAggregate(AGGREGATE_KEYS.CONTACTS, { contacts: [] });
1455
1390
  }
@@ -1460,10 +1395,7 @@ var ContactService = class {
1460
1395
  async listContacts() {
1461
1396
  const aleph = this.core.getAlephService();
1462
1397
  try {
1463
- const aggregate = await aleph.fetchAggregate(
1464
- AGGREGATE_KEYS.CONTACTS,
1465
- ContactsAggregateSchema
1466
- );
1398
+ const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema);
1467
1399
  return aggregate.contacts;
1468
1400
  } catch (error) {
1469
1401
  throw new ContactError(`Failed to fetch contacts: ${error.message}`);
@@ -1514,13 +1446,9 @@ var ContactService = class {
1514
1446
  address,
1515
1447
  public_key: publicKey
1516
1448
  };
1517
- await aleph.updateAggregate(
1518
- AGGREGATE_KEYS.CONTACTS,
1519
- ContactsAggregateSchema,
1520
- async (aggregate) => ({
1521
- contacts: [...aggregate.contacts, newContact]
1522
- })
1523
- );
1449
+ await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
1450
+ contacts: [...aggregate.contacts, newContact]
1451
+ }));
1524
1452
  return newContact;
1525
1453
  } catch (error) {
1526
1454
  if (error instanceof ContactError) {
@@ -1537,13 +1465,9 @@ var ContactService = class {
1537
1465
  const aleph = this.core.getAlephService();
1538
1466
  try {
1539
1467
  await this.getContact(publicKey);
1540
- await aleph.updateAggregate(
1541
- AGGREGATE_KEYS.CONTACTS,
1542
- ContactsAggregateSchema,
1543
- async (aggregate) => ({
1544
- contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
1545
- })
1546
- );
1468
+ await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
1469
+ contacts: aggregate.contacts.filter((c) => c.public_key !== publicKey)
1470
+ }));
1547
1471
  } catch (error) {
1548
1472
  if (error instanceof ContactError) {
1549
1473
  throw error;
@@ -1564,15 +1488,9 @@ var ContactService = class {
1564
1488
  ...existingContact,
1565
1489
  name: newName
1566
1490
  };
1567
- await aleph.updateAggregate(
1568
- AGGREGATE_KEYS.CONTACTS,
1569
- ContactsAggregateSchema,
1570
- async (aggregate) => ({
1571
- contacts: aggregate.contacts.map(
1572
- (c) => c.public_key === publicKey ? updatedContact : c
1573
- )
1574
- })
1575
- );
1491
+ await aleph.updateAggregate(AGGREGATE_KEYS.CONTACTS, ContactsAggregateSchema, async (aggregate) => ({
1492
+ contacts: aggregate.contacts.map((c) => c.public_key === publicKey ? updatedContact : c)
1493
+ }));
1576
1494
  return updatedContact;
1577
1495
  } catch (error) {
1578
1496
  if (error instanceof ContactError) {
@@ -1589,9 +1507,7 @@ var ContactService = class {
1589
1507
  try {
1590
1508
  await this.getContact(publicKey);
1591
1509
  const entries = await this.fileService.fetchFileEntries();
1592
- const sharedEntries = entries.filter(
1593
- (entry) => entry.shared_with.includes(publicKey)
1594
- );
1510
+ const sharedEntries = entries.filter((entry) => entry.shared_with.includes(publicKey));
1595
1511
  const files = await this.fileService.fetchFilesMetaFromEntries(sharedEntries);
1596
1512
  return files;
1597
1513
  } catch (error) {
@@ -1614,9 +1530,7 @@ var ContactService = class {
1614
1530
  contact.address
1615
1531
  // Important: contact's address, not current user's
1616
1532
  );
1617
- const sharedEntries = contactEntries.files.filter(
1618
- (entry) => entry.shared_with.includes(currentUserPublicKey)
1619
- );
1533
+ const sharedEntries = contactEntries.files.filter((entry) => entry.shared_with.includes(currentUserPublicKey));
1620
1534
  const files = await this.fileService.fetchFilesMetaFromEntries(
1621
1535
  sharedEntries,
1622
1536
  contact.address
@@ -1666,10 +1580,7 @@ var KnowledgeBaseService = class {
1666
1580
  async setup() {
1667
1581
  const aleph = this.core.getAlephService();
1668
1582
  try {
1669
- await aleph.fetchAggregate(
1670
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1671
- KnowledgeBasesAggregateSchema
1672
- );
1583
+ await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
1673
1584
  } catch {
1674
1585
  await aleph.createAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, { knowledge_bases: [] });
1675
1586
  }
@@ -1680,10 +1591,7 @@ var KnowledgeBaseService = class {
1680
1591
  async listKnowledgeBases() {
1681
1592
  const aleph = this.core.getAlephService();
1682
1593
  try {
1683
- const aggregate = await aleph.fetchAggregate(
1684
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1685
- KnowledgeBasesAggregateSchema
1686
- );
1594
+ const aggregate = await aleph.fetchAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema);
1687
1595
  return aggregate.knowledge_bases;
1688
1596
  } catch (error) {
1689
1597
  throw new KnowledgeBaseError(`Failed to fetch knowledge bases: ${error.message}`);
@@ -1721,13 +1629,9 @@ var KnowledgeBaseService = class {
1721
1629
  created_at: now,
1722
1630
  updated_at: now
1723
1631
  };
1724
- await aleph.updateAggregate(
1725
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1726
- KnowledgeBasesAggregateSchema,
1727
- async (aggregate) => ({
1728
- knowledge_bases: [...aggregate.knowledge_bases, newKb]
1729
- })
1730
- );
1632
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1633
+ knowledge_bases: [...aggregate.knowledge_bases, newKb]
1634
+ }));
1731
1635
  return newKb;
1732
1636
  } catch (error) {
1733
1637
  if (error instanceof KnowledgeBaseError) {
@@ -1744,13 +1648,9 @@ var KnowledgeBaseService = class {
1744
1648
  const aleph = this.core.getAlephService();
1745
1649
  try {
1746
1650
  await this.getKnowledgeBase(name);
1747
- await aleph.updateAggregate(
1748
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1749
- KnowledgeBasesAggregateSchema,
1750
- async (aggregate) => ({
1751
- knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
1752
- })
1753
- );
1651
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1652
+ knowledge_bases: aggregate.knowledge_bases.filter((k) => k.name !== name)
1653
+ }));
1754
1654
  } catch (error) {
1755
1655
  if (error instanceof KnowledgeBaseError) {
1756
1656
  throw error;
@@ -1776,15 +1676,9 @@ var KnowledgeBaseService = class {
1776
1676
  name: newName,
1777
1677
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1778
1678
  };
1779
- await aleph.updateAggregate(
1780
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1781
- KnowledgeBasesAggregateSchema,
1782
- async (aggregate) => ({
1783
- knowledge_bases: aggregate.knowledge_bases.map(
1784
- (k) => k.name === oldName ? updatedKb : k
1785
- )
1786
- })
1787
- );
1679
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1680
+ knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === oldName ? updatedKb : k)
1681
+ }));
1788
1682
  return updatedKb;
1789
1683
  } catch (error) {
1790
1684
  if (error instanceof KnowledgeBaseError) {
@@ -1807,15 +1701,9 @@ var KnowledgeBaseService = class {
1807
1701
  file_paths: filePaths,
1808
1702
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1809
1703
  };
1810
- await aleph.updateAggregate(
1811
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1812
- KnowledgeBasesAggregateSchema,
1813
- async (aggregate) => ({
1814
- knowledge_bases: aggregate.knowledge_bases.map(
1815
- (k) => k.name === name ? updatedKb : k
1816
- )
1817
- })
1818
- );
1704
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1705
+ knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
1706
+ }));
1819
1707
  return updatedKb;
1820
1708
  } catch (error) {
1821
1709
  if (error instanceof KnowledgeBaseError) {
@@ -1839,15 +1727,9 @@ var KnowledgeBaseService = class {
1839
1727
  file_paths: updatedFilePaths,
1840
1728
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1841
1729
  };
1842
- await aleph.updateAggregate(
1843
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1844
- KnowledgeBasesAggregateSchema,
1845
- async (aggregate) => ({
1846
- knowledge_bases: aggregate.knowledge_bases.map(
1847
- (k) => k.name === name ? updatedKb : k
1848
- )
1849
- })
1850
- );
1730
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1731
+ knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
1732
+ }));
1851
1733
  return updatedKb;
1852
1734
  } catch (error) {
1853
1735
  if (error instanceof KnowledgeBaseError) {
@@ -1865,23 +1747,15 @@ var KnowledgeBaseService = class {
1865
1747
  const aleph = this.core.getAlephService();
1866
1748
  try {
1867
1749
  const existingKb = await this.getKnowledgeBase(name);
1868
- const updatedFilePaths = existingKb.file_paths.filter(
1869
- (path) => !filePaths.includes(path)
1870
- );
1750
+ const updatedFilePaths = existingKb.file_paths.filter((path) => !filePaths.includes(path));
1871
1751
  const updatedKb = {
1872
1752
  ...existingKb,
1873
1753
  file_paths: updatedFilePaths,
1874
1754
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
1875
1755
  };
1876
- await aleph.updateAggregate(
1877
- AGGREGATE_KEYS.KNOWLEDGE_BASES,
1878
- KnowledgeBasesAggregateSchema,
1879
- async (aggregate) => ({
1880
- knowledge_bases: aggregate.knowledge_bases.map(
1881
- (k) => k.name === name ? updatedKb : k
1882
- )
1883
- })
1884
- );
1756
+ await aleph.updateAggregate(AGGREGATE_KEYS.KNOWLEDGE_BASES, KnowledgeBasesAggregateSchema, async (aggregate) => ({
1757
+ knowledge_bases: aggregate.knowledge_bases.map((k) => k.name === name ? updatedKb : k)
1758
+ }));
1885
1759
  return updatedKb;
1886
1760
  } catch (error) {
1887
1761
  if (error instanceof KnowledgeBaseError) {
@@ -2020,11 +1894,7 @@ var BedrockClient = class _BedrockClient {
2020
1894
  * WARNING: This will delete all user data from Aleph
2021
1895
  */
2022
1896
  async resetAllData() {
2023
- await Promise.all([
2024
- this.resetFiles(),
2025
- this.resetContacts(),
2026
- this.resetKnowledgeBases()
2027
- ]);
1897
+ await Promise.all([this.resetFiles(), this.resetContacts(), this.resetKnowledgeBases()]);
2028
1898
  }
2029
1899
  /**
2030
1900
  * Reset all files
@@ -2057,11 +1927,7 @@ var BedrockClient = class _BedrockClient {
2057
1927
  * Setup all services (create aggregates if they don't exist)
2058
1928
  */
2059
1929
  async setup() {
2060
- await Promise.all([
2061
- this.files.setup(),
2062
- this.contacts.setup(),
2063
- this.knowledgeBases.setup()
2064
- ]);
1930
+ await Promise.all([this.files.setup(), this.contacts.setup(), this.knowledgeBases.setup()]);
2065
1931
  }
2066
1932
  };
2067
1933