use std::pin::Pin;
use std::sync::Arc;
use serde_json::Value;
use super::message::{AssistantMessage, LoopMessage, ToolResultMessage};
use super::result::{AfterToolCallResult, BeforeToolCallResult, LoopToolResult};
use super::types::{Context, TurnUpdate};
#[derive(Debug, Clone)]
pub struct BeforeToolCallContext {
#[allow(dead_code)]
pub assistant_message: AssistantMessage,
#[allow(dead_code)]
pub tool_call_id: String,
#[cfg_attr(not(feature = "plugin"), allow(dead_code))]
pub tool_call_name: String,
#[cfg_attr(not(feature = "plugin"), allow(dead_code))]
pub args: Value,
}
#[derive(Debug, Clone, Default)]
pub struct BeforeToolCallReturn {
pub result: Option<BeforeToolCallResult>,
pub args: Value,
}
pub type BeforeToolCallFn = Arc<
dyn Fn(BeforeToolCallContext) -> Pin<Box<dyn Future<Output = BeforeToolCallReturn> + Send>>
+ Send
+ Sync,
>;
#[derive(Debug, Clone)]
pub struct AfterToolCallContext {
#[allow(dead_code)]
pub assistant_message: AssistantMessage,
#[allow(dead_code)]
pub tool_call_id: String,
#[cfg_attr(not(feature = "plugin"), allow(dead_code))]
pub tool_call_name: String,
#[allow(dead_code)]
pub args: Value,
#[cfg_attr(not(feature = "plugin"), allow(dead_code))]
pub result: LoopToolResult,
#[allow(dead_code)]
pub is_error: bool,
}
pub type AfterToolCallFn = Arc<
dyn Fn(
AfterToolCallContext,
) -> Pin<Box<dyn Future<Output = Option<AfterToolCallResult>> + Send>>
+ Send
+ Sync,
>;
#[derive(Debug, Clone)]
pub struct TurnHookContext {
#[allow(dead_code)]
pub message: AssistantMessage,
#[allow(dead_code)]
pub tool_results: Vec<ToolResultMessage>,
#[allow(dead_code)]
pub context: Context,
#[allow(dead_code)]
pub new_messages: Vec<LoopMessage>,
}
pub type PrepareNextTurnFn = Arc<
dyn Fn(TurnHookContext) -> Pin<Box<dyn Future<Output = Option<TurnUpdate>> + Send>>
+ Send
+ Sync,
>;
pub type ShouldStopAfterTurnFn =
Arc<dyn Fn(TurnHookContext) -> Pin<Box<dyn Future<Output = bool> + Send>> + Send + Sync>;
pub type GetSteeringMessagesFn =
Arc<dyn Fn() -> Pin<Box<dyn Future<Output = Vec<LoopMessage>> + Send>> + Send + Sync>;
pub type GetFollowupMessagesFn =
Arc<dyn Fn() -> Pin<Box<dyn Future<Output = Vec<LoopMessage>> + Send>> + Send + Sync>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn before_return_default() {
let r = BeforeToolCallReturn::default();
assert!(r.result.is_none());
assert_eq!(r.args, Value::Null);
}
}