objectiveai_sdk/cli/command/command_executor.rs
1use futures::Stream;
2
3use crate::cli::command::CommandRequest;
4use crate::cli::command::CommandResponse;
5
6pub mod binary;
7pub mod plugin;
8
9pub use binary::BinaryExecutor;
10
11/// Run a [`CommandRequest`] against some backend (subprocess of the cli
12/// binary, in-process router, mock, …) and surface its output as a
13/// stream of typed items.
14///
15/// `T` is left to the caller: pick a concrete leaf response type
16/// (`agents::spawn::Response`, `functions::execute::standard::ResponseItem`,
17/// …) or a more general `serde_json::Value` for opaque consumption.
18///
19/// Every call accepts an optional [`AgentArguments`] bag controlling
20/// per-call identity. When `Some`, subprocess-spawning executors stamp
21/// each `Some(v)` field on the child env and `env_remove` each `None`
22/// — atomic per-call override. When `None`, the child inherits parent
23/// env unchanged. In-process executors (e.g. the plugin executor)
24/// accept the parameter for trait-signature symmetry and ignore it.
25pub trait CommandExecutor {
26 type Error: Send + 'static;
27 type Stream<T>: Stream<Item = Result<T, Self::Error>> + Send + 'static
28 where
29 T: Send + 'static;
30
31 fn execute<R, T>(
32 &self,
33 request: R,
34 agent_arguments: Option<&super::AgentArguments>,
35 ) -> impl Future<Output = Result<Self::Stream<T>, Self::Error>> + Send
36 where
37 R: CommandRequest + Send,
38 T: CommandResponse + serde::Serialize + serde::de::DeserializeOwned + Send + 'static;
39
40 /// Convenience for unary commands: run the request and resolve the
41 /// first item from the stream. Implementations should error with
42 /// their own "empty stream" variant if the stream closes without
43 /// producing an item.
44 fn execute_one<R, T>(
45 &self,
46 request: R,
47 agent_arguments: Option<&super::AgentArguments>,
48 ) -> impl Future<Output = Result<T, Self::Error>> + Send
49 where
50 R: CommandRequest + Send,
51 T: CommandResponse + serde::Serialize + serde::de::DeserializeOwned + Send + 'static;
52}