vtcode_commons/
reasoning.rs1use serde::{Deserialize, Deserializer, Serialize};
9use std::fmt;
10
11pub mod constants {
13 pub const NONE: &str = "none";
14 pub const MINIMAL: &str = "minimal";
15 pub const LOW: &str = "low";
16 pub const MEDIUM: &str = "medium";
17 pub const HIGH: &str = "high";
18 pub const XHIGH: &str = "xhigh";
19 pub const MAX: &str = "max";
20 pub const ALLOWED_LEVELS: &[&str] = &[MINIMAL, LOW, MEDIUM, HIGH, XHIGH, MAX];
21 pub const LABEL_LOW: &str = "Low";
22 pub const LABEL_MEDIUM: &str = "Medium";
23 pub const LABEL_HIGH: &str = "High";
24 pub const DESCRIPTION_LOW: &str = "Fast responses with lightweight reasoning.";
25 pub const DESCRIPTION_MEDIUM: &str = "Balanced depth and speed for general tasks. (Note: May not be fully available for all models including Gemini 3 Pro)";
26 pub const DESCRIPTION_HIGH: &str = "Maximum reasoning depth for complex problems.";
27}
28
29#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
35#[serde(rename_all = "lowercase")]
36#[derive(Default)]
37pub enum ReasoningEffortLevel {
38 None,
40 Minimal,
42 Low,
44 #[default]
46 Medium,
47 High,
49 XHigh,
51 Max,
53}
54
55impl ReasoningEffortLevel {
56 pub fn as_str(self) -> &'static str {
58 match self {
59 Self::None => constants::NONE,
60 Self::Minimal => constants::MINIMAL,
61 Self::Low => constants::LOW,
62 Self::Medium => constants::MEDIUM,
63 Self::High => constants::HIGH,
64 Self::XHigh => constants::XHIGH,
65 Self::Max => constants::MAX,
66 }
67 }
68
69 pub fn parse(value: &str) -> Option<Self> {
71 let normalized = value.trim();
72 if normalized.eq_ignore_ascii_case(constants::NONE) {
73 Some(Self::None)
74 } else if normalized.eq_ignore_ascii_case(constants::MINIMAL) {
75 Some(Self::Minimal)
76 } else if normalized.eq_ignore_ascii_case(constants::LOW) {
77 Some(Self::Low)
78 } else if normalized.eq_ignore_ascii_case(constants::MEDIUM) {
79 Some(Self::Medium)
80 } else if normalized.eq_ignore_ascii_case(constants::HIGH) {
81 Some(Self::High)
82 } else if normalized.eq_ignore_ascii_case(constants::XHIGH) {
83 Some(Self::XHigh)
84 } else if normalized.eq_ignore_ascii_case(constants::MAX) {
85 Some(Self::Max)
86 } else {
87 None
88 }
89 }
90
91 pub fn allowed_values() -> &'static [&'static str] {
93 constants::ALLOWED_LEVELS
94 }
95}
96
97impl fmt::Display for ReasoningEffortLevel {
98 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
99 f.write_str(self.as_str())
100 }
101}
102
103impl<'de> Deserialize<'de> for ReasoningEffortLevel {
104 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
105 where
106 D: Deserializer<'de>,
107 {
108 let raw = String::deserialize(deserializer)?;
109 if let Some(parsed) = Self::parse(&raw) {
110 Ok(parsed)
111 } else {
112 Ok(Self::default())
113 }
114 }
115}
116
117#[cfg(test)]
118mod tests {
119 use super::*;
120
121 #[test]
122 fn test_reasoning_effort_parse_and_allowed_values_include_max() {
123 assert_eq!(
124 ReasoningEffortLevel::parse("max"),
125 Some(ReasoningEffortLevel::Max)
126 );
127 assert_eq!(ReasoningEffortLevel::Max.as_str(), "max");
128 assert!(ReasoningEffortLevel::allowed_values().contains(&"max"));
129 }
130}