systemprompt_api/services/gateway/protocol/inbound/
mod.rs1pub mod anthropic_messages;
13pub mod openai_chat;
14pub mod openai_responses;
15
16use bytes::Bytes;
17use http::StatusCode;
18use systemprompt_models::profile::WireProtocol;
19
20use super::canonical::CanonicalRequest;
21use super::canonical_response::{CanonicalEvent, CanonicalResponse};
22
23#[derive(Debug, thiserror::Error)]
24pub enum InboundParseError {
25 #[error("invalid request body: {0}")]
26 InvalidJson(String),
27 #[error("missing required field: {0}")]
28 MissingField(&'static str),
29 #[error("unsupported value for {field}: {detail}")]
30 Unsupported { field: &'static str, detail: String },
31}
32
33pub trait InboundAdapter: Send + Sync + std::fmt::Debug {
34 fn wire_name(&self) -> &'static str;
35
36 fn passthrough_wire(&self) -> Option<WireProtocol> {
37 None
38 }
39
40 fn parse_request(&self, raw: &Bytes) -> Result<CanonicalRequest, InboundParseError>;
41 fn render_response(&self, response: &CanonicalResponse) -> Bytes;
42 fn render_event(&self, event: &CanonicalEvent, model: &str) -> Option<Bytes>;
43
44 fn render_terminal_event(
45 &self,
46 event: &CanonicalEvent,
47 snapshot: &CanonicalResponse,
48 model: &str,
49 ) -> Option<Bytes> {
50 let _ = (event, snapshot, model);
52 None
53 }
54
55 fn render_error(&self, status: StatusCode, message: &str) -> Bytes;
56 fn streaming_content_type(&self) -> &'static str {
57 "text/event-stream"
58 }
59}