Skip to main content

gproxy_protocol/transform/generate/stream/responses/
mod.rs

1//! Bounded native Responses SSE lifecycle, collection and synthesis.
2
3mod collector;
4mod emit;
5mod events;
6mod items;
7mod lifecycle;
8mod parts;
9mod snapshots;
10mod status;
11mod synthesize;
12use crate::transform::TransformError;
13use crate::wire::openai::responses::{input as i, response as r, stream as s};
14pub use collector::{ResponsesStreamCollector, ResponsesStreamLimits};
15pub use synthesize::synthesize_responses_stream;
16
17fn invalid(message: &'static str) -> TransformError {
18    TransformError::invalid_result("responses.stream", message)
19}
20
21fn limit() -> TransformError {
22    TransformError::new(
23        crate::transform::TransformErrorKind::Limit,
24        "responses.stream",
25        "Responses stream limit exceeded",
26    )
27}
28
29fn bounded<T: serde::Serialize>(value: &T, cap: usize) -> Result<usize, TransformError> {
30    crate::codec::encode_json(
31        value,
32        crate::codec::CodecLimits {
33            max_body_bytes: cap as u64,
34            max_value_bytes: cap as u64,
35            max_buffer_bytes: cap as u64,
36            max_line_bytes: cap as u64,
37            max_part_bytes: cap as u64,
38            max_parts: 0,
39        },
40    )
41    .map(|v| v.len())
42    .map_err(|e| {
43        if e.kind() == crate::codec::CodecErrorKind::Limit {
44            limit()
45        } else {
46            invalid("cannot encode declared stream value")
47        }
48    })
49}