Skip to main content

ag_runtime/
provider.rs

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