UNPKG

@monsoft/mcp-docscribe

Version:

A Model Context Protocol implementation for generating comprehensive documentation

94 lines (93 loc) 3.89 kB
import { DocumentGenerationParams, DocumentGenerationResult } from '../types/documentation-types.js'; /** * Service for generating documentation using AI providers via Vercel AI SDK * * This service implements document generation using the Vercel AI SDK to abstract * communication with different AI providers (Anthropic and OpenAI). It supports * both Claude (3.5 Sonnet, 3 Opus) and GPT (GPT-4o, GPT-4 Turbo) models. * * The Vercel AI SDK provides a unified interface for interacting with these models, * making it easy to switch between providers without changing the implementation logic. */ export declare class AIService { private apiToken; private provider; /** * Creates an instance of AIService * @param apiToken - API token for the AI service (Anthropic or OpenAI) * @param provider - AI provider to use ('anthropic' or 'openai') */ constructor(apiToken: string, provider?: 'anthropic' | 'openai'); /** * Generates documentation based on the provided parameters * * This method orchestrates the document generation process by: * 1. Determining which document types to generate based on the input * 2. Creating appropriate prompts for each document type * 3. Calling the AI provider to generate the content * 4. Packaging the generated content with metadata * * @param params - Parameters for document generation * @returns Promise resolving to the generation result * @throws {AIServiceError} When the AI service returns an error * @throws {GenerationFailedError} When document generation fails */ generateDocumentation(params: DocumentGenerationParams): Promise<DocumentGenerationResult>; /** * Generate content using the selected AI provider via Vercel AI SDK * * This method acts as a router to direct the request to the appropriate * provider-specific implementation. * * @param prompt - Prompt for the AI * @param systemPrompt - System prompt to use * @returns Promise resolving to the generated content * @throws {AIServiceError} When the AI service returns an error */ private generateWithAI; /** * Generate content using Anthropic Claude via AI SDK * * Uses the Vercel AI SDK's generateText function with the anthropic provider. * This implementation includes Claude's reasoning capabilities for improved * document generation quality. * * @param prompt - Prompt for Claude * @param systemPrompt - System prompt to use * @returns Promise resolving to the generated content * @throws {AIServiceError} When there's an error with the Anthropic API */ private generateWithAnthropic; /** * Generate content using OpenAI models via AI SDK * * Uses the Vercel AI SDK's generateText function with the openai provider. * This implementation supports GPT-4o and GPT-4 Turbo models. * * @param prompt - Prompt for OpenAI * @param systemPrompt - System prompt to use * @returns Promise resolving to the generated content * @throws {AIServiceError} When there's an error with the OpenAI API */ private generateWithOpenAI; /** * Gets the document types to generate based on the requested type * @param documentType - Requested document type * @returns Array of document types to generate */ private getDocumentTypesToGenerate; /** * Gets the title for a document * @param documentType - Type of document * @param projectName - Name of the project * @returns Document title */ private getDocumentTitle; /** * Gets a suggested filename for a document * @param documentType - Type of document * @param projectName - Name of the project * @returns Suggested filename */ private getSuggestedFilename; }