objectiveai_sdk/cli/command/viewer/kill/
mod.rs1use crate::cli::command::CommandRequest;
4
5#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
6#[schemars(rename = "cli.command.viewer.kill.Request")]
7pub struct Request {
8 pub path_type: Path,
9 pub scope: crate::cli::command::SetScope,
10 #[serde(flatten)]
11 pub base: crate::cli::command::RequestBase,
12}
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
15#[schemars(rename = "cli.command.viewer.kill.Path")]
16pub enum Path {
17 #[serde(rename = "viewer/kill")]
18 ViewerKill,
19}
20impl CommandRequest for Request {
21 fn request_base(&self) -> &crate::cli::command::RequestBase {
22 &self.base
23 }
24
25 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
26 Some(&mut self.base)
27 }
28}
29
30#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
31#[schemars(rename = "cli.command.viewer.kill.Response")]
32pub struct Response {
33 pub killed: usize,
34}
35
36#[derive(clap::Args)]
37pub struct Args {
38 #[arg(long)]
40 pub global: bool,
41 #[arg(long)]
43 pub state: bool,
44 #[command(flatten)]
45 pub base: crate::cli::command::RequestBaseArgs,
46}
47
48#[derive(clap::Args)]
49#[command(args_conflicts_with_subcommands = true)]
50pub struct Command {
51 #[command(flatten)]
52 pub args: Args,
53 #[command(subcommand)]
54 pub schema: Option<Schema>,
55}
56
57#[derive(clap::Subcommand)]
58pub enum Schema {
59 RequestSchema(request_schema::Args),
61 ResponseSchema(response_schema::Args),
63}
64
65impl TryFrom<Args> for Request {
66 type Error = crate::cli::command::FromArgsError;
67 fn try_from(args: Args) -> Result<Self, Self::Error> {
68 let scope = match (args.global, args.state) {
69 (true, false) => crate::cli::command::SetScope::Global,
70 (false, true) => crate::cli::command::SetScope::State,
71 _ => {
72 return Err(crate::cli::command::FromArgsError {
73 field: "scope",
74 source: crate::cli::command::FromArgsErrorSource::Plain(
75 "exactly one of --global, --state is required".to_string(),
76 ),
77 });
78 }
79 };
80 Ok(Self { path_type: Path::ViewerKill, scope, base: args.base.into() })
81 }
82}
83
84#[cfg(feature = "cli-executor")]
85pub async fn execute<E: crate::cli::command::CommandExecutor>(
86 executor: &E,
87 mut request: Request,
88
89 agent_arguments: Option<&crate::cli::command::AgentArguments>,
90 ) -> Result<Response, E::Error> {
91 request.base.clear_transform();
92 executor.execute_one(request, agent_arguments).await
93}
94
95#[cfg(feature = "cli-executor")]
96pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
97 executor: &E,
98 mut request: Request,
99 transform: crate::cli::command::Transform,
100
101 agent_arguments: Option<&crate::cli::command::AgentArguments>,
102 ) -> Result<serde_json::Value, E::Error> {
103 request.base.set_transform(transform);
104 executor.execute_one(request, agent_arguments).await
105}
106
107#[cfg(feature = "mcp")]
108impl crate::cli::command::CommandResponse for Response {
109 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
110 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
111 }
112}
113
114pub mod request_schema;
115
116pub mod response_schema;