@mintlify/common 1.0.710 → 1.0.712

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.
@@ -0,0 +1,11 @@
1
+ export declare function computeLevenshteinDistance(a: string, b: string): number;
2
+ export declare function computeStringSimilarity(a: string, b: string): number;
3
+ export interface BestMatchResult {
4
+ similarity: number;
5
+ startIndex: number;
6
+ endIndex: number;
7
+ }
8
+ export declare function findBestMatch(content: string, target: string, options?: {
9
+ minSimilarity?: number;
10
+ windowSize?: number;
11
+ }): BestMatchResult | null;
@@ -0,0 +1,56 @@
1
+ export function computeLevenshteinDistance(a, b) {
2
+ if (a.length === 0)
3
+ return b.length;
4
+ if (b.length === 0)
5
+ return a.length;
6
+ const matrix = [];
7
+ for (let i = 0; i <= b.length; i++) {
8
+ matrix[i] = [i];
9
+ }
10
+ for (let j = 0; j <= a.length; j++) {
11
+ matrix[0][j] = j;
12
+ }
13
+ for (let i = 1; i <= b.length; i++) {
14
+ for (let j = 1; j <= a.length; j++) {
15
+ if (b.charAt(i - 1) === a.charAt(j - 1)) {
16
+ matrix[i][j] = matrix[i - 1][j - 1];
17
+ }
18
+ else {
19
+ matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j] + 1);
20
+ }
21
+ }
22
+ }
23
+ return matrix[b.length][a.length];
24
+ }
25
+ export function computeStringSimilarity(a, b) {
26
+ if (a.length === 0 && b.length === 0)
27
+ return 1;
28
+ if (a.length === 0 || b.length === 0)
29
+ return 0;
30
+ const distance = computeLevenshteinDistance(a, b);
31
+ const maxLength = Math.max(a.length, b.length);
32
+ return 1 - distance / maxLength;
33
+ }
34
+ export function findBestMatch(content, target, options) {
35
+ var _a, _b;
36
+ const minSimilarity = (_a = options === null || options === void 0 ? void 0 : options.minSimilarity) !== null && _a !== void 0 ? _a : 0.85;
37
+ const windowSize = (_b = options === null || options === void 0 ? void 0 : options.windowSize) !== null && _b !== void 0 ? _b : Math.ceil(target.length * 1.5);
38
+ if (content.length === 0 || target.length === 0)
39
+ return null;
40
+ let bestMatch = null;
41
+ const minLen = Math.ceil(target.length * 0.5);
42
+ for (let i = 0; i <= content.length - minLen; i++) {
43
+ for (let len = minLen; len <= Math.min(windowSize, content.length - i); len++) {
44
+ const candidate = content.slice(i, i + len);
45
+ const similarity = computeStringSimilarity(candidate, target);
46
+ if (similarity >= minSimilarity && (!bestMatch || similarity > bestMatch.similarity)) {
47
+ bestMatch = {
48
+ similarity,
49
+ startIndex: i,
50
+ endIndex: i + len,
51
+ };
52
+ }
53
+ }
54
+ }
55
+ return bestMatch;
56
+ }
@@ -0,0 +1,2 @@
1
+ import type { CommentAnchor, TextSearchResult } from './types.js';
2
+ export declare function findOriginalTextInContent(content: string, anchor: CommentAnchor): TextSearchResult;
@@ -0,0 +1,45 @@
1
+ export function findOriginalTextInContent(content, anchor) {
2
+ var _a, _b;
3
+ const exactIndex = content.indexOf(anchor.originalText);
4
+ if (exactIndex !== -1) {
5
+ return {
6
+ found: true,
7
+ startIndex: exactIndex,
8
+ endIndex: exactIndex + anchor.originalText.length,
9
+ };
10
+ }
11
+ const contextPattern = anchor.contextBefore + anchor.originalText + anchor.contextAfter;
12
+ const contextIndex = content.indexOf(contextPattern);
13
+ if (contextIndex !== -1) {
14
+ const startIndex = contextIndex + anchor.contextBefore.length;
15
+ return {
16
+ found: true,
17
+ startIndex,
18
+ endIndex: startIndex + anchor.originalText.length,
19
+ };
20
+ }
21
+ const lines = content.split('\n');
22
+ if (anchor.line <= lines.length) {
23
+ const targetLine = lines[anchor.line - 1];
24
+ if (targetLine) {
25
+ const lineIndex = targetLine.indexOf(anchor.originalText);
26
+ if (lineIndex !== -1) {
27
+ let startIndex = 0;
28
+ for (let i = 0; i < anchor.line - 1; i++) {
29
+ startIndex += ((_b = (_a = lines[i]) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) + 1;
30
+ }
31
+ startIndex += lineIndex;
32
+ return {
33
+ found: true,
34
+ startIndex,
35
+ endIndex: startIndex + anchor.originalText.length,
36
+ };
37
+ }
38
+ }
39
+ }
40
+ return {
41
+ found: false,
42
+ startIndex: -1,
43
+ endIndex: -1,
44
+ };
45
+ }
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './computeStringSimilarity.js';
3
+ export * from './findTextInContent.js';
4
+ export * from './resolveAnchor.js';
5
+ export * from './resolveAnchors.js';
@@ -0,0 +1,5 @@
1
+ export * from './types.js';
2
+ export * from './computeStringSimilarity.js';
3
+ export * from './findTextInContent.js';
4
+ export * from './resolveAnchor.js';
5
+ export * from './resolveAnchors.js';
@@ -0,0 +1,2 @@
1
+ import type { CommentAnchor, AnchorResolutionResult, ResolveAnchorOptions } from './types.js';
2
+ export declare function resolveAnchor(content: string, anchor: CommentAnchor, options?: ResolveAnchorOptions): AnchorResolutionResult;
@@ -0,0 +1,49 @@
1
+ import { findBestMatch } from './computeStringSimilarity.js';
2
+ import { findOriginalTextInContent } from './findTextInContent.js';
3
+ const DEFAULT_SIMILARITY_THRESHOLD = 0.85;
4
+ export function resolveAnchor(content, anchor, options) {
5
+ var _a;
6
+ const similarityThreshold = (_a = options === null || options === void 0 ? void 0 : options.similarityThreshold) !== null && _a !== void 0 ? _a : DEFAULT_SIMILARITY_THRESHOLD;
7
+ if ((options === null || options === void 0 ? void 0 : options.currentCommit) && options.currentCommit === anchor.anchorCommit) {
8
+ const lines = content.split('\n');
9
+ let startIndex = 0;
10
+ for (let i = 0; i < anchor.line - 1 && i < lines.length; i++) {
11
+ startIndex += lines[i].length + 1;
12
+ }
13
+ startIndex += anchor.startCol;
14
+ return {
15
+ status: 'found',
16
+ range: {
17
+ startIndex,
18
+ endIndex: startIndex + anchor.originalText.length,
19
+ },
20
+ };
21
+ }
22
+ const searchResult = findOriginalTextInContent(content, anchor);
23
+ if (searchResult.found) {
24
+ return {
25
+ status: 'found',
26
+ range: {
27
+ startIndex: searchResult.startIndex,
28
+ endIndex: searchResult.endIndex,
29
+ },
30
+ };
31
+ }
32
+ const fuzzyMatch = findBestMatch(content, anchor.originalText, {
33
+ minSimilarity: similarityThreshold,
34
+ });
35
+ if (fuzzyMatch) {
36
+ return {
37
+ status: 'stale',
38
+ range: {
39
+ startIndex: fuzzyMatch.startIndex,
40
+ endIndex: fuzzyMatch.endIndex,
41
+ },
42
+ similarity: fuzzyMatch.similarity,
43
+ };
44
+ }
45
+ return {
46
+ status: 'orphan',
47
+ range: null,
48
+ };
49
+ }
@@ -0,0 +1,2 @@
1
+ import type { ThreadResolutionInput, ThreadResolutionResult, ResolveAnchorOptions } from './types.js';
2
+ export declare function resolveAnchors<T = unknown>(content: string, threads: ThreadResolutionInput<T>[], options?: ResolveAnchorOptions): ThreadResolutionResult<T>[];
@@ -0,0 +1,59 @@
1
+ import { resolveAnchor } from './resolveAnchor.js';
2
+ function computeLineAndCol(content, startIndex, endIndex) {
3
+ const lines = content.split('\n');
4
+ let charCount = 0;
5
+ let line = 1;
6
+ for (let i = 0; i < lines.length; i++) {
7
+ const lineLength = lines[i].length + 1;
8
+ if (charCount + lineLength > startIndex) {
9
+ line = i + 1;
10
+ break;
11
+ }
12
+ charCount += lineLength;
13
+ }
14
+ const startCol = startIndex - charCount;
15
+ const lineContent = lines[line - 1] || '';
16
+ const contextBeforeStart = Math.max(0, startCol - 50);
17
+ const contextBefore = lineContent.slice(contextBeforeStart, startCol);
18
+ let endCharCount = 0;
19
+ let endLine = 1;
20
+ for (let i = 0; i < lines.length; i++) {
21
+ const lineLength = lines[i].length + 1;
22
+ if (endCharCount + lineLength > endIndex) {
23
+ endLine = i + 1;
24
+ break;
25
+ }
26
+ endCharCount += lineLength;
27
+ }
28
+ const endCol = endIndex - endCharCount;
29
+ const endLineContent = lines[endLine - 1] || '';
30
+ const contextAfter = endLineContent.slice(endCol, endCol + 50);
31
+ return { line, startCol, endCol, contextBefore, contextAfter };
32
+ }
33
+ export function resolveAnchors(content, threads, options) {
34
+ return threads.map((thread) => {
35
+ const resolution = resolveAnchor(content, thread.anchor, options);
36
+ let updatedAnchor;
37
+ if (resolution.range && resolution.status !== 'orphan') {
38
+ const { line, startCol, endCol, contextBefore, contextAfter } = computeLineAndCol(content, resolution.range.startIndex, resolution.range.endIndex);
39
+ const originalText = content.slice(resolution.range.startIndex, resolution.range.endIndex);
40
+ const positionChanged = line !== thread.anchor.line ||
41
+ startCol !== thread.anchor.startCol ||
42
+ originalText !== thread.anchor.originalText;
43
+ if (positionChanged) {
44
+ updatedAnchor = Object.assign(Object.assign({}, thread.anchor), { line,
45
+ startCol,
46
+ endCol,
47
+ originalText,
48
+ contextBefore,
49
+ contextAfter, anchorCommit: (options === null || options === void 0 ? void 0 : options.currentCommit) || thread.anchor.anchorCommit });
50
+ }
51
+ }
52
+ return {
53
+ threadId: thread.threadId,
54
+ resolution,
55
+ updatedAnchor,
56
+ metadata: thread.metadata,
57
+ };
58
+ });
59
+ }
@@ -0,0 +1,41 @@
1
+ export interface CommentAnchor {
2
+ anchorCommit: string;
3
+ line: number;
4
+ startCol: number;
5
+ endCol: number;
6
+ originalText: string;
7
+ contextBefore: string;
8
+ contextAfter: string;
9
+ createdAt: Date;
10
+ createdBy: string;
11
+ }
12
+ export type AnchorResolutionStatus = 'found' | 'stale' | 'orphan';
13
+ export interface TextRange {
14
+ startIndex: number;
15
+ endIndex: number;
16
+ }
17
+ export interface AnchorResolutionResult {
18
+ status: AnchorResolutionStatus;
19
+ range: TextRange | null;
20
+ similarity?: number;
21
+ }
22
+ export interface ThreadResolutionInput<T = unknown> {
23
+ threadId: string;
24
+ anchor: CommentAnchor;
25
+ metadata?: T;
26
+ }
27
+ export interface ThreadResolutionResult<T = unknown> {
28
+ threadId: string;
29
+ resolution: AnchorResolutionResult;
30
+ updatedAnchor?: CommentAnchor;
31
+ metadata?: T;
32
+ }
33
+ export interface ResolveAnchorOptions {
34
+ currentCommit?: string;
35
+ similarityThreshold?: number;
36
+ }
37
+ export interface TextSearchResult {
38
+ found: boolean;
39
+ startIndex: number;
40
+ endIndex: number;
41
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.d.ts CHANGED
@@ -28,3 +28,4 @@ export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
30
  export * from './exponentialBackoff.js';
31
+ export * from './editor/index.js';
package/dist/index.js CHANGED
@@ -28,3 +28,4 @@ export * from './api-reference/parseApiTargetFromMetadata.js';
28
28
  export * from './mintIgnore.js';
29
29
  export * from './getDisplayDomain.js';
30
30
  export * from './exponentialBackoff.js';
31
+ export * from './editor/index.js';