UNPKG

@bobmatnyc/ai-code-review

Version:

A TypeScript-based tool for automated code reviews using AI models from Google Gemini, Anthropic Claude, and OpenRouter

101 lines (100 loc) 3.65 kB
/** * @fileoverview Prompt strategy interface and base class. * * This module defines the interface and base class for prompt strategies, * which are responsible for generating and formatting prompts for different * models and review types. */ import { ReviewOptions, ReviewType } from '../../types/review'; import { ProjectDocs } from '../../utils/projectDocs'; import { PromptManager } from '../PromptManager'; import { PromptCache } from '../cache/PromptCache'; import { PromptTemplate as LangChainPromptTemplate } from '@langchain/core/prompts'; /** * Interface for prompt strategies */ export interface IPromptStrategy { /** * Generate a prompt for a review * @param reviewType Type of review * @param options Review options * @param projectDocs Project documentation * @returns Promise resolving to the generated prompt */ generatePrompt(reviewType: ReviewType, options: ReviewOptions, projectDocs?: ProjectDocs | null): Promise<string>; /** * Format a prompt for a specific model * @param prompt Raw prompt * @param options Review options * @returns Formatted prompt (can be synchronous or asynchronous) */ formatPrompt(prompt: string, options: ReviewOptions): string | Promise<string>; /** * Get a LangChain prompt template * @param prompt Raw prompt template * @param options Review options * @returns LangChain prompt template (can be asynchronous) */ getLangChainTemplate(prompt: string, options: ReviewOptions): LangChainPromptTemplate | Promise<LangChainPromptTemplate>; /** * Get the name of the strategy * @returns Strategy name */ getName(): string; /** * Get the description of the strategy * @returns Strategy description */ getDescription(): string; } /** * Base class for prompt strategies */ export declare abstract class PromptStrategy implements IPromptStrategy { protected promptManager: PromptManager; protected promptCache: PromptCache; /** * Create a new prompt strategy * @param promptManager Prompt manager instance * @param promptCache Prompt cache instance */ constructor(promptManager: PromptManager, promptCache: PromptCache); /** * Generate a prompt for a review * @param reviewType Type of review * @param options Review options * @param projectDocs Project documentation * @returns Promise resolving to the generated prompt */ generatePrompt(reviewType: ReviewType, options: ReviewOptions, _projectDocs?: ProjectDocs | null): Promise<string>; /** * Format a prompt for a specific model * @param prompt Raw prompt * @param options Review options * @returns Formatted prompt (can be synchronous or asynchronous) */ abstract formatPrompt(prompt: string, options: ReviewOptions): string | Promise<string>; /** * Get a LangChain prompt template * @param prompt Raw prompt template * @param options Review options * @returns LangChain prompt template */ getLangChainTemplate(prompt: string, options: ReviewOptions): Promise<LangChainPromptTemplate>; /** * Extract input variables from a prompt template * @param prompt Prompt template * @returns Array of input variable names */ protected extractInputVariables(prompt: string): string[]; /** * Get the name of the strategy * @returns Strategy name */ abstract getName(): string; /** * Get the description of the strategy * @returns Strategy description */ abstract getDescription(): string; }