@semiont/api-client 0.2.35-build.97 → 0.2.35-build.99
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.d.ts +1 -1
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +19 -4
- package/dist/utils/index.js +19 -9
- package/dist/utils/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _semiont_core from '@semiont/core';
|
|
2
2
|
import { BaseUrl, Logger, ResourceUri, EntityType, AccessToken, AnnotationUri, components, Email, paths, RefreshToken, GoogleCredential, ContentFormat, SearchQuery, CloneToken, ResourceAnnotationUri, Motivation, UserDID, JobId } from '@semiont/core';
|
|
3
3
|
export { Logger } from '@semiont/core';
|
|
4
|
-
export { BoundingBox, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, MatchQuality, Point, Selector, SvgSelector, TextPosition, TextPositionSelector, TextQuoteSelector, ValidatedAnnotation, ValidationFailure, ValidationResult, ValidationSuccess, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition } from './utils/index.js';
|
|
4
|
+
export { BoundingBox, ContentCache, FragmentSelector, JWTTokenSchema, LOCALES, LocaleInfo, MatchQuality, Point, Selector, SvgSelector, TextPosition, TextPositionSelector, TextQuoteSelector, ValidatedAnnotation, ValidationFailure, ValidationResult, ValidationSuccess, buildContentCache, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isReference, isResolvedReference, isStubReference, isTag, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition } from './utils/index.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* TypeScript types for Server-Sent Events (SSE) streaming
|
package/dist/index.js
CHANGED
|
@@ -1328,7 +1328,13 @@ function levenshteinDistance(str1, str2) {
|
|
|
1328
1328
|
}
|
|
1329
1329
|
return matrix[len1][len2];
|
|
1330
1330
|
}
|
|
1331
|
-
function
|
|
1331
|
+
function buildContentCache(content) {
|
|
1332
|
+
return {
|
|
1333
|
+
normalizedContent: normalizeText(content),
|
|
1334
|
+
lowerContent: content.toLowerCase()
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
function findBestTextMatch(content, searchText, positionHint, cache) {
|
|
1332
1338
|
const maxFuzzyDistance = Math.max(5, Math.floor(searchText.length * 0.05));
|
|
1333
1339
|
const exactIndex = content.indexOf(searchText);
|
|
1334
1340
|
if (exactIndex !== -1) {
|
|
@@ -1339,8 +1345,7 @@ function findBestTextMatch(content, searchText, positionHint) {
|
|
|
1339
1345
|
};
|
|
1340
1346
|
}
|
|
1341
1347
|
const normalizedSearch = normalizeText(searchText);
|
|
1342
|
-
const
|
|
1343
|
-
const normalizedIndex = normalizedContent.indexOf(normalizedSearch);
|
|
1348
|
+
const normalizedIndex = cache.normalizedContent.indexOf(normalizedSearch);
|
|
1344
1349
|
if (normalizedIndex !== -1) {
|
|
1345
1350
|
let actualPos = 0;
|
|
1346
1351
|
let normalizedPos = 0;
|
|
@@ -1358,9 +1363,8 @@ function findBestTextMatch(content, searchText, positionHint) {
|
|
|
1358
1363
|
matchQuality: "normalized"
|
|
1359
1364
|
};
|
|
1360
1365
|
}
|
|
1361
|
-
const lowerContent = content.toLowerCase();
|
|
1362
1366
|
const lowerSearch = searchText.toLowerCase();
|
|
1363
|
-
const caseInsensitiveIndex = lowerContent.indexOf(lowerSearch);
|
|
1367
|
+
const caseInsensitiveIndex = cache.lowerContent.indexOf(lowerSearch);
|
|
1364
1368
|
if (caseInsensitiveIndex !== -1) {
|
|
1365
1369
|
return {
|
|
1366
1370
|
start: caseInsensitiveIndex,
|
|
@@ -1391,8 +1395,13 @@ function findBestTextMatch(content, searchText, positionHint) {
|
|
|
1391
1395
|
}
|
|
1392
1396
|
return null;
|
|
1393
1397
|
}
|
|
1394
|
-
function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
1398
|
+
function findTextWithContext(content, exact, prefix, suffix, positionHint, cache) {
|
|
1395
1399
|
if (!exact) return null;
|
|
1400
|
+
if (positionHint !== void 0 && positionHint >= 0 && positionHint + exact.length <= content.length) {
|
|
1401
|
+
if (content.substring(positionHint, positionHint + exact.length) === exact) {
|
|
1402
|
+
return { start: positionHint, end: positionHint + exact.length };
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1396
1405
|
const occurrences = [];
|
|
1397
1406
|
let index = content.indexOf(exact);
|
|
1398
1407
|
while (index !== -1) {
|
|
@@ -1400,7 +1409,7 @@ function findTextWithContext(content, exact, prefix, suffix, positionHint) {
|
|
|
1400
1409
|
index = content.indexOf(exact, index + 1);
|
|
1401
1410
|
}
|
|
1402
1411
|
if (occurrences.length === 0) {
|
|
1403
|
-
const fuzzyMatch = findBestTextMatch(content, exact, positionHint);
|
|
1412
|
+
const fuzzyMatch = findBestTextMatch(content, exact, positionHint, cache);
|
|
1404
1413
|
if (fuzzyMatch) {
|
|
1405
1414
|
return { start: fuzzyMatch.start, end: fuzzyMatch.end };
|
|
1406
1415
|
}
|
|
@@ -1708,7 +1717,8 @@ function validateAndCorrectOffsets(content, aiStart, aiEnd, exact) {
|
|
|
1708
1717
|
matchQuality: "exact"
|
|
1709
1718
|
};
|
|
1710
1719
|
}
|
|
1711
|
-
const
|
|
1720
|
+
const cache = buildContentCache(content);
|
|
1721
|
+
const match = findBestTextMatch(content, exact, aiStart, cache);
|
|
1712
1722
|
if (!match) {
|
|
1713
1723
|
throw new Error(
|
|
1714
1724
|
"Cannot find acceptable match for text in content. All search strategies failed. Text may be hallucinated."
|
|
@@ -1816,6 +1826,6 @@ function getMimeCategory(mimeType) {
|
|
|
1816
1826
|
return "unsupported";
|
|
1817
1827
|
}
|
|
1818
1828
|
|
|
1819
|
-
export { APIError, JWTTokenSchema, LOCALES, SSEClient, SSE_STREAM_CONNECTED, SemiontApiClient, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getExtensionForMimeType, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getMimeCategory, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isImageMimeType, isPdfMimeType, isReference, isResolvedReference, isStubReference, isTag, isTextMimeType, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
|
|
1829
|
+
export { APIError, JWTTokenSchema, LOCALES, SSEClient, SSE_STREAM_CONNECTED, SemiontApiClient, buildContentCache, createCircleSvg, createPolygonSvg, createRectangleSvg, decodeRepresentation, decodeWithCharset, extractBoundingBox, extractCharset, extractContext, findBestTextMatch, findTextWithContext, formatLocaleDisplay, getAllLocaleCodes, getAnnotationExactText, getBodySource, getBodyType, getChecksum, getCommentText, getCreator, getDerivedFrom, getExactText, getExtensionForMimeType, getFragmentSelector, getLanguage, getLocaleEnglishName, getLocaleInfo, getLocaleNativeName, getMimeCategory, getNodeEncoding, getPrimaryMediaType, getPrimaryRepresentation, getPrimarySelector, getResourceEntityTypes, getResourceId, getStorageUri, getSvgSelector, getTargetSelector, getTargetSource, getTextPositionSelector, getTextQuoteSelector, hasTargetSelector, isArchived, isAssessment, isBodyResolved, isComment, isDraft, isHighlight, isImageMimeType, isPdfMimeType, isReference, isResolvedReference, isStubReference, isTag, isTextMimeType, isValidEmail, normalizeCoordinates, normalizeText, parseSvgSelector, scaleSvgToNative, validateAndCorrectOffsets, validateData, validateSvgMarkup, verifyPosition };
|
|
1820
1830
|
//# sourceMappingURL=index.js.map
|
|
1821
1831
|
//# sourceMappingURL=index.js.map
|