Model
Defined in: src/models/model.ts:110
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.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type | Description |
|---|---|---|
T extends BaseModelConfig | BaseModelConfig | Model configuration type extending BaseModelConfig |
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Model<T>(): Model<T>;Returns
Section titled “Returns”Model<T>
Methods
Section titled “Methods”updateConfig()
Section titled “updateConfig()”abstract updateConfig(modelConfig): void;Defined in: src/models/model.ts:117
Updates the model configuration. Merges the provided configuration with existing settings.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
modelConfig | T | Configuration object with model-specific settings to update |
Returns
Section titled “Returns”void
getConfig()
Section titled “getConfig()”abstract getConfig(): T;Defined in: src/models/model.ts:124
Retrieves the current model configuration.
Returns
Section titled “Returns”T
The current configuration object
stream()
Section titled “stream()”abstract stream(messages, options?): AsyncIterable<ModelStreamEvent>;Defined in: src/models/model.ts:134
Streams a conversation with the model. Returns an async iterable that yields streaming events as they occur.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
messages | Message[] | Array of conversation messages |
options? | StreamOptions | Optional streaming configuration |
Returns
Section titled “Returns”AsyncIterable<ModelStreamEvent>
Async iterable of streaming events
streamAggregated()
Section titled “streamAggregated()”streamAggregated(messages, options?): AsyncGenerator< | ModelStreamEvent| ContentBlock, StreamAggregatedResult, undefined>;Defined in: src/models/model.ts:188
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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
messages | Message[] | Array of conversation messages |
options? | StreamOptions | Optional streaming configuration |
Returns
Section titled “Returns”AsyncGenerator<
| ModelStreamEvent
| ContentBlock, StreamAggregatedResult, undefined>
Async generator yielding ModelStreamEvent | ContentBlock and returning a StreamAggregatedResult
Throws
Section titled “Throws”ModelError - Base class for all model-related errors
Throws
Section titled “Throws”ContextWindowOverflowError - When input exceeds the model’s context window
Throws
Section titled “Throws”ModelThrottledError - When the model provider throttles requests
Throws
Section titled “Throws”MaxTokensError - When the model reaches its maximum token limit