objectiveai_sdk/cli/command/tasks/delete/
mod.rs1use crate::cli::command::CommandRequest;
13
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
16#[serde(tag = "namespace", rename_all = "snake_case")]
17#[schemars(rename = "cli.command.tasks.delete.DeleteNamespace")]
18pub enum DeleteNamespace {
19 #[schemars(title = "Caller")]
22 Caller,
23 #[schemars(title = "NoPlugin")]
25 NoPlugin,
26 #[schemars(title = "Plugin")]
28 Plugin {
29 owner: String,
30 name: String,
31 version: String,
32 },
33}
34
35impl Default for DeleteNamespace {
36 fn default() -> Self {
37 Self::Caller
38 }
39}
40
41#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
42#[schemars(rename = "cli.command.tasks.delete.Request")]
43pub struct Request {
44 pub path_type: Path,
45 pub id: String,
47 #[serde(default)]
50 pub namespace: DeleteNamespace,
51 #[serde(flatten)]
52 pub base: crate::cli::command::RequestBase,
53}
54
55#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
56#[schemars(rename = "cli.command.tasks.delete.Path")]
57pub enum Path {
58 #[serde(rename = "tasks/delete")]
59 TasksDelete,
60}
61
62impl CommandRequest for Request {
63 fn request_base(&self) -> &crate::cli::command::RequestBase {
64 &self.base
65 }
66
67 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
68 Some(&mut self.base)
69 }
70}
71
72#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
73#[schemars(rename = "cli.command.tasks.delete.Response")]
74pub struct Response {
75 pub deleted: bool,
77}
78
79#[derive(clap::Args)]
80#[command(group(clap::ArgGroup::new("id_required").required(true).args(["id"])))]
81pub struct Args {
82 #[arg(long)]
84 pub id: Option<String>,
85 #[arg(long, conflicts_with_all = ["plugin_owner", "plugin_name", "plugin_version"])]
88 pub no_plugin: bool,
89 #[arg(long, requires_all = ["plugin_name", "plugin_version"])]
93 pub plugin_owner: Option<String>,
94 #[arg(long, requires_all = ["plugin_owner", "plugin_version"])]
95 pub plugin_name: Option<String>,
96 #[arg(long, requires_all = ["plugin_owner", "plugin_name"])]
97 pub plugin_version: Option<String>,
98 #[command(flatten)]
99 pub base: crate::cli::command::RequestBaseArgs,
100}
101
102#[derive(clap::Args)]
103#[command(args_conflicts_with_subcommands = true)]
104pub struct Command {
105 #[command(flatten)]
106 pub args: Args,
107 #[command(subcommand)]
108 pub schema: Option<Schema>,
109}
110
111#[derive(clap::Subcommand)]
112pub enum Schema {
113 RequestSchema(request_schema::Args),
115 ResponseSchema(response_schema::Args),
117}
118
119impl TryFrom<Args> for Request {
120 type Error = crate::cli::command::FromArgsError;
121 fn try_from(args: Args) -> Result<Self, Self::Error> {
122 let id = args.id.ok_or_else(|| {
123 crate::cli::command::FromArgsError::path_parse("id", "--id is required".to_string())
124 })?;
125 let namespace = match (args.no_plugin, args.plugin_owner, args.plugin_name, args.plugin_version) {
128 (true, _, _, _) => DeleteNamespace::NoPlugin,
129 (false, Some(owner), Some(name), Some(version)) => {
130 DeleteNamespace::Plugin { owner, name, version }
131 }
132 _ => DeleteNamespace::Caller,
133 };
134 Ok(Self {
135 path_type: Path::TasksDelete,
136 id,
137 namespace,
138 base: args.base.into(),
139 })
140 }
141}
142
143#[cfg(feature = "mcp")]
144impl crate::cli::command::CommandResponse for Response {
145 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
146 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
147 }
148}
149
150#[cfg(feature = "cli-executor")]
151pub async fn execute<E: crate::cli::command::CommandExecutor>(
152 executor: &E,
153 mut request: Request,
154 identity: Option<&crate::identity::Identity>,
155) -> Result<Response, E::Error> {
156 request.base.clear_transform();
157 executor.execute_one(request, identity).await
158}
159
160#[cfg(feature = "cli-executor")]
161pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
162 executor: &E,
163 mut request: Request,
164 transform: crate::cli::command::Transform,
165 identity: Option<&crate::identity::Identity>,
166) -> Result<serde_json::Value, E::Error> {
167 request.base.set_transform(transform);
168 executor.execute_one(request, identity).await
169}
170
171pub mod request_schema;
172
173pub mod response_schema;
174
175#[cfg(all(feature = "cli", feature = "daemon"))]
180pub struct ListenerExecution {
181 pub request: Request,
182 pub identity: crate::identity::Identity,
183 pub response: crate::daemon::command_listener::UnaryResponse<Response>,
184}