Skip to main content

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

1pub mod anthropic_messages;
2pub mod openai_responses;
3
4use bytes::Bytes;
5use http::StatusCode;
6
7use super::canonical::CanonicalRequest;
8use super::canonical_response::{CanonicalEvent, CanonicalResponse};
9
10#[derive(Debug, thiserror::Error)]
11pub enum InboundParseError {
12    #[error("invalid request body: {0}")]
13    InvalidJson(String),
14    #[error("missing required field: {0}")]
15    MissingField(&'static str),
16    #[error("unsupported value for {field}: {detail}")]
17    Unsupported { field: &'static str, detail: String },
18}
19
20pub trait InboundAdapter: Send + Sync + std::fmt::Debug {
21    fn wire_name(&self) -> &'static str;
22    fn parse_request(&self, raw: &Bytes) -> Result<CanonicalRequest, InboundParseError>;
23    fn render_response(&self, response: &CanonicalResponse) -> Bytes;
24    fn render_event(&self, event: &CanonicalEvent, model: &str) -> Option<Bytes>;
25    fn render_error(&self, status: StatusCode, message: &str) -> Bytes;
26    fn streaming_content_type(&self) -> &'static str {
27        "text/event-stream"
28    }
29}