@absolutejs/rag 0.3.0 → 0.5.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 +38 -13
- package/dist/adapter-kit/index.js.map +3 -3
- package/dist/index.js +38 -13
- package/dist/index.js.map +3 -3
- package/package.json +1 -1
|
@@ -15696,6 +15696,7 @@ var extractNativePDFText = (data) => {
|
|
|
15696
15696
|
var readUInt16LE = (data, offset) => data[offset] | data[offset + 1] << 8;
|
|
15697
15697
|
var readUInt32LE = (data, offset) => (data[offset] | data[offset + 1] << 8 | data[offset + 2] << 16 | data[offset + 3] << 24) >>> 0;
|
|
15698
15698
|
var decodeUtf8 = (data) => Buffer.from(data).toString("utf8");
|
|
15699
|
+
var decodeLatin1 = (data) => Buffer.from(data).toString("latin1");
|
|
15699
15700
|
var isZipData = (data) => data.length >= 4 && data[0] === 80 && data[1] === 75 && data[2] === 3 && data[3] === 4;
|
|
15700
15701
|
var unzipEntries = (data) => {
|
|
15701
15702
|
const entries = [];
|
|
@@ -16847,6 +16848,16 @@ var parseMaildirMetadata = (source) => {
|
|
|
16847
16848
|
...maildirKey ? { emailMailboxKey: maildirKey } : {}
|
|
16848
16849
|
};
|
|
16849
16850
|
};
|
|
16851
|
+
var RFC2047_WORD = /=\?([^?]+)\?([BbQq])\?([^?]*)\?=/g;
|
|
16852
|
+
var decodeEncodedWord = (charset, encoding, text) => {
|
|
16853
|
+
const bytes = encoding.toUpperCase() === "B" ? Buffer.from(text, "base64") : Buffer.from(decodeQuotedPrintable(text.replace(/_/g, " ")), "latin1");
|
|
16854
|
+
try {
|
|
16855
|
+
return new TextDecoder(charset.trim().toLowerCase()).decode(bytes);
|
|
16856
|
+
} catch {
|
|
16857
|
+
return bytes.toString("utf8");
|
|
16858
|
+
}
|
|
16859
|
+
};
|
|
16860
|
+
var decodeRfc2047 = (value) => value.includes("=?") ? value.replace(/\?=\s+=\?/g, "?==?").replace(RFC2047_WORD, (_match, charset, enc, text) => decodeEncodedWord(charset, enc, text)) : value;
|
|
16850
16861
|
var parseHeaderBlock = (headerBlock) => {
|
|
16851
16862
|
const unfolded = headerBlock.replace(/\n[ \t]+/g, " ");
|
|
16852
16863
|
const headers = new Map;
|
|
@@ -16856,7 +16867,7 @@ var parseHeaderBlock = (headerBlock) => {
|
|
|
16856
16867
|
if (separator < 0) {
|
|
16857
16868
|
continue;
|
|
16858
16869
|
}
|
|
16859
|
-
headers.set(line.slice(0, separator).trim().toLowerCase(), line.slice(separator + 1).trim());
|
|
16870
|
+
headers.set(line.slice(0, separator).trim().toLowerCase(), decodeRfc2047(line.slice(separator + 1).trim()));
|
|
16860
16871
|
}
|
|
16861
16872
|
return headers;
|
|
16862
16873
|
};
|
|
@@ -16868,9 +16879,21 @@ var decodeEmailPartBody = (body, encoding) => {
|
|
|
16868
16879
|
return new Uint8Array(Buffer.from(trimmed.replace(/\s+/g, ""), "base64"));
|
|
16869
16880
|
}
|
|
16870
16881
|
if (normalizedEncoding === "quoted-printable") {
|
|
16871
|
-
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "
|
|
16882
|
+
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "latin1"));
|
|
16883
|
+
}
|
|
16884
|
+
return new Uint8Array(Buffer.from(body, "latin1"));
|
|
16885
|
+
};
|
|
16886
|
+
var parseMimeCharset = (contentType) => contentType?.match(/charset\s*=\s*"?([^";\s]+)"?/i)?.[1];
|
|
16887
|
+
var decodeWithCharset = (data, contentType) => {
|
|
16888
|
+
const charset = parseMimeCharset(contentType)?.trim().toLowerCase();
|
|
16889
|
+
if (!charset || charset === "utf-8" || charset === "utf8") {
|
|
16890
|
+
return decodeUtf8(data);
|
|
16891
|
+
}
|
|
16892
|
+
try {
|
|
16893
|
+
return new TextDecoder(charset).decode(data);
|
|
16894
|
+
} catch {
|
|
16895
|
+
return decodeUtf8(data);
|
|
16872
16896
|
}
|
|
16873
|
-
return new Uint8Array(Buffer.from(body, "utf8"));
|
|
16874
16897
|
};
|
|
16875
16898
|
var parseMimeBoundary = (contentType) => {
|
|
16876
16899
|
const match = contentType?.match(/boundary="?([^";]+)"?/i);
|
|
@@ -17262,7 +17285,7 @@ var chooseEmailBodyCandidate = (current, candidate) => {
|
|
|
17262
17285
|
}
|
|
17263
17286
|
return candidate.length > current.length ? candidate : current;
|
|
17264
17287
|
};
|
|
17265
|
-
var parseEmailMimeParts = (body, contentType) => {
|
|
17288
|
+
var parseEmailMimeParts = (body, contentType, transferEncoding) => {
|
|
17266
17289
|
const attachments = [];
|
|
17267
17290
|
let bodyText;
|
|
17268
17291
|
let bodyHtml;
|
|
@@ -17284,12 +17307,12 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17284
17307
|
const nestedContentType = headers.get("content-type");
|
|
17285
17308
|
const disposition = headers.get("content-disposition");
|
|
17286
17309
|
const dispositionType = disposition?.split(";")[0]?.trim().toLowerCase();
|
|
17287
|
-
const
|
|
17310
|
+
const transferEncoding2 = headers.get("content-transfer-encoding");
|
|
17288
17311
|
const contentId = normalizeEmailContentId(headers.get("content-id"));
|
|
17289
17312
|
const contentLocation = normalizeWhitespace(headers.get("content-location") ?? "");
|
|
17290
17313
|
const filename = disposition?.match(/filename="?([^";]+)"?/i)?.[1] ?? nestedContentType?.match(/name="?([^";]+)"?/i)?.[1];
|
|
17291
|
-
const decodedBytes = decodeEmailPartBody(nestedBody,
|
|
17292
|
-
const decodedText =
|
|
17314
|
+
const decodedBytes = decodeEmailPartBody(nestedBody, transferEncoding2);
|
|
17315
|
+
const decodedText = decodeWithCharset(decodedBytes, nestedContentType);
|
|
17293
17316
|
const normalizedContentType = nestedContentType?.toLowerCase() ?? "";
|
|
17294
17317
|
const isMultipart = normalizedContentType.startsWith("multipart/");
|
|
17295
17318
|
const isHtml = normalizedContentType.includes("text/html");
|
|
@@ -17336,7 +17359,8 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17336
17359
|
}
|
|
17337
17360
|
}
|
|
17338
17361
|
};
|
|
17339
|
-
|
|
17362
|
+
const topLevelBody = transferEncoding && !parseMimeBoundary(contentType) ? decodeWithCharset(decodeEmailPartBody(body, transferEncoding), contentType) : body;
|
|
17363
|
+
collectMimeParts(topLevelBody, contentType);
|
|
17340
17364
|
return {
|
|
17341
17365
|
attachments,
|
|
17342
17366
|
bodyHtml,
|
|
@@ -17352,7 +17376,7 @@ var authoredEmailText = (text) => {
|
|
|
17352
17376
|
var extractEmailText = (raw) => {
|
|
17353
17377
|
const { body, headerBlock } = splitEmailMessage(raw);
|
|
17354
17378
|
const headers = parseHeaderBlock(headerBlock);
|
|
17355
|
-
const parsed = parseEmailMimeParts(body, headers.get("content-type"));
|
|
17379
|
+
const parsed = parseEmailMimeParts(body, headers.get("content-type"), headers.get("content-transfer-encoding"));
|
|
17356
17380
|
const htmlText = parsed.bodyHtml ? stripEmailHtml(parsed.bodyHtml) : undefined;
|
|
17357
17381
|
const plainText = parsed.bodyText ? normalizeWhitespace(parsed.bodyText) : undefined;
|
|
17358
17382
|
const preferredBodyText = choosePreferredEmailBodyText(htmlText, plainText);
|
|
@@ -17409,6 +17433,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17409
17433
|
ccAddressEntries: ccParsed.entries,
|
|
17410
17434
|
ccAddresses: ccParsed.addresses,
|
|
17411
17435
|
contentType: getHeader("Content-Type"),
|
|
17436
|
+
contentTransferEncoding: getHeader("Content-Transfer-Encoding"),
|
|
17412
17437
|
from,
|
|
17413
17438
|
fromAddress: fromParsed.addresses[0],
|
|
17414
17439
|
fromAddressEntries: fromParsed.entries,
|
|
@@ -17433,7 +17458,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17433
17458
|
var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
17434
17459
|
const headers = parseEmailHeaders(raw);
|
|
17435
17460
|
const { body } = splitEmailMessage(raw);
|
|
17436
|
-
const parsed = parseEmailMimeParts(body, headers.contentType);
|
|
17461
|
+
const parsed = parseEmailMimeParts(body, headers.contentType, headers.contentTransferEncoding);
|
|
17437
17462
|
const source = options?.source ?? input.source ?? input.path ?? input.name ?? `${slugify(input.title ?? DEFAULT_BINARY_NAME)}.eml`;
|
|
17438
17463
|
const maildirMetadata = parseMaildirMetadata(source);
|
|
17439
17464
|
const mergedMetadata = {
|
|
@@ -17636,7 +17661,7 @@ var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
|
17636
17661
|
return [messageDocument, ...attachmentDocuments.flat()];
|
|
17637
17662
|
};
|
|
17638
17663
|
var normalizeEmailThreadKey = (value) => {
|
|
17639
|
-
const normalized = normalizeWhitespace(value?.replace(/^(re|fw|fwd)\s*:\s
|
|
17664
|
+
const normalized = normalizeWhitespace(value?.replace(/^(?:(?:re|fw|fwd|aw|sv|vs|antw)\s*:\s*)+/i, "")?.replace(/[<>]/g, "")?.toLowerCase() ?? "");
|
|
17640
17665
|
return normalized || undefined;
|
|
17641
17666
|
};
|
|
17642
17667
|
var normalizeEmailMessageId = (value) => {
|
|
@@ -17984,7 +18009,7 @@ var createEmailExtractor = () => ({
|
|
|
17984
18009
|
const source = input.source ?? input.path ?? input.name ?? `${slugify(input.title ?? DEFAULT_BINARY_NAME)}.eml`;
|
|
17985
18010
|
const extension = inferExtensionFromInput(input);
|
|
17986
18011
|
const emlx = extension === ".emlx" ? decodeEmlxMessageData(input.data) : undefined;
|
|
17987
|
-
const raw = emlx?.raw ??
|
|
18012
|
+
const raw = emlx?.raw ?? decodeLatin1(input.data);
|
|
17988
18013
|
if (extension === ".emlx") {
|
|
17989
18014
|
return extractEmailDocumentsFromRawMessage(input, raw, {
|
|
17990
18015
|
metadata: {
|
|
@@ -31340,5 +31365,5 @@ export {
|
|
|
31340
31365
|
RAG_NATIVE_QUERY_CANDIDATE_LIMIT
|
|
31341
31366
|
};
|
|
31342
31367
|
|
|
31343
|
-
//# debugId=
|
|
31368
|
+
//# debugId=7097CF082CBBCC6664756E2164756E21
|
|
31344
31369
|
//# sourceMappingURL=index.js.map
|