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