objectiveai_sdk/cli/command/functions/inventions/recursive/create/alpha_scalar/
mod.rs1use crate::cli::command::CommandRequest;
4use crate::cli::command::agents::spawn::AgentSpec;
5
6#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
7#[schemars(rename = "cli.command.functions.inventions.recursive.create.alpha_scalar.Request")]
8pub struct Request {
9 pub path_type: Path,
10 pub params: RequestParams,
11 pub agent: AgentSpec,
12 pub continuation: Option<String>,
13 pub seed: Option<i64>,
14 pub dangerous_advanced: Option<RequestDangerousAdvanced>,
15 pub jq: Option<String>,
16}
17
18#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
19#[schemars(rename = "cli.command.functions.inventions.recursive.create.alpha_scalar.Path")]
20pub enum Path {
21 #[serde(rename = "functions/inventions/recursive/create/alpha_scalar")]
22 FunctionsInventionsRecursiveCreateAlphaScalar,
23}
24
25#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
26#[schemars(rename = "cli.command.functions.inventions.recursive.create.alpha_scalar.RequestParams")]
27pub struct RequestParams {
28 pub name: String,
29 pub spec: String,
30 pub depth: u64,
31 pub min_branch_width: u64,
32 pub max_branch_width: u64,
33 pub min_leaf_width: u64,
34 pub max_leaf_width: u64,
35}
36
37impl RequestParams {
38 fn push_flags(&self, out: &mut Vec<String>) {
39 out.push("--name".to_string());
40 out.push(self.name.clone());
41 out.push("--spec".to_string());
42 out.push(self.spec.clone());
43 out.push("--depth".to_string());
44 out.push(self.depth.to_string());
45 out.push("--min-branch-width".to_string());
46 out.push(self.min_branch_width.to_string());
47 out.push("--max-branch-width".to_string());
48 out.push(self.max_branch_width.to_string());
49 out.push("--min-leaf-width".to_string());
50 out.push(self.min_leaf_width.to_string());
51 out.push("--max-leaf-width".to_string());
52 out.push(self.max_leaf_width.to_string());
53 }
54}
55
56impl CommandRequest for Request {
57 fn into_command(&self) -> Vec<String> {
58 let mut argv = vec![
59 "functions".to_string(),
60 "inventions".to_string(),
61 "recursive".to_string(),
62 "create".to_string(),
63 "alpha-scalar".to_string(),
64 ];
65 self.params.push_flags(&mut argv);
66 argv.push("--agent-inline".to_string());
67 argv.push(serde_json::to_string(&self.agent).expect("agent serializes"));
68 if let Some(c) = &self.continuation {
69 argv.push("--continuation".to_string());
70 argv.push(c.clone());
71 }
72 if let Some(seed) = self.seed {
73 argv.push("--seed".to_string());
74 argv.push(seed.to_string());
75 }
76 if let Some(advanced) = &self.dangerous_advanced {
77 argv.push("--dangerous-advanced".to_string());
78 argv.push(
79 serde_json::to_string(advanced)
80 .expect("RequestDangerousAdvanced serializes"),
81 );
82 }
83 if let Some(jq) = &self.jq {
84 argv.push("--jq".to_string());
85 argv.push(jq.clone());
86 }
87 argv
88 }
89}
90
91#[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
92#[schemars(rename = "cli.command.functions.inventions.recursive.create.alpha_scalar.RequestDangerousAdvanced")]
93pub struct RequestDangerousAdvanced {
94 #[serde(default, skip_serializing_if = "Option::is_none")]
95 #[schemars(extend("omitempty" = true))]
96 pub stream: Option<bool>,
97}
98
99#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
100#[serde(untagged)]
101#[schemars(rename = "cli.command.functions.inventions.recursive.create.alpha_scalar.ResponseItem")]
102pub enum ResponseItem {
103 #[schemars(title = "Chunk")]
104 Chunk(crate::functions::inventions::recursive::response::streaming::FunctionInventionRecursiveChunk),
105 #[schemars(title = "Id")]
106 Id(String),
107}
108
109pub type Response = String;
113
114#[derive(clap::Args)]
115pub struct Args {
116 #[arg(long)]
118 pub name: String,
119 #[arg(long)]
121 pub spec: String,
122 #[arg(long)]
124 pub depth: u64,
125 #[arg(long)]
127 pub min_branch_width: u64,
128 #[arg(long)]
130 pub max_branch_width: u64,
131 #[arg(long)]
133 pub min_leaf_width: u64,
134 #[arg(long)]
136 pub max_leaf_width: u64,
137 #[arg(long)]
139 pub agent_inline: String,
140 #[arg(long)]
142 pub continuation: Option<String>,
143 #[arg(long)]
145 pub seed: Option<i64>,
146 #[arg(long)]
148 pub dangerous_advanced: Option<String>,
149 #[arg(long)]
151 pub jq: Option<String>,
152}
153
154#[derive(clap::Args)]
155#[command(args_conflicts_with_subcommands = true)]
156pub struct Command {
157 #[command(flatten)]
158 pub args: Args,
159 #[command(subcommand)]
160 pub schema: Option<Schema>,
161}
162
163#[derive(clap::Subcommand)]
164pub enum Schema {
165 RequestSchema(request_schema::Args),
167 ResponseSchema(response_schema::Args),
169}
170
171impl TryFrom<Args> for Request {
172 type Error = crate::cli::command::FromArgsError;
173 fn try_from(args: Args) -> Result<Self, Self::Error> {
174 let agent = {
175 let mut de = serde_json::Deserializer::from_str(&args.agent_inline);
176 serde_path_to_error::deserialize(&mut de).map_err(|source| {
177 crate::cli::command::FromArgsError {
178 field: "agent_inline",
179 source: source.into(),
180 }
181 })?
182 };
183 let dangerous_advanced = if let Some(s) = args.dangerous_advanced {
184 let mut de = serde_json::Deserializer::from_str(&s);
185 let v = serde_path_to_error::deserialize(&mut de).map_err(|source| {
186 crate::cli::command::FromArgsError {
187 field: "dangerous_advanced",
188 source: source.into(),
189 }
190 })?;
191 Some(v)
192 } else {
193 None
194 };
195 Ok(Self { path_type: Path::FunctionsInventionsRecursiveCreateAlphaScalar,
196 params: RequestParams {
197 name: args.name,
198 spec: args.spec,
199 depth: args.depth,
200 min_branch_width: args.min_branch_width,
201 max_branch_width: args.max_branch_width,
202 min_leaf_width: args.min_leaf_width,
203 max_leaf_width: args.max_leaf_width,
204 },
205 agent,
206 continuation: args.continuation,
207 seed: args.seed,
208 dangerous_advanced,
209 jq: args.jq,
210 })
211 }
212}
213
214#[cfg(feature = "cli-executor")]
215pub async fn execute_streaming<E: crate::cli::command::CommandExecutor>(
216 executor: &E,
217 mut request: Request,
218
219 agent_arguments: Option<&crate::cli::command::AgentArguments>,
220 ) -> Result<E::Stream<ResponseItem>, E::Error> {
221 request.jq = None;
222 let mut advanced = request.dangerous_advanced.unwrap_or_default();
223 advanced.stream = Some(true);
224 request.dangerous_advanced = Some(advanced);
225 executor.execute(request, agent_arguments).await
226}
227
228#[cfg(feature = "cli-executor")]
229pub async fn execute_streaming_jq<E: crate::cli::command::CommandExecutor>(
230 executor: &E,
231 mut request: Request,
232 jq: String,
233
234 agent_arguments: Option<&crate::cli::command::AgentArguments>,
235 ) -> Result<E::Stream<serde_json::Value>, E::Error> {
236 request.jq = Some(jq);
237 let mut advanced = request.dangerous_advanced.unwrap_or_default();
238 advanced.stream = Some(true);
239 request.dangerous_advanced = Some(advanced);
240 executor.execute(request, agent_arguments).await
241}
242
243#[cfg(feature = "cli-executor")]
244pub async fn execute<E: crate::cli::command::CommandExecutor>(
245 executor: &E,
246 mut request: Request,
247
248 agent_arguments: Option<&crate::cli::command::AgentArguments>,
249 ) -> Result<Response, E::Error> {
250 request.jq = None;
251 if let Some(advanced) = request.dangerous_advanced.as_mut() {
252 advanced.stream = None;
253 }
254 executor.execute_one(request, agent_arguments).await
255}
256
257#[cfg(feature = "cli-executor")]
258pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
259 executor: &E,
260 mut request: Request,
261 jq: String,
262
263 agent_arguments: Option<&crate::cli::command::AgentArguments>,
264 ) -> Result<serde_json::Value, E::Error> {
265 request.jq = Some(jq);
266 if let Some(advanced) = request.dangerous_advanced.as_mut() {
267 advanced.stream = None;
268 }
269 executor.execute_one(request, agent_arguments).await
270}
271
272#[cfg(feature = "mcp")]
273impl crate::cli::command::CommandResponse for ResponseItem {
274 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
275 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
276 }
277}
278
279pub mod request_schema;
280
281
282pub mod response_schema;