Skip to main content

systemprompt_api/services/gateway/protocol/outbound/
mod.rs

1pub 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// Why: #[async_trait] is required — the upstream registry stores adapters as
30// `Arc<dyn OutboundAdapter>`, so the trait must stay dyn-compatible.
31#[async_trait]
32pub trait OutboundAdapter: Send + Sync {
33    fn provider_tag(&self) -> &'static str;
34    async fn send(&self, ctx: OutboundCtx<'_>) -> Result<OutboundOutcome>;
35}
36
37#[derive(Debug, Clone, Copy)]
38pub struct OutboundAdapterRegistration {
39    pub tag: &'static str,
40    pub factory: fn() -> Arc<dyn OutboundAdapter>,
41}
42
43inventory::collect!(OutboundAdapterRegistration);