/** * Claude AI Client * * Wrapper for Anthropic SDK with prompt caching and hierarchical context management. * * Features: * - Anthropic prompt caching (cache_control: ephemeral) * - Hierarchical context chunking for AAS content (L1/L2/L3) * - Local response cache for repeated queries * - Token usage tracking */ import type { Logger } from 'pino'; /** * AI Client configuration */ export interface AIClientConfig { /** Anthropic API key */ apiKey: string; /** Model to use */ model: string; /** Maximum tokens for responses */ maxTokens: number; /** Enable local response caching */ enableCaching: boolean; /** Local cache TTL in seconds */ cacheTtlSeconds: number; /** Enable Anthropic prompt caching (cache_control) */ enablePromptCaching: boolean; } /** * Default AI client configuration */ export declare const DEFAULT_AI_CONFIG: AIClientConfig; /** * Context chunk level for hierarchical retrieval */ export type ContextLevel = 'L1' | 'L2' | 'L3'; /** * Context chunk with level metadata */ export interface ContextChunk { /** Hierarchical level: L1 (summary), L2 (submodel), L3 (element) */ level: ContextLevel; /** Semantic ID or path for this chunk */ path: string; /** Content of the chunk */ content: string; /** Estimated token count */ tokenEstimate: number; } /** * Hierarchical context for AAS documents * * L1: Document summary (AAS, submodel counts, key identifiers) * L2: Submodel level (semantic IDs, element summaries) * L3: Element level (full property/collection details) */ export interface HierarchicalContext { /** L1: High-level document summary */ summary: ContextChunk; /** L2: Submodel-level context */ submodels: ContextChunk[]; /** L3: Element-level context (loaded on demand) */ elements: Map; /** Total token budget */ tokenBudget: number; /** Current token usage */ currentTokens: number; } /** * Message for AI conversation */ export interface AIMessage { role: 'user' | 'assistant'; content: string; } /** * AI completion options */ export interface CompletionOptions { /** System prompt */ system?: string; /** Messages to send */ messages: AIMessage[]; /** Override max tokens */ maxTokens?: number; /** Stop sequences */ stopSequences?: string[]; /** Temperature (0-1) */ temperature?: number; /** Enable prompt caching for system prompt */ cacheSystemPrompt?: boolean; /** Enable prompt caching for first message */ cacheFirstMessage?: boolean; } /** * AI completion result */ export interface CompletionResult { /** Response content */ content: string; /** Tokens used */ usage: { inputTokens: number; outputTokens: number; /** Tokens read from Anthropic's prompt cache */ cacheReadInputTokens?: number; /** Tokens written to Anthropic's prompt cache */ cacheCreationInputTokens?: number; }; /** Stop reason */ stopReason: string; /** Whether local cache was used */ cacheHit: boolean; /** Whether Anthropic prompt cache was used */ promptCacheHit: boolean; } /** * Claude AI client with caching */ export declare class AIClient { private client; private config; private logger; private cache; constructor(config: Partial, logger: Logger); /** * Generate a completion with optional Anthropic prompt caching */ complete(options: CompletionOptions): Promise; /** * Build system prompt blocks with optional cache_control */ private buildSystemBlocks; /** * Build message array with optional cache_control on first message */ private buildMessages; /** * Generate a structured JSON response */ completeJson(options: CompletionOptions): Promise; /** * Clear the response cache */ clearCache(): void; /** * Generate cache key from options */ private getCacheKey; } /** * Hierarchical context builder for AAS documents * * Creates a tiered context representation: * - L1: Document summary (cached, always included) * - L2: Submodel summaries (cached, included based on relevance) * - L3: Element details (on-demand, for specific queries) */ export declare class HierarchicalContextBuilder { private readonly DEFAULT_TOKEN_BUDGET; private readonly CHARS_PER_TOKEN; /** * Build hierarchical context from an AAS Environment */ buildContext(environment: Record, tokenBudget?: number): HierarchicalContext; /** * Build L1: High-level document summary */ private buildL1Summary; /** * Build L2: Submodel-level context */ private buildL2Submodels; /** * Build L3: Element-level detail (on-demand) */ buildL3Element(element: unknown, path: string): ContextChunk; /** * Select context chunks within token budget * * Strategy: * 1. Always include L1 summary * 2. Include L2 submodels up to 60% of budget * 3. Reserve 40% for L3 elements and response */ selectForBudget(context: HierarchicalContext, relevantPaths?: string[]): { system: string; userContext: string; }; /** * Sort chunks by relevance to given paths */ private sortByRelevance; /** * Estimate token count from string length */ private estimateTokens; } //# sourceMappingURL=client.d.ts.map