Defined in: packages/ai/src/activities/chat/adapter.ts:67
Text adapter interface with pre-resolved generics.
An adapter is created by a provider function: provider('model') → adapter All type resolution happens at the provider call site, not in this interface.
Generic parameters:
TModel extends string
TProviderOptions extends Record<string, any>
TInputModalities extends ReadonlyArray<Modality>
TMessageMetadataByModality extends DefaultMessageMetadataByModality
TToolCapabilities extends ReadonlyArray<string> = ReadonlyArray<string>
TToolCallMetadata = unknown
TSystemPromptMetadata = never
~types: object;Defined in: packages/ai/src/activities/chat/adapter.ts:111
Internal
Type-only properties for inference. Not assigned at runtime.
inputModalities: TInputModalities;messageMetadataByModality: TMessageMetadataByModality;providerOptions: TProviderOptions;systemPromptMetadata: TSystemPromptMetadata;toolCallMetadata: TToolCallMetadata;toolCapabilities: TToolCapabilities;chatStream: (options) => AsyncIterable<AdapterYieldChunk>;Defined in: packages/ai/src/activities/chat/adapter.ts:123
Stream text completions from the model
TextOptions<TProviderOptions>
AsyncIterable<AdapterYieldChunk>
optional combinedStructuredOutputSource?: (modelOptions?) => "text" | "event";Defined in: packages/ai/src/activities/chat/adapter.ts:190
Where native-combined structured output is taken from.
TProviderOptions
"text" | "event"
readonly optional inputModalities?: readonly ("text" | "image" | "audio" | "video" | "document")[];Defined in: packages/ai/src/activities/chat/adapter.ts:106
The input kinds the model reads, at runtime, from the provider's model metadata. undefined means not known. This mirrors the type-level '~types'.inputModalities, which has no runtime value.
readonly kind: "text";Defined in: packages/ai/src/activities/chat/adapter.ts:77
Discriminator for adapter kind
readonly model: TModel;Defined in: packages/ai/src/activities/chat/adapter.ts:81
The model this adapter is configured for
readonly name: string;Defined in: packages/ai/src/activities/chat/adapter.ts:79
Provider name identifier (e.g., 'openai', 'anthropic')
readonly optional requires?: readonly CapabilityHandle[];Defined in: packages/ai/src/activities/chat/adapter.ts:90
Capabilities this adapter requires at runtime. chat() validates that the configured middleware provides each one. Model adapters omit this; harness adapters (e.g. a future claudeCode()) declare e.g. [sandboxCapability]. Runtime access to capabilities from inside the adapter is not yet wired — this is the declaration/validation surface only.
structuredOutput: (options) => Promise<StructuredOutputResult<unknown>>;Defined in: packages/ai/src/activities/chat/adapter.ts:135
Generate structured output using the provider's native structured output API. This method uses stream: false and sends the JSON schema to the provider to ensure the response conforms to the expected structure.
StructuredOutputOptions<TProviderOptions>
Structured output options containing chat options and JSON schema
Promise<StructuredOutputResult<unknown>>
Promise with the raw data (validation is done in the chat function)
optional structuredOutputStream?: (options) => AsyncIterable<AdapterYieldChunk>;Defined in: packages/ai/src/activities/chat/adapter.ts:153
Stream structured output using the provider's native streaming structured output API (stream + response_format json_schema in a single request).
Optional — adapters without native streaming JSON omit this method and the activity layer synthesizes a stream around the non-streaming structuredOutput call.
Implementations must emit standard AG-UI lifecycle events (RUN_STARTED, TEXT_MESSAGE_*, RUN_FINISHED) carrying raw JSON text deltas, plus a final CUSTOM event named structured-output.complete whose value is { object, raw, reasoning? }. Events must be timestamped when emitted so their timestamps follow stream order.
StructuredOutputOptions<TProviderOptions>
AsyncIterable<AdapterYieldChunk>
optional supportsCombinedToolsAndSchema?: (modelOptions?) => boolean;Defined in: packages/ai/src/activities/chat/adapter.ts:176
Declares whether the adapter supports combining tools and a schema-constrained final answer in a single streaming request.
When true, the engine wires outputSchema into the regular chatStream() call and skips the separate runStructuredFinalization round-trip. The model's natural final turn carries the schema-constrained JSON text and the engine harvests it from the agent loop's accumulated content.
When false, undefined, or the method is omitted, the engine runs the agent loop without outputSchema and then issues a separate structuredOutput / structuredOutputStream call against the JSON schema for finalization (the legacy path).
The method receives the per-call modelOptions so providers whose support depends on the resolved upstream model (e.g. OpenRouter) can answer per-request. Most adapters can return a constant.
TProviderOptions
boolean
readonly optional supportsFileSources?: boolean;Defined in: packages/ai/src/activities/chat/adapter.ts:99
Declares that this adapter can consume { type: 'file' } content sources (provider Files API references). chat() rejects file sources in preflight for adapters that don't declare this, so an adapter written before the file arm existed fails closed instead of silently mis-mapping a reference onto its URL/data branch.