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