objectiveai_sdk/cli/command/agents/logs/token_usage/get/
mod.rs1use crate::cli::command::CommandRequest;
6
7#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
8#[schemars(rename = "cli.command.agents.logs.token_usage.get.Request")]
9pub struct Request {
10 pub path_type: Path,
11 pub agent_instance_hierarchy: String,
13 #[serde(flatten)]
14 pub base: crate::cli::command::RequestBase,
15}
16
17#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
18#[schemars(rename = "cli.command.agents.logs.token_usage.get.Path")]
19pub enum Path {
20 #[serde(rename = "agents/logs/token-usage/get")]
21 AgentsLogsTokenUsageGet,
22}
23
24impl CommandRequest for Request {
25 fn request_base(&self) -> &crate::cli::command::RequestBase {
26 &self.base
27 }
28
29 fn request_base_mut(&mut self) -> Option<&mut crate::cli::command::RequestBase> {
30 Some(&mut self.base)
31 }
32}
33
34#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
37#[schemars(rename = "cli.command.agents.logs.token_usage.get.Response")]
38pub struct Response {
39 pub agent_instance_hierarchy: String,
40 #[serde(default, skip_serializing_if = "Option::is_none")]
41 #[schemars(extend("omitempty" = true))]
42 pub total_tokens: Option<i64>,
43}
44
45#[derive(clap::Args)]
46#[command(group(clap::ArgGroup::new("aih_required").required(true).args(["agent_instance_hierarchy"])))]
47pub struct Args {
48 #[arg(long = "agent-instance-hierarchy")]
50 pub agent_instance_hierarchy: Option<String>,
51 #[command(flatten)]
52 pub base: crate::cli::command::RequestBaseArgs,
53}
54
55#[derive(clap::Args)]
56#[command(args_conflicts_with_subcommands = true)]
57pub struct Command {
58 #[command(flatten)]
59 pub args: Args,
60 #[command(subcommand)]
61 pub schema: Option<Schema>,
62}
63
64#[derive(clap::Subcommand)]
65pub enum Schema {
66 RequestSchema(request_schema::Args),
68 ResponseSchema(response_schema::Args),
70}
71
72impl TryFrom<Args> for Request {
73 type Error = crate::cli::command::FromArgsError;
74 fn try_from(args: Args) -> Result<Self, Self::Error> {
75 Ok(Self {
76 path_type: Path::AgentsLogsTokenUsageGet,
77 agent_instance_hierarchy: args.agent_instance_hierarchy.ok_or_else(|| {
78 crate::cli::command::FromArgsError::path_parse(
79 "agent-instance-hierarchy",
80 "--agent-instance-hierarchy is required".to_string(),
81 )
82 })?,
83 base: args.base.into(),
84 })
85 }
86}
87
88#[cfg(feature = "mcp")]
89impl crate::cli::command::CommandResponse for Response {
90 fn into_mcp(self) -> crate::cli::command::McpResponseItem {
91 crate::cli::command::McpResponseItem::JSONL(serde_json::to_value(self).unwrap())
92 }
93}
94
95#[cfg(feature = "cli-executor")]
96pub async fn execute<E: crate::cli::command::CommandExecutor>(
97 executor: &E,
98 mut request: Request,
99 agent_arguments: Option<&crate::cli::command::AgentArguments>,
100) -> Result<Response, E::Error> {
101 request.base.clear_transform();
102 executor.execute_one(request, agent_arguments).await
103}
104
105#[cfg(feature = "cli-executor")]
106pub async fn execute_transform<E: crate::cli::command::CommandExecutor>(
107 executor: &E,
108 mut request: Request,
109 transform: crate::cli::command::Transform,
110 agent_arguments: Option<&crate::cli::command::AgentArguments>,
111) -> Result<serde_json::Value, E::Error> {
112 request.base.set_transform(transform);
113 executor.execute_one(request, agent_arguments).await
114}
115
116pub mod request_schema;
117
118pub mod response_schema;
119
120#[cfg(feature = "cli-listener")]
125pub struct ListenerExecution {
126 pub request: Request,
127 pub agent_arguments: crate::cli::command::AgentArguments,
128 pub response: crate::cli::websocket_listener::UnaryResponse<Response>,
129}