mcp-resend 1.0.0-1
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/LICENSE +190 -0
- package/README.md +257 -0
- package/data/embeddings.json +245241 -0
- package/dist/config/environment.d.ts +152 -0
- package/dist/config/environment.d.ts.map +1 -0
- package/dist/config/environment.js +217 -0
- package/dist/config/environment.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +119 -0
- package/dist/index.js.map +1 -0
- package/dist/services/rate-limiter.d.ts +90 -0
- package/dist/services/rate-limiter.d.ts.map +1 -0
- package/dist/services/rate-limiter.js +267 -0
- package/dist/services/rate-limiter.js.map +1 -0
- package/dist/services/tool-registry.d.ts +219 -0
- package/dist/services/tool-registry.d.ts.map +1 -0
- package/dist/services/tool-registry.js +459 -0
- package/dist/services/tool-registry.js.map +1 -0
- package/dist/tools/docs/embeddings-loader.d.ts +69 -0
- package/dist/tools/docs/embeddings-loader.d.ts.map +1 -0
- package/dist/tools/docs/embeddings-loader.js +218 -0
- package/dist/tools/docs/embeddings-loader.js.map +1 -0
- package/dist/tools/docs/errors.d.ts +75 -0
- package/dist/tools/docs/errors.d.ts.map +1 -0
- package/dist/tools/docs/errors.js +145 -0
- package/dist/tools/docs/errors.js.map +1 -0
- package/dist/tools/docs/index.d.ts +11 -0
- package/dist/tools/docs/index.d.ts.map +1 -0
- package/dist/tools/docs/index.js +14 -0
- package/dist/tools/docs/index.js.map +1 -0
- package/dist/tools/docs/metrics.d.ts +94 -0
- package/dist/tools/docs/metrics.d.ts.map +1 -0
- package/dist/tools/docs/metrics.js +174 -0
- package/dist/tools/docs/metrics.js.map +1 -0
- package/dist/tools/docs/search-docs-tool.d.ts +54 -0
- package/dist/tools/docs/search-docs-tool.d.ts.map +1 -0
- package/dist/tools/docs/search-docs-tool.js +231 -0
- package/dist/tools/docs/search-docs-tool.js.map +1 -0
- package/dist/tools/docs/types.d.ts +70 -0
- package/dist/tools/docs/types.d.ts.map +1 -0
- package/dist/tools/docs/types.js +7 -0
- package/dist/tools/docs/types.js.map +1 -0
- package/dist/tools/docs/vector-search.d.ts +80 -0
- package/dist/tools/docs/vector-search.d.ts.map +1 -0
- package/dist/tools/docs/vector-search.js +297 -0
- package/dist/tools/docs/vector-search.js.map +1 -0
- package/dist/tools/index.d.ts +27 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +3413 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/utils/mcp-errors.d.ts +109 -0
- package/dist/utils/mcp-errors.d.ts.map +1 -0
- package/dist/utils/mcp-errors.js +306 -0
- package/dist/utils/mcp-errors.js.map +1 -0
- package/package.json +77 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lazy loader for pre-computed embeddings.
|
|
3
|
+
* Loads embeddings from data/embeddings.json on first access and caches them.
|
|
4
|
+
* Uses ES module path resolution for compatibility with both dev (tsx) and production (node).
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { dirname, join } from "node:path";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { createDocsError, DocsErrorCode } from "./errors.js";
|
|
10
|
+
// NOTE: Use console.error for logging - stdout is reserved for MCP protocol
|
|
11
|
+
const log = (message) => console.error(`[docs-search] ${message}`);
|
|
12
|
+
/** Expected schema version - must match build-embeddings.ts INDEX_VERSION */
|
|
13
|
+
export const EXPECTED_SCHEMA_VERSION = "1.0.0";
|
|
14
|
+
/** Expected embedding dimensions for Xenova/all-MiniLM-L6-v2 */
|
|
15
|
+
export const EXPECTED_DIMENSIONS = 384;
|
|
16
|
+
/** Maximum age in days before showing a warning */
|
|
17
|
+
const FRESHNESS_WARNING_DAYS = 14;
|
|
18
|
+
/** Maximum age in days before returning an error hint */
|
|
19
|
+
const FRESHNESS_ERROR_DAYS = 30;
|
|
20
|
+
/** Cached embeddings index, null if not yet loaded */
|
|
21
|
+
let cachedEmbeddings = null;
|
|
22
|
+
/** Loading promise to prevent concurrent loads */
|
|
23
|
+
let loadingPromise = null;
|
|
24
|
+
/** Freshness warning message if embeddings are stale */
|
|
25
|
+
let freshnessWarning = null;
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the path to the embeddings.json file.
|
|
28
|
+
* Uses import.meta.url for ES module path resolution.
|
|
29
|
+
*
|
|
30
|
+
* In development (tsx): src/tools/docs/embeddings-loader.ts -> data/embeddings.json
|
|
31
|
+
* In production (node): dist/tools/docs/embeddings-loader.js -> data/embeddings.json
|
|
32
|
+
*
|
|
33
|
+
* Both resolve to the same data/ directory at project root.
|
|
34
|
+
*/
|
|
35
|
+
function getEmbeddingsPath() {
|
|
36
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
// From src/tools/docs/ or dist/tools/docs/, go up 3 levels to project root
|
|
38
|
+
return join(currentDir, "..", "..", "..", "data", "embeddings.json");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Validate the schema version of loaded embeddings.
|
|
42
|
+
*
|
|
43
|
+
* @param index - The loaded embeddings index
|
|
44
|
+
* @throws DocsError if version mismatch
|
|
45
|
+
*/
|
|
46
|
+
function validateSchemaVersion(index) {
|
|
47
|
+
if (!index.version) {
|
|
48
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, "Embeddings file missing version field");
|
|
49
|
+
}
|
|
50
|
+
// For now, only accept exact version match
|
|
51
|
+
// Future: implement semver compatibility checking
|
|
52
|
+
if (index.version !== EXPECTED_SCHEMA_VERSION) {
|
|
53
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_VERSION_MISMATCH, `Embeddings version mismatch: expected ${EXPECTED_SCHEMA_VERSION}, got ${index.version}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check embeddings freshness and set warning if stale.
|
|
58
|
+
*
|
|
59
|
+
* @param index - The loaded embeddings index
|
|
60
|
+
* @returns Warning message if stale, null otherwise
|
|
61
|
+
*/
|
|
62
|
+
function checkFreshness(index) {
|
|
63
|
+
if (!index.generatedAt) {
|
|
64
|
+
return "Embeddings file missing generatedAt timestamp";
|
|
65
|
+
}
|
|
66
|
+
const generatedDate = new Date(index.generatedAt);
|
|
67
|
+
const now = new Date();
|
|
68
|
+
const ageMs = now.getTime() - generatedDate.getTime();
|
|
69
|
+
const ageDays = ageMs / (1000 * 60 * 60 * 24);
|
|
70
|
+
if (ageDays > FRESHNESS_ERROR_DAYS) {
|
|
71
|
+
return `Embeddings are ${Math.floor(ageDays)} days old (generated: ${index.generatedAt}). Consider running 'npm run build:embeddings' to update.`;
|
|
72
|
+
}
|
|
73
|
+
if (ageDays > FRESHNESS_WARNING_DAYS) {
|
|
74
|
+
return `Embeddings are ${Math.floor(ageDays)} days old. Consider refreshing soon.`;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validate embedding dimensions match expected model output.
|
|
80
|
+
*
|
|
81
|
+
* @param index - The loaded embeddings index
|
|
82
|
+
* @throws DocsError if dimension mismatch
|
|
83
|
+
*/
|
|
84
|
+
function validateDimensions(index) {
|
|
85
|
+
if (index.dimensions !== EXPECTED_DIMENSIONS) {
|
|
86
|
+
throw createDocsError(DocsErrorCode.DIMENSION_MISMATCH, `Embeddings dimension mismatch: expected ${EXPECTED_DIMENSIONS}, got ${index.dimensions}. ` +
|
|
87
|
+
"This may indicate the embeddings were generated with a different model.");
|
|
88
|
+
}
|
|
89
|
+
// Also validate first chunk's actual embedding length
|
|
90
|
+
if (index.chunks.length > 0) {
|
|
91
|
+
const firstChunk = index.chunks[0];
|
|
92
|
+
if (firstChunk.embedding && firstChunk.embedding.length !== index.dimensions) {
|
|
93
|
+
throw createDocsError(DocsErrorCode.DIMENSION_MISMATCH, `Chunk embedding dimension mismatch: header says ${index.dimensions}, actual is ${firstChunk.embedding.length}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Load embeddings from disk.
|
|
99
|
+
* This is the internal loader, called once and cached.
|
|
100
|
+
* Performs schema version validation and freshness checks.
|
|
101
|
+
*/
|
|
102
|
+
async function loadFromDisk() {
|
|
103
|
+
const embeddingsPath = getEmbeddingsPath();
|
|
104
|
+
log(`Loading embeddings from: ${embeddingsPath}`);
|
|
105
|
+
const startTime = Date.now();
|
|
106
|
+
try {
|
|
107
|
+
const content = await readFile(embeddingsPath, "utf-8");
|
|
108
|
+
let index;
|
|
109
|
+
try {
|
|
110
|
+
index = JSON.parse(content);
|
|
111
|
+
}
|
|
112
|
+
catch (parseError) {
|
|
113
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, `Failed to parse embeddings JSON: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
114
|
+
}
|
|
115
|
+
const loadTime = Date.now() - startTime;
|
|
116
|
+
log(`Loaded ${index.chunks.length} chunks (${index.dimensions}D vectors) in ${loadTime}ms`);
|
|
117
|
+
// Validate schema version
|
|
118
|
+
validateSchemaVersion(index);
|
|
119
|
+
// Validate dimensions
|
|
120
|
+
validateDimensions(index);
|
|
121
|
+
// Validate basic structure
|
|
122
|
+
if (!index.chunks || !Array.isArray(index.chunks)) {
|
|
123
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, "Invalid embeddings format: missing chunks array");
|
|
124
|
+
}
|
|
125
|
+
if (index.chunks.length === 0) {
|
|
126
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, "Invalid embeddings format: empty chunks array");
|
|
127
|
+
}
|
|
128
|
+
// Validate first chunk has expected fields
|
|
129
|
+
const firstChunk = index.chunks[0];
|
|
130
|
+
if (!firstChunk.embedding || !Array.isArray(firstChunk.embedding)) {
|
|
131
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, "Invalid embeddings format: chunk missing embedding array");
|
|
132
|
+
}
|
|
133
|
+
// Check freshness and store warning
|
|
134
|
+
freshnessWarning = checkFreshness(index);
|
|
135
|
+
if (freshnessWarning) {
|
|
136
|
+
log(`Freshness warning: ${freshnessWarning}`);
|
|
137
|
+
}
|
|
138
|
+
return index;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
// Re-throw DocsError as-is
|
|
142
|
+
if (error && typeof error === "object" && "code" in error) {
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") {
|
|
146
|
+
throw createDocsError(DocsErrorCode.EMBEDDINGS_NOT_FOUND, `Embeddings file not found at ${embeddingsPath}`);
|
|
147
|
+
}
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Load embeddings asynchronously with caching.
|
|
153
|
+
* Safe to call multiple times; will return cached data after first load.
|
|
154
|
+
* Concurrent calls will share the same loading promise.
|
|
155
|
+
*
|
|
156
|
+
* @returns Promise resolving to the embeddings index
|
|
157
|
+
* @throws Error if embeddings file is missing or invalid
|
|
158
|
+
*/
|
|
159
|
+
export async function loadEmbeddings() {
|
|
160
|
+
// Return cached if available
|
|
161
|
+
if (cachedEmbeddings !== null) {
|
|
162
|
+
return cachedEmbeddings;
|
|
163
|
+
}
|
|
164
|
+
// If already loading, wait for that promise
|
|
165
|
+
if (loadingPromise !== null) {
|
|
166
|
+
return loadingPromise;
|
|
167
|
+
}
|
|
168
|
+
// Start loading and cache the promise
|
|
169
|
+
loadingPromise = loadFromDisk()
|
|
170
|
+
.then((index) => {
|
|
171
|
+
cachedEmbeddings = index;
|
|
172
|
+
loadingPromise = null;
|
|
173
|
+
return index;
|
|
174
|
+
})
|
|
175
|
+
.catch((error) => {
|
|
176
|
+
loadingPromise = null;
|
|
177
|
+
throw error;
|
|
178
|
+
});
|
|
179
|
+
return loadingPromise;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Get cached embeddings synchronously.
|
|
183
|
+
* Returns null if embeddings haven't been loaded yet.
|
|
184
|
+
* Use loadEmbeddings() for guaranteed access.
|
|
185
|
+
*
|
|
186
|
+
* @returns The cached embeddings index, or null if not loaded
|
|
187
|
+
*/
|
|
188
|
+
export function getLoadedEmbeddings() {
|
|
189
|
+
return cachedEmbeddings;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Clear the embeddings cache.
|
|
193
|
+
* Primarily for testing purposes.
|
|
194
|
+
*/
|
|
195
|
+
export function clearEmbeddingsCache() {
|
|
196
|
+
cachedEmbeddings = null;
|
|
197
|
+
loadingPromise = null;
|
|
198
|
+
freshnessWarning = null;
|
|
199
|
+
log("Embeddings cache cleared");
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Get the freshness warning message if embeddings are stale.
|
|
203
|
+
* Returns null if embeddings are fresh or not yet loaded.
|
|
204
|
+
*
|
|
205
|
+
* @returns Freshness warning message, or null
|
|
206
|
+
*/
|
|
207
|
+
export function getFreshnessWarning() {
|
|
208
|
+
return freshnessWarning;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Check if embeddings are currently loaded.
|
|
212
|
+
*
|
|
213
|
+
* @returns true if embeddings are cached
|
|
214
|
+
*/
|
|
215
|
+
export function isEmbeddingsLoaded() {
|
|
216
|
+
return cachedEmbeddings !== null;
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=embeddings-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings-loader.js","sourceRoot":"","sources":["../../../src/tools/docs/embeddings-loader.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE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ED,4CAA4C;IAC5C,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;QAC5B,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,sCAAsC;IACtC,cAAc,GAAG,YAAY,EAAE;SAC5B,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;QACd,gBAAgB,GAAG,KAAK,CAAC;QACzB,cAAc,GAAG,IAAI,CAAC;QACtB,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACf,cAAc,GAAG,IAAI,CAAC;QACtB,MAAM,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IAEL,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,gBAAgB,GAAG,IAAI,CAAC;IACxB,cAAc,GAAG,IAAI,CAAC;IACtB,gBAAgB,GAAG,IAAI,CAAC;IACxB,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAClC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,gBAAgB,CAAC;AAC1B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,gBAAgB,KAAK,IAAI,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error definitions for the documentation search tool.
|
|
3
|
+
* Provides consistent error codes, messages, hints, and recoverability flags.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Error codes for documentation search failures.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum DocsErrorCode {
|
|
9
|
+
/** Embeddings file not found at expected path */
|
|
10
|
+
EMBEDDINGS_NOT_FOUND = "EMBEDDINGS_NOT_FOUND",
|
|
11
|
+
/** Embeddings file exists but is corrupted or malformed */
|
|
12
|
+
EMBEDDINGS_CORRUPT = "EMBEDDINGS_CORRUPT",
|
|
13
|
+
/** Embeddings file version does not match expected schema version */
|
|
14
|
+
EMBEDDINGS_VERSION_MISMATCH = "EMBEDDINGS_VERSION_MISMATCH",
|
|
15
|
+
/** Failed to load the embedding model */
|
|
16
|
+
MODEL_LOAD_FAILURE = "MODEL_LOAD_FAILURE",
|
|
17
|
+
/** Network request timed out */
|
|
18
|
+
NETWORK_TIMEOUT = "NETWORK_TIMEOUT",
|
|
19
|
+
/** Vector dimensions do not match between query and stored embeddings */
|
|
20
|
+
DIMENSION_MISMATCH = "DIMENSION_MISMATCH",
|
|
21
|
+
/** General search failure */
|
|
22
|
+
SEARCH_FAILED = "SEARCH_FAILED",
|
|
23
|
+
/** Embeddings are stale and should be regenerated */
|
|
24
|
+
EMBEDDINGS_STALE = "EMBEDDINGS_STALE"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Structured error with code, message, hint, and recoverability.
|
|
28
|
+
*/
|
|
29
|
+
export interface DocsError {
|
|
30
|
+
/** Machine-readable error code */
|
|
31
|
+
code: DocsErrorCode;
|
|
32
|
+
/** Human-readable error message */
|
|
33
|
+
message: string;
|
|
34
|
+
/** Actionable hint for resolving the error */
|
|
35
|
+
hint: string;
|
|
36
|
+
/** Whether the error is potentially recoverable with retry */
|
|
37
|
+
recoverable: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create a structured DocsError from an error code and message.
|
|
41
|
+
*
|
|
42
|
+
* @param code - The error code
|
|
43
|
+
* @param message - Custom error message describing the specific failure
|
|
44
|
+
* @returns A structured DocsError object
|
|
45
|
+
*/
|
|
46
|
+
export declare function createDocsError(code: DocsErrorCode, message: string): DocsError;
|
|
47
|
+
/**
|
|
48
|
+
* Type guard to check if an error is a DocsError.
|
|
49
|
+
*
|
|
50
|
+
* @param error - The error to check
|
|
51
|
+
* @returns True if the error is a DocsError
|
|
52
|
+
*/
|
|
53
|
+
export declare function isDocsError(error: unknown): error is DocsError;
|
|
54
|
+
/**
|
|
55
|
+
* Convert an unknown error to a DocsError.
|
|
56
|
+
* Attempts to classify the error based on its message.
|
|
57
|
+
*
|
|
58
|
+
* @param error - The error to convert
|
|
59
|
+
* @returns A structured DocsError
|
|
60
|
+
*/
|
|
61
|
+
export declare function toDocsError(error: unknown): DocsError;
|
|
62
|
+
/**
|
|
63
|
+
* Format a DocsError for MCP response output.
|
|
64
|
+
*
|
|
65
|
+
* @param error - The DocsError to format
|
|
66
|
+
* @returns Formatted error object suitable for JSON serialization
|
|
67
|
+
*/
|
|
68
|
+
export declare function formatErrorResponse(error: DocsError): {
|
|
69
|
+
error: true;
|
|
70
|
+
code: string;
|
|
71
|
+
message: string;
|
|
72
|
+
hint: string;
|
|
73
|
+
recoverable: boolean;
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/tools/docs/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,oBAAY,aAAa;IACvB,iDAAiD;IACjD,oBAAoB,yBAAyB;IAC7C,2DAA2D;IAC3D,kBAAkB,uBAAuB;IACzC,qEAAqE;IACrE,2BAA2B,gCAAgC;IAC3D,yCAAyC;IACzC,kBAAkB,uBAAuB;IACzC,gCAAgC;IAChC,eAAe,oBAAoB;IACnC,yEAAyE;IACzE,kBAAkB,uBAAuB;IACzC,6BAA6B;IAC7B,aAAa,kBAAkB;IAC/B,qDAAqD;IACrD,gBAAgB,qBAAqB;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,kCAAkC;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,8CAA8C;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,WAAW,EAAE,OAAO,CAAC;CACtB;AAwCD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,CAQ/E;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,SAAS,CAU9D;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAmCrD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,GAAG;IACrD,KAAK,EAAE,IAAI,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;CACtB,CAQA"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured error definitions for the documentation search tool.
|
|
3
|
+
* Provides consistent error codes, messages, hints, and recoverability flags.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Error codes for documentation search failures.
|
|
7
|
+
*/
|
|
8
|
+
export var DocsErrorCode;
|
|
9
|
+
(function (DocsErrorCode) {
|
|
10
|
+
/** Embeddings file not found at expected path */
|
|
11
|
+
DocsErrorCode["EMBEDDINGS_NOT_FOUND"] = "EMBEDDINGS_NOT_FOUND";
|
|
12
|
+
/** Embeddings file exists but is corrupted or malformed */
|
|
13
|
+
DocsErrorCode["EMBEDDINGS_CORRUPT"] = "EMBEDDINGS_CORRUPT";
|
|
14
|
+
/** Embeddings file version does not match expected schema version */
|
|
15
|
+
DocsErrorCode["EMBEDDINGS_VERSION_MISMATCH"] = "EMBEDDINGS_VERSION_MISMATCH";
|
|
16
|
+
/** Failed to load the embedding model */
|
|
17
|
+
DocsErrorCode["MODEL_LOAD_FAILURE"] = "MODEL_LOAD_FAILURE";
|
|
18
|
+
/** Network request timed out */
|
|
19
|
+
DocsErrorCode["NETWORK_TIMEOUT"] = "NETWORK_TIMEOUT";
|
|
20
|
+
/** Vector dimensions do not match between query and stored embeddings */
|
|
21
|
+
DocsErrorCode["DIMENSION_MISMATCH"] = "DIMENSION_MISMATCH";
|
|
22
|
+
/** General search failure */
|
|
23
|
+
DocsErrorCode["SEARCH_FAILED"] = "SEARCH_FAILED";
|
|
24
|
+
/** Embeddings are stale and should be regenerated */
|
|
25
|
+
DocsErrorCode["EMBEDDINGS_STALE"] = "EMBEDDINGS_STALE";
|
|
26
|
+
})(DocsErrorCode || (DocsErrorCode = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Error definitions with their hints and recoverability.
|
|
29
|
+
*/
|
|
30
|
+
const ERROR_DEFINITIONS = {
|
|
31
|
+
[DocsErrorCode.EMBEDDINGS_NOT_FOUND]: {
|
|
32
|
+
hint: "Run 'npm run build:embeddings' to generate the embeddings index.",
|
|
33
|
+
recoverable: false,
|
|
34
|
+
},
|
|
35
|
+
[DocsErrorCode.EMBEDDINGS_CORRUPT]: {
|
|
36
|
+
hint: "Run 'npm run build:embeddings:force' to regenerate the embeddings index.",
|
|
37
|
+
recoverable: false,
|
|
38
|
+
},
|
|
39
|
+
[DocsErrorCode.EMBEDDINGS_VERSION_MISMATCH]: {
|
|
40
|
+
hint: "Run 'npm run build:embeddings:force' to regenerate with the current schema version.",
|
|
41
|
+
recoverable: false,
|
|
42
|
+
},
|
|
43
|
+
[DocsErrorCode.MODEL_LOAD_FAILURE]: {
|
|
44
|
+
hint: "Check network connectivity. The model is downloaded on first use. Retry may help.",
|
|
45
|
+
recoverable: true,
|
|
46
|
+
},
|
|
47
|
+
[DocsErrorCode.NETWORK_TIMEOUT]: {
|
|
48
|
+
hint: "Network request timed out. Check your connection and retry.",
|
|
49
|
+
recoverable: true,
|
|
50
|
+
},
|
|
51
|
+
[DocsErrorCode.DIMENSION_MISMATCH]: {
|
|
52
|
+
hint: "Embeddings were generated with a different model. Run 'npm run build:embeddings:force' to regenerate.",
|
|
53
|
+
recoverable: false,
|
|
54
|
+
},
|
|
55
|
+
[DocsErrorCode.SEARCH_FAILED]: {
|
|
56
|
+
hint: "Check server logs for details. If the issue persists, try regenerating embeddings.",
|
|
57
|
+
recoverable: true,
|
|
58
|
+
},
|
|
59
|
+
[DocsErrorCode.EMBEDDINGS_STALE]: {
|
|
60
|
+
hint: "Embeddings are outdated. Run 'npm run build:embeddings' to update.",
|
|
61
|
+
recoverable: false,
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Create a structured DocsError from an error code and message.
|
|
66
|
+
*
|
|
67
|
+
* @param code - The error code
|
|
68
|
+
* @param message - Custom error message describing the specific failure
|
|
69
|
+
* @returns A structured DocsError object
|
|
70
|
+
*/
|
|
71
|
+
export function createDocsError(code, message) {
|
|
72
|
+
const definition = ERROR_DEFINITIONS[code];
|
|
73
|
+
return {
|
|
74
|
+
code,
|
|
75
|
+
message,
|
|
76
|
+
hint: definition.hint,
|
|
77
|
+
recoverable: definition.recoverable,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Type guard to check if an error is a DocsError.
|
|
82
|
+
*
|
|
83
|
+
* @param error - The error to check
|
|
84
|
+
* @returns True if the error is a DocsError
|
|
85
|
+
*/
|
|
86
|
+
export function isDocsError(error) {
|
|
87
|
+
return (typeof error === "object" &&
|
|
88
|
+
error !== null &&
|
|
89
|
+
"code" in error &&
|
|
90
|
+
"message" in error &&
|
|
91
|
+
"hint" in error &&
|
|
92
|
+
"recoverable" in error &&
|
|
93
|
+
Object.values(DocsErrorCode).includes(error.code));
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Convert an unknown error to a DocsError.
|
|
97
|
+
* Attempts to classify the error based on its message.
|
|
98
|
+
*
|
|
99
|
+
* @param error - The error to convert
|
|
100
|
+
* @returns A structured DocsError
|
|
101
|
+
*/
|
|
102
|
+
export function toDocsError(error) {
|
|
103
|
+
// Already a DocsError
|
|
104
|
+
if (isDocsError(error)) {
|
|
105
|
+
return error;
|
|
106
|
+
}
|
|
107
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
108
|
+
// Classify based on message content
|
|
109
|
+
if (message.includes("ENOENT") || message.includes("not found")) {
|
|
110
|
+
return createDocsError(DocsErrorCode.EMBEDDINGS_NOT_FOUND, message);
|
|
111
|
+
}
|
|
112
|
+
if (message.includes("Invalid embeddings format") || message.includes("JSON")) {
|
|
113
|
+
return createDocsError(DocsErrorCode.EMBEDDINGS_CORRUPT, message);
|
|
114
|
+
}
|
|
115
|
+
if (message.includes("version") || message.includes("schema")) {
|
|
116
|
+
return createDocsError(DocsErrorCode.EMBEDDINGS_VERSION_MISMATCH, message);
|
|
117
|
+
}
|
|
118
|
+
if (message.includes("dimension") || message.includes("Vector dimension mismatch")) {
|
|
119
|
+
return createDocsError(DocsErrorCode.DIMENSION_MISMATCH, message);
|
|
120
|
+
}
|
|
121
|
+
if (message.includes("model") || message.includes("pipeline") || message.includes("transformers")) {
|
|
122
|
+
return createDocsError(DocsErrorCode.MODEL_LOAD_FAILURE, message);
|
|
123
|
+
}
|
|
124
|
+
if (message.includes("timeout") || message.includes("ETIMEDOUT")) {
|
|
125
|
+
return createDocsError(DocsErrorCode.NETWORK_TIMEOUT, message);
|
|
126
|
+
}
|
|
127
|
+
// Default to generic search failure
|
|
128
|
+
return createDocsError(DocsErrorCode.SEARCH_FAILED, message);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Format a DocsError for MCP response output.
|
|
132
|
+
*
|
|
133
|
+
* @param error - The DocsError to format
|
|
134
|
+
* @returns Formatted error object suitable for JSON serialization
|
|
135
|
+
*/
|
|
136
|
+
export function formatErrorResponse(error) {
|
|
137
|
+
return {
|
|
138
|
+
error: true,
|
|
139
|
+
code: error.code,
|
|
140
|
+
message: error.message,
|
|
141
|
+
hint: error.hint,
|
|
142
|
+
recoverable: error.recoverable,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/tools/docs/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,CAAN,IAAY,aAiBX;AAjBD,WAAY,aAAa;IACvB,iDAAiD;IACjD,8DAA6C,CAAA;IAC7C,2DAA2D;IAC3D,0DAAyC,CAAA;IACzC,qEAAqE;IACrE,4EAA2D,CAAA;IAC3D,yCAAyC;IACzC,0DAAyC,CAAA;IACzC,gCAAgC;IAChC,oDAAmC,CAAA;IACnC,yEAAyE;IACzE,0DAAyC,CAAA;IACzC,6BAA6B;IAC7B,gDAA+B,CAAA;IAC/B,qDAAqD;IACrD,sDAAqC,CAAA;AACvC,CAAC,EAjBW,aAAa,KAAb,aAAa,QAiBxB;AAgBD;;GAEG;AACH,MAAM,iBAAiB,GAA+D;IACpF,CAAC,aAAa,CAAC,oBAAoB,CAAC,EAAE;QACpC,IAAI,EAAE,kEAAkE;QACxE,WAAW,EAAE,KAAK;KACnB;IACD,CAAC,aAAa,CAAC,kBAAkB,CAAC,EAAE;QAClC,IAAI,EAAE,0EAA0E;QAChF,WAAW,EAAE,KAAK;KACnB;IACD,CAAC,aAAa,CAAC,2BAA2B,CAAC,EAAE;QAC3C,IAAI,EAAE,qFAAqF;QAC3F,WAAW,EAAE,KAAK;KACnB;IACD,CAAC,aAAa,CAAC,kBAAkB,CAAC,EAAE;QAClC,IAAI,EAAE,mFAAmF;QACzF,WAAW,EAAE,IAAI;KAClB;IACD,CAAC,aAAa,CAAC,eAAe,CAAC,EAAE;QAC/B,IAAI,EAAE,6DAA6D;QACnE,WAAW,EAAE,IAAI;KAClB;IACD,CAAC,aAAa,CAAC,kBAAkB,CAAC,EAAE;QAClC,IAAI,EAAE,uGAAuG;QAC7G,WAAW,EAAE,KAAK;KACnB;IACD,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE;QAC7B,IAAI,EAAE,oFA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,WAAW,EAAE,KAAK,CAAC,WAAW;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documentation search tool module exports.
|
|
3
|
+
* Provides semantic search functionality for Resend API documentation.
|
|
4
|
+
*/
|
|
5
|
+
export { getDefinition as getSearchDocsDefinition, execute as executeSearchDocs, } from "./search-docs-tool.js";
|
|
6
|
+
export type { SearchResult, SearchResponse, SearchErrorResponse, SearchResponseType, ScoredChunk, } from "./types.js";
|
|
7
|
+
export { DocsErrorCode, createDocsError, isDocsError, toDocsError, formatErrorResponse, type DocsError, } from "./errors.js";
|
|
8
|
+
export { recordSearch, recordSearchError, recordModelLoaded, recordEmbeddingsLoaded, setEmbeddingsCacheStatus, getSearchStats, clearMetricsHistory, getHistorySize, type SearchMetrics, type MetricType, } from "./metrics.js";
|
|
9
|
+
export { loadEmbeddings, getLoadedEmbeddings, clearEmbeddingsCache, isEmbeddingsLoaded, getFreshnessWarning, EXPECTED_SCHEMA_VERSION, EXPECTED_DIMENSIONS, } from "./embeddings-loader.js";
|
|
10
|
+
export { semanticSearch, keywordSearch, cosineSimilarity, truncateToTokenBudget, getEmbeddingsStats, loadEmbedder, } from "./vector-search.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/docs/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACL,aAAa,IAAI,uBAAuB,EACxC,OAAO,IAAI,iBAAiB,GAC7B,MAAM,uBAAuB,CAAC;AAG/B,YAAY,EACV,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,aAAa,EACb,eAAe,EACf,WAAW,EACX,WAAW,EACX,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Documentation search tool module exports.
|
|
3
|
+
* Provides semantic search functionality for Resend API documentation.
|
|
4
|
+
*/
|
|
5
|
+
// Tool implementation
|
|
6
|
+
export { getDefinition as getSearchDocsDefinition, execute as executeSearchDocs, } from "./search-docs-tool.js";
|
|
7
|
+
// Error handling
|
|
8
|
+
export { DocsErrorCode, createDocsError, isDocsError, toDocsError, formatErrorResponse, } from "./errors.js";
|
|
9
|
+
// Metrics
|
|
10
|
+
export { recordSearch, recordSearchError, recordModelLoaded, recordEmbeddingsLoaded, setEmbeddingsCacheStatus, getSearchStats, clearMetricsHistory, getHistorySize, } from "./metrics.js";
|
|
11
|
+
// Utilities for testing/debugging
|
|
12
|
+
export { loadEmbeddings, getLoadedEmbeddings, clearEmbeddingsCache, isEmbeddingsLoaded, getFreshnessWarning, EXPECTED_SCHEMA_VERSION, EXPECTED_DIMENSIONS, } from "./embeddings-loader.js";
|
|
13
|
+
export { semanticSearch, keywordSearch, cosineSimilarity, truncateToTokenBudget, getEmbeddingsStats, loadEmbedder, } from "./vector-search.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/docs/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,sBAAsB;AACtB,OAAO,EACL,aAAa,IAAI,uBAAuB,EACxC,OAAO,IAAI,iBAAiB,GAC7B,MAAM,uBAAuB,CAAC;AAW/B,iBAAiB;AACjB,OAAO,EACL,aAAa,EACb,eAAe,EACf,WAAW,EACX,WAAW,EACX,mBAAmB,GAEpB,MAAM,aAAa,CAAC;AAErB,UAAU;AACV,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,cAAc,GAGf,MAAM,cAAc,CAAC;AAEtB,kCAAkC;AAClC,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EACL,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,qBAAqB,EACrB,kBAAkB,EAClB,YAAY,GACb,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metrics tracking for documentation search.
|
|
3
|
+
* Collects search performance metrics and outputs them as JSON lines to stderr.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Metric types for documentation search.
|
|
7
|
+
*/
|
|
8
|
+
export type MetricType = "search_completed" | "search_error" | "model_loaded" | "embeddings_loaded";
|
|
9
|
+
/**
|
|
10
|
+
* Search metrics data structure.
|
|
11
|
+
*/
|
|
12
|
+
export interface SearchMetrics {
|
|
13
|
+
/** Metric type identifier */
|
|
14
|
+
_type: "metric";
|
|
15
|
+
/** Name of the metric */
|
|
16
|
+
name: MetricType;
|
|
17
|
+
/** Timestamp in ISO format */
|
|
18
|
+
timestamp: string;
|
|
19
|
+
/** Search latency in milliseconds */
|
|
20
|
+
search_latency_ms?: number;
|
|
21
|
+
/** Number of results returned */
|
|
22
|
+
result_count?: number;
|
|
23
|
+
/** Type of search performed */
|
|
24
|
+
search_type?: "semantic" | "keyword" | "hybrid";
|
|
25
|
+
/** Whether embeddings were cached */
|
|
26
|
+
cache_hit?: boolean;
|
|
27
|
+
/** Error code if search failed */
|
|
28
|
+
error_code?: string;
|
|
29
|
+
/** Additional context */
|
|
30
|
+
context?: Record<string, unknown>;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Record a successful search and emit metric.
|
|
34
|
+
*
|
|
35
|
+
* @param latencyMs - Search latency in milliseconds
|
|
36
|
+
* @param resultCount - Number of results returned
|
|
37
|
+
* @param searchType - Type of search performed
|
|
38
|
+
* @param cacheHit - Whether embeddings were cached
|
|
39
|
+
*/
|
|
40
|
+
export declare function recordSearch(latencyMs: number, resultCount: number, searchType: "semantic" | "keyword" | "hybrid", cacheHit: boolean): void;
|
|
41
|
+
/**
|
|
42
|
+
* Record a search error and emit metric.
|
|
43
|
+
*
|
|
44
|
+
* @param latencyMs - Time until error in milliseconds
|
|
45
|
+
* @param errorCode - Error code from DocsErrorCode
|
|
46
|
+
* @param context - Additional error context
|
|
47
|
+
*/
|
|
48
|
+
export declare function recordSearchError(latencyMs: number, errorCode: string, context?: Record<string, unknown>): void;
|
|
49
|
+
/**
|
|
50
|
+
* Record model loaded event.
|
|
51
|
+
*
|
|
52
|
+
* @param latencyMs - Model load time in milliseconds
|
|
53
|
+
*/
|
|
54
|
+
export declare function recordModelLoaded(latencyMs: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Record embeddings loaded event.
|
|
57
|
+
*
|
|
58
|
+
* @param latencyMs - Embeddings load time in milliseconds
|
|
59
|
+
* @param cacheHit - Whether loaded from cache
|
|
60
|
+
* @param chunkCount - Number of chunks loaded
|
|
61
|
+
*/
|
|
62
|
+
export declare function recordEmbeddingsLoaded(latencyMs: number, cacheHit: boolean, chunkCount: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Check if embeddings are cached (for cache_hit metric).
|
|
65
|
+
*
|
|
66
|
+
* @param isCached - Whether embeddings are currently cached
|
|
67
|
+
*/
|
|
68
|
+
export declare function setEmbeddingsCacheStatus(isCached: boolean): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get aggregated statistics from the rolling window.
|
|
71
|
+
*
|
|
72
|
+
* @returns Statistics object with averages and counts
|
|
73
|
+
*/
|
|
74
|
+
export declare function getSearchStats(): {
|
|
75
|
+
totalSearches: number;
|
|
76
|
+
successfulSearches: number;
|
|
77
|
+
failedSearches: number;
|
|
78
|
+
averageLatencyMs: number;
|
|
79
|
+
averageResultCount: number;
|
|
80
|
+
searchTypeDistribution: Record<string, number>;
|
|
81
|
+
cacheHitRate: number;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Clear metrics history.
|
|
85
|
+
* Primarily for testing purposes.
|
|
86
|
+
*/
|
|
87
|
+
export declare function clearMetricsHistory(): void;
|
|
88
|
+
/**
|
|
89
|
+
* Get the current rolling window size.
|
|
90
|
+
*
|
|
91
|
+
* @returns Number of entries in the rolling window
|
|
92
|
+
*/
|
|
93
|
+
export declare function getHistorySize(): number;
|
|
94
|
+
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/tools/docs/metrics.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,MAAM,MAAM,UAAU,GAClB,kBAAkB,GAClB,cAAc,GACd,cAAc,GACd,mBAAmB,CAAC;AAExB;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,KAAK,EAAE,QAAQ,CAAC;IAChB,yBAAyB;IACzB,IAAI,EAAE,UAAU,CAAC;IACjB,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,iCAAiC;IACjC,YAAY,CAAC,EAAE,MAAM,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