@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
package/dist/index.js
CHANGED
|
@@ -15975,6 +15975,7 @@ var extractNativePDFText = (data) => {
|
|
|
15975
15975
|
var readUInt16LE = (data, offset) => data[offset] | data[offset + 1] << 8;
|
|
15976
15976
|
var readUInt32LE = (data, offset) => (data[offset] | data[offset + 1] << 8 | data[offset + 2] << 16 | data[offset + 3] << 24) >>> 0;
|
|
15977
15977
|
var decodeUtf8 = (data) => Buffer.from(data).toString("utf8");
|
|
15978
|
+
var decodeLatin1 = (data) => Buffer.from(data).toString("latin1");
|
|
15978
15979
|
var isZipData = (data) => data.length >= 4 && data[0] === 80 && data[1] === 75 && data[2] === 3 && data[3] === 4;
|
|
15979
15980
|
var unzipEntries = (data) => {
|
|
15980
15981
|
const entries = [];
|
|
@@ -17126,6 +17127,16 @@ var parseMaildirMetadata = (source) => {
|
|
|
17126
17127
|
...maildirKey ? { emailMailboxKey: maildirKey } : {}
|
|
17127
17128
|
};
|
|
17128
17129
|
};
|
|
17130
|
+
var RFC2047_WORD = /=\?([^?]+)\?([BbQq])\?([^?]*)\?=/g;
|
|
17131
|
+
var decodeEncodedWord = (charset, encoding, text) => {
|
|
17132
|
+
const bytes = encoding.toUpperCase() === "B" ? Buffer.from(text, "base64") : Buffer.from(decodeQuotedPrintable(text.replace(/_/g, " ")), "latin1");
|
|
17133
|
+
try {
|
|
17134
|
+
return new TextDecoder(charset.trim().toLowerCase()).decode(bytes);
|
|
17135
|
+
} catch {
|
|
17136
|
+
return bytes.toString("utf8");
|
|
17137
|
+
}
|
|
17138
|
+
};
|
|
17139
|
+
var decodeRfc2047 = (value) => value.includes("=?") ? value.replace(/\?=\s+=\?/g, "?==?").replace(RFC2047_WORD, (_match, charset, enc, text) => decodeEncodedWord(charset, enc, text)) : value;
|
|
17129
17140
|
var parseHeaderBlock = (headerBlock) => {
|
|
17130
17141
|
const unfolded = headerBlock.replace(/\n[ \t]+/g, " ");
|
|
17131
17142
|
const headers = new Map;
|
|
@@ -17135,7 +17146,7 @@ var parseHeaderBlock = (headerBlock) => {
|
|
|
17135
17146
|
if (separator < 0) {
|
|
17136
17147
|
continue;
|
|
17137
17148
|
}
|
|
17138
|
-
headers.set(line.slice(0, separator).trim().toLowerCase(), line.slice(separator + 1).trim());
|
|
17149
|
+
headers.set(line.slice(0, separator).trim().toLowerCase(), decodeRfc2047(line.slice(separator + 1).trim()));
|
|
17139
17150
|
}
|
|
17140
17151
|
return headers;
|
|
17141
17152
|
};
|
|
@@ -17147,9 +17158,21 @@ var decodeEmailPartBody = (body, encoding) => {
|
|
|
17147
17158
|
return new Uint8Array(Buffer.from(trimmed.replace(/\s+/g, ""), "base64"));
|
|
17148
17159
|
}
|
|
17149
17160
|
if (normalizedEncoding === "quoted-printable") {
|
|
17150
|
-
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "
|
|
17161
|
+
return new Uint8Array(Buffer.from(decodeQuotedPrintable(body), "latin1"));
|
|
17162
|
+
}
|
|
17163
|
+
return new Uint8Array(Buffer.from(body, "latin1"));
|
|
17164
|
+
};
|
|
17165
|
+
var parseMimeCharset = (contentType) => contentType?.match(/charset\s*=\s*"?([^";\s]+)"?/i)?.[1];
|
|
17166
|
+
var decodeWithCharset = (data, contentType) => {
|
|
17167
|
+
const charset = parseMimeCharset(contentType)?.trim().toLowerCase();
|
|
17168
|
+
if (!charset || charset === "utf-8" || charset === "utf8") {
|
|
17169
|
+
return decodeUtf8(data);
|
|
17170
|
+
}
|
|
17171
|
+
try {
|
|
17172
|
+
return new TextDecoder(charset).decode(data);
|
|
17173
|
+
} catch {
|
|
17174
|
+
return decodeUtf8(data);
|
|
17151
17175
|
}
|
|
17152
|
-
return new Uint8Array(Buffer.from(body, "utf8"));
|
|
17153
17176
|
};
|
|
17154
17177
|
var parseMimeBoundary = (contentType) => {
|
|
17155
17178
|
const match = contentType?.match(/boundary="?([^";]+)"?/i);
|
|
@@ -17541,7 +17564,7 @@ var chooseEmailBodyCandidate = (current, candidate) => {
|
|
|
17541
17564
|
}
|
|
17542
17565
|
return candidate.length > current.length ? candidate : current;
|
|
17543
17566
|
};
|
|
17544
|
-
var parseEmailMimeParts = (body, contentType) => {
|
|
17567
|
+
var parseEmailMimeParts = (body, contentType, transferEncoding) => {
|
|
17545
17568
|
const attachments = [];
|
|
17546
17569
|
let bodyText;
|
|
17547
17570
|
let bodyHtml;
|
|
@@ -17563,12 +17586,12 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17563
17586
|
const nestedContentType = headers.get("content-type");
|
|
17564
17587
|
const disposition = headers.get("content-disposition");
|
|
17565
17588
|
const dispositionType = disposition?.split(";")[0]?.trim().toLowerCase();
|
|
17566
|
-
const
|
|
17589
|
+
const transferEncoding2 = headers.get("content-transfer-encoding");
|
|
17567
17590
|
const contentId = normalizeEmailContentId(headers.get("content-id"));
|
|
17568
17591
|
const contentLocation = normalizeWhitespace(headers.get("content-location") ?? "");
|
|
17569
17592
|
const filename = disposition?.match(/filename="?([^";]+)"?/i)?.[1] ?? nestedContentType?.match(/name="?([^";]+)"?/i)?.[1];
|
|
17570
|
-
const decodedBytes = decodeEmailPartBody(nestedBody,
|
|
17571
|
-
const decodedText =
|
|
17593
|
+
const decodedBytes = decodeEmailPartBody(nestedBody, transferEncoding2);
|
|
17594
|
+
const decodedText = decodeWithCharset(decodedBytes, nestedContentType);
|
|
17572
17595
|
const normalizedContentType = nestedContentType?.toLowerCase() ?? "";
|
|
17573
17596
|
const isMultipart = normalizedContentType.startsWith("multipart/");
|
|
17574
17597
|
const isHtml = normalizedContentType.includes("text/html");
|
|
@@ -17615,7 +17638,8 @@ var parseEmailMimeParts = (body, contentType) => {
|
|
|
17615
17638
|
}
|
|
17616
17639
|
}
|
|
17617
17640
|
};
|
|
17618
|
-
|
|
17641
|
+
const topLevelBody = transferEncoding && !parseMimeBoundary(contentType) ? decodeWithCharset(decodeEmailPartBody(body, transferEncoding), contentType) : body;
|
|
17642
|
+
collectMimeParts(topLevelBody, contentType);
|
|
17619
17643
|
return {
|
|
17620
17644
|
attachments,
|
|
17621
17645
|
bodyHtml,
|
|
@@ -17631,7 +17655,7 @@ var authoredEmailText = (text) => {
|
|
|
17631
17655
|
var extractEmailText = (raw) => {
|
|
17632
17656
|
const { body, headerBlock } = splitEmailMessage(raw);
|
|
17633
17657
|
const headers = parseHeaderBlock(headerBlock);
|
|
17634
|
-
const parsed = parseEmailMimeParts(body, headers.get("content-type"));
|
|
17658
|
+
const parsed = parseEmailMimeParts(body, headers.get("content-type"), headers.get("content-transfer-encoding"));
|
|
17635
17659
|
const htmlText = parsed.bodyHtml ? stripEmailHtml(parsed.bodyHtml) : undefined;
|
|
17636
17660
|
const plainText = parsed.bodyText ? normalizeWhitespace(parsed.bodyText) : undefined;
|
|
17637
17661
|
const preferredBodyText = choosePreferredEmailBodyText(htmlText, plainText);
|
|
@@ -17688,6 +17712,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17688
17712
|
ccAddressEntries: ccParsed.entries,
|
|
17689
17713
|
ccAddresses: ccParsed.addresses,
|
|
17690
17714
|
contentType: getHeader("Content-Type"),
|
|
17715
|
+
contentTransferEncoding: getHeader("Content-Transfer-Encoding"),
|
|
17691
17716
|
from,
|
|
17692
17717
|
fromAddress: fromParsed.addresses[0],
|
|
17693
17718
|
fromAddressEntries: fromParsed.entries,
|
|
@@ -17712,7 +17737,7 @@ var parseEmailHeaders = (raw) => {
|
|
|
17712
17737
|
var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
17713
17738
|
const headers = parseEmailHeaders(raw);
|
|
17714
17739
|
const { body } = splitEmailMessage(raw);
|
|
17715
|
-
const parsed = parseEmailMimeParts(body, headers.contentType);
|
|
17740
|
+
const parsed = parseEmailMimeParts(body, headers.contentType, headers.contentTransferEncoding);
|
|
17716
17741
|
const source = options?.source ?? input.source ?? input.path ?? input.name ?? `${slugify(input.title ?? DEFAULT_BINARY_NAME)}.eml`;
|
|
17717
17742
|
const maildirMetadata = parseMaildirMetadata(source);
|
|
17718
17743
|
const mergedMetadata = {
|
|
@@ -17915,7 +17940,7 @@ var extractEmailDocumentsFromRawMessage = async (input, raw, options) => {
|
|
|
17915
17940
|
return [messageDocument, ...attachmentDocuments.flat()];
|
|
17916
17941
|
};
|
|
17917
17942
|
var normalizeEmailThreadKey = (value) => {
|
|
17918
|
-
const normalized = normalizeWhitespace(value?.replace(/^(re|fw|fwd)\s*:\s
|
|
17943
|
+
const normalized = normalizeWhitespace(value?.replace(/^(?:(?:re|fw|fwd|aw|sv|vs|antw)\s*:\s*)+/i, "")?.replace(/[<>]/g, "")?.toLowerCase() ?? "");
|
|
17919
17944
|
return normalized || undefined;
|
|
17920
17945
|
};
|
|
17921
17946
|
var normalizeEmailMessageId = (value) => {
|
|
@@ -18263,7 +18288,7 @@ var createEmailExtractor = () => ({
|
|
|
18263
18288
|
const source = input.source ?? input.path ?? input.name ?? `${slugify(input.title ?? DEFAULT_BINARY_NAME)}.eml`;
|
|
18264
18289
|
const extension = inferExtensionFromInput(input);
|
|
18265
18290
|
const emlx = extension === ".emlx" ? decodeEmlxMessageData(input.data) : undefined;
|
|
18266
|
-
const raw = emlx?.raw ??
|
|
18291
|
+
const raw = emlx?.raw ?? decodeLatin1(input.data);
|
|
18267
18292
|
if (extension === ".emlx") {
|
|
18268
18293
|
return extractEmailDocumentsFromRawMessage(input, raw, {
|
|
18269
18294
|
metadata: {
|
|
@@ -36371,5 +36396,5 @@ export {
|
|
|
36371
36396
|
addRAGEvaluationSuiteCase
|
|
36372
36397
|
};
|
|
36373
36398
|
|
|
36374
|
-
//# debugId=
|
|
36399
|
+
//# debugId=935E9CE2ED17498064756E2164756E21
|
|
36375
36400
|
//# sourceMappingURL=index.js.map
|