objectiveai_sdk/cli/command/viewer/send/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.viewer.send.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub path: String,
10 pub body: serde_json::Value,
11 pub jq: Option<String>,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.viewer.send.Path")]
16pub enum Path {
17 #[serde(rename = "viewer/send")]
18 ViewerSend,
19}
20
21impl CommandRequest for Request {
22 fn into_command(&self) -> Vec<String> {
23 let mut argv = vec![
24 "viewer".to_string(),
25 "send".to_string(),
26 self.path.clone(),
27 serde_json::to_string(&self.body).expect("body serializes"),
28 ];
29 if let Some(jq) = &self.jq {
30 argv.push("--jq".to_string());
31 argv.push(jq.clone());
32 }
33 argv
34 }
35}
36
37#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
38#[schemars(rename = "cli.command.viewer.send.Response")]
39pub struct Response {
40 pub status: u16,
41 pub body: serde_json::Value,
42}
43
44fn parse_json_value(s: &str) -> Result<serde_json::Value, serde_json::Error> {
45 serde_json::from_str(s)
46}
47
48#[derive(clap::Args)]
49pub struct Args {
50 pub path: String,
52 #[arg(value_parser = parse_json_value)]
54 pub body: serde_json::Value,
55 #[arg(long)]
57 pub jq: Option<String>,
58}
59
60#[derive(clap::Args)]
61#[command(args_conflicts_with_subcommands = true)]
62pub struct Command {
63 #[command(flatten)]
64 pub args: Args,
65 #[command(subcommand)]
66 pub schema: Option<Schema>,
67}
68
69#[derive(clap::Subcommand)]
70pub enum Schema {
71 RequestSchema(request_schema::Args),
73 ResponseSchema(response_schema::Args),
75}
76
77impl TryFrom<Args> for Request {
78 type Error = crate::cli::command::FromArgsError;
79 fn try_from(args: Args) -> Result<Self, Self::Error> {
80 Ok(Self {
81 path_type: Path::ViewerSend,
82 path: args.path,
83 body: args.body,
84 jq: args.jq,
85 })
86 }
87}
88
89#[cfg(feature = "cli-executor")]
90pub async fn execute<E: crate::cli::command::CommandExecutor>(
91 executor: &E,
92 mut request: Request,
93
94 agent_arguments: Option<&crate::cli::command::AgentArguments>,
95 ) -> Result<Response, E::Error> {
96 request.jq = None;
97 executor.execute_one(request, agent_arguments).await
98}
99
100#[cfg(feature = "cli-executor")]
101pub async fn execute_jq<E: crate::cli::command::CommandExecutor>(
102 executor: &E,
103 mut request: Request,
104 jq: String,
105
106 agent_arguments: Option<&crate::cli::command::AgentArguments>,
107 ) -> Result<serde_json::Value, E::Error> {
108 request.jq = Some(jq);
109 executor.execute_one(request, agent_arguments).await
110}
111
112#[cfg(feature = "mcp")]
113impl crate::cli::command::CommandResponse for Response {
114 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
115 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
116 }
117}
118
119pub mod request_schema;
120
121
122pub mod response_schema;