@absolutejs/rag 0.3.0 → 0.4.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.
- package/dist/adapter-kit/index.js +22 -10
- package/dist/adapter-kit/index.js.map +3 -3
- package/dist/index.js +22 -10
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -16847,6 +16847,16 @@ var parseMaildirMetadata = (source) => {
|
|
|
16847
16847
|
...maildirKey ? { emailMailboxKey: maildirKey } : {}
|
|
16848
16848
|
};
|
|
16849
16849
|
};
|
|
16850
|
+
var RFC2047_WORD = /=\?([^?]+)\?([BbQq])\?([^?]*)\?=/g;
|
|
16851
|
+
var decodeEncodedWord = (charset, encoding, text) => {
|
|
16852
|
+
const bytes = encoding.toUpperCase() === "B" ? Buffer.from(text, "base64") : Buffer.from(decodeQuotedPrintable(text.replace(/_/g, " ")), "latin1");
|
|
16853
|
+
try {
|
|
16854
|
+
return new TextDecoder(charset.trim().toLowerCase()).decode(bytes);
|
|
16855
|
+
} catch {
|
|
16856
|
+
return bytes.toString("utf8");
|
|
16857
|
+
}
|
|
16858
|
+
};
|
|
16859
|
+
var decodeRfc2047 = (value) => value.includes("=?") ? value.replace(/\?=\s+=\?/g, "?==?").replace(RFC2047_WORD, (_match, charset, enc, text) => decodeEncodedWord(charset, enc, text)) : value;
|
|
16850
16860
|
var parseHeaderBlock = (headerBlock) => {
|
|
16851
16861
|
const unfolded = headerBlock.replace(/\n[ \t]+/g, " ");
|
|
16852
16862
|
const headers = new Map;
|
|
@@ -16856,7 +16866,7 @@ var parseHeaderBlock = (headerBlock) => {
|
|
|
16856
16866
|
if (separator < 0) {
|
|
16857
16867
|
continue;
|
|
16858
16868
|
}
|
|
16859
|
-
headers.set(line.slice(0, separator).trim().toLowerCase(), line.slice(separator + 1).trim());
|
|
16869
|
+
headers.set(line.slice(0, separator).trim().toLowerCase(), decodeRfc2047(line.slice(separator + 1).trim()));
|
|
16860
16870
|
}
|
|
16861
16871
|
return headers;
|
|
16862
16872
|
};
|
|
@@ -16868,7 +16878,7 @@ var decodeEmailPartBody = (body, encoding) => {
|
|
|
16868
16878
|
return new Uint8Array(Buffer.from(trimmed.replace(/\s+/g, ""), "base64"));
|
|
16869
16879
|
}
|
|
16870
16880
|
if (normalizedEncoding === "quoted-printable") {
|
|
16871
|
-
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "
|
|
16881
|
+
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "latin1"));
|
|
16872
16882
|
}
|
|
16873
16883
|
return new Uint8Array(Buffer.from(body, "utf8"));
|
|
16874
16884
|
};
|
|
@@ -17262,7 +17272,7 @@ var chooseEmailBodyCandidate = (current, candidate) => {
|
|
|
17262
17272
|
}
|
|
17263
17273
|
return candidate.length > current.length ? candidate : current;
|
|
17264
17274
|
};
|
|
17265
|
-
var parseEmailMimeParts = (body, contentType) => {
|
|
17275
|
+
var parseEmailMimeParts = (body, contentType, transferEncoding) => {
|
|
17266
17276
|
const attachments = [];
|
|
17267
17277
|
let bodyText;
|
|
17268
17278
|
let bodyHtml;
|
|
@@ -17284,11 +17294,11 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17284
17294
|
const nestedContentType = headers.get("content-type");
|
|
17285
17295
|
const disposition = headers.get("content-disposition");
|
|
17286
17296
|
const dispositionType = disposition?.split(";")[0]?.trim().toLowerCase();
|
|
17287
|
-
const
|
|
17297
|
+
const transferEncoding2 = headers.get("content-transfer-encoding");
|
|
17288
17298
|
const contentId = normalizeEmailContentId(headers.get("content-id"));
|
|
17289
17299
|
const contentLocation = normalizeWhitespace(headers.get("content-location") ?? "");
|
|
17290
17300
|
const filename = disposition?.match(/filename="?([^";]+)"?/i)?.[1] ?? nestedContentType?.match(/name="?([^";]+)"?/i)?.[1];
|
|
17291
|
-
const decodedBytes = decodeEmailPartBody(nestedBody,
|
|
17301
|
+
const decodedBytes = decodeEmailPartBody(nestedBody, transferEncoding2);
|
|
17292
17302
|
const decodedText = Buffer.from(decodedBytes).toString("utf8");
|
|
17293
17303
|
const normalizedContentType = nestedContentType?.toLowerCase() ?? "";
|
|
17294
17304
|
const isMultipart = normalizedContentType.startsWith("multipart/");
|
|
@@ -17336,7 +17346,8 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17336
17346
|
}
|
|
17337
17347
|
}
|
|
17338
17348
|
};
|
|
17339
|
-
|
|
17349
|
+
const topLevelBody = transferEncoding && !parseMimeBoundary(contentType) ? decodeUtf8(decodeEmailPartBody(body, transferEncoding)) : body;
|
|
17350
|
+
collectMimeParts(topLevelBody, contentType);
|
|
17340
17351
|
return {
|
|
17341
17352
|
attachments,
|
|
17342
17353
|
bodyHtml,
|
|
@@ -17352,7 +17363,7 @@ var authoredEmailText = (text) => {
|
|
|
17352
17363
|
var extractEmailText = (raw) => {
|
|
17353
17364
|
const { body, headerBlock } = splitEmailMessage(raw);
|
|
17354
17365
|
const headers = parseHeaderBlock(headerBlock);
|
|
17355
|
-
const parsed = parseEmailMimeParts(body, headers.get("content-type"));
|
|
17366
|
+
const parsed = parseEmailMimeParts(body, headers.get("content-type"), headers.get("content-transfer-encoding"));
|
|
17356
17367
|
const htmlText = parsed.bodyHtml ? stripEmailHtml(parsed.bodyHtml) : undefined;
|
|
17357
17368
|
const plainText = parsed.bodyText ? normalizeWhitespace(parsed.bodyText) : undefined;
|
|
17358
17369
|
const preferredBodyText = choosePreferredEmailBodyText(htmlText, plainText);
|
|
@@ -17409,6 +17420,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17409
17420
|
ccAddressEntries: ccParsed.entries,
|
|
17410
17421
|
ccAddresses: ccParsed.addresses,
|
|
17411
17422
|
contentType: getHeader("Content-Type"),
|
|
17423
|
+
contentTransferEncoding: getHeader("Content-Transfer-Encoding"),
|
|
17412
17424
|
from,
|
|
17413
17425
|
fromAddress: fromParsed.addresses[0],
|
|
17414
17426
|
fromAddressEntries: fromParsed.entries,
|
|
@@ -17433,7 +17445,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17433
17445
|
var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
17434
17446
|
const headers = parseEmailHeaders(raw);
|
|
17435
17447
|
const { body } = splitEmailMessage(raw);
|
|
17436
|
-
const parsed = parseEmailMimeParts(body, headers.contentType);
|
|
17448
|
+
const parsed = parseEmailMimeParts(body, headers.contentType, headers.contentTransferEncoding);
|
|
17437
17449
|
const source = options?.source ?? input.source ?? input.path ?? input.name ?? `${slugify(input.title ?? DEFAULT_BINARY_NAME)}.eml`;
|
|
17438
17450
|
const maildirMetadata = parseMaildirMetadata(source);
|
|
17439
17451
|
const mergedMetadata = {
|
|
@@ -17636,7 +17648,7 @@ var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
|
17636
17648
|
return [messageDocument, ...attachmentDocuments.flat()];
|
|
17637
17649
|
};
|
|
17638
17650
|
var normalizeEmailThreadKey = (value) => {
|
|
17639
|
-
const normalized = normalizeWhitespace(value?.replace(/^(re|fw|fwd)\s*:\s
|
|
17651
|
+
const normalized = normalizeWhitespace(value?.replace(/^(?:(?:re|fw|fwd|aw|sv|vs|antw)\s*:\s*)+/i, "")?.replace(/[<>]/g, "")?.toLowerCase() ?? "");
|
|
17640
17652
|
return normalized || undefined;
|
|
17641
17653
|
};
|
|
17642
17654
|
var normalizeEmailMessageId = (value) => {
|
|
@@ -31340,5 +31352,5 @@ export {
|
|
|
31340
31352
|
RAG_NATIVE_QUERY_CANDIDATE_LIMIT
|
|
31341
31353
|
};
|
|
31342
31354
|
|
|
31343
|
-
//# debugId=
|
|
31355
|
+
//# debugId=EDE8F57AE9AB8A5064756E2164756E21
|
|
31344
31356
|
//# sourceMappingURL=index.js.map
|