/** * Agentic QE v3 - MCP Security: Sampling Server * Server-initiated LLM for AI-driven decisions (ADR-012) * * Features: * - Server-initiated sampling for AI-driven QE decisions * - Request/response management for LLM interactions * - Configurable prompts and model parameters * - Rate limiting and quota management for sampling * - Caching for repeated sampling requests */ /** * Sampling request configuration */ export interface SamplingRequest { /** Unique request ID */ requestId: string; /** System prompt for context */ systemPrompt?: string; /** Messages for the sampling */ messages: SamplingMessage[]; /** Model to use */ model?: string; /** Maximum tokens to generate */ maxTokens?: number; /** Temperature for randomness */ temperature?: number; /** Stop sequences */ stopSequences?: string[]; /** Metadata for the request */ metadata?: Record; /** Include sample in response */ includeSample?: 'none' | 'full' | 'truncated'; } /** * Sampling message */ export interface SamplingMessage { role: 'user' | 'assistant' | 'system'; content: string | SamplingContent[]; } /** * Rich content for sampling */ export interface SamplingContent { type: 'text' | 'code' | 'resource'; text?: string; code?: { language: string; content: string; }; resource?: { uri: string; mimeType?: string; content?: string; }; } /** * Sampling response */ export interface SamplingResponse { requestId: string; content: string; stopReason: 'end_turn' | 'max_tokens' | 'stop_sequence'; model: string; usage: TokenUsage; cached: boolean; latencyMs: number; } /** * Token usage statistics */ export interface TokenUsage { inputTokens: number; outputTokens: number; totalTokens: number; } /** * Sampling handler function type */ export type SamplingHandler = (request: SamplingRequest) => Promise; /** * Sampling server configuration */ export interface SamplingServerConfig { /** Default model to use */ defaultModel: string; /** Default max tokens */ defaultMaxTokens: number; /** Default temperature */ defaultTemperature: number; /** Enable caching */ enableCaching: boolean; /** Cache TTL in ms */ cacheTTL: number; /** Max requests per minute */ maxRequestsPerMinute: number; /** Max tokens per minute */ maxTokensPerMinute: number; } /** * Quota tracking */ export interface QuotaUsage { requests: number; tokens: number; windowStart: number; } /** * Cached response */ export interface CachedResponse { response: SamplingResponse; expiresAt: number; } /** * Sampling server statistics */ export interface SamplingServerStats { totalRequests: number; cachedRequests: number; totalTokensUsed: number; averageLatencyMs: number; quotaResetTime: number; remainingRequests: number; remainingTokens: number; } /** * Pre-built prompts for QE decisions */ export declare const QEDecisionPrompts: { /** * Test generation decision prompt */ testGenerationDecision: (context: { sourceCode: string; existingTests?: string; coverageData?: { lineCoverage: number; branchCoverage: number; }; }) => { systemPrompt: string; messages: { role: "user"; content: ({ type: "text"; text: string; code?: undefined; } | { type: "code"; code: { language: string; content: string; }; text?: undefined; })[]; }[]; }; /** * Quality gate decision prompt */ qualityGateDecision: (context: { metrics: Record; thresholds: Record; trends: { metric: string; direction: "up" | "down" | "stable"; change: number; }[]; }) => { systemPrompt: string; messages: { role: "user"; content: string; }[]; }; /** * Defect prediction decision prompt */ defectPredictionDecision: (context: { codeChanges: { file: string; additions: number; deletions: number; complexity: number; }[]; historicalDefects: { file: string; defectCount: number; lastDefect: string; }[]; riskFactors: string[]; }) => { systemPrompt: string; messages: { role: "user"; content: string; }[]; }; /** * Security vulnerability analysis prompt */ securityAnalysisDecision: (context: { findings: { type: string; severity: string; location: string; description: string; }[]; codeContext: string; }) => { systemPrompt: string; messages: { role: "user"; content: ({ type: "text"; text: string; code?: undefined; } | { type: "code"; code: { language: string; content: string; }; text?: undefined; })[]; }[]; }; }; /** * Sampling Server for AI-driven QE decisions */ export declare class SamplingServer { private readonly config; private readonly handlers; private readonly cache; private readonly quota; private stats; private cleanupTimer; constructor(config?: Partial); /** * Register a sampling handler */ registerHandler(name: string, handler: SamplingHandler): void; /** * Create a sampling request */ createRequest(options: Omit): SamplingRequest; /** * Process a sampling request */ sample(request: SamplingRequest, handlerName?: string): Promise; /** * Sample with a pre-built QE decision prompt */ sampleQEDecision(promptType: T, context: Parameters<(typeof QEDecisionPrompts)[T]>[0], options?: Partial): Promise; /** * Get server statistics */ getStats(): SamplingServerStats; /** * Clear the cache */ clearCache(): void; /** * Dispose the server */ dispose(): void; private defaultHandler; private generateSimulatedResponse; private estimateTokens; private generateRequestId; private getCacheKey; private getCached; private setCached; private checkQuota; private resetQuotaIfNeeded; private startCleanup; } /** * Create a new sampling server */ export declare function createSamplingServer(config?: Partial): SamplingServer; /** * Get the default sampling server instance */ export declare function getSamplingServer(): SamplingServer; //# sourceMappingURL=sampling-server.d.ts.map