@arabold/docs-mcp-server 1.11.0 → 1.12.0

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,174 @@
1
+ import { BedrockEmbeddings } from "@langchain/aws";
2
+ import { GoogleGenerativeAIEmbeddings } from "@langchain/google-genai";
3
+ import { VertexAIEmbeddings } from "@langchain/google-vertexai";
4
+ import { AzureOpenAIEmbeddings, OpenAIEmbeddings } from "@langchain/openai";
5
+ import { v as DimensionError, w as VECTOR_DIMENSION } from "./DocumentManagementService-_qCZ1Hi2.js";
6
+ import { Embeddings } from "@langchain/core/embeddings";
7
+ class FixedDimensionEmbeddings extends Embeddings {
8
+ constructor(embeddings, targetDimension, providerAndModel, allowTruncate = false) {
9
+ super({});
10
+ this.embeddings = embeddings;
11
+ this.targetDimension = targetDimension;
12
+ this.allowTruncate = allowTruncate;
13
+ const [providerOrModel, modelName] = providerAndModel.split(":");
14
+ this.provider = modelName ? providerOrModel : "openai";
15
+ this.model = modelName || providerOrModel;
16
+ }
17
+ provider;
18
+ model;
19
+ /**
20
+ * Normalize a vector to the target dimension by truncating (for MRL models) or padding.
21
+ * @throws {DimensionError} If vector is too large and provider doesn't support MRL
22
+ */
23
+ normalizeVector(vector) {
24
+ const dimension = vector.length;
25
+ if (dimension > this.targetDimension) {
26
+ if (this.allowTruncate) {
27
+ return vector.slice(0, this.targetDimension);
28
+ }
29
+ throw new DimensionError(
30
+ `${this.provider}:${this.model}`,
31
+ dimension,
32
+ this.targetDimension
33
+ );
34
+ }
35
+ if (dimension < this.targetDimension) {
36
+ return [...vector, ...new Array(this.targetDimension - dimension).fill(0)];
37
+ }
38
+ return vector;
39
+ }
40
+ async embedQuery(text) {
41
+ const vector = await this.embeddings.embedQuery(text);
42
+ return this.normalizeVector(vector);
43
+ }
44
+ async embedDocuments(documents) {
45
+ const vectors = await this.embeddings.embedDocuments(documents);
46
+ return vectors.map((vector) => this.normalizeVector(vector));
47
+ }
48
+ }
49
+ class UnsupportedProviderError extends Error {
50
+ constructor(provider) {
51
+ super(`Unsupported embedding provider: ${provider}`);
52
+ this.name = "UnsupportedProviderError";
53
+ }
54
+ }
55
+ class ModelConfigurationError extends Error {
56
+ constructor(message) {
57
+ super(message);
58
+ this.name = "ModelConfigurationError";
59
+ }
60
+ }
61
+ function createEmbeddingModel(providerAndModel) {
62
+ const [providerOrModel, modelName] = providerAndModel.split(":");
63
+ const provider = modelName ? providerOrModel : "openai";
64
+ const model = modelName || providerOrModel;
65
+ const baseConfig = { stripNewLines: true };
66
+ switch (provider) {
67
+ case "openai": {
68
+ const config = {
69
+ ...baseConfig,
70
+ modelName: model,
71
+ batchSize: 512
72
+ // OpenAI supports large batches
73
+ };
74
+ const baseURL = process.env.OPENAI_API_BASE;
75
+ if (baseURL) {
76
+ config.configuration = { baseURL };
77
+ }
78
+ return new OpenAIEmbeddings(config);
79
+ }
80
+ case "vertex": {
81
+ if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
82
+ throw new ModelConfigurationError(
83
+ "GOOGLE_APPLICATION_CREDENTIALS environment variable is required for Google Cloud Vertex AI"
84
+ );
85
+ }
86
+ return new VertexAIEmbeddings({
87
+ ...baseConfig,
88
+ model
89
+ // e.g., "text-embedding-004"
90
+ });
91
+ }
92
+ case "gemini": {
93
+ if (!process.env.GOOGLE_API_KEY) {
94
+ throw new ModelConfigurationError(
95
+ "GOOGLE_API_KEY environment variable is required for Google AI (Gemini)"
96
+ );
97
+ }
98
+ const baseEmbeddings = new GoogleGenerativeAIEmbeddings({
99
+ ...baseConfig,
100
+ apiKey: process.env.GOOGLE_API_KEY,
101
+ model
102
+ // e.g., "gemini-embedding-exp-03-07"
103
+ });
104
+ return new FixedDimensionEmbeddings(
105
+ baseEmbeddings,
106
+ VECTOR_DIMENSION,
107
+ providerAndModel,
108
+ true
109
+ );
110
+ }
111
+ case "aws": {
112
+ const region = process.env.BEDROCK_AWS_REGION || process.env.AWS_REGION;
113
+ if (!region) {
114
+ throw new ModelConfigurationError(
115
+ "BEDROCK_AWS_REGION or AWS_REGION environment variable is required for AWS Bedrock"
116
+ );
117
+ }
118
+ if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
119
+ throw new ModelConfigurationError(
120
+ "AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are required for AWS Bedrock"
121
+ );
122
+ }
123
+ return new BedrockEmbeddings({
124
+ ...baseConfig,
125
+ model,
126
+ // e.g., "amazon.titan-embed-text-v1"
127
+ region,
128
+ credentials: {
129
+ accessKeyId: process.env.AWS_ACCESS_KEY_ID,
130
+ secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
131
+ sessionToken: process.env.AWS_SESSION_TOKEN
132
+ }
133
+ });
134
+ }
135
+ case "microsoft": {
136
+ if (!process.env.AZURE_OPENAI_API_KEY) {
137
+ throw new ModelConfigurationError(
138
+ "AZURE_OPENAI_API_KEY environment variable is required for Azure OpenAI"
139
+ );
140
+ }
141
+ if (!process.env.AZURE_OPENAI_API_INSTANCE_NAME) {
142
+ throw new ModelConfigurationError(
143
+ "AZURE_OPENAI_API_INSTANCE_NAME environment variable is required for Azure OpenAI"
144
+ );
145
+ }
146
+ if (!process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME) {
147
+ throw new ModelConfigurationError(
148
+ "AZURE_OPENAI_API_DEPLOYMENT_NAME environment variable is required for Azure OpenAI"
149
+ );
150
+ }
151
+ if (!process.env.AZURE_OPENAI_API_VERSION) {
152
+ throw new ModelConfigurationError(
153
+ "AZURE_OPENAI_API_VERSION environment variable is required for Azure OpenAI"
154
+ );
155
+ }
156
+ return new AzureOpenAIEmbeddings({
157
+ ...baseConfig,
158
+ azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
159
+ azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
160
+ azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
161
+ azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
162
+ deploymentName: model
163
+ });
164
+ }
165
+ default:
166
+ throw new UnsupportedProviderError(provider);
167
+ }
168
+ }
169
+ export {
170
+ ModelConfigurationError,
171
+ UnsupportedProviderError,
172
+ createEmbeddingModel
173
+ };
174
+ //# sourceMappingURL=EmbeddingFactory-BJMbJvje.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EmbeddingFactory-BJMbJvje.js","sources":["../src/store/embeddings/FixedDimensionEmbeddings.ts","../src/store/embeddings/EmbeddingFactory.ts"],"sourcesContent":["import { Embeddings } from \"@langchain/core/embeddings\";\nimport { DimensionError } from \"../errors\";\n\n/**\n * Wrapper around an Embeddings implementation that ensures vectors have a fixed dimension.\n * - If a vector's dimension is greater than the target and truncation is allowed,\n * the vector is truncated (e.g., for models that support MRL - Matryoshka\n * Representation Learning).\n * - If a vector's dimension is greater than the target and truncation is not\n * allowed, a DimensionError is thrown.\n * - If a vector's dimension is less than the target, it is padded with zeros.\n */\nexport class FixedDimensionEmbeddings extends Embeddings {\n private provider: string;\n private model: string;\n\n constructor(\n private readonly embeddings: Embeddings,\n private readonly targetDimension: number,\n providerAndModel: string,\n private readonly allowTruncate: boolean = false,\n ) {\n super({});\n // Parse provider and model from string (e.g., \"gemini:embedding-001\" or just \"text-embedding-3-small\")\n const [providerOrModel, modelName] = providerAndModel.split(\":\");\n this.provider = modelName ? providerOrModel : \"openai\"; // Default to openai if no provider specified\n this.model = modelName || providerOrModel;\n }\n\n /**\n * Normalize a vector to the target dimension by truncating (for MRL models) or padding.\n * @throws {DimensionError} If vector is too large and provider doesn't support MRL\n */\n private normalizeVector(vector: number[]): number[] {\n const dimension = vector.length;\n\n if (dimension > this.targetDimension) {\n // If truncation is allowed (e.g., for MRL models like Gemini), truncate the vector\n if (this.allowTruncate) {\n return vector.slice(0, this.targetDimension);\n }\n // Otherwise, throw an error\n throw new DimensionError(\n `${this.provider}:${this.model}`,\n dimension,\n this.targetDimension,\n );\n }\n\n if (dimension < this.targetDimension) {\n // Pad with zeros to reach target dimension\n return [...vector, ...new Array(this.targetDimension - dimension).fill(0)];\n }\n\n return vector;\n }\n\n async embedQuery(text: string): Promise<number[]> {\n const vector = await this.embeddings.embedQuery(text);\n return this.normalizeVector(vector);\n }\n\n async embedDocuments(documents: string[]): Promise<number[][]> {\n const vectors = await this.embeddings.embedDocuments(documents);\n return vectors.map((vector) => this.normalizeVector(vector));\n }\n}\n","import { BedrockEmbeddings } from \"@langchain/aws\";\nimport type { Embeddings } from \"@langchain/core/embeddings\";\nimport { GoogleGenerativeAIEmbeddings } from \"@langchain/google-genai\";\nimport { VertexAIEmbeddings } from \"@langchain/google-vertexai\";\nimport {\n AzureOpenAIEmbeddings,\n type ClientOptions,\n OpenAIEmbeddings,\n type OpenAIEmbeddingsParams,\n} from \"@langchain/openai\";\nimport { VECTOR_DIMENSION } from \"../types\";\nimport { FixedDimensionEmbeddings } from \"./FixedDimensionEmbeddings\";\n\n/**\n * Supported embedding model providers. Each provider requires specific environment\n * variables to be set for API access.\n */\nexport type EmbeddingProvider = \"openai\" | \"vertex\" | \"gemini\" | \"aws\" | \"microsoft\";\n\n/**\n * Error thrown when an invalid or unsupported embedding provider is specified.\n */\nexport class UnsupportedProviderError extends Error {\n constructor(provider: string) {\n super(`Unsupported embedding provider: ${provider}`);\n this.name = \"UnsupportedProviderError\";\n }\n}\n\n/**\n * Error thrown when there's an issue with the model configuration or missing environment variables.\n */\nexport class ModelConfigurationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"ModelConfigurationError\";\n }\n}\n\n/**\n * Creates an embedding model instance based on the specified provider and model name.\n * The provider and model name should be specified in the format \"provider:model_name\"\n * (e.g., \"google:text-embedding-004\"). If no provider is specified (i.e., just \"model_name\"),\n * OpenAI is used as the default provider.\n *\n * Environment variables required per provider:\n * - OpenAI: OPENAI_API_KEY (and optionally OPENAI_API_BASE, OPENAI_ORG_ID)\n * - Google Cloud Vertex AI: GOOGLE_APPLICATION_CREDENTIALS (path to service account JSON)\n * - Google GenAI (Gemini): GOOGLE_API_KEY\n * - AWS: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION (or BEDROCK_AWS_REGION)\n * - Microsoft: AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_INSTANCE_NAME, AZURE_OPENAI_API_DEPLOYMENT_NAME, AZURE_OPENAI_API_VERSION\n *\n * @param providerAndModel - The provider and model name in the format \"provider:model_name\"\n * or just \"model_name\" for OpenAI models.\n * @returns A configured instance of the appropriate Embeddings implementation.\n * @throws {UnsupportedProviderError} If an unsupported provider is specified.\n * @throws {ModelConfigurationError} If there's an issue with the model configuration.\n */\nexport function createEmbeddingModel(providerAndModel: string): Embeddings {\n // Parse provider and model name\n const [providerOrModel, modelName] = providerAndModel.split(\":\");\n const provider = modelName ? (providerOrModel as EmbeddingProvider) : \"openai\";\n const model = modelName || providerOrModel;\n\n // Default configuration for each provider\n const baseConfig = { stripNewLines: true };\n\n switch (provider) {\n case \"openai\": {\n const config: Partial<OpenAIEmbeddingsParams> & { configuration?: ClientOptions } =\n {\n ...baseConfig,\n modelName: model,\n batchSize: 512, // OpenAI supports large batches\n };\n // Add custom base URL if specified\n const baseURL = process.env.OPENAI_API_BASE;\n if (baseURL) {\n config.configuration = { baseURL };\n }\n return new OpenAIEmbeddings(config);\n }\n\n case \"vertex\": {\n if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) {\n throw new ModelConfigurationError(\n \"GOOGLE_APPLICATION_CREDENTIALS environment variable is required for Google Cloud Vertex AI\",\n );\n }\n return new VertexAIEmbeddings({\n ...baseConfig,\n model: model, // e.g., \"text-embedding-004\"\n });\n }\n\n case \"gemini\": {\n if (!process.env.GOOGLE_API_KEY) {\n throw new ModelConfigurationError(\n \"GOOGLE_API_KEY environment variable is required for Google AI (Gemini)\",\n );\n }\n // Create base embeddings and wrap with FixedDimensionEmbeddings since Gemini\n // supports MRL (Matryoshka Representation Learning) for safe truncation\n const baseEmbeddings = new GoogleGenerativeAIEmbeddings({\n ...baseConfig,\n apiKey: process.env.GOOGLE_API_KEY,\n model: model, // e.g., \"gemini-embedding-exp-03-07\"\n });\n return new FixedDimensionEmbeddings(\n baseEmbeddings,\n VECTOR_DIMENSION,\n providerAndModel,\n true,\n );\n }\n\n case \"aws\": {\n // For AWS, model should be the full Bedrock model ID\n const region = process.env.BEDROCK_AWS_REGION || process.env.AWS_REGION;\n if (!region) {\n throw new ModelConfigurationError(\n \"BEDROCK_AWS_REGION or AWS_REGION environment variable is required for AWS Bedrock\",\n );\n }\n if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {\n throw new ModelConfigurationError(\n \"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are required for AWS Bedrock\",\n );\n }\n\n return new BedrockEmbeddings({\n ...baseConfig,\n model: model, // e.g., \"amazon.titan-embed-text-v1\"\n region,\n credentials: {\n accessKeyId: process.env.AWS_ACCESS_KEY_ID,\n secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n sessionToken: process.env.AWS_SESSION_TOKEN,\n },\n });\n }\n\n case \"microsoft\": {\n // For Azure, model name corresponds to the deployment name\n if (!process.env.AZURE_OPENAI_API_KEY) {\n throw new ModelConfigurationError(\n \"AZURE_OPENAI_API_KEY environment variable is required for Azure OpenAI\",\n );\n }\n if (!process.env.AZURE_OPENAI_API_INSTANCE_NAME) {\n throw new ModelConfigurationError(\n \"AZURE_OPENAI_API_INSTANCE_NAME environment variable is required for Azure OpenAI\",\n );\n }\n if (!process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME) {\n throw new ModelConfigurationError(\n \"AZURE_OPENAI_API_DEPLOYMENT_NAME environment variable is required for Azure OpenAI\",\n );\n }\n if (!process.env.AZURE_OPENAI_API_VERSION) {\n throw new ModelConfigurationError(\n \"AZURE_OPENAI_API_VERSION environment variable is required for Azure OpenAI\",\n );\n }\n\n return new AzureOpenAIEmbeddings({\n ...baseConfig,\n azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,\n azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,\n azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,\n azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,\n deploymentName: model,\n });\n }\n\n default:\n throw new UnsupportedProviderError(provider);\n }\n}\n"],"names":[],"mappings":";;;;;;AAYO,MAAM,iCAAiC,WAAW;AAAA,EAIvD,YACmB,YACA,iBACjB,kBACiB,gBAAyB,OAC1C;AACA,UAAM,CAAA,CAAE;AALS,SAAA,aAAA;AACA,SAAA,kBAAA;AAEA,SAAA,gBAAA;AAIjB,UAAM,CAAC,iBAAiB,SAAS,IAAI,iBAAiB,MAAM,GAAG;AAC1D,SAAA,WAAW,YAAY,kBAAkB;AAC9C,SAAK,QAAQ,aAAa;AAAA,EAAA;AAAA,EAbpB;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAmBA,gBAAgB,QAA4B;AAClD,UAAM,YAAY,OAAO;AAErB,QAAA,YAAY,KAAK,iBAAiB;AAEpC,UAAI,KAAK,eAAe;AACtB,eAAO,OAAO,MAAM,GAAG,KAAK,eAAe;AAAA,MAAA;AAG7C,YAAM,IAAI;AAAA,QACR,GAAG,KAAK,QAAQ,IAAI,KAAK,KAAK;AAAA,QAC9B;AAAA,QACA,KAAK;AAAA,MACP;AAAA,IAAA;AAGE,QAAA,YAAY,KAAK,iBAAiB;AAEpC,aAAO,CAAC,GAAG,QAAQ,GAAG,IAAI,MAAM,KAAK,kBAAkB,SAAS,EAAE,KAAK,CAAC,CAAC;AAAA,IAAA;AAGpE,WAAA;AAAA,EAAA;AAAA,EAGT,MAAM,WAAW,MAAiC;AAChD,UAAM,SAAS,MAAM,KAAK,WAAW,WAAW,IAAI;AAC7C,WAAA,KAAK,gBAAgB,MAAM;AAAA,EAAA;AAAA,E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B;AAAA,MAAA,CACjB;AAAA,IAAA;AAAA,IAGH;AACQ,YAAA,IAAI,yBAAyB,QAAQ;AAAA,EAAA;AAEjD;"}
@@ -0,0 +1,170 @@
1
+ import { j as ScrapeMode, T as ToolError, l as logger, k as HtmlPlaywrightMiddleware, m as HtmlCheerioParserMiddleware, n as HtmlMetadataExtractorMiddleware, o as HtmlSanitizerMiddleware, p as HtmlToMarkdownMiddleware, C as ContentProcessingPipeline, M as MarkdownMetadataExtractorMiddleware, q as ScraperError, V as VersionNotFoundError } from "./DocumentManagementService-_qCZ1Hi2.js";
2
+ import "node:vm";
3
+ import "jsdom";
4
+ class FetchUrlTool {
5
+ /**
6
+ * Collection of fetchers that will be tried in order for a given URL.
7
+ */
8
+ fetchers;
9
+ constructor(httpFetcher, fileFetcher) {
10
+ this.fetchers = [httpFetcher, fileFetcher];
11
+ }
12
+ /**
13
+ * Fetches content from a URL and converts it to Markdown.
14
+ * Supports both HTTP/HTTPS URLs and local file URLs (file://).
15
+ * @returns The processed Markdown content
16
+ * @throws {ToolError} If fetching or processing fails
17
+ */
18
+ async execute(options) {
19
+ const { url, scrapeMode = ScrapeMode.Auto } = options;
20
+ const canFetchResults = this.fetchers.map((f) => f.canFetch(url));
21
+ const fetcherIndex = canFetchResults.findIndex((result) => result === true);
22
+ if (fetcherIndex === -1) {
23
+ throw new ToolError(
24
+ `Invalid URL: ${url}. Must be an HTTP/HTTPS URL or a file:// URL.`,
25
+ this.constructor.name
26
+ );
27
+ }
28
+ const fetcher = this.fetchers[fetcherIndex];
29
+ const playwrightMiddleware = new HtmlPlaywrightMiddleware();
30
+ try {
31
+ logger.info(`📡 Fetching ${url}...`);
32
+ const rawContent = await fetcher.fetch(url, {
33
+ followRedirects: options.followRedirects ?? true,
34
+ maxRetries: 3
35
+ // Keep retries for fetching
36
+ });
37
+ logger.info("🔄 Processing content...");
38
+ const initialContext = {
39
+ content: rawContent.content,
40
+ contentType: rawContent.mimeType,
41
+ source: rawContent.source,
42
+ metadata: {},
43
+ links: [],
44
+ // Links not needed for this tool's output
45
+ errors: [],
46
+ fetcher,
47
+ // Create a minimal ScraperOptions object for the context
48
+ options: {
49
+ url,
50
+ // Use the input URL
51
+ library: "",
52
+ // Not applicable for this tool
53
+ version: "",
54
+ // Use empty string instead of undefined
55
+ // Default other options as needed by middleware
56
+ maxDepth: 0,
57
+ maxPages: 1,
58
+ maxConcurrency: 1,
59
+ scope: "subpages",
60
+ // Default, though not used for single page fetch
61
+ followRedirects: options.followRedirects ?? true,
62
+ excludeSelectors: void 0,
63
+ // Not currently configurable via this tool
64
+ ignoreErrors: false,
65
+ scrapeMode
66
+ // Pass the scrapeMode
67
+ }
68
+ };
69
+ let pipeline;
70
+ if (initialContext.contentType.startsWith("text/html")) {
71
+ const htmlPipelineSteps = [
72
+ playwrightMiddleware,
73
+ // Use the instantiated middleware
74
+ new HtmlCheerioParserMiddleware(),
75
+ // Always runs after content is finalized
76
+ new HtmlMetadataExtractorMiddleware(),
77
+ // Keep for potential future use
78
+ // No Link Extractor needed for this tool
79
+ new HtmlSanitizerMiddleware(),
80
+ // Element remover
81
+ new HtmlToMarkdownMiddleware()
82
+ ];
83
+ pipeline = new ContentProcessingPipeline(htmlPipelineSteps);
84
+ } else if (initialContext.contentType === "text/markdown" || initialContext.contentType === "text/plain") {
85
+ pipeline = new ContentProcessingPipeline([
86
+ new MarkdownMetadataExtractorMiddleware()
87
+ // Extract title (though not used)
88
+ // No further processing needed for Markdown/Plain text for this tool
89
+ ]);
90
+ } else {
91
+ logger.warn(
92
+ `Unsupported content type "${initialContext.contentType}" for ${url}. Returning raw content.`
93
+ );
94
+ const contentString = typeof rawContent.content === "string" ? rawContent.content : Buffer.from(rawContent.content).toString("utf-8");
95
+ return contentString;
96
+ }
97
+ const finalContext = await pipeline.run(initialContext);
98
+ for (const err of finalContext.errors) {
99
+ logger.warn(`Processing error for ${url}: ${err.message}`);
100
+ }
101
+ if (typeof finalContext.content !== "string" || !finalContext.content.trim()) {
102
+ throw new ToolError(
103
+ `Processing resulted in empty content for ${url}`,
104
+ this.constructor.name
105
+ );
106
+ }
107
+ logger.info(`✅ Successfully processed ${url}`);
108
+ return finalContext.content;
109
+ } catch (error) {
110
+ if (error instanceof ScraperError || error instanceof ToolError) {
111
+ throw new ToolError(
112
+ `Failed to fetch or process URL: ${error.message}`,
113
+ this.constructor.name
114
+ );
115
+ }
116
+ throw new ToolError(
117
+ `Failed to fetch or process URL: ${error instanceof Error ? error.message : String(error)}`,
118
+ this.constructor.name
119
+ );
120
+ } finally {
121
+ await playwrightMiddleware.closeBrowser();
122
+ }
123
+ }
124
+ }
125
+ class FindVersionTool {
126
+ docService;
127
+ constructor(docService) {
128
+ this.docService = docService;
129
+ }
130
+ /**
131
+ * Executes the tool to find the best matching version and checks for unversioned docs.
132
+ * @returns A descriptive string indicating the best match and unversioned status, or an error message.
133
+ */
134
+ async execute(options) {
135
+ const { library, targetVersion } = options;
136
+ const targetVersionString = targetVersion ? `@${targetVersion}` : "";
137
+ try {
138
+ const { bestMatch, hasUnversioned } = await this.docService.findBestVersion(
139
+ library,
140
+ targetVersion
141
+ );
142
+ let message = "";
143
+ if (bestMatch) {
144
+ message = `Best match: ${bestMatch}.`;
145
+ if (hasUnversioned) {
146
+ message += " Unversioned docs also available.";
147
+ }
148
+ } else if (hasUnversioned) {
149
+ message = `No matching version found for ${library}${targetVersionString}, but unversioned docs exist.`;
150
+ } else {
151
+ message = `No matching version or unversioned documents found for ${library}${targetVersionString}.`;
152
+ }
153
+ return message;
154
+ } catch (error) {
155
+ if (error instanceof VersionNotFoundError) {
156
+ logger.info(`ℹ️ Version not found: ${error.message}`);
157
+ return `No matching version or unversioned documents found for ${library}${targetVersionString}. Available: ${error.availableVersions.length > 0 ? error.availableVersions.map((v) => v.version).join(", ") : "None"}.`;
158
+ }
159
+ logger.error(
160
+ `❌ Error finding version for ${library}${targetVersionString}: ${error instanceof Error ? error.message : error}`
161
+ );
162
+ throw error;
163
+ }
164
+ }
165
+ }
166
+ export {
167
+ FetchUrlTool as F,
168
+ FindVersionTool as a
169
+ };
170
+ //# sourceMappingURL=FindVersionTool-CH1c3Tyu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FindVersionTool-CH1c3Tyu.js","sources":["../src/tools/FetchUrlTool.ts","../src/tools/FindVersionTool.ts"],"sourcesContent":["import type {\n ContentFetcher,\n FileFetcher,\n HttpFetcher,\n RawContent,\n} from \"../scraper/fetcher\";\nimport { ContentProcessingPipeline } from \"../scraper/middleware/ContentProcessorPipeline\";\nimport {\n HtmlCheerioParserMiddleware,\n HtmlMetadataExtractorMiddleware,\n HtmlPlaywrightMiddleware,\n HtmlSanitizerMiddleware,\n HtmlToMarkdownMiddleware,\n MarkdownMetadataExtractorMiddleware,\n} from \"../scraper/middleware/components\";\nimport type { ContentProcessorMiddleware } from \"../scraper/middleware/types\";\nimport type { ContentProcessingContext } from \"../scraper/middleware/types\";\nimport { ScrapeMode, type ScraperOptions } from \"../scraper/types\";\nimport { ScraperError } from \"../utils/errors\";\nimport { logger } from \"../utils/logger\";\nimport { ToolError } from \"./errors\";\n\nexport interface FetchUrlToolOptions {\n /**\n * The URL to fetch and convert to markdown.\n * Must be a valid HTTP/HTTPS URL or file:// URL.\n */\n url: string;\n\n /**\n * Whether to follow HTTP redirects.\n * @default true\n */\n followRedirects?: boolean;\n\n /**\n * Determines the HTML processing strategy.\n * - 'fetch': Use a simple DOM parser (faster, less JS support).\n * - 'playwright': Use a headless browser (slower, full JS support).\n * - 'auto': Automatically select the best strategy (currently defaults to 'playwright').\n * @default ScrapeMode.Auto\n */\n scrapeMode?: ScrapeMode;\n}\n\n/**\n * Tool for fetching a single URL and converting its content to Markdown.\n * Unlike scrape_docs, this tool only processes one page without crawling\n * or storing the content.\n *\n * Supports both HTTP/HTTPS URLs and local file URLs (file://).\n */\nexport class FetchUrlTool {\n /**\n * Collection of fetchers that will be tried in order for a given URL.\n */\n private readonly fetchers: ContentFetcher[];\n\n constructor(httpFetcher: HttpFetcher, fileFetcher: FileFetcher) {\n // Removed processor dependency\n this.fetchers = [httpFetcher, fileFetcher];\n }\n\n /**\n * Fetches content from a URL and converts it to Markdown.\n * Supports both HTTP/HTTPS URLs and local file URLs (file://).\n * @returns The processed Markdown content\n * @throws {ToolError} If fetching or processing fails\n */\n async execute(options: FetchUrlToolOptions): Promise<string> {\n const { url, scrapeMode = ScrapeMode.Auto } = options; // Destructure scrapeMode with enum default\n\n // Check all fetchers first (helpful for testing and future extensions)\n const canFetchResults = this.fetchers.map((f) => f.canFetch(url));\n\n // Find an appropriate fetcher for this URL\n const fetcherIndex = canFetchResults.findIndex((result) => result === true);\n if (fetcherIndex === -1) {\n throw new ToolError(\n `Invalid URL: ${url}. Must be an HTTP/HTTPS URL or a file:// URL.`,\n this.constructor.name,\n );\n }\n\n const fetcher = this.fetchers[fetcherIndex];\n\n // Instantiate Playwright middleware locally for this execution\n const playwrightMiddleware = new HtmlPlaywrightMiddleware();\n\n try {\n // Fetch the content\n logger.info(`📡 Fetching ${url}...`);\n const rawContent: RawContent = await fetcher.fetch(url, {\n followRedirects: options.followRedirects ?? true,\n maxRetries: 3, // Keep retries for fetching\n });\n\n // --- Start Middleware Pipeline ---\n logger.info(\"🔄 Processing content...\");\n const initialContext: ContentProcessingContext = {\n content: rawContent.content,\n contentType: rawContent.mimeType,\n source: rawContent.source,\n metadata: {},\n links: [], // Links not needed for this tool's output\n errors: [],\n fetcher,\n // Create a minimal ScraperOptions object for the context\n options: {\n url: url, // Use the input URL\n library: \"\", // Not applicable for this tool\n version: \"\", // Use empty string instead of undefined\n // Default other options as needed by middleware\n maxDepth: 0,\n maxPages: 1,\n maxConcurrency: 1,\n scope: \"subpages\", // Default, though not used for single page fetch\n followRedirects: options.followRedirects ?? true,\n excludeSelectors: undefined, // Not currently configurable via this tool\n ignoreErrors: false,\n scrapeMode: scrapeMode, // Pass the scrapeMode\n } satisfies ScraperOptions,\n };\n\n let pipeline: ContentProcessingPipeline;\n if (initialContext.contentType.startsWith(\"text/html\")) {\n // Construct HTML pipeline similar to WebScraperStrategy\n const htmlPipelineSteps: ContentProcessorMiddleware[] = [\n playwrightMiddleware, // Use the instantiated middleware\n new HtmlCheerioParserMiddleware(), // Always runs after content is finalized\n new HtmlMetadataExtractorMiddleware(), // Keep for potential future use\n // No Link Extractor needed for this tool\n new HtmlSanitizerMiddleware(), // Element remover\n new HtmlToMarkdownMiddleware(),\n ];\n pipeline = new ContentProcessingPipeline(htmlPipelineSteps);\n } else if (\n initialContext.contentType === \"text/markdown\" ||\n initialContext.contentType === \"text/plain\"\n ) {\n pipeline = new ContentProcessingPipeline([\n new MarkdownMetadataExtractorMiddleware(), // Extract title (though not used)\n // No further processing needed for Markdown/Plain text for this tool\n ]);\n } else {\n // If content type is not HTML or Markdown/Plain, return raw content as string\n logger.warn(\n `Unsupported content type \"${initialContext.contentType}\" for ${url}. Returning raw content.`,\n );\n const contentString =\n typeof rawContent.content === \"string\"\n ? rawContent.content\n : Buffer.from(rawContent.content).toString(\"utf-8\");\n return contentString;\n }\n\n const finalContext = await pipeline.run(initialContext);\n // --- End Middleware Pipeline ---\n\n // Log any processing errors\n for (const err of finalContext.errors) {\n logger.warn(`Processing error for ${url}: ${err.message}`);\n }\n\n if (typeof finalContext.content !== \"string\" || !finalContext.content.trim()) {\n throw new ToolError(\n `Processing resulted in empty content for ${url}`,\n this.constructor.name,\n );\n }\n\n logger.info(`✅ Successfully processed ${url}`);\n return finalContext.content; // Return the final processed content string\n } catch (error) {\n // Handle fetch errors and pipeline errors\n if (error instanceof ScraperError || error instanceof ToolError) {\n throw new ToolError(\n `Failed to fetch or process URL: ${error.message}`,\n this.constructor.name,\n );\n }\n throw new ToolError(\n `Failed to fetch or process URL: ${error instanceof Error ? error.message : String(error)}`,\n this.constructor.name,\n );\n } finally {\n // Ensure the browser is closed after execution\n await playwrightMiddleware.closeBrowser();\n }\n }\n}\n","import type { DocumentManagementService } from \"../store\";\nimport { logger } from \"../utils/logger\";\nimport { VersionNotFoundError } from \"./errors\";\n\nexport interface FindVersionToolOptions {\n library: string;\n targetVersion?: string;\n}\n\n/**\n * Tool for finding the best matching version of a library in the store.\n * Supports exact version matches and X-Range patterns (e.g., '5.x', '5.2.x').\n */\nexport class FindVersionTool {\n private docService: DocumentManagementService;\n\n constructor(docService: DocumentManagementService) {\n this.docService = docService;\n }\n\n /**\n * Executes the tool to find the best matching version and checks for unversioned docs.\n * @returns A descriptive string indicating the best match and unversioned status, or an error message.\n */\n async execute(options: FindVersionToolOptions): Promise<string> {\n const { library, targetVersion } = options;\n const targetVersionString = targetVersion ? `@${targetVersion}` : \"\";\n\n try {\n const { bestMatch, hasUnversioned } = await this.docService.findBestVersion(\n library,\n targetVersion,\n );\n\n let message = \"\";\n if (bestMatch) {\n message = `Best match: ${bestMatch}.`;\n if (hasUnversioned) {\n message += \" Unversioned docs also available.\";\n }\n } else if (hasUnversioned) {\n message = `No matching version found for ${library}${targetVersionString}, but unversioned docs exist.`;\n } else {\n // This case should ideally be caught by VersionNotFoundError below,\n // but added for completeness.\n message = `No matching version or unversioned documents found for ${library}${targetVersionString}.`;\n }\n return message;\n } catch (error) {\n if (error instanceof VersionNotFoundError) {\n // This error is thrown when no semver versions AND no unversioned docs exist.\n logger.info(`ℹ️ Version not found: ${error.message}`);\n return `No matching version or unversioned documents found for ${library}${targetVersionString}. Available: ${\n error.availableVersions.length > 0\n ? error.availableVersions.map((v) => v.version).join(\", \")\n : \"None\"\n }.`;\n }\n // Re-throw unexpected errors\n logger.error(\n `❌ Error finding version for ${library}${targetVersionString}: ${error instanceof Error ? error.message : error}`,\n );\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;;AAoDO,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA,EAIP;AAAA,EAEjB,YAAY,aAA0B,aAA0B;AAEzD,SAAA,WAAW,CAAC,aAAa,WAAW;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS3C,MAAM,QAAQ,SAA+C;A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AAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOpB,MAAM,QAAQ,SAAkD;AACxD,UAAA,EAAE,SAAS,cAAA,IAAkB;AACnC,UAAM,sBAAsB,gBAAgB,IAAI,aAAa,KAAK;AAE9D,QAAA;AACF,YAAM,EAAE,WAAW,eAAA,IAAmB,MAAM,KAAK,WAAW;AAAA,QAC1D;AAAA,QACA;AAAA,MACF;AAEA,UAAI,UAAU;AACd,UAAI,WAAW;AACb,kBAAU,eAAe,SAAS;AAClC,YAAI,gBAAgB;AACP,qBAAA;AAAA,QAAA;AAAA,iBAEJ,gBAAgB;AACf,kBAAA,iCAAiC,OAAO,GAAG,mBAAmB;AAAA,MAAA,OACnE;AAGK,kBAAA,0DAA0D,OAAO,GAAG,mBAAmB;AAAA,MAAA;AAE5F,aAAA;AAAA,aACA,OAAO;AACd,UAAI,iBAAiB,sBAAsB;AAEzC,eAAO,KAAK,yBAAyB,MAAM,OAAO,EAAE;AAC7C,eAAA,0DAA0D,OAAO,GAAG,mBAAmB,gBAC5F,MAAM,kBAAkB,SAAS,IAC7B,MAAM,kBAAkB,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,IAAI,IACvD,MACN;AAAA,MAAA;AAGK,aAAA;AAAA,QACL,+BAA+B,OAAO,GAAG,mBAAmB,KAAK,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAAA,MACjH;AACM,YAAA;AAAA,IAAA;AAAA,EACR;AAEJ;"}
@@ -0,0 +1,65 @@
1
+ import { l as logger, T as ToolError } from "./DocumentManagementService-_qCZ1Hi2.js";
2
+ class ListJobsTool {
3
+ manager;
4
+ // Change property name and type
5
+ /**
6
+ * Creates an instance of ListJobsTool.
7
+ * @param manager The PipelineManager instance.
8
+ */
9
+ constructor(manager) {
10
+ this.manager = manager;
11
+ }
12
+ /**
13
+ * Executes the tool to retrieve a list of pipeline jobs.
14
+ * @param input - The input parameters, optionally including a status filter.
15
+ * @returns A promise that resolves with the list of simplified job objects.
16
+ * @throws {PipelineStateError} If the pipeline manager is somehow unavailable.
17
+ */
18
+ async execute(input) {
19
+ const jobs = await this.manager.getJobs(input.status);
20
+ const simplifiedJobs = jobs.map(
21
+ (job) => ({
22
+ id: job.id,
23
+ library: job.library,
24
+ version: job.version,
25
+ status: job.status,
26
+ createdAt: job.createdAt.toISOString(),
27
+ startedAt: job.startedAt?.toISOString() ?? null,
28
+ finishedAt: job.finishedAt?.toISOString() ?? null,
29
+ error: job.error?.message ?? null
30
+ })
31
+ );
32
+ return { jobs: simplifiedJobs };
33
+ }
34
+ }
35
+ class RemoveTool {
36
+ constructor(documentManagementService) {
37
+ this.documentManagementService = documentManagementService;
38
+ }
39
+ /**
40
+ * Executes the tool to remove the specified library version documents.
41
+ * Assumes args have been validated by the caller (McpServer) against inputSchema.
42
+ * Returns a simple success message or throws an error.
43
+ */
44
+ async execute(args) {
45
+ const { library, version } = args;
46
+ logger.info(
47
+ `Removing library: ${library}${version ? `, version: ${version}` : " (unversioned)"}`
48
+ );
49
+ try {
50
+ await this.documentManagementService.removeAllDocuments(library, version);
51
+ const message = `Successfully removed documents for ${library}${version ? `@${version}` : " (unversioned)"}.`;
52
+ logger.info(message);
53
+ return { message };
54
+ } catch (error) {
55
+ const errorMessage = `Failed to remove documents for ${library}${version ? `@${version}` : " (unversioned)"}: ${error instanceof Error ? error.message : String(error)}`;
56
+ logger.error(`Error removing library: ${errorMessage}`);
57
+ throw new ToolError(errorMessage, this.constructor.name);
58
+ }
59
+ }
60
+ }
61
+ export {
62
+ ListJobsTool as L,
63
+ RemoveTool as R
64
+ };
65
+ //# sourceMappingURL=RemoveTool-DmB1YJTA.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RemoveTool-DmB1YJTA.js","sources":["../src/tools/ListJobsTool.ts","../src/tools/RemoveTool.ts"],"sourcesContent":["import type { PipelineManager } from \"../pipeline/PipelineManager\";\nimport type { PipelineJob, PipelineJobStatus } from \"../pipeline/types\";\nimport type { JobInfo } from \"./GetJobInfoTool\"; // Import JobInfo\n\n/**\n * Input parameters for the ListJobsTool.\n */\nexport interface ListJobsInput {\n /** Optional status to filter jobs by. */\n status?: PipelineJobStatus;\n}\n\n/**\n * Response structure for the ListJobsTool.\n */\nexport interface ListJobsToolResponse {\n jobs: JobInfo[];\n}\n\n/**\n * Tool for listing pipeline jobs managed by the PipelineManager.\n * Allows filtering jobs by their status.\n */\nexport class ListJobsTool {\n private manager: PipelineManager; // Change property name and type\n\n /**\n * Creates an instance of ListJobsTool.\n * @param manager The PipelineManager instance.\n */\n constructor(manager: PipelineManager) {\n // Change constructor parameter\n this.manager = manager;\n }\n\n /**\n * Executes the tool to retrieve a list of pipeline jobs.\n * @param input - The input parameters, optionally including a status filter.\n * @returns A promise that resolves with the list of simplified job objects.\n * @throws {PipelineStateError} If the pipeline manager is somehow unavailable.\n */\n async execute(input: ListJobsInput): Promise<ListJobsToolResponse> {\n const jobs = await this.manager.getJobs(input.status);\n\n // Transform jobs into simplified objects\n const simplifiedJobs: JobInfo[] = jobs.map(\n (job: PipelineJob): JobInfo => ({\n id: job.id,\n library: job.library,\n version: job.version,\n status: job.status,\n createdAt: job.createdAt.toISOString(),\n startedAt: job.startedAt?.toISOString() ?? null,\n finishedAt: job.finishedAt?.toISOString() ?? null,\n error: job.error?.message ?? null,\n }),\n );\n\n return { jobs: simplifiedJobs };\n }\n}\n","import type { DocumentManagementService } from \"../store\";\nimport { logger } from \"../utils/logger\";\nimport { ToolError } from \"./errors\";\n\n/**\n * Represents the arguments for the remove_docs tool.\n * The MCP server should validate the input against RemoveToolInputSchema before calling execute.\n */\nexport interface RemoveToolArgs {\n library: string;\n version?: string;\n}\n\n/**\n * Tool to remove indexed documentation for a specific library version.\n * This class provides the core logic, intended to be called by the McpServer.\n */\nexport class RemoveTool {\n constructor(private readonly documentManagementService: DocumentManagementService) {}\n\n /**\n * Executes the tool to remove the specified library version documents.\n * Assumes args have been validated by the caller (McpServer) against inputSchema.\n * Returns a simple success message or throws an error.\n */\n async execute(args: RemoveToolArgs): Promise<{ message: string }> {\n const { library, version } = args;\n\n logger.info(\n `Removing library: ${library}${version ? `, version: ${version}` : \" (unversioned)\"}`,\n );\n\n try {\n // Core logic: Call the document management service\n await this.documentManagementService.removeAllDocuments(library, version);\n\n const message = `Successfully removed documents for ${library}${version ? `@${version}` : \" (unversioned)\"}.`;\n logger.info(message);\n // Return a simple success object, the McpServer will format the final response\n return { message };\n } catch (error) {\n const errorMessage = `Failed to remove documents for ${library}${version ? `@${version}` : \" (unversioned)\"}: ${error instanceof Error ? error.message : String(error)}`;\n logger.error(`Error removing library: ${errorMessage}`);\n // Re-throw the error for the McpServer to handle and format\n throw new ToolError(errorMessage, this.constructor.name);\n }\n }\n}\n"],"names":[],"mappings":";AAuBO,MAAM,aAAa;AAAA,EAChB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,YAAY,SAA0B;AAEpC,SAAK,UAAU;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASjB,MAAM,QAAQ,OAAqD;AACjE,UAAM,OAAO,MAAM,KAAK,QAAQ,QAAQ,MAAM,MAAM;AAGpD,UAAM,iBAA4B,KAAK;AAAA,MACrC,CAAC,SAA+B;AAAA,QAC9B,IAAI,IAAI;AAAA,QACR,SAAS,IAAI;AAAA,QACb,SAAS,IAAI;AAAA,QACb,QAAQ,IAAI;AAAA,QACZ,WAAW,IAAI,UAAU,YAAY;AAAA,QACrC,WAAW,IAAI,WAAW,YAAiB,KAAA;AAAA,QAC3C,YAAY,IAAI,YAAY,YAAiB,KAAA;AAAA,QAC7C,OAAO,IAAI,OAAO,WAAW;AAAA,MAC/B;AAAA,IACF;AAEO,WAAA,EAAE,MAAM,eAAe;AAAA,EAAA;AAElC;AC3CO,MAAM,WAAW;AAAA,EACtB,YAA6B,2BAAsD;AAAtD,SAAA,4BAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAO7B,MAAM,QAAQ,MAA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