Skip to main content

agent_air_runtime/client/
traits.rs

1use super::error::LlmError;
2use super::http::HttpClient;
3use super::models::{Message, MessageOptions, StreamEvent};
4use futures::Stream;
5use std::future::Future;
6use std::pin::Pin;
7
8/// A boxed stream of LLM streaming events.
9pub type StreamEventStream = Pin<Box<dyn Stream<Item = Result<StreamEvent, LlmError>> + Send>>;
10
11/// A boxed future that resolves to a stream of LLM events.
12pub type StreamMsgFuture =
13    Pin<Box<dyn Future<Output = Result<StreamEventStream, LlmError>> + Send>>;
14
15/// Provider interface for LLM APIs.
16///
17/// Implement this trait to add support for new LLM providers.
18pub trait LlmProvider {
19    /// Send a message to the LLM.
20    /// Returns the assistant's response message or an error.
21    fn send_msg(
22        &self,
23        client: &HttpClient,
24        messages: &[Message],
25        options: &MessageOptions,
26    ) -> Pin<Box<dyn Future<Output = Result<Message, LlmError>> + Send>>;
27
28    /// Send a streaming message to the LLM.
29    /// Returns a stream of events as they arrive from the API.
30    fn send_msg_stream(
31        &self,
32        _client: &HttpClient,
33        _messages: &[Message],
34        _options: &MessageOptions,
35    ) -> StreamMsgFuture {
36        Box::pin(async {
37            Err(LlmError::new(
38                "NOT_IMPLEMENTED",
39                "Streaming not supported for this provider",
40            ))
41        })
42    }
43}