chat_provider library

The chat view-model contract: the bridge between an AIAgent and any chat UI.

This is a separate entry point from package:agents_flutter/agents_flutter.dart because ChatMessage here is the UI-facing message (display text, attachments, origin) and would otherwise collide with package:extensions/ai.dart's wire-level ChatMessage in every file that imports both. Import this library from chat UI code; import the main barrel everywhere else.

Classes

AgentLlmProvider
Bridges an AIAgent into the chat UI's LlmProvider contract.
Attachment
An abstract class representing an attachment in a chat message.
ChatMessage
Represents a message in a chat conversation.
EchoLlmProvider
A simple LLM provider that echoes the input prompt and attachment information.
FileAttachment
Represents a file attachment in a chat message.
ImageFileAttachment
Represents an image attachment in a chat message.
LinkAttachment
Represents a link attachment in a chat message.
LlmProvider
An abstract class representing a Language Model (LLM) provider.
TokenSmoother
Re-paces a token stream into a steady, typewriter-style character stream.
ToolApprovalRequest
A tool call awaiting the user's approval decision.
ToolApprovalSupport
An LlmProvider that can surface user-in-the-loop tool approvals.

Enums

MessageOrigin
Represents the origin of a chat message.
ToolApprovalDecision
The user's decision for a pending ToolApprovalRequest.

Extensions

SmoothedStream on Stream<String>
Convenience methods for smoothing text streams.

Typedefs

AtomicChunkPredicate = bool Function(String chunk)
Whether chunk should be released whole rather than paced grapheme by grapheme. The default treats every chunk as ordinary text.
LlmStreamGenerator = Stream<String> Function(String prompt, {required Iterable<Attachment> attachments})
A function that generates a stream of text based on a prompt and attachments.
LlmSubmissionCallback = FutureOr<void> Function(String prompt, {required Iterable<Attachment> attachments})
A callback invoked when a chat prompt is submitted.
SpeechToTextConverter = Stream<String> Function(XFile file)
A function that converts speech to text.

Exceptions / Errors

LlmCancelException
Exception thrown when an LLM operation is cancelled.
LlmException
Exception class for LLM-related errors.
LlmFailureException
Exception thrown when an LLM operation fails.