objectiveai_sdk/cli/command/api/kill/
mod.rs1use 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 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 into_command(&self) -> Vec<String> {
23 let mut argv = vec!["api".to_string(), "kill".to_string()];
24 argv.push("--global".to_string());
25 self.base.push_flags(&mut argv);
26 argv
27 }
28
29 fn request_base(&self) -> &crate::cli::command::RequestBase {
30 &self.base
31 }
32
33 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
34 Some(&mut self.base)
35 }
36}
37
38#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
39#[schemars(rename = "cli.command.api.kill.Response")]
40pub struct Response {
41 pub killed: usize,
42}
43
44#[derive(clap::Args)]
45pub struct Args {
46 #[arg(long)]
48 pub global: bool,
49 #[command(flatten)]
50 pub base: crate::cli::command::RequestBaseArgs,
51}
52
53#[derive(clap::Args)]
54#[command(args_conflicts_with_subcommands = true)]
55pub struct Command {
56 #[command(flatten)]
57 pub args: Args,
58 #[command(subcommand)]
59 pub schema: Option<Schema>,
60}
61
62#[derive(clap::Subcommand)]
63pub enum Schema {
64 RequestSchema(request_schema::Args),
66 ResponseSchema(response_schema::Args),
68}
69
70impl TryFrom<Args> for Request {
71 type Error = crate::cli::command::FromArgsError;
72 fn try_from(args: Args) -> Result<Self, Self::Error> {
73 if !args.global {
74 return Err(crate::cli::command::FromArgsError {
75 field: "scope",
76 source: crate::cli::command::FromArgsErrorSource::Plain(
77 "api kill requires --global".to_string(),
78 ),
79 });
80 }
81 Ok(Self {
82 path_type: Path::ApiKill,
83 scope: crate::cli::command::SetScope::Global,
84 base: args.base.into(),
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.base.clear_transform();
97 executor.execute_one(request, agent_arguments).await
98}
99
100#[cfg(feature = "cli-executor")]
101pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
102 executor: &E,
103 mut request: Request,
104 transform: crate::cli::command::Transform,
105
106 agent_arguments: Option<&crate::cli::command::AgentArguments>,
107 ) -> Result<serde_json::Value, E::Error> {
108 request.base.set_transform(transform);
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
121pub mod response_schema;