@absolutejs/absolute 0.19.0-beta.501 → 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
@@ -7217,6 +7217,23 @@ var toManagedSyncDocument = (sourceId, document, syncKey) => ({
7217
7217
  syncSourceId: sourceId
7218
7218
  }
7219
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
+ };
7220
7237
  var isManagedBySyncSource = (document, sourceId) => document.metadata?.syncSourceId === sourceId;
7221
7238
  var getDocumentSyncFingerprint = (document) => typeof document.metadata?.syncFingerprint === "string" ? document.metadata.syncFingerprint : undefined;
7222
7239
  var reconcileManagedDocuments = async (input) => {
@@ -7442,6 +7459,95 @@ var createRAGStorageSyncSource = (options) => ({
7442
7459
  };
7443
7460
  }
7444
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
+ });
7445
7551
  var createRAGSyncManager = (options) => {
7446
7552
  const sourceMap = new Map(options.sources.map((source) => [source.id, source]));
7447
7553
  const state = new Map(options.sources.map((source) => [source.id, toSourceRecord(source)]));
@@ -9642,6 +9748,7 @@ export {
9642
9748
  createRAGSyncScheduler,
9643
9749
  createRAGSyncManager,
9644
9750
  createRAGStorageSyncSource,
9751
+ createRAGStaticEmailSyncClient,
9645
9752
  createRAGReranker,
9646
9753
  createRAGQueryTransform,
9647
9754
  createRAGPDFOCRExtractor,
@@ -9655,6 +9762,7 @@ export {
9655
9762
  createRAGFileExtractor,
9656
9763
  createRAGEvaluationSuite,
9657
9764
  createRAGEmbeddingProvider,
9765
+ createRAGEmailSyncSource,
9658
9766
  createRAGDirectorySyncSource,
9659
9767
  createRAGCollection,
9660
9768
  createRAGClient,
@@ -9697,5 +9805,5 @@ export {
9697
9805
  aiChat
9698
9806
  };
9699
9807
 
9700
- //# debugId=1890BBB7D959483A64756E2164756E21
9808
+ //# debugId=CE610CD2937858F264756E2164756E21
9701
9809
  //# sourceMappingURL=index.js.map