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
34 fn render_terminal_event(
41 &self,
42 event: &CanonicalEvent,
43 snapshot: &CanonicalResponse,
44 model: &str,
45 ) -> Option<Bytes> {
46 let _ = (event, snapshot, model);
49 None
50 }
51
52 fn render_error(&self, status: StatusCode, message: &str) -> Bytes;
53 fn streaming_content_type(&self) -> &'static str {
54 "text/event-stream"
55 }
56}