StreamFunction typedef

StreamFunction = AssistantMessageEventStream Function(Model model, Context context, {CancelToken? cancelToken})

Provider adapter contract consumed by the agent loop.

Matches the shape of the provider adapters (streamOpenAICompletions, streamAnthropic, streamGoogle): a model and a Context in, an AssistantMessageEventStream out. The adapters' extra positional options are adapted with a thin closure, e.g.

(model, context, {cancelToken}) => streamOpenAICompletions(
  model,
  context,
  OpenAICompletionsOptions(cancelToken: cancelToken),
)

Contract (identical to the adapters'): never throw; all failures — network, rate limiting, abort — arrive as an ErrorEvent on the returned stream with StopReason.error or StopReason.aborted. The loop is defensive anyway: a throw or a stream that closes without a terminal event is converted into an error AssistantMessage.

Implementation

typedef StreamFunction =
    AssistantMessageEventStream Function(
      Model model,
      Context context, {
      CancelToken? cancelToken,
    });