Skip to main content

flashmind_types/
lib.rs

1//! Shared types for the Flashmind AI agent framework.
2//!
3//! This crate defines the traits, wire types, and event structures shared by all
4//! Flashmind crates. It is the foundation that both library consumers and provider
5//! implementations depend on.
6//!
7//! # Core traits
8//!
9//! | Trait | Purpose |
10//! |-------|---------|
11//! | [`LlmProvider`] | Streaming completions from any LLM backend |
12//! | [`Tool`] | Function-calling tools the agent can invoke |
13//! | [`MemoryProvider`] | Store/search/forget long-term memories |
14//!
15//! # Modules
16//!
17//! | Module | Types |
18//! |--------|-------|
19//! | [`event`] | [`AgentEvent`], [`AgentInput`], [`TurnStatus`], [`TurnUsage`] — telemetry |
20//! | [`llm`] | [`LlmProvider`], [`CompletionRequest`], [`StreamEvent`], [`FinishReason`] |
21//! | [`memory`] | [`MemoryEntry`], [`MemoryMetadata`], [`MemoryProvider`] |
22//! | [`message`] | [`Message`], [`Role`], [`ToolCall`], [`ContentPart`] — LLM wire format |
23//! | [`model`] | [`Model`], [`Provider`], [`SamplingParams`], [`ReasoningLevel`] |
24//! | [`tool`] | [`Tool`], [`ToolRegistry`], [`ToolContext`], [`ToolResult`](tool::ToolResult) |
25//! | [`stream`] | [`AgentStream`], [`Outcome`] — stream-with-final-result pattern |
26//! | [`utils`] | UTF-8-safe string truncation helpers |
27//!
28//! # Example: implementing a provider
29//!
30//! ```rust
31//! use async_trait::async_trait;
32//! use flashmind_types::{
33//!     CompletionRequest, CompletionStream, LlmProvider, Provider, StreamEvent, FinishReason,
34//! };
35//!
36//! struct MyProvider;
37//!
38//! #[async_trait]
39//! impl LlmProvider for MyProvider {
40//!     fn name(&self) -> &str { "my-provider" }
41//!     fn provider(&self) -> Provider { Provider::OpenAi }
42//!
43//!     fn complete(&self, _request: CompletionRequest) -> CompletionStream {
44//!         Box::pin(async_stream::stream! {
45//!             yield Ok(StreamEvent::ContentDelta("Hello!".into()));
46//!             yield Ok(StreamEvent::Finished(FinishReason::Stop));
47//!         })
48//!     }
49//! }
50//! ```
51
52pub mod credits;
53pub mod error;
54pub mod event;
55pub mod humanize;
56pub mod interaction_mode;
57pub mod llm;
58pub mod memory;
59pub mod message;
60pub mod model;
61pub mod reasoning;
62pub mod session;
63pub mod stream;
64pub mod tool;
65pub mod utils;
66pub use credits::{CreditBalance, CreditScope, CreditUnit};
67pub use error::{LlmError, LlmErrorKind, ParseError};
68pub use event::{
69    AgentEvent, AgentInput, CompactionReason, Source, TurnResult, TurnStatus, TurnUsage,
70};
71pub use interaction_mode::InteractionMode;
72pub use llm::{
73    AudioFormat, AudioOutputConfig, CompletionRequest, CompletionResponse, CompletionStream,
74    FinishReason, FrameImage, ImageEditRequest, ImageGenConfig, ImageGenRequest, ImageOutputFormat,
75    LlmProvider, Modality, ModelCapabilities, ModelCategory, ModelInfo, ModelPricing,
76    NativeCompaction, ProviderRegistry, StreamEvent, SttRequest, TokenUsage, ToolDefinition,
77    TtsRequest, VideoGenRequest, Voice, mime_from_extension,
78};
79pub use memory::{MemoryEntry, MemoryMetadata, MemoryProvider};
80pub use message::{ContentPart, Message, Role, ToolCall, ToolResult};
81pub use model::{
82    AgentLlmConfig, AliasedModel, Model, Provider, ProviderPreferences, ProviderSort, Quantization,
83    ReasoningLevel, SamplingParams,
84};
85pub use reasoning::{NativeReasoningFormat, ReasoningDetails};
86pub use session::{SessionId, SessionIdError, SessionUsage};
87pub use stream::{AgentStream, Outcome};
88pub use tool::{
89    ForbiddenCmd, GateAnswer, GateAsk, GateDecision, Tool, ToolContext, ToolGate, ToolRegistry,
90};
91
92/// Minimum length for a secret value to be redacted from output.
93///
94/// Secrets shorter than this are left as-is to avoid false positives.
95pub const MIN_SECRET_REDACT_LEN: usize = 8;