Skip to main content

objectiveai_sdk/cli/command/update/
mod.rs

1//! `update` — 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.update.Request")]
7pub struct Request {
8    pub path_type: Path,
9    #[serde(flatten)]
10    pub base: crate::cli::command::RequestBase,
11}
12
13#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
14#[schemars(rename = "cli.command.update.Path")]
15pub enum Path {
16    #[serde(rename = "update")]
17    Update,
18}
19impl CommandRequest for Request {
20    fn request_base(&self) -> &crate::cli::command::RequestBase {
21        &self.base
22    }
23
24    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
25        Some(&mut self.base)
26    }
27}
28
29/// Per-stage update event. Update is a streaming leaf — one
30/// `ResponseItem` per (asset, stage) pair as the update progresses
31/// through the four shipped binaries (cli, api, viewer, mcp).
32#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
33#[serde(tag = "type", rename_all = "snake_case")]
34#[schemars(rename = "cli.command.update.ResponseItem")]
35pub enum ResponseItem {
36    #[schemars(title = "Checking")]
37    Checking {
38        asset_name: String,
39        current_version: String,
40    },
41    #[schemars(title = "Found")]
42    Found {
43        current_version: String,
44        remote_version: String,
45        asset_name: String,
46        url: String,
47    },
48    #[schemars(title = "Installed")]
49    Installed {
50        current_version: String,
51        remote_version: String,
52    },
53    #[schemars(title = "Skipped")]
54    Skipped {
55        reason: ResponseSkipReason,
56    },
57    #[schemars(title = "UpToDate")]
58    UpToDate {
59        current_version: String,
60        remote_version: String,
61    },
62}
63
64/// All-at-once view of an update run. Used only for schema generation
65/// (`response-schema`); the leaf's `execute` returns
66/// `Stream<ResponseItem>` rather than building a `Response`.
67#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
68#[schemars(rename = "cli.command.update.Response")]
69pub struct Response {
70    pub items: Vec<ResponseItem>,
71}
72
73#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
74#[serde(rename_all = "snake_case")]
75#[schemars(rename = "cli.command.update.ResponseSkipReason")]
76pub enum ResponseSkipReason {
77    DevTree,
78    UnsupportedPlatform,
79    IncompleteRelease,
80}
81
82#[derive(clap::Args)]
83pub struct Args {
84    #[command(flatten)]
85    pub base: crate::cli::command::RequestBaseArgs,
86}
87
88#[derive(clap::Args)]
89#[command(args_conflicts_with_subcommands = true)]
90pub struct Command {
91    #[command(flatten)]
92    pub args: Args,
93    #[command(subcommand)]
94    pub schema: Option<Schema>,
95}
96
97#[derive(clap::Subcommand)]
98pub enum Schema {
99    /// Emit the JSON Schema for this leaf's `Request` type and exit.
100    RequestSchema(request_schema::Args),
101    /// Emit the JSON Schema for this leaf's `Response` type and exit.
102    ResponseSchema(response_schema::Args),
103}
104
105impl TryFrom<Args> for Request {
106    type Error = crate::cli::command::FromArgsError;
107    fn try_from(args: Args) -> Result<Self, Self::Error> {
108        Ok(Self { path_type: Path::Update, base: args.base.into() })
109    }
110}
111
112#[cfg(feature = "cli-executor")]
113pub async fn execute<E: crate::cli::command::CommandExecutor>(
114    executor: &E,
115    mut request: Request,
116
117        agent_arguments: Option<&crate::cli::command::AgentArguments>,
118    ) -> Result<E::Stream<ResponseItem>, E::Error> {
119    request.base.clear_transform();
120    executor.execute(request, agent_arguments).await
121}
122
123#[cfg(feature = "cli-executor")]
124pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
125    executor: &E,
126    mut request: Request,
127    transform: crate::cli::command::Transform,
128
129        agent_arguments: Option<&crate::cli::command::AgentArguments>,
130    ) -> Result<E::Stream<serde_json::Value>, E::Error> {
131    request.base.set_transform(transform);
132    executor.execute(request, agent_arguments).await
133}
134
135#[cfg(feature = "mcp")]
136impl crate::cli::command::CommandResponse for ResponseItem {
137    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
138        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
139    }
140}
141
142#[cfg(feature = "mcp")]
143impl crate::cli::command::CommandResponse for Response {
144    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
145        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
146    }
147}
148
149pub mod request_schema;
150
151pub mod response_schema;