use super::permission::PermissionDecision;
use crate::{
cli_runtime::{
agent_event::AgentEvent,
status_sink::{RateLimitRecorder, RuntimeLabel},
stream_effect::StreamEffect,
CliExecutable,
},
session_environment::Ambient,
};
use agent_client_protocol::v1::schema::{
AuthMethod, AuthMethodId, Meta, RequestPermissionRequest, SessionConfigId, SessionConfigOption,
SessionConfigValueId, SessionModeId, SessionUpdate, ToolCall, ToolCallUpdate, ToolKind,
};
use serde_json::Value;
use std::{
ffi::OsString,
path::{Path, PathBuf},
};
#[derive(Clone, Copy, Debug)]
pub(crate) struct AgentToolCallRef<'a> {
pub(crate) meta: Option<&'a Meta>,
pub(crate) name: Option<&'a str>,
pub(crate) kind: Option<ToolKind>,
}
impl<'a> From<&'a ToolCall> for AgentToolCallRef<'a> {
fn from(call: &'a ToolCall) -> Self {
Self {
meta: call.meta.as_ref(),
name: call.name.as_deref(),
kind: Some(call.kind),
}
}
}
impl<'a> From<&'a ToolCallUpdate> for AgentToolCallRef<'a> {
fn from(update: &'a ToolCallUpdate) -> Self {
Self {
meta: update.meta.as_ref(),
name: update.fields.name.as_deref(),
kind: update.fields.kind,
}
}
}
pub(crate) trait AcpAgentPolicy: Send + 'static {
fn label(&self) -> RuntimeLabel;
fn resolve_executable(&self, environment: &Ambient) -> Result<CliExecutable, String>;
fn spawn_plan(&self) -> Result<AcpSpawnPlan, String>;
fn prepare(&mut self, run_dir: &Path) -> Result<(), String>;
fn log_path(&self, output_file: &Path) -> PathBuf;
fn auth_method(&self, advertised: &[AuthMethod]) -> Option<AuthMethodId>;
fn session_mode(&self) -> Option<SessionModeId>;
fn session_meta(&self) -> Option<Meta> {
None
}
fn session_config(&self) -> Vec<SessionConfigChoice> {
Vec::new()
}
fn config_seen(&self, _options: &[SessionConfigOption]) {}
fn decide_permission(&self, request: &RequestPermissionRequest) -> PermissionDecision;
fn agent_tool<'a>(&self, _call: AgentToolCallRef<'a>) -> Option<&'a str> {
None
}
fn leave_plan(&mut self, _to: crate::permission::PermissionMode) -> bool {
false
}
fn answer_extension(&self, method: &str, params: &Value) -> Option<ExtensionAnswer>;
fn rate_limit_recorder(&self) -> Option<Box<dyn RateLimitRecorder>> {
None
}
fn status_effects(&self, _update: &SessionUpdate) -> Vec<StreamEffect> {
Vec::new()
}
}
pub(crate) struct AcpSpawnPlan {
pub(crate) argv: Vec<OsString>,
pub(crate) cwd: PathBuf,
pub(crate) env: Vec<(OsString, OsString)>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct SessionConfigChoice {
pub(crate) id: SessionConfigId,
pub(crate) value: SessionConfigValueId,
}
pub(crate) struct ExtensionAnswer {
pub(crate) reply: Value,
pub(crate) events: Vec<AgentEvent>,
}