streamChat method

Stream<ChatEvent> streamChat({
  1. required String providerId,
  2. required ChatRequest request,
})

Streams chat events from the named provider.

Providers emit chat.delta events for incremental text and a final chat.completed event with the accumulated content. Providers that do not implement native streaming inherit a fallback that emits only the final completion event.

Implementation

Stream<ChatEvent> streamChat({
  required String providerId,
  required ChatRequest request,
}) {
  final provider = providers.chatProvider(providerId);
  if (provider == null) {
    throw StateError('Unknown AI chat provider: $providerId');
  }
  return provider.stream(request);
}