bamboo_agent/agent/llm/protocol/
mod.rs1mod anthropic;
15mod errors;
16pub mod gemini;
17mod openai;
18
19pub use anthropic::AnthropicProtocol;
20pub use errors::{ProtocolError, ProtocolResult};
21pub use gemini::GeminiProtocol;
22pub use openai::OpenAIProtocol;
23
24use crate::agent::core::Message;
25
26pub trait FromProvider<T>: Sized {
30 fn from_provider(value: T) -> ProtocolResult<Self>;
32}
33
34pub trait ToProvider<T>: Sized {
38 fn to_provider(&self) -> ProtocolResult<T>;
40}
41
42pub trait FromProviderBatch<T>: Sized {
44 fn from_provider_batch(values: Vec<T>) -> ProtocolResult<Vec<Self>>;
45}
46
47pub trait ToProviderBatch<T>: Sized {
49 fn to_provider_batch(&self) -> ProtocolResult<Vec<T>>;
50}
51
52impl FromProviderBatch<crate::agent::llm::api::models::ChatMessage> for Message {
55 fn from_provider_batch(
56 values: Vec<crate::agent::llm::api::models::ChatMessage>,
57 ) -> ProtocolResult<Vec<Self>> {
58 values.into_iter().map(Self::from_provider).collect()
59 }
60}
61
62impl ToProviderBatch<crate::agent::llm::api::models::ChatMessage> for Vec<Message> {
63 fn to_provider_batch(
64 &self,
65 ) -> ProtocolResult<Vec<crate::agent::llm::api::models::ChatMessage>> {
66 self.iter().map(|msg| msg.to_provider()).collect()
67 }
68}
69
70#[cfg(test)]
71mod tests {
72 use super::*;
73
74 #[test]
75 fn test_trait_bounds() {
76 fn assert_from_provider<T, U>()
78 where
79 T: FromProvider<U>,
80 {
81 }
82
83 fn assert_to_provider<T, U>()
84 where
85 T: ToProvider<U>,
86 {
87 }
88
89 assert_from_provider::<Message, crate::agent::llm::api::models::ChatMessage>();
91 assert_to_provider::<Message, crate::agent::llm::api::models::ChatMessage>();
92 }
93}