@semiont/api-client 0.2.34-build.92 → 0.2.34-build.93
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.js +0 -47
- package/dist/index.js.map +1 -1
- package/dist/utils/index.js +0 -47
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1400,15 +1400,10 @@ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
|
1400
1400
|
index = content.indexOf(exact, index + 1);
|
|
1401
1401
|
}
|
|
1402
1402
|
if (occurrences.length === 0) {
|
|
1403
|
-
console.warn(`[FuzzyAnchor] Exact text not found, trying fuzzy match: "${exact.substring(0, 50)}..."`);
|
|
1404
1403
|
const fuzzyMatch = findBestTextMatch(content, exact, positionHint);
|
|
1405
1404
|
if (fuzzyMatch) {
|
|
1406
|
-
console.warn(
|
|
1407
|
-
`[FuzzyAnchor] Found ${fuzzyMatch.matchQuality} match at position ${fuzzyMatch.start}`
|
|
1408
|
-
);
|
|
1409
1405
|
return { start: fuzzyMatch.start, end: fuzzyMatch.end };
|
|
1410
1406
|
}
|
|
1411
|
-
console.warn(`[FuzzyAnchor] No acceptable match found for: "${exact.substring(0, 50)}..."`);
|
|
1412
1407
|
return null;
|
|
1413
1408
|
}
|
|
1414
1409
|
if (occurrences.length === 1) {
|
|
@@ -1427,23 +1422,16 @@ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
|
1427
1422
|
return { start: pos2, end: pos2 + exact.length };
|
|
1428
1423
|
}
|
|
1429
1424
|
}
|
|
1430
|
-
console.warn(
|
|
1431
|
-
`[FuzzyAnchor] Multiple matches found but none match prefix/suffix exactly. Exact: "${exact.substring(0, 30)}...", Prefix: "${prefix?.substring(0, 20) || "none"}", Suffix: "${suffix?.substring(0, 20) || "none"}"`
|
|
1432
|
-
);
|
|
1433
1425
|
for (const pos2 of occurrences) {
|
|
1434
1426
|
const actualPrefix = content.substring(Math.max(0, pos2 - (prefix?.length || 0)), pos2);
|
|
1435
1427
|
const actualSuffix = content.substring(pos2 + exact.length, pos2 + exact.length + (suffix?.length || 0));
|
|
1436
1428
|
const fuzzyPrefixMatch = !prefix || actualPrefix.includes(prefix.trim());
|
|
1437
1429
|
const fuzzySuffixMatch = !suffix || actualSuffix.includes(suffix.trim());
|
|
1438
1430
|
if (fuzzyPrefixMatch && fuzzySuffixMatch) {
|
|
1439
|
-
console.warn(`[FuzzyAnchor] Using fuzzy context match at position ${pos2}`);
|
|
1440
1431
|
return { start: pos2, end: pos2 + exact.length };
|
|
1441
1432
|
}
|
|
1442
1433
|
}
|
|
1443
1434
|
}
|
|
1444
|
-
console.warn(
|
|
1445
|
-
`[FuzzyAnchor] Multiple matches but no context match. Using first occurrence. Exact: "${exact.substring(0, 30)}..."`
|
|
1446
|
-
);
|
|
1447
1435
|
const pos = occurrences[0];
|
|
1448
1436
|
return { start: pos, end: pos + exact.length };
|
|
1449
1437
|
}
|
|
@@ -1707,7 +1695,6 @@ function extractContext(content, start, end) {
|
|
|
1707
1695
|
return { prefix, suffix };
|
|
1708
1696
|
}
|
|
1709
1697
|
function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
1710
|
-
const exactPreview = exact.length > 50 ? exact.substring(0, 50) + "..." : exact;
|
|
1711
1698
|
const textAtOffset = content.substring(aiStart, aiEnd);
|
|
1712
1699
|
if (textAtOffset === exact) {
|
|
1713
1700
|
const context2 = extractContext(content, aiStart, aiEnd);
|
|
@@ -1721,47 +1708,13 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
|
1721
1708
|
matchQuality: "exact"
|
|
1722
1709
|
};
|
|
1723
1710
|
}
|
|
1724
|
-
const foundPreview = textAtOffset.length > 50 ? textAtOffset.substring(0, 50) + "..." : textAtOffset;
|
|
1725
|
-
console.warn(
|
|
1726
|
-
`[validateAndCorrectOffsets] \u26A0 AI offset mismatch:
|
|
1727
|
-
Expected text: "${exactPreview}"
|
|
1728
|
-
Found at AI offset (${aiStart}-${aiEnd}): "${foundPreview}"
|
|
1729
|
-
Attempting multi-strategy search...`
|
|
1730
|
-
);
|
|
1731
1711
|
const match = findBestTextMatch(content, exact, aiStart);
|
|
1732
1712
|
if (!match) {
|
|
1733
|
-
const exactLong = exact.length > 100 ? exact.substring(0, 100) + "..." : exact;
|
|
1734
|
-
console.error(
|
|
1735
|
-
`[validateAndCorrectOffsets] \u2717 No acceptable match found:
|
|
1736
|
-
AI offsets: start=${aiStart}, end=${aiEnd}
|
|
1737
|
-
AI text: "${exactLong}"
|
|
1738
|
-
Text at AI offset: "${foundPreview}"
|
|
1739
|
-
All search strategies (exact, case-insensitive, fuzzy) failed.
|
|
1740
|
-
This suggests the AI hallucinated text that doesn't exist in the document.`
|
|
1741
|
-
);
|
|
1742
1713
|
throw new Error(
|
|
1743
1714
|
"Cannot find acceptable match for text in content. All search strategies failed. Text may be hallucinated."
|
|
1744
1715
|
);
|
|
1745
1716
|
}
|
|
1746
1717
|
const actualText = content.substring(match.start, match.end);
|
|
1747
|
-
const actualPreview = actualText.length > 50 ? actualText.substring(0, 50) + "..." : actualText;
|
|
1748
|
-
const offsetDelta = match.start - aiStart;
|
|
1749
|
-
const matchSymbol = match.matchQuality === "exact" ? "\u2713" : match.matchQuality === "case-insensitive" ? "\u2248" : "~";
|
|
1750
|
-
console.warn(
|
|
1751
|
-
`[validateAndCorrectOffsets] ${matchSymbol} Found ${match.matchQuality} match:
|
|
1752
|
-
AI offsets: start=${aiStart}, end=${aiEnd}
|
|
1753
|
-
Corrected: start=${match.start}, end=${match.end}
|
|
1754
|
-
Offset delta: ${offsetDelta} characters
|
|
1755
|
-
Actual text: "${actualPreview}"`
|
|
1756
|
-
);
|
|
1757
|
-
if (match.matchQuality === "fuzzy") {
|
|
1758
|
-
console.warn(
|
|
1759
|
-
`[validateAndCorrectOffsets] Fuzzy match details:
|
|
1760
|
-
AI provided: "${exactPreview}"
|
|
1761
|
-
Found in doc: "${actualPreview}"
|
|
1762
|
-
Minor text differences detected - using document version`
|
|
1763
|
-
);
|
|
1764
|
-
}
|
|
1765
1718
|
const context = extractContext(content, match.start, match.end);
|
|
1766
1719
|
return {
|
|
1767
1720
|
start: match.start,
|