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