gproxy_protocol/transform/generate/stream/chat/
mod.rs1mod choice;
4mod collector;
5pub(crate) mod logs;
6mod synthesize;
7pub(crate) mod usage;
8pub use collector::{ChatStreamCollector, ChatStreamContext, ChatStreamLimits};
9pub use synthesize::synthesize_chat_stream;
10
11fn limit(field: &str) -> crate::transform::TransformError {
12 crate::transform::TransformError::new(
13 crate::transform::TransformErrorKind::Limit,
14 format!("stream.{field}"),
15 "Chat stream limit exceeded",
16 )
17}
18
19fn encoded<T: serde::Serialize>(
20 value: &T,
21 remaining: usize,
22) -> Result<usize, crate::transform::TransformError> {
23 let n = remaining as u64;
24 crate::codec::encode_json(
25 value,
26 crate::codec::CodecLimits {
27 max_value_bytes: n,
28 max_body_bytes: n,
29 max_buffer_bytes: n,
30 max_line_bytes: n,
31 max_part_bytes: n,
32 max_parts: usize::MAX,
33 },
34 )
35 .map(|v| v.len())
36 .map_err(|e| {
37 if e.kind() == crate::codec::CodecErrorKind::Limit {
38 limit("bytes")
39 } else {
40 crate::transform::TransformError::shape("stream", e.to_string())
41 }
42 })
43}