/** * Advanced Template Engine for Requirements Gathering Agent * * Revolutionary context injection and AI instruction system with database backing. * Preserves the brilliant context building and injection architecture while adding * dynamic, database-driven template management. * * @version 3.0.0 * @author Requirements Gathering Agent Team * @created June 2025 * * Key Revolutionary Features: * - Dynamic context building with dependency resolution * - AI instruction templates with variable injection * - Large context management and intelligent chunking * - Database-backed template versioning and evolution * - Cross-document relationship analysis * - Context inheritance and composition * * @filepath c:\Users\menno\Source\Repos\requirements-gathering-agent\src\modules\templates\AdvancedTemplateEngine.ts */ import type { ContextInjectionPoint, TemplateVariable, ConditionalRule } from './types/template.types.js'; import { AIProcessor } from '../ai/AIProcessor.js'; import { ContextManager } from '../contextManager.js'; import { TemplateRepository } from '../../repositories/TemplateRepository.js'; export interface ContextDependency { documentKey: string; required: boolean; weight: number; maxAge?: number; contextTransform?: (content: string) => string; } export interface AIInstructionTemplate { id: string; name: string; category: string; systemPrompt: string; userPromptTemplate: string; contextInjectionPoints: ContextInjectionPoint[]; variables: TemplateVariable[]; conditionalLogic: ConditionalRule[]; maxTokens: number; temperature: number; modelPreferences: string[]; qualityChecks: QualityCheck[]; createdAt: Date; updatedAt: Date; version: string; isActive: boolean; } export interface QualityCheck { name: string; type: 'length' | 'keywords' | 'structure' | 'compliance' | 'custom'; criteria: any; weight: number; } export interface ContextRepository { getDocument(key: string): Promise; getRelatedDocuments(key: string): Promise; getDocumentMetadata(key: string): Promise; searchDocuments(query: string): Promise; cacheContext(key: string, context: string, ttl: number): Promise; getCachedContext(key: string): Promise; } export interface DocumentMetadata { key: string; title: string; category: string; lastModified: Date; dependencies: string[]; tags: string[]; contentHash: string; wordCount: number; quality: number; } export interface SearchResult { key: string; title: string; relevance: number; excerpt: string; } export declare class AdvancedTemplateEngine { private aiProcessor; private contextManager; private contextRepository; private templateRepository; private templates; private contextCache; constructor(contextRepository: ContextRepository, aiProcessor?: AIProcessor, contextManager?: ContextManager, templateRepository?: TemplateRepository); /** * Revolutionary Context Building with Smart Dependency Resolution * * This method implements the brilliant context injection architecture * but with database backing and intelligent dependency management. */ buildEnhancedContext(templateId: string, baseContext: string, variables?: Record): Promise; /** * Build Context Segment with Intelligent Dependency Resolution * * This preserves your revolutionary dependency-based context building * while adding database-backed dynamic resolution. */ private buildContextSegment; /** * Revolutionary Dependency Resolution with Cross-Document Intelligence */ private resolveDependency; /** * Intelligent Context Aggregation with Multiple Strategies */ private aggregateContextSegments; /** * AI-Powered Context Summarization for Large Context Management */ private summarizeSegments; /** * Priority-Based Context Assembly */ private prioritizeSegments; /** * Template-Based Context Assembly */ private templateAggregation; /** * Simple concatenation with length management */ private concatenateSegments; /** * Apply Conditional Logic to Template Content */ private applyConditionalLogic; /** * Safe condition evaluation (simplified for security) */ private evaluateCondition; /** * Context Optimization for Large Context Management */ private optimizeContext; /** * Generate Document with Revolutionary Context Injection * * This is the main method that brings together all the revolutionary features */ generateDocument(templateId: string, baseContext: string, variables?: Record): Promise; /** * Template Management Methods */ saveTemplate(template: AIInstructionTemplate): Promise; loadTemplate(templateId: string): Promise; loadAllTemplates(): Promise; /** * Cache Management */ private getCachedContext; private cacheContext; /** * Utility Methods */ private removeSection; private modifySection; private performQualityChecks; } /** * Factory for creating template engine with database repository */ export declare class TemplateEngineFactory { static createWithDatabase(databaseConfig: any, aiProcessor?: AIProcessor, contextManager?: ContextManager): Promise; } //# sourceMappingURL=AdvancedTemplateEngine.d.ts.map