vtcode_config/constants/
output_limits.rs1pub const MAX_AGENT_MESSAGES_SIZE: usize = 10 * 1024 * 1024;
7
8pub const MAX_ALL_MESSAGES_SIZE: usize = 50 * 1024 * 1024;
10
11pub const MAX_LINE_LENGTH: usize = 1024 * 1024;
14
15pub const DEFAULT_MESSAGE_LIMIT: usize = 10_000;
17
18pub const MAX_MESSAGE_LIMIT: usize = 50_000;
20
21pub const TRUNCATION_MARKER: &str = "\n[... content truncated due to size limit ...]";
23
24#[inline]
36pub fn collect_with_truncation(
37 output: &mut String,
38 new_content: &str,
39 max_size: usize,
40 truncated: &mut bool,
41) -> bool {
42 let new_size = output.len() + new_content.len();
43
44 if new_size > max_size {
45 if !*truncated {
46 output.push_str(TRUNCATION_MARKER);
47 *truncated = true;
48 }
49 return false;
50 }
51
52 output.push_str(new_content);
53 true
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_collect_within_limit() {
62 let mut output = String::new();
63 let mut truncated = false;
64
65 assert!(collect_with_truncation(
66 &mut output,
67 "hello",
68 100,
69 &mut truncated
70 ));
71 assert_eq!(output, "hello");
72 assert!(!truncated);
73 }
74
75 #[test]
76 fn test_collect_at_limit_triggers_truncation() {
77 let mut output = String::from("hello");
78 let mut truncated = false;
79
80 assert!(!collect_with_truncation(
81 &mut output,
82 " world that exceeds",
83 10,
84 &mut truncated
85 ));
86 assert!(output.contains(TRUNCATION_MARKER));
87 assert!(truncated);
88 }
89
90 #[test]
91 fn test_truncation_marker_appended_only_once() {
92 let mut output = String::new();
93 let mut truncated = false;
94
95 collect_with_truncation(&mut output, "first", 8, &mut truncated);
96 let len_after_first = output.len();
97
98 collect_with_truncation(&mut output, "second", 8, &mut truncated);
99 assert_eq!(output.len(), len_after_first);
100 assert!(truncated);
101 }
102}