@absolutejs/rag 0.1.3 → 0.3.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.
@@ -14824,6 +14824,8 @@ var emailStructureUnits = (value, metadata) => {
14824
14824
  return "Forwarded Headers";
14825
14825
  case "quoted_history":
14826
14826
  return "Quoted History";
14827
+ case "signature":
14828
+ return "Signature";
14827
14829
  }
14828
14830
  };
14829
14831
  const familyKeyBase = threadTopic || from || "Email Message";
@@ -17032,15 +17034,30 @@ var EMAIL_FORWARDED_HEADER_PATTERN = /^(?:from|sent|to|cc|bcc|subject|date|reply
17032
17034
  var EMAIL_FORWARDED_SEPARATOR_PATTERN = /^-{2,}\s*forwarded message\s*-{2,}$/i;
17033
17035
  var EMAIL_HTML_QUOTE_OPEN_TOKEN = "[[ABS_EMAIL_QUOTE_OPEN]]";
17034
17036
  var EMAIL_HTML_QUOTE_CLOSE_TOKEN = "[[ABS_EMAIL_QUOTE_CLOSE]]";
17037
+ var EMAIL_ATTRIBUTION_PATTERNS = [
17038
+ /^on\s.+\bwrote:$/iu,
17039
+ /^on\s.+\bat\s.+\bwrote:$/iu,
17040
+ /^-+\s*original message\s*-+$/iu,
17041
+ /^_{5,}$/u,
17042
+ /^el\s.+\bescribi\u00F3:$/iu,
17043
+ /^le\s.+\ba \u00E9crit\s*:$/iu
17044
+ ];
17045
+ var EMAIL_SIGNATURE_DELIMITER = /^--\s?$/u;
17035
17046
  var classifyEmailBodyLine = (line, currentKind) => {
17036
17047
  const trimmed = line.trim();
17037
17048
  if (!trimmed) {
17038
17049
  return currentKind;
17039
17050
  }
17051
+ if (currentKind === "signature") {
17052
+ return "signature";
17053
+ }
17054
+ if (EMAIL_SIGNATURE_DELIMITER.test(line)) {
17055
+ return "signature";
17056
+ }
17040
17057
  if (/^>+/.test(trimmed)) {
17041
17058
  return "quoted_history";
17042
17059
  }
17043
- if (/^on .+wrote:$/i.test(trimmed)) {
17060
+ if (EMAIL_ATTRIBUTION_PATTERNS.some((pattern) => pattern.test(trimmed))) {
17044
17061
  return "quoted_history";
17045
17062
  }
17046
17063
  if (EMAIL_FORWARDED_SEPARATOR_PATTERN.test(trimmed)) {
@@ -17228,16 +17245,8 @@ var scoreEmailBodyCandidate = (candidate) => {
17228
17245
  return Number.NEGATIVE_INFINITY;
17229
17246
  }
17230
17247
  const sections = parseEmailBodySections(candidate);
17231
- const structuralScore = sections.reduce((score, section) => {
17232
- if (section.kind === "forwarded_headers") {
17233
- return score + 8;
17234
- }
17235
- if (section.kind === "quoted_history") {
17236
- return score + 6 + (section.quotedDepth ?? 0);
17237
- }
17238
- return score + 1;
17239
- }, 0);
17240
- return structuralScore * 10 + Math.min(candidate.length, 5000) / 100;
17248
+ const authoredChars = sections.filter((section) => section.kind === "authored_text").reduce((total, section) => total + section.text.trim().length, 0);
17249
+ return authoredChars * 10 + Math.min(candidate.length, 5000) / 1000;
17241
17250
  };
17242
17251
  var choosePreferredEmailBodyText = (htmlText, plainText) => {
17243
17252
  const htmlScore = scoreEmailBodyCandidate(htmlText);
@@ -17334,6 +17343,12 @@ var parseEmailMimeParts = (body, contentType) => {
17334
17343
  bodyText
17335
17344
  };
17336
17345
  };
17346
+ var authoredEmailText = (text) => {
17347
+ const authored = parseEmailBodySections(text).filter((section) => section.kind === "authored_text").map((section) => section.text.trim()).filter(Boolean).join(`
17348
+
17349
+ `).trim();
17350
+ return authored || text;
17351
+ };
17337
17352
  var extractEmailText = (raw) => {
17338
17353
  const { body, headerBlock } = splitEmailMessage(raw);
17339
17354
  const headers = parseHeaderBlock(headerBlock);
@@ -19029,7 +19044,10 @@ var sourceAwareUnits = (document, format, normalizedText) => {
19029
19044
  }
19030
19045
  };
19031
19046
  var overlapTail = (value, overlap) => {
19032
- if (overlap <= 0 || value.length <= overlap) {
19047
+ if (overlap <= 0) {
19048
+ return "";
19049
+ }
19050
+ if (value.length <= overlap) {
19033
19051
  return value;
19034
19052
  }
19035
19053
  const candidate = value.slice(-overlap);
@@ -19044,11 +19062,16 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19044
19062
  };
19045
19063
  const mergeSmallChunk = (merged2, chunk) => {
19046
19064
  const last = merged2[merged2.length - 1];
19047
- if (!(last && chunk.length < minChunkLength)) {
19065
+ if (last === undefined || chunk.length >= minChunkLength) {
19066
+ merged2.push(chunk);
19067
+ return;
19068
+ }
19069
+ const candidate = normalizeWhitespace(`${last} ${chunk}`);
19070
+ if (candidate.length > maxChunkLength) {
19048
19071
  merged2.push(chunk);
19049
19072
  return;
19050
19073
  }
19051
- merged2[merged2.length - 1] = normalizeWhitespace(`${last} ${chunk}`);
19074
+ merged2[merged2.length - 1] = candidate;
19052
19075
  };
19053
19076
  const appendUnitToChunk = (trimmed) => {
19054
19077
  if (!current) {
@@ -19069,11 +19092,21 @@ var chunkFromUnits = (units, maxChunkLength, chunkOverlap, minChunkLength) => {
19069
19092
  const carry = overlapTail(current, chunkOverlap);
19070
19093
  current = carry.length > 0 ? `${carry} ${trimmed}`.trim() : trimmed;
19071
19094
  };
19095
+ const explodeOversized = (unit) => {
19096
+ if (unit.length <= maxChunkLength)
19097
+ return [unit];
19098
+ const sentences = sentenceUnits(unit);
19099
+ if (sentences.length > 1)
19100
+ return sentences.flatMap(explodeOversized);
19101
+ return fixedUnits(unit, maxChunkLength);
19102
+ };
19072
19103
  for (const unit of units) {
19073
- const trimmed = unit.trim();
19074
- if (!trimmed)
19075
- continue;
19076
- appendUnitToChunk(trimmed);
19104
+ for (const piece of explodeOversized(unit.trim())) {
19105
+ const trimmed = piece.trim();
19106
+ if (!trimmed)
19107
+ continue;
19108
+ appendUnitToChunk(trimmed);
19109
+ }
19077
19110
  }
19078
19111
  if (current) {
19079
19112
  appendChunk(current);
@@ -31307,5 +31340,5 @@ export {
31307
31340
  RAG_NATIVE_QUERY_CANDIDATE_LIMIT
31308
31341
  };
31309
31342
 
31310
- //# debugId=7D3E433ED526972764756E2164756E21
31343
+ //# debugId=03EEE30357F4429664756E2164756E21
31311
31344
  //# sourceMappingURL=index.js.map