import { type ContentBlock, Message, type StopReason, type SystemPrompt } from '../types/messages.js'; import type { StateStore } from '../state-store.js'; import type { ToolChoice, ToolSpec } from '../tools/types.js'; import { ModelMetadataEvent, type ModelStreamEvent } from './streaming.js'; import type { Redaction } from '../hooks/events.js'; /** * Resolves model metadata fields on a config object from built-in lookup tables * when not explicitly set. Explicit values pass through unchanged. * * @internal * @param config - The stored model config * @param modelId - The model ID to look up * @returns A new config with resolved metadata, or the original config if nothing to resolve */ export declare function resolveConfigMetadata(config: T, modelId: string): T; /** * Configuration for prompt caching. */ export interface CacheConfig { /** * Caching strategy to use. * - "auto": Automatically inject cache points at optimal positions based on model ID detection * (after tools, after last user message) * - "anthropic": Force enable Anthropic-style caching (useful for application inference profiles) */ strategy: 'auto' | 'anthropic'; } /** * Base configuration interface for all model providers. * * This interface defines the common configuration properties that all * model providers should support. Provider-specific configurations * should extend this interface. */ export interface BaseModelConfig { /** * The model identifier. * This typically specifies which model to use from the provider's catalog. */ modelId?: string; /** * Maximum number of tokens to generate in the response. * * @see Provider-specific documentation for exact behavior */ maxTokens?: number; /** * Controls randomness in generation. * * @see Provider-specific documentation for valid range */ temperature?: number; /** * Controls diversity via nucleus sampling. * * @see Provider-specific documentation for details */ topP?: number; /** * Maximum context window size in tokens for the model. * * This value represents the total token capacity shared between input and output. * When not provided, it is automatically resolved from a built-in lookup table * based on the configured model ID. An explicit value always takes precedence. * * When `modelId` is changed via `updateConfig()`, this value is automatically * re-resolved if it was initially auto-populated. Explicitly set values are preserved. */ contextWindowLimit?: number; } /** * Options interface for configuring streaming model invocation. */ export interface StreamOptions { /** * System prompt to guide the model's behavior. * Can be a simple string or an array of content blocks for advanced caching. */ systemPrompt?: SystemPrompt; /** * Array of tool specifications that the model can use. */ toolSpecs?: ToolSpec[]; /** * Controls how the model selects tools to use. */ toolChoice?: ToolChoice; /** * Runtime state for model providers that manage server-side conversation state. * The model can read and write this state during streaming (e.g., to store a * response ID for conversation chaining). Mutations via `set`/`delete` are * visible to the caller after the stream completes. */ modelState?: StateStore; } /** * Options for counting tokens in a set of messages. */ export interface CountTokensOptions { /** * System prompt to guide the model's behavior. * Can be a simple string or an array of content blocks for advanced caching. */ systemPrompt?: SystemPrompt; /** * Array of tool specifications to include in the count. */ toolSpecs?: ToolSpec[]; } /** * Result interface for the streamAggregated method. * Contains the complete message, stop reason, and optional metadata. */ export interface StreamAggregatedResult { /** * The complete message from the model. */ message: Message; /** * The reason why the model stopped generating. */ stopReason: StopReason; /** * Optional metadata about the model invocation, including usage statistics and metrics. */ metadata?: ModelMetadataEvent; /** * Optional redaction information when guardrails blocked input. * Output redaction is handled by updating the message directly. */ redaction?: Redaction; } /** * Base abstract class for model providers. * Defines the contract that all model provider implementations must follow. * * Model providers handle communication with LLM APIs and implement streaming * responses using async iterables. * * @typeParam T - Model configuration type extending BaseModelConfig */ export declare abstract class Model { /** * Updates the model configuration. * Merges the provided configuration with existing settings. * * @param modelConfig - Configuration object with model-specific settings to update */ abstract updateConfig(modelConfig: T): void; /** * Retrieves the current model configuration. * * @returns The current configuration object */ abstract getConfig(): T; /** * The model ID from the current configuration, if configured. */ get modelId(): string | undefined; /** * Whether this model manages conversation state server-side. * * When `true`, the server tracks conversation context across turns, so the SDK * sends only the latest message instead of the full history. After each invocation, * the agent's local message history is cleared automatically. * * Model providers that support server-side state management should override this * to return `true`. * * @returns `false` by default */ get stateful(): boolean; /** * Streams a conversation with the model. * Returns an async iterable that yields streaming events as they occur. * * @param messages - Array of conversation messages * @param options - Optional streaming configuration * @returns Async iterable of streaming events */ abstract stream(messages: Message[], options?: StreamOptions): AsyncIterable; /** * Count tokens for the given input before sending to the model. * * Used for proactive context management (e.g., triggering compression at a threshold). * The base implementation uses a character-based heuristic (chars/4 for text, chars/2 for JSON). * * Subclasses should override this method to use native token counting APIs * (e.g., Bedrock CountTokens, Anthropic countTokens, Gemini countTokens) * for improved accuracy, falling back to `super.countTokens()` on API failure. * * @param messages - Array of conversation messages to count tokens for * @param options - Optional options containing system prompt and tool specs * @returns Total input token count */ countTokens(messages: Message[], options?: CountTokensOptions): Promise; /** * Converts event data to event class representation * * @param event_data - Interface representation of event * @returns Class representation of event */ private _convert_to_class_event; /** * Streams a conversation with aggregated content blocks and messages. * Returns an async generator that yields streaming events and content blocks, and returns the final message with stop reason and optional metadata. * * This method enhances the basic stream() by collecting streaming events into complete * ContentBlock and Message objects, which are needed by the agentic loop for tool execution * and conversation management. * * The method yields: * - ModelStreamEvent - Original streaming events (passed through) * - ContentBlock - Complete content block (emitted when block completes) * * The method returns: * - StreamAggregatedResult containing the complete message, stop reason, and optional metadata * * All exceptions thrown from this method are wrapped in ModelError to provide * a consistent error type for model-related errors. Specific error subtypes like * ContextWindowOverflowError, ModelThrottledError, and MaxTokensError are preserved. * * @param messages - Array of conversation messages * @param options - Optional streaming configuration * @returns Async generator yielding ModelStreamEvent | ContentBlock and returning a StreamAggregatedResult * @throws ModelError - Base class for all model-related errors * @throws ContextWindowOverflowError - When input exceeds the model's context window * @throws ModelThrottledError - When the model provider throttles requests * @throws MaxTokensError - When the model reaches its maximum token limit */ streamAggregated(messages: Message[], options?: StreamOptions): AsyncGenerator; } //# sourceMappingURL=model.d.ts.map