Skip to main content

ag_agent/model/
agent.rs

1pub use ag_runtime::ReasoningLevel;
2pub use ag_session::{
3    AgentKind, AgentModel, AgentSelection, AgentSelectionMetadata,
4    parse_persisted_session_agent_model, resolve_agent_kind_for_model,
5    resolve_agent_selection_for_model, resolve_model_for_available_agent_kinds,
6    resolve_prompt_model_agent_kind, selectable_models_for_agent_kinds,
7};
8
9/// Automatic update and version probe state for one locally runnable agent
10/// CLI.
11#[derive(Debug, Clone, PartialEq, Eq)]
12pub enum AgentCliVersion {
13    /// Startup update plus version detection is still running in the
14    /// background.
15    Loading,
16    /// Version detection finished, but the executable did not report a usable
17    /// version.
18    Unknown,
19    /// Version detection finished with a parsed display value.
20    Value(String),
21}
22
23/// One locally runnable agent CLI and the installed version refreshed at
24/// startup.
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct AgentCliInfo {
27    /// Executable name used to launch the provider CLI.
28    pub executable_name: &'static str,
29    /// Agent provider family backed by the executable.
30    pub kind: AgentKind,
31    /// Current automatic update and version probe state for this executable.
32    pub version: AgentCliVersion,
33}
34
35impl AgentCliInfo {
36    /// Creates one CLI availability row for a provider and optional version.
37    pub fn new(kind: AgentKind, version: Option<String>) -> Self {
38        Self {
39            executable_name: kind.executable_name(),
40            kind,
41            version: version.map_or(AgentCliVersion::Unknown, AgentCliVersion::Value),
42        }
43    }
44
45    /// Creates one CLI availability row whose update/version refresh is still
46    /// loading.
47    pub fn loading(kind: AgentKind) -> Self {
48        Self {
49            executable_name: kind.executable_name(),
50            kind,
51            version: AgentCliVersion::Loading,
52        }
53    }
54
55    /// Builds unknown-version CLI rows for an existing provider availability
56    /// list.
57    pub fn from_kinds(agent_kinds: &[AgentKind]) -> Vec<Self> {
58        agent_kinds
59            .iter()
60            .copied()
61            .map(|agent_kind| Self::new(agent_kind, None))
62            .collect()
63    }
64
65    /// Builds loading CLI rows for an existing provider availability list
66    /// while the background update/version refresh is running.
67    pub fn loading_from_kinds(agent_kinds: &[AgentKind]) -> Vec<Self> {
68        agent_kinds.iter().copied().map(Self::loading).collect()
69    }
70}