llm_core 0.3.1
llm_core: ^0.3.1 copied to clipboard
Core abstractions for LLM (Large Language Model) interactions. Provides common interfaces, models, and utilities used by LLM backend implementations.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[Unreleased] #
0.3.1 - 2026-08-18 #
Added #
createLLMHttpClient()— the default HTTP client for every backend. AppliesTimeoutConfig.connectionTimeout, bounds the pool per host, and retires idle connections after 3s.WriteGatedHttpClient— bounds how many requests may be connecting and writing at once (4 slots on macOS/iOS) to work around a Dart VM kqueue defect that loses writable events. Seedocs/concurrent-send-stall.md.LLMChunkMessage.rawContent— the assistant turn as the model emitted it, tool-call markup intact. Set by local-inference backends.RetryUtil.executeWithRetryaccepts anonRetrycallback and warns on every retry.
Changed #
HttpClientHelper.sendStreamingRequestnow applies a timeout tosend()by default. It previously did not, so a request that wedged before response headers arrived never recovered.- Streaming requests are built with
http.Request+bodyBytesinstead ofStreamedRequest. - Dependency floors raised: Dart SDK
^3.12.0(was^3.8.0),http ^1.6.0,lints ^6.1.0,test ^1.31.0.
0.3.0 - 2026-08-17 #
Added #
ReasoningEffortenum (none…max) andLLMChatOptions.reasoningEffort— a portable reasoning-depth knob alongsidereasoningBudget.reasoningEffortForBudget()for backends without a native token budget.LLMUsage.reasoningTokensfor providers that report reasoning-token usage.
0.2.0 - 2026-08-12 #
Fixed #
LLMFinishReason.fromProvidernow recognizesstop_sequence,model_context_window_exceeded,refusal, and Gemini'sRECITATION/PROHIBITED_CONTENT/BLOCKLIST/SPII/IMAGE_SAFETY, which previously all collapsed tounknown.
Added #
LLMFinishReason.refusalfor provider safety declines, which arrive as successful responses with empty or partial content.- Typed message content parts, typed tool calls, provider capabilities, response usage, finish reasons, thinking output, and provider metadata.
LLMChatOptionsfor generation, reasoning, tool behavior, structured output, timeout, retry, cache, metrics, and backend-specific options.- Shared repository feature helpers for cache and metrics handling.
LLMResponseFormatsealed class hierarchy for structured output:JsonFormat— simple JSON mode; instructs the model to produce valid JSON without schema enforcementJsonSchemaFormat({required name, required schema, strict = true})— full JSON Schema mode; schema is forwarded to the backend verbatim- Both are
const-constructible and work with exhaustiveswitchpattern matching
responseFormatfield onStreamChatOptions(nullable, defaults tonull; fully backward compatible)StreamChatOptionsMergerandMergedOptionsnow carry and propagateresponseFormat
Changed #
- Breaking: Core chat APIs now accept
LLMChatOptions?;StreamChatOptionsremains as a compatibility alias. - Cache keys now use stable JSON-shaped request data instead of object stringification.
0.1.9 - 2026-02-28 #
Changed #
- Breaking: Removed
requireFinalAssistantResponseoption fromStreamChatOptions,StreamChatOptionsMerger, andStreamToolExecutor. Tool loops now always require a final assistant response — there is no reason to allow tool loops to end without the assistant reporting back. maxToolAttemptsdefault increased from 25 to 90 across all repositories and builders.chatResponse()tool loop detection refined: only actual tool result chunks (LLMRole.tool) trigger the incomplete-loop check, not tool calls appearing alongside content.
0.1.8 - 2026-02-26 #
Added #
- Tool result chunks emitted to stream:
StreamToolExecutornow yieldsLLMChunkwithrole: LLMRole.toolafter each tool execution, so chat consumers can display "Tool X returned: Y" per OpenAI function calling specs LLMToolCall.toApiFormat()helper for converting to OpenAI/Ollama API format- Assistant message with
tool_callsadded to message history before tool results (API-compliant sequence) - Content accumulation from stream chunks for assistant messages that include both text and tool calls
Changed #
- Breaking: Removed
toolNamefromLLMMessageandLLMChunkMessage; usetoolCallIdonly (OpenAI canonical format) - Breaking: Tool message validation now requires
toolCallId(removedtoolNameoption) StreamToolExecutoraccumulates content and thinking from chunks for the assistant message
0.1.7 - 2026-02-10 #
Added #
batchEmbed()onLLMChatRepository: explicit API for embedding multiple texts in one call. Same signature asembed(); default implementation delegates toembed(). Documented for Ollama, OpenAI, and llama.cpp backends.
0.1.6 - 2026-02-10 #
Fixed #
- Hardened
StreamToolExecutorto always synthesize a non-emptytoolCallIdforLLMRole.toolmessages when a backend-providedLLMToolCall.idis missing or empty, preventingTool message must have toolCallIdvalidation errors. - Improved tool execution error handling so that thrown tool exceptions are surfaced as tool messages rather than crashing the stream.
0.1.5 - 2026-01-26 #
Added #
StreamChatOptionsclass to encapsulate all streaming chat options and reduce parameter proliferationRetryConfigandRetryUtilfor configurable retry logic with exponential backoffTimeoutConfigfor flexible timeout configuration (connection, read, total, large payloads)LLMMetricsinterface andDefaultLLMMetricsimplementation for optional metrics collectionchatResponse()method onLLMChatRepositoryfor non-streaming complete responses- Input validation utilities in
Validationclass ChatRepositoryBuilderBasefor implementing builder patterns in repository implementationsStreamChatOptionsMergerfor merging options from multiple sources- HTTP client utilities (
HttpClientHelper) for consistent request handling - Error handling utilities (
ErrorHandlers,BackendErrorHandler) for standardized error processing - Tool execution utilities (
ToolExecutor) for managing tool calling workflows
Changed #
streamChat()now accepts optionalStreamChatOptionsparameter- Improved error handling and retry logic across all backends
- Enhanced documentation
0.1.0 - 2026-01-19 #
Added #
- Initial release
- Core abstractions for LLM interactions:
LLMChatRepository- Abstract interface for chat completionsLLMMessage- Message representation with roles and contentLLMResponse- Response wrapper with metadataLLMChunk- Streaming response chunksLLMEmbedding- Text embedding representation
- Tool calling support:
LLMTool- Tool definition with JSON Schema parametersLLMToolCall- Tool invocation representationLLMToolParam- Parameter definitions
- Exception types for error handling