@absolutejs/absolute 0.19.0-beta.500 → 0.19.0-beta.502

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/ai/index.js CHANGED
@@ -7186,6 +7186,7 @@ var resolveRAGStreamStage = ({
7186
7186
  return "streaming";
7187
7187
  };
7188
7188
  // src/ai/rag/sync.ts
7189
+ var {S3Client } = globalThis.Bun;
7189
7190
  import { createHash } from "crypto";
7190
7191
  import { mkdir, readFile as readFile2, writeFile } from "fs/promises";
7191
7192
  import { dirname, resolve as resolve2 } from "path";
@@ -7216,6 +7217,23 @@ var toManagedSyncDocument = (sourceId, document, syncKey) => ({
7216
7217
  syncSourceId: sourceId
7217
7218
  }
7218
7219
  });
7220
+ var encodeAttachmentContent = (attachment) => typeof attachment.content === "string" ? {
7221
+ content: attachment.content,
7222
+ encoding: attachment.encoding ?? "utf8"
7223
+ } : {
7224
+ content: Buffer.from(attachment.content).toString("base64"),
7225
+ encoding: "base64"
7226
+ };
7227
+ var toTimestamp = (value) => {
7228
+ if (typeof value === "number" && Number.isFinite(value)) {
7229
+ return value;
7230
+ }
7231
+ if (typeof value === "string" || value instanceof Date) {
7232
+ const parsed = new Date(value).getTime();
7233
+ return Number.isFinite(parsed) ? parsed : undefined;
7234
+ }
7235
+ return;
7236
+ };
7219
7237
  var isManagedBySyncSource = (document, sourceId) => document.metadata?.syncSourceId === sourceId;
7220
7238
  var getDocumentSyncFingerprint = (document) => typeof document.metadata?.syncFingerprint === "string" ? document.metadata.syncFingerprint : undefined;
7221
7239
  var reconcileManagedDocuments = async (input) => {
@@ -7337,6 +7355,199 @@ var createRAGUrlSyncSource = (options) => ({
7337
7355
  };
7338
7356
  }
7339
7357
  });
7358
+ var createRAGBunS3SyncClient = (input) => {
7359
+ const client = input instanceof S3Client ? input : new S3Client(input);
7360
+ return {
7361
+ file: (key) => client.file(key),
7362
+ list: async (options) => {
7363
+ const result = await client.list({
7364
+ maxKeys: options?.maxKeys,
7365
+ prefix: options?.prefix,
7366
+ startAfter: options?.startAfter
7367
+ });
7368
+ return {
7369
+ contents: (result.contents ?? []).map((entry) => ({
7370
+ etag: entry.eTag,
7371
+ key: entry.key,
7372
+ lastModified: entry.lastModified,
7373
+ size: entry.size
7374
+ })),
7375
+ isTruncated: result.isTruncated,
7376
+ nextContinuationToken: result.nextContinuationToken
7377
+ };
7378
+ }
7379
+ };
7380
+ };
7381
+ var createRAGStorageSyncSource = (options) => ({
7382
+ description: options.description,
7383
+ id: options.id,
7384
+ kind: "storage",
7385
+ label: options.label,
7386
+ metadata: options.metadata,
7387
+ retryAttempts: options.retryAttempts,
7388
+ retryDelayMs: options.retryDelayMs,
7389
+ target: options.keys?.length ? `${options.keys.length} object${options.keys.length === 1 ? "" : "s"}` : options.prefix ?? "storage://",
7390
+ sync: async ({ collection, deleteDocument, listDocuments }) => {
7391
+ const keys = options.keys && options.keys.length > 0 ? options.keys : await (async () => {
7392
+ const listed = [];
7393
+ let startAfter;
7394
+ let remaining = options.maxKeys;
7395
+ for (;; ) {
7396
+ const response = await options.client.list({
7397
+ maxKeys: typeof remaining === "number" ? Math.max(1, remaining) : undefined,
7398
+ prefix: options.prefix,
7399
+ startAfter
7400
+ });
7401
+ for (const entry of response.contents) {
7402
+ listed.push(entry.key);
7403
+ startAfter = entry.key;
7404
+ if (typeof remaining === "number" && listed.length >= remaining) {
7405
+ return listed;
7406
+ }
7407
+ }
7408
+ if (!response.isTruncated || response.contents.length === 0) {
7409
+ return listed;
7410
+ }
7411
+ if (typeof remaining === "number") {
7412
+ remaining -= response.contents.length;
7413
+ if (remaining <= 0) {
7414
+ return listed;
7415
+ }
7416
+ }
7417
+ }
7418
+ })();
7419
+ const uploads = await Promise.all(keys.map(async (key) => {
7420
+ const object = options.client.file(key);
7421
+ const bytes = new Uint8Array(await object.arrayBuffer());
7422
+ return {
7423
+ chunking: options.defaultChunking,
7424
+ content: Buffer.from(bytes).toString("base64"),
7425
+ contentType: undefined,
7426
+ encoding: "base64",
7427
+ metadata: {
7428
+ ...options.baseMetadata ?? {},
7429
+ storageKey: key
7430
+ },
7431
+ name: key.split("/").at(-1) ?? key,
7432
+ source: `storage/${key}`,
7433
+ title: key.split("/").at(-1) ?? key
7434
+ };
7435
+ }));
7436
+ const loaded = await loadRAGDocumentsFromUploads({
7437
+ baseMetadata: options.baseMetadata,
7438
+ defaultChunking: options.defaultChunking,
7439
+ extractors: options.extractors,
7440
+ uploads
7441
+ });
7442
+ const managedDocuments = loaded.documents.map((document) => toManagedSyncDocument(options.id, document, typeof document.metadata?.storageKey === "string" ? document.metadata.storageKey : document.source ?? document.title ?? ""));
7443
+ const reconciled = await reconcileManagedDocuments({
7444
+ collection,
7445
+ deleteDocument,
7446
+ documents: managedDocuments,
7447
+ listDocuments,
7448
+ sourceId: options.id
7449
+ });
7450
+ return {
7451
+ chunkCount: reconciled.chunkCount,
7452
+ documentCount: reconciled.documentCount,
7453
+ metadata: {
7454
+ deletedCount: reconciled.deletedCount,
7455
+ keyCount: keys.length,
7456
+ prefix: options.prefix,
7457
+ updatedCount: reconciled.updatedCount
7458
+ }
7459
+ };
7460
+ }
7461
+ });
7462
+ var createRAGStaticEmailSyncClient = (input) => ({
7463
+ listMessages: (options) => ({
7464
+ messages: typeof options?.maxResults === "number" ? input.messages.slice(0, options.maxResults) : input.messages
7465
+ })
7466
+ });
7467
+ var createRAGEmailSyncSource = (options) => ({
7468
+ description: options.description,
7469
+ id: options.id,
7470
+ kind: "email",
7471
+ label: options.label,
7472
+ metadata: options.metadata,
7473
+ retryAttempts: options.retryAttempts,
7474
+ retryDelayMs: options.retryDelayMs,
7475
+ target: options.label,
7476
+ sync: async ({ collection, deleteDocument, listDocuments }) => {
7477
+ const listed = await options.client.listMessages({
7478
+ maxResults: options.maxResults
7479
+ });
7480
+ const messageDocuments = listed.messages.map((message) => ({
7481
+ chunking: options.defaultChunking,
7482
+ format: message.bodyHtml ? "html" : "text",
7483
+ id: `email-${message.id}`,
7484
+ metadata: {
7485
+ ...options.baseMetadata ?? {},
7486
+ ...message.metadata ?? {},
7487
+ emailKind: "message",
7488
+ from: message.from,
7489
+ hasAttachments: (message.attachments?.length ?? 0) > 0,
7490
+ messageId: message.id,
7491
+ receivedAt: toTimestamp(message.receivedAt),
7492
+ sentAt: toTimestamp(message.sentAt),
7493
+ threadId: message.threadId,
7494
+ threadTopic: message.subject,
7495
+ to: message.to,
7496
+ cc: message.cc
7497
+ },
7498
+ source: `email/${message.threadId ?? message.id}`,
7499
+ text: message.bodyText,
7500
+ title: message.subject ?? message.id
7501
+ }));
7502
+ const attachmentUploads = listed.messages.flatMap((message) => (message.attachments ?? []).map((attachment, index) => ({
7503
+ ...encodeAttachmentContent(attachment),
7504
+ chunking: attachment.chunking ?? options.defaultChunking,
7505
+ contentType: attachment.contentType,
7506
+ format: attachment.format,
7507
+ metadata: {
7508
+ ...options.baseMetadata ?? {},
7509
+ ...attachment.metadata ?? {},
7510
+ attachmentId: attachment.id ?? `${message.id}-attachment-${index + 1}`,
7511
+ emailKind: "attachment",
7512
+ from: message.from,
7513
+ messageId: message.id,
7514
+ sentAt: toTimestamp(message.sentAt),
7515
+ threadId: message.threadId,
7516
+ threadTopic: message.subject
7517
+ },
7518
+ name: attachment.name,
7519
+ source: attachment.source ?? `email/${message.threadId ?? message.id}/attachments/${attachment.name}`,
7520
+ title: attachment.title ?? `${message.subject ?? message.id} \xB7 ${attachment.name}`
7521
+ })));
7522
+ const loadedAttachments = attachmentUploads.length > 0 ? await loadRAGDocumentsFromUploads({
7523
+ baseMetadata: options.baseMetadata,
7524
+ defaultChunking: options.defaultChunking,
7525
+ extractors: options.extractors,
7526
+ uploads: attachmentUploads
7527
+ }) : { documents: [] };
7528
+ const managedDocuments = [
7529
+ ...messageDocuments.map((document) => toManagedSyncDocument(options.id, document, `message:${document.metadata?.messageId}`)),
7530
+ ...loadedAttachments.documents.map((document) => toManagedSyncDocument(options.id, document, `attachment:${String(document.metadata?.attachmentId ?? document.source ?? document.title ?? "")}`))
7531
+ ];
7532
+ const reconciled = await reconcileManagedDocuments({
7533
+ collection,
7534
+ deleteDocument,
7535
+ documents: managedDocuments,
7536
+ listDocuments,
7537
+ sourceId: options.id
7538
+ });
7539
+ return {
7540
+ chunkCount: reconciled.chunkCount,
7541
+ documentCount: reconciled.documentCount,
7542
+ metadata: {
7543
+ deletedCount: reconciled.deletedCount,
7544
+ messageCount: listed.messages.length,
7545
+ nextCursor: listed.nextCursor,
7546
+ updatedCount: reconciled.updatedCount
7547
+ }
7548
+ };
7549
+ }
7550
+ });
7340
7551
  var createRAGSyncManager = (options) => {
7341
7552
  const sourceMap = new Map(options.sources.map((source) => [source.id, source]));
7342
7553
  const state = new Map(options.sources.map((source) => [source.id, toSourceRecord(source)]));
@@ -9536,6 +9747,8 @@ export {
9536
9747
  createAIStream as createRAGTransport,
9537
9748
  createRAGSyncScheduler,
9538
9749
  createRAGSyncManager,
9750
+ createRAGStorageSyncSource,
9751
+ createRAGStaticEmailSyncClient,
9539
9752
  createRAGReranker,
9540
9753
  createRAGQueryTransform,
9541
9754
  createRAGPDFOCRExtractor,
@@ -9549,9 +9762,11 @@ export {
9549
9762
  createRAGFileExtractor,
9550
9763
  createRAGEvaluationSuite,
9551
9764
  createRAGEmbeddingProvider,
9765
+ createRAGEmailSyncSource,
9552
9766
  createRAGDirectorySyncSource,
9553
9767
  createRAGCollection,
9554
9768
  createRAGClient,
9769
+ createRAGBunS3SyncClient,
9555
9770
  createRAGArchiveFileExtractor,
9556
9771
  createRAGArchiveExpander,
9557
9772
  createRAGAnswerWorkflow,
@@ -9590,5 +9805,5 @@ export {
9590
9805
  aiChat
9591
9806
  };
9592
9807
 
9593
- //# debugId=61173B84573291CC64756E2164756E21
9808
+ //# debugId=CE610CD2937858F264756E2164756E21
9594
9809
  //# sourceMappingURL=index.js.map