Skip to main content

distri_types/configuration/
package.rs

1use crate::ToolDefinition;
2use crate::agent::StandardDefinition;
3use crate::configuration::manifest::DistriServerConfig;
4use serde::{Deserialize, Serialize};
5use std::path::PathBuf;
6
7/// Tool definition ready for DAP registration with runtime info
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct PluginToolDefinition {
10    pub name: String,
11    pub package_name: String,
12    pub description: String,
13    #[serde(default)]
14    pub parameters: serde_json::Value,
15    #[serde(default, skip_serializing_if = "Option::is_none")]
16    pub auth: Option<crate::auth::AuthRequirement>,
17}
18
19/// Cloud-specific metadata for agents (optional, only present in cloud responses)
20#[derive(Debug, Clone, Serialize, Deserialize, Default)]
21pub struct AgentCloudMetadata {
22    #[serde(default, skip_serializing_if = "Option::is_none")]
23    pub id: Option<uuid::Uuid>,
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub published: Option<bool>,
26    #[serde(default, skip_serializing_if = "Option::is_none")]
27    pub published_at: Option<chrono::DateTime<chrono::Utc>>,
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub is_owner: Option<bool>,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct AgentConfigWithTools {
34    #[serde(flatten)]
35    pub agent: AgentConfig,
36    #[serde(default, skip_serializing_if = "Vec::is_empty")]
37    pub resolved_tools: Vec<ToolDefinition>,
38    #[serde(default, skip_serializing_if = "Option::is_none")]
39    pub markdown: Option<String>,
40    /// Cloud-specific metadata (optional, only present in cloud responses)
41    #[serde(flatten, default)]
42    pub cloud: AgentCloudMetadata,
43}
44
45/// Unified agent configuration enum
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(tag = "agent_type", rename_all = "snake_case")]
48pub enum AgentConfig {
49    /// Standard markdown-based agent
50    StandardAgent(StandardDefinition),
51}
52
53impl AgentConfig {
54    /// Get the name of the agent
55    pub fn get_name(&self) -> &str {
56        match self {
57            AgentConfig::StandardAgent(def) => &def.name,
58        }
59    }
60
61    pub fn get_definition(&self) -> &StandardDefinition {
62        match self {
63            AgentConfig::StandardAgent(def) => &def,
64        }
65    }
66
67    /// Get the description of the agent
68    pub fn get_description(&self) -> &str {
69        match self {
70            AgentConfig::StandardAgent(def) => &def.description,
71        }
72    }
73
74    /// Validate the configuration
75    pub fn validate(&self) -> anyhow::Result<()> {
76        match self {
77            AgentConfig::StandardAgent(def) => def.validate(),
78        }
79    }
80
81    /// Get the working directory with fallback chain: agent config -> package config -> DISTRI_HOME -> current_dir
82    pub fn get_working_directory(
83        &self,
84        package_config: Option<&DistriServerConfig>,
85    ) -> anyhow::Result<std::path::PathBuf> {
86        // Fall back to package configuration
87        if let Some(config) = package_config {
88            return config.get_working_directory();
89        }
90
91        // Try DISTRI_HOME environment variable
92        if let Ok(distri_home) = std::env::var("DISTRI_HOME") {
93            return Ok(std::path::PathBuf::from(distri_home));
94        }
95
96        // Fallback to current directory
97        std::env::current_dir()
98            .map_err(|e| anyhow::anyhow!("Failed to get current directory: {}", e))
99    }
100}
101
102/// Agent definition ready for DAP registration with runtime info
103#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct PluginAgentDefinition {
105    pub name: String,
106    pub package_name: String,
107    pub description: String,
108    pub file_path: PathBuf,
109    /// The full agent configuration (supports all agent types)
110    pub agent_config: AgentConfig,
111}
112
113/// Built DAP package artifact ready for registration in distri
114#[derive(Debug, Clone, Serialize, Deserialize)]
115pub struct PluginArtifact {
116    pub name: String,
117    pub path: PathBuf,
118    pub configuration: crate::configuration::manifest::DistriServerConfig,
119    pub tools: Vec<PluginToolDefinition>,
120    pub agents: Vec<PluginAgentDefinition>,
121}