mermaid_cli/models/
traits.rs

1/// Core Model trait - the public API for model interactions
2///
3/// This is what external code uses. Internally, it wraps the Backend system.
4
5use async_trait::async_trait;
6
7use super::config::ModelConfig;
8use super::error::Result;
9use super::types::{ChatMessage, ModelResponse, ProjectContext, StreamCallback};
10
11/// Core trait that all model implementations must provide
12///
13/// This is the public API. Internal backends implement this via UnifiedModel wrapper.
14#[async_trait]
15pub trait Model: Send + Sync {
16    /// Send a chat conversation to the model and get a response
17    async fn chat(
18        &mut self,
19        messages: &[ChatMessage],
20        context: &ProjectContext,
21        config: &ModelConfig,
22        stream_callback: Option<StreamCallback>,
23    ) -> Result<ModelResponse>;
24
25    /// Get the name of the model
26    fn name(&self) -> &str;
27
28    /// Check if this is a local model (no external API calls)
29    fn is_local(&self) -> bool;
30
31    /// Validate that the model is accessible
32    async fn validate_connection(&self) -> Result<bool> {
33        Ok(true)
34    }
35}