Skip to main content

objectiveai_sdk/cli/command/api/kill/
mod.rs

1//! `api kill` — 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.api.kill.Request")]
7pub struct Request {
8    pub path_type: Path,
9    /// Always Global — api has a single machine-wide lock.
10    pub scope: crate::cli::command::SetScope,
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.api.kill.Path")]
17pub enum Path {
18    #[serde(rename = "api/kill")]
19    ApiKill,
20}
21impl CommandRequest for Request {
22    fn request_base(&self) -> &crate::cli::command::RequestBase {
23        &self.base
24    }
25
26    fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
27        Some(&mut self.base)
28    }
29}
30
31#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
32#[schemars(rename = "cli.command.api.kill.Response")]
33pub struct Response {
34    pub killed: usize,
35}
36
37#[derive(clap::Args)]
38pub struct Args {
39    /// Kill api servers across all states (required — api is machine-wide).
40    #[arg(long)]
41    pub global: bool,
42    #[command(flatten)]
43    pub base: crate::cli::command::RequestBaseArgs,
44}
45
46#[derive(clap::Args)]
47#[command(args_conflicts_with_subcommands = true)]
48pub struct Command {
49    #[command(flatten)]
50    pub args: Args,
51    #[command(subcommand)]
52    pub schema: Option<Schema>,
53}
54
55#[derive(clap::Subcommand)]
56pub enum Schema {
57    /// Emit the JSON Schema for this leaf's `Request` type and exit.
58    RequestSchema(request_schema::Args),
59    /// Emit the JSON Schema for this leaf's `Response` type and exit.
60    ResponseSchema(response_schema::Args),
61}
62
63impl TryFrom<Args> for Request {
64    type Error = crate::cli::command::FromArgsError;
65    fn try_from(args: Args) -> Result<Self, Self::Error> {
66        if !args.global {
67            return Err(crate::cli::command::FromArgsError {
68                field: "scope",
69                source: crate::cli::command::FromArgsErrorSource::Plain(
70                    "api kill requires --global".to_string(),
71                ),
72            });
73        }
74        Ok(Self {
75            path_type: Path::ApiKill,
76            scope: crate::cli::command::SetScope::Global,
77            base: args.base.into(),
78        })
79    }
80}
81
82#[cfg(feature = "cli-executor")]
83pub async fn execute<E: crate::cli::command::CommandExecutor>(
84    executor: &E,
85    mut request: Request,
86
87        agent_arguments: Option<&crate::cli::command::AgentArguments>,
88    ) -> Result<Response, E::Error> {
89    request.base.clear_transform();
90    executor.execute_one(request, agent_arguments).await
91}
92
93#[cfg(feature = "cli-executor")]
94pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
95    executor: &E,
96    mut request: Request,
97    transform: crate::cli::command::Transform,
98
99        agent_arguments: Option<&crate::cli::command::AgentArguments>,
100    ) -> Result<serde_json::Value, E::Error> {
101    request.base.set_transform(transform);
102    executor.execute_one(request, agent_arguments).await
103}
104
105#[cfg(feature = "mcp")]
106impl crate::cli::command::CommandResponse for Response {
107    fn into_mcp(self) -> crate::cli::command::McpResponseItem {
108        crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
109    }
110}
111
112pub mod request_schema;
113
114pub mod response_schema;