systemprompt_api/services/gateway/protocol/outbound/
mod.rs1pub mod anthropic;
2pub mod openai_chat;
3pub mod openai_responses;
4
5use std::sync::Arc;
6
7use anyhow::Result;
8use async_trait::async_trait;
9use futures_util::stream::BoxStream;
10use systemprompt_models::profile::GatewayRoute;
11
12use super::canonical::CanonicalRequest;
13use super::canonical_response::{CanonicalEvent, CanonicalResponse};
14
15#[derive(Debug)]
16pub struct OutboundCtx<'a> {
17 pub route: &'a GatewayRoute,
18 pub api_key: &'a str,
19 pub request: &'a CanonicalRequest,
20 pub upstream_model: &'a str,
21}
22
23#[allow(missing_debug_implementations)]
24pub enum OutboundOutcome {
25 Buffered(CanonicalResponse),
26 Streaming(BoxStream<'static, Result<CanonicalEvent, String>>),
27}
28
29#[async_trait]
30pub trait OutboundAdapter: Send + Sync {
31 fn provider_tag(&self) -> &'static str;
32 async fn send(&self, ctx: OutboundCtx<'_>) -> Result<OutboundOutcome>;
33}
34
35#[derive(Debug, Clone, Copy)]
36pub struct OutboundAdapterRegistration {
37 pub tag: &'static str,
38 pub factory: fn() -> Arc<dyn OutboundAdapter>,
39}
40
41inventory::collect!(OutboundAdapterRegistration);