@flutchai/flutch-sdk 0.6.6 → 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
@@ -5113,6 +5113,49 @@ function _ts_decorate21(decorators, target, key, desc) {
5113
5113
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5114
5114
  }
5115
5115
  __name(_ts_decorate21, "_ts_decorate");
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
+ }
5125
+ let out = "";
5126
+ for (const part of kept) {
5127
+ if (!part.trim()) continue;
5128
+ if (!out || /\s$/.test(out) || /^\s/.test(part)) out += part;
5129
+ else out += "\n\n" + part;
5130
+ }
5131
+ return out.replace(/\n{3,}/g, "\n\n");
5132
+ }
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");
5116
5159
  exports.EventProcessor = class _EventProcessor {
5117
5160
  static {
5118
5161
  __name(this, "EventProcessor");
@@ -5548,7 +5591,7 @@ exports.EventProcessor = class _EventProcessor {
5548
5591
  totalEvents: acc.traceEvents.length
5549
5592
  } : null;
5550
5593
  const textChain = allChains.find((c) => c.channel === "text");
5551
- const text = textChain ? textChain.steps.filter((step) => step.type === "text").map((step) => step.text || "").join("") : "";
5594
+ const text = textChain ? joinTextSteps(textChain.steps.filter((step) => step.type === "text").map((step) => step.text || "")) : "";
5552
5595
  this.logger.log("\u{1F4CA} [EventProcessor] Final result assembled", {
5553
5596
  totalChains: allChains.length,
5554
5597
  textChains: allChains.filter((c) => c.channel === "text").length,
@@ -8683,6 +8726,7 @@ exports.isInternalMode = isInternalMode;
8683
8726
  exports.isReasoningBlock = isReasoningBlock;
8684
8727
  exports.isReasoningModel = isReasoningModel;
8685
8728
  exports.isSendableReasoningBlock = isSendableReasoningBlock;
8729
+ exports.joinTextSteps = joinTextSteps;
8686
8730
  exports.loadOAuthProviders = loadOAuthProviders;
8687
8731
  exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
8688
8732
  exports.modelSupportsPromptCache = modelSupportsPromptCache;