ai_bridge_core library

Core models, interfaces, and utilities for Flutter AI Bridge.

This package provides the foundational abstractions for integrating AI providers into Flutter applications with a unified API.

Classes

AIAttachment
An attachment that can be sent with a message.
AIAudioProvider
Core interface for Audio capabilities.
AIBridge
The main entry point for Flutter AI Bridge.
AICompletionProvider
Core interface for AI text completion.
AIConfig
Configuration for an AI provider.
AIDocument
A chunk of textual data, usually parsed from a larger document.
AIEmbeddingProvider
Abstract interface for providers that support text embeddings.
AIMessage
A single message in an AI conversation.
AIProvider
Full-featured AI provider interface.
AIRequest
A request to an AI provider.
AIResponse
A unified response from any AI provider.
AIRouter
Smart router that decides which AI provider handles each request.
AIStreamChunk
A single chunk from a streaming AI response.
AIStreamingProvider
Interface for providers that support streaming responses.
AITool
Defines a tool or function that the AI can call.
AIToolCall
Represents a specific invocation of a tool requested by the AI.
AIUsage
Token usage information from an AI response.
CancellationToken
A token that allows cancellation of in-flight AI requests.
CircuitBreaker
Circuit breaker pattern to prevent cascading failures.
Conversation
Represents a conversation with an AI provider.
ConversationManager
Manages conversations with AI providers.
CostOptimizedStrategy
Selects providers by estimated cost-per-token (cheapest first).
DocumentChunker
Splits long text into manageable chunks for vector embeddings.
FallbackChain
Executes a request through a chain of providers with automatic fallback.
InMemoryVectorStore
A simple, local, list-backed Vector Store.
LatencyOptimizedStrategy
Selects providers with the lowest average latency first.
PrimaryStrategy
Uses the first available provider (insertion order).
QualityFirstStrategy
Selects providers in reverse insertion order (assumed quality order).
ResponseCache
Caches AI responses to reduce redundant API calls and costs.
RetryHandler
Handles automatic retries for retryable AI errors.
RoundRobinStrategy
Round-robin rotation across providers.
RoutingStrategyHandler
Abstract interface for routing strategy implementations.
StorageProvider
An abstract interface for storing and retrieving conversations.
StreamHandler
Manages streaming AI responses with unified handling.
TokenBudget
Controls token spending with configurable budgets.
TokenTracker
Tracks token usage across requests and sessions.
ToolExecutionLoop
Handles the autonomous tool execution loop.
VectorStore
Abstract interface for a Vector Database/Store used in RAG.

Enums

AIAttachmentType
The type of content in an attachment.
AICapability
Capabilities that an AI provider may support.
AIRole
Represents a role in an AI conversation.
CircuitState
States the circuit breaker can be in.
RoutingStrategy
Strategy for routing requests to providers.

Extensions

RoutingStrategyExtension on RoutingStrategy
Extension for backward compatibility: convert enum to handler.

Typedefs

OnChunkCallback = void Function(AIStreamChunk chunk)
Callback for each received chunk.
OnCompleteCallback = void Function(String fullText, AIUsage? usage)
Callback when streaming completes.
OnStreamErrorCallback = void Function(Object error)
Callback for stream errors.

Exceptions / Errors

AIAuthError
Authentication error — invalid or expired API key.
AIBudgetExceededError
Budget/quota exceeded.
AIContentFilterError
Content was filtered by safety settings.
AIError
Base class for all AI Bridge errors.
AIModelNotFoundError
Model not found or not available.
AINetworkError
Network error — connection issues, timeouts.
AIRateLimitError
Rate limit exceeded — too many requests.
AIServerError
Server error from the provider (5xx).
AITokenOverflowError
Token limit exceeded — input or output too long.
AIUnknownError
Unknown/unclassified error.
CancelledException
Exception thrown when an operation is cancelled via CancellationToken.