@flutchai/flutch-sdk 0.6.7 → 0.6.8

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/index.cjs CHANGED
@@ -5114,15 +5114,48 @@ function _ts_decorate21(decorators, target, key, desc) {
5114
5114
  }
5115
5115
  __name(_ts_decorate21, "_ts_decorate");
5116
5116
  function joinTextSteps(parts) {
5117
+ const kept = parts.filter(Boolean);
5118
+ for (let i = 1; i < kept.length; i++) {
5119
+ for (const paragraph of paragraphsOf(kept[i])) {
5120
+ for (let j = 0; j < i; j++) {
5121
+ kept[j] = removeNearDuplicate(kept[j], paragraph);
5122
+ }
5123
+ }
5124
+ }
5117
5125
  let out = "";
5118
- for (const part of parts) {
5119
- if (!part) continue;
5126
+ for (const part of kept) {
5127
+ if (!part.trim()) continue;
5120
5128
  if (!out || /\s$/.test(out) || /^\s/.test(part)) out += part;
5121
5129
  else out += "\n\n" + part;
5122
5130
  }
5123
- return out;
5131
+ return out.replace(/\n{3,}/g, "\n\n");
5124
5132
  }
5125
5133
  __name(joinTextSteps, "joinTextSteps");
5134
+ var MIN_DUPLICATE_WORDS = 8;
5135
+ var DUPLICATE_SIMILARITY = 0.75;
5136
+ function paragraphsOf(text) {
5137
+ return text.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
5138
+ }
5139
+ __name(paragraphsOf, "paragraphsOf");
5140
+ function wordsOf(text) {
5141
+ return new Set(text.toLowerCase().match(/[\p{L}\p{N}$]+/gu) ?? []);
5142
+ }
5143
+ __name(wordsOf, "wordsOf");
5144
+ function similarity(a, b) {
5145
+ let common = 0;
5146
+ for (const w of a) if (b.has(w)) common++;
5147
+ return common / (a.size + b.size - common);
5148
+ }
5149
+ __name(similarity, "similarity");
5150
+ function removeNearDuplicate(text, paragraph) {
5151
+ const target = wordsOf(paragraph);
5152
+ if (target.size < MIN_DUPLICATE_WORDS) return text;
5153
+ return paragraphsOf(text).filter((p) => {
5154
+ const words = wordsOf(p);
5155
+ return words.size < MIN_DUPLICATE_WORDS || similarity(words, target) < DUPLICATE_SIMILARITY;
5156
+ }).join("\n\n");
5157
+ }
5158
+ __name(removeNearDuplicate, "removeNearDuplicate");
5126
5159
  exports.EventProcessor = class _EventProcessor {
5127
5160
  static {
5128
5161
  __name(this, "EventProcessor");