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 #[serde(flatten)]
12 pub base: crate::cli::command::RequestBase,
13}
14
15#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
16#[schemars(rename = "cli.command.viewer.send.Path")]
17pub enum Path {
18 #[serde(rename = "viewer/send")]
19 ViewerSend,
20}
21
22impl CommandRequest for Request {
23 fn request_base(&self) -> &crate::cli::command::RequestBase {
24 &self.base
25 }
26
27 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
28 Some(&mut self.base)
29 }
30}
31
32#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
33#[schemars(rename = "cli.command.viewer.send.Response")]
34pub struct Response {
35 pub status: u16,
36 pub body: serde_json::Value,
37}
38
39fn parse_json_value(s: &str) -> Result<serde_json::Value, serde_json::Error> {
40 serde_json::from_str(s)
41}
42
43#[derive(clap::Args)]
44#[command(group(clap::ArgGroup::new("path_required").required(true).args(["path"])))]
45#[command(group(clap::ArgGroup::new("body_required").required(true).args(["body"])))]
46pub struct Args {
47 #[arg(long)]
49 pub path: Option<String>,
50 #[arg(long, value_parser = parse_json_value)]
52 pub body: Option<serde_json::Value>,
53 #[command(flatten)]
54 pub base: crate::cli::command::RequestBaseArgs,
55}
56
57#[derive(clap::Args)]
58#[command(args_conflicts_with_subcommands = true)]
59pub struct Command {
60 #[command(flatten)]
61 pub args: Args,
62 #[command(subcommand)]
63 pub schema: Option<Schema>,
64}
65
66#[derive(clap::Subcommand)]
67pub enum Schema {
68 RequestSchema(request_schema::Args),
70 ResponseSchema(response_schema::Args),
72}
73
74impl TryFrom<Args> for Request {
75 type Error = crate::cli::command::FromArgsError;
76 fn try_from(args: Args) -> Result<Self, Self::Error> {
77 Ok(Self {
78 path_type: Path::ViewerSend,
79 path: args.path.ok_or_else(|| {
80 crate::cli::command::FromArgsError::path_parse(
81 "path",
82 "--path is required".to_string(),
83 )
84 })?,
85 body: args.body.ok_or_else(|| {
86 crate::cli::command::FromArgsError::path_parse(
87 "body",
88 "--body is required".to_string(),
89 )
90 })?,
91 base: args.base.into(),
92 })
93 }
94}
95
96#[cfg(feature = "cli-executor")]
97pub async fn execute<E: crate::cli::command::CommandExecutor>(
98 executor: &E,
99 mut request: Request,
100
101 agent_arguments: Option<&crate::cli::command::AgentArguments>,
102 ) -> Result<Response, E::Error> {
103 request.base.clear_transform();
104 executor.execute_one(request, agent_arguments).await
105}
106
107#[cfg(feature = "cli-executor")]
108pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
109 executor: &E,
110 mut request: Request,
111 transform: crate::cli::command::Transform,
112
113 agent_arguments: Option<&crate::cli::command::AgentArguments>,
114 ) -> Result<serde_json::Value, E::Error> {
115 request.base.set_transform(transform);
116 executor.execute_one(request, agent_arguments).await
117}
118
119#[cfg(feature = "mcp")]
120impl crate::cli::command::CommandResponse for Response {
121 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
122 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
123 }
124}
125
126pub mod request_schema;
127
128
129pub mod response_schema;