flutter_ai_core 0.1.14 copy "flutter_ai_core: ^0.1.14" to clipboard
flutter_ai_core: ^0.1.14 copied to clipboard

Dependency-free Dart foundation for AI chat: message models, a streaming MessageProcessor, and the provider and renderer contracts the flutter_ai family builds on.

flutter_ai_core

The dependency-free Dart engine under flutter_ai — immutable conversation models, a streaming-event reducer, and the LlmProvider contract every provider speaks.

flutter_ai: a streaming answer with chain-of-thought and a generative-UI task card

flutter_ai_core on pub.dev pub points License: BSD-3-Clause

Family: flutter_ai · client · elements · openai · anthropic · gemini · tools · mcp · voice
Recipes · Migrating from the Vercel AI SDK

The transcript above is produced by this package's MessageProcessor folding provider events into messages (rendered with flutter_ai_elements).


Dependency-free Dart foundation for building AI chat experiences — the shared contract layer of the flutter_ai package family.

flutter_ai_core has no runtime dependencies beyond dart:core and dart:convert: no Flutter, no code generation, no build_runner. That keeps it safe to depend on from anywhere and free of version conflicts.

What's inside #

  • ModelsAiConversation, AiMessage, and the sealed AiPart hierarchy (TextPart, ReasoningPart, ToolCallPart, ToolResultPart, FilePart, SourcePart, DataPart). All immutable value types with manual, hand-written JSON.
  • Streaming — the sealed AiStreamEvent set and a MessageProcessor that folds events into conversation state, reporting exactly which messages changed so a UI can rebuild only those nodes.
  • Tolerant JSONJsonAccumulator parses partial tool-call arguments as they stream, repairing incomplete JSON without ever throwing.
  • ContractsLlmProvider (provider abstraction) and TextRenderer (pluggable text rendering), with AiRequestOptions and ToolDefinition.

Design principles #

  • Un-opinionated. No bundled state manager. The processor is a pure, synchronous reducer; batching updates to the frame boundary is the consumer's job, which keeps this package UI-agnostic and trivially testable.
  • Granular by construction. MutationResult.changedMessageIds lets the UI avoid rebuilding the whole transcript on every token.
  • Fails soft. Malformed streamed tool arguments mark a single call errored rather than crashing the stream.

Example #

import 'package:flutter_ai_core/flutter_ai_core.dart';

void main() {
  final processor = MessageProcessor();

  // Events would normally come from an LlmProvider's stream.
  processor.apply(const MessageStarted(messageId: 'a1', role: AiRole.assistant));
  processor.apply(const TextDelta(messageId: 'a1', delta: 'Hello, '));
  final result = processor.apply(const TextDelta(messageId: 'a1', delta: 'world!'));

  print(result.conversation.messageById('a1')!.text); // Hello, world!
  print(result.changedMessageIds); // {a1}
}

See example/ for a fuller walkthrough including tool calls.

Status #

Part of the flutter_ai ecosystem; the UI layer (flutter_ai_elements) and provider/controller layer (flutter_ai_client) build on these types. See the CHANGELOG for version history.

If flutter_ai saves you time, you can buy me a coffee ☕.

1
likes
160
points
435
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Dependency-free Dart foundation for AI chat: message models, a streaming MessageProcessor, and the provider and renderer contracts the flutter_ai family builds on.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#ai #llm #chat #streaming #flutter

License

BSD-3-Clause (license)

More

Packages that depend on flutter_ai_core