@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 +36 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5084,15 +5084,48 @@ function _ts_decorate21(decorators, target, key, desc) {
|
|
|
5084
5084
|
}
|
|
5085
5085
|
__name(_ts_decorate21, "_ts_decorate");
|
|
5086
5086
|
function joinTextSteps(parts) {
|
|
5087
|
+
const kept = parts.filter(Boolean);
|
|
5088
|
+
for (let i = 1; i < kept.length; i++) {
|
|
5089
|
+
for (const paragraph of paragraphsOf(kept[i])) {
|
|
5090
|
+
for (let j = 0; j < i; j++) {
|
|
5091
|
+
kept[j] = removeNearDuplicate(kept[j], paragraph);
|
|
5092
|
+
}
|
|
5093
|
+
}
|
|
5094
|
+
}
|
|
5087
5095
|
let out = "";
|
|
5088
|
-
for (const part of
|
|
5089
|
-
if (!part) continue;
|
|
5096
|
+
for (const part of kept) {
|
|
5097
|
+
if (!part.trim()) continue;
|
|
5090
5098
|
if (!out || /\s$/.test(out) || /^\s/.test(part)) out += part;
|
|
5091
5099
|
else out += "\n\n" + part;
|
|
5092
5100
|
}
|
|
5093
|
-
return out;
|
|
5101
|
+
return out.replace(/\n{3,}/g, "\n\n");
|
|
5094
5102
|
}
|
|
5095
5103
|
__name(joinTextSteps, "joinTextSteps");
|
|
5104
|
+
var MIN_DUPLICATE_WORDS = 8;
|
|
5105
|
+
var DUPLICATE_SIMILARITY = 0.75;
|
|
5106
|
+
function paragraphsOf(text) {
|
|
5107
|
+
return text.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
|
|
5108
|
+
}
|
|
5109
|
+
__name(paragraphsOf, "paragraphsOf");
|
|
5110
|
+
function wordsOf(text) {
|
|
5111
|
+
return new Set(text.toLowerCase().match(/[\p{L}\p{N}$]+/gu) ?? []);
|
|
5112
|
+
}
|
|
5113
|
+
__name(wordsOf, "wordsOf");
|
|
5114
|
+
function similarity(a, b) {
|
|
5115
|
+
let common = 0;
|
|
5116
|
+
for (const w of a) if (b.has(w)) common++;
|
|
5117
|
+
return common / (a.size + b.size - common);
|
|
5118
|
+
}
|
|
5119
|
+
__name(similarity, "similarity");
|
|
5120
|
+
function removeNearDuplicate(text, paragraph) {
|
|
5121
|
+
const target = wordsOf(paragraph);
|
|
5122
|
+
if (target.size < MIN_DUPLICATE_WORDS) return text;
|
|
5123
|
+
return paragraphsOf(text).filter((p) => {
|
|
5124
|
+
const words = wordsOf(p);
|
|
5125
|
+
return words.size < MIN_DUPLICATE_WORDS || similarity(words, target) < DUPLICATE_SIMILARITY;
|
|
5126
|
+
}).join("\n\n");
|
|
5127
|
+
}
|
|
5128
|
+
__name(removeNearDuplicate, "removeNearDuplicate");
|
|
5096
5129
|
var EventProcessor = class _EventProcessor {
|
|
5097
5130
|
static {
|
|
5098
5131
|
__name(this, "EventProcessor");
|