1use super::{
4 Backend, ModelId,
5 location::Location,
6 validation::{self, positive_integer, present, script, text, timeout},
7};
8use serde::{Deserialize, Serialize};
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12#[serde(rename_all = "lowercase")]
13pub enum Reasoning {
14 None,
15 Minimal,
16 Low,
17 Medium,
18 High,
19 Xhigh,
20 Max,
21}
22impl Reasoning {
23 pub fn as_str(self) -> &'static str {
24 match self {
25 Self::None => "none",
26 Self::Minimal => "minimal",
27 Self::Low => "low",
28 Self::Medium => "medium",
29 Self::High => "high",
30 Self::Xhigh => "xhigh",
31 Self::Max => "max",
32 }
33 }
34}
35impl std::fmt::Display for Reasoning {
36 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 formatter.write_str(self.as_str())
38 }
39}
40
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(tag = "kind", rename_all = "lowercase", deny_unknown_fields)]
43pub enum Profile {
44 Agent {
45 backend: Backend,
46 model: ModelId,
47 #[serde(default, deserialize_with = "present")]
48 reasoning: Option<Reasoning>,
49 #[serde(
50 rename(serialize = "timeoutMs", deserialize = "timeout_ms"),
51 default,
52 deserialize_with = "timeout",
53 serialize_with = "validation::milliseconds::serialize"
54 )]
55 timeout_ms: Option<std::time::Duration>,
56 #[serde(
57 rename(serialize = "maxToolCalls", deserialize = "max_tool_calls"),
58 default,
59 deserialize_with = "positive_integer"
60 )]
61 max_tool_calls: Option<u64>,
62 #[serde(
63 rename(serialize = "maxTokens", deserialize = "max_tokens"),
64 default,
65 deserialize_with = "positive_integer"
66 )]
67 max_tokens: Option<u64>,
68 },
69 Human {},
70 Runtime {
71 #[serde(serialize_with = "crate::platform::serialize_program")]
72 command: String,
73 args: Vec<crate::scope::Argument>,
74 #[serde(
75 rename(serialize = "timeoutMs", deserialize = "timeout_ms"),
76 default,
77 deserialize_with = "timeout",
78 serialize_with = "validation::milliseconds::serialize"
79 )]
80 timeout_ms: Option<std::time::Duration>,
81 },
82}
83
84impl Profile {
85 pub(super) fn validate(&self, location: &Location<'_, '_>) -> Result<(), String> {
86 match self {
87 Self::Agent {
88 backend,
89 model,
90 reasoning,
91 ..
92 } => {
93 location
94 .child("model")
95 .check(text(model, "Agent profile model"))?;
96 if let (Some(reasoning), Some(provider)) = (reasoning, backend.builtin()) {
99 location.child("reasoning").check(
100 crate::llm::Api::from(provider).validate_reasoning(reasoning.as_str()),
101 )?;
102 }
103 Ok(())
104 }
105 Self::Human {} => Ok(()),
106 Self::Runtime { command, args, .. } => location.check(script(command, args)),
107 }
108 }
109
110 pub fn kind(&self) -> ProfileKind {
111 match self {
112 Self::Agent { .. } => ProfileKind::Agent,
113 Self::Human {} => ProfileKind::Human,
114 Self::Runtime { .. } => ProfileKind::Runtime,
115 }
116 }
117}
118
119#[derive(
121 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize, clap::ValueEnum,
122)]
123#[serde(rename_all = "lowercase")]
124pub enum ProfileKind {
125 Runtime,
127 Agent,
129 Human,
131}
132
133impl ProfileKind {
134 pub fn name(self) -> &'static str {
135 match self {
136 Self::Runtime => "runtime",
137 Self::Agent => "agent",
138 Self::Human => "human",
139 }
140 }
141}