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

Dependency-free Dart foundation for AI chat: message and conversation models, a streaming MessageProcessor with granular mutations, and the provider and renderer contracts the rest of the flutter_ai f [...]

flutter_ai_core #

☕ Support this project #

Buy me a coffee on Ko-fi

If flutter_ai saves you time, buy me a coffee ☕ — it keeps the whole family maintained.


Streaming chat

The live 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 #

0.1.1. Part of the flutter_ai ecosystem; the UI layer (flutter_ai_elements) and provider/controller layer (flutter_ai_client) build on these types.

1
likes
0
points
542
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues

Topics

#ai #llm #chat #streaming #flutter

License

unknown (license)

More

Packages that depend on flutter_ai_core