Skip to main content

objectiveai_sdk/cli/command/viewer/send/
mod.rs

1//! `viewer send` — async handler stub.
2
3use 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 into_command(&self) -> Vec<String> {
24        let mut argv = vec![
25            "viewer".to_string(),
26            "send".to_string(),
27            self.path.clone(),
28            serde_json::to_string(&self.body).expect("body serializes"),
29        ];
30        self.base.push_flags(&mut argv);
31        argv
32    }
33
34    fn request_base(&self) -> &crate::cli::command::RequestBase {
35        &self.base
36    }
37
38    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
39        Some(&mut self.base)
40    }
41}
42
43#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
44#[schemars(rename = "cli.command.viewer.send.Response")]
45pub struct Response {
46    pub status: u16,
47    pub body: serde_json::Value,
48}
49
50fn parse_json_value(s: &str) -> Result<serde_json::Value, serde_json::Error> {
51    serde_json::from_str(s)
52}
53
54#[derive(clap::Args)]
55pub struct Args {
56    /// HTTP path on the viewer to POST to.
57    pub path: String,
58    /// Request body as JSON.
59    #[arg(value_parser = parse_json_value)]
60    pub body: serde_json::Value,
61    #[command(flatten)]
62    pub base: crate::cli::command::RequestBaseArgs,
63}
64
65#[derive(clap::Args)]
66#[command(args_conflicts_with_subcommands = true)]
67pub struct Command {
68    #[command(flatten)]
69    pub args: Args,
70    #[command(subcommand)]
71    pub schema: Option<Schema>,
72}
73
74#[derive(clap::Subcommand)]
75pub enum Schema {
76    /// Emit the JSON Schema for this leaf's `Request` type and exit.
77    RequestSchema(request_schema::Args),
78    /// Emit the JSON Schema for this leaf's `Response` type and exit.
79    ResponseSchema(response_schema::Args),
80}
81
82impl TryFrom<Args> for Request {
83    type Error = crate::cli::command::FromArgsError;
84    fn try_from(args: Args) -> Result<Self, Self::Error> {
85        Ok(Self {
86            path_type: Path::ViewerSend,
87            path: args.path,
88            body: args.body,
89            base: args.base.into(),
90        })
91    }
92}
93
94#[cfg(feature = "cli-executor")]
95pub async fn execute<E: crate::cli::command::CommandExecutor>(
96    executor: &E,
97    mut request: Request,
98
99        agent_arguments: Option<&crate::cli::command::AgentArguments>,
100    ) -> Result<Response, E::Error> {
101    request.base.clear_transform();
102    executor.execute_one(request, agent_arguments).await
103}
104
105#[cfg(feature = "cli-executor")]
106pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
107    executor: &E,
108    mut request: Request,
109    transform: crate::cli::command::Transform,
110
111        agent_arguments: Option<&crate::cli::command::AgentArguments>,
112    ) -> Result<serde_json::Value, E::Error> {
113    request.base.set_transform(transform);
114    executor.execute_one(request, agent_arguments).await
115}
116
117#[cfg(feature = "mcp")]
118impl crate::cli::command::CommandResponse for Response {
119    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
120        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
121    }
122}
123
124pub mod request_schema;
125
126
127pub mod response_schema;