Skip to main content

ag_runtime/
provider.rs

1use std::path::Path;
2
3use ag_contracts::AgentError;
4use ag_session::{AgentAvailabilityProbe, AgentCliInfo, AgentKind, AgentModel};
5
6/// Machine-scoped provider discovery through the concrete adapter registry.
7pub struct RealAgentAvailabilityProbe;
8
9impl AgentAvailabilityProbe for RealAgentAvailabilityProbe {
10    fn available_agent_kinds(&self) -> Vec<AgentKind> {
11        ag_agent::RealAgentAvailabilityProbe.available_agent_kinds()
12    }
13
14    fn available_agent_clis(&self) -> Vec<AgentCliInfo> {
15        ag_agent::RealAgentAvailabilityProbe.available_agent_clis()
16    }
17
18    fn native_harness_default_model(&self) -> Option<AgentModel> {
19        ag_agent::RealAgentAvailabilityProbe.native_harness_default_model()
20    }
21}
22
23/// Initializes provider resources in a session workspace.
24///
25/// # Errors
26/// Returns a normalized adapter setup failure.
27pub fn setup_backend(kind: AgentKind, folder: &Path) -> Result<(), AgentError> {
28    ag_agent::create_backend(kind)
29        .setup(folder)
30        .map_err(Into::into)
31}
32
33/// Whether the selected provider retains a process between turns.
34pub fn uses_persistent_session(kind: AgentKind) -> bool {
35    ag_agent::transport_mode(kind).uses_app_server()
36}
37
38/// Reclaims adapter-owned resources during workspace deletion.
39///
40/// # Errors
41/// Returns the runtime artifact cleanup failure.
42pub fn cleanup_session_worktree_artifacts(folder: &Path) -> Result<(), AgentError> {
43    ag_agent::cleanup_session_worktree_artifacts(folder).map_err(Into::into)
44}