Skip to main content

vtcode_core/marketplace/
mod.rs

1//! Plugin marketplace system for VT Code
2//!
3//! This module implements a marketplace system for VT Code,
4//! allowing users to discover and install plugins from various sources.
5
6use std::path::PathBuf;
7
8use crate::tools::plugins::PluginRuntime;
9use anyhow::Result;
10use serde::{Deserialize, Serialize};
11
12pub mod config;
13pub mod installer;
14pub mod manifest;
15pub mod registry;
16pub mod testing;
17
18pub use installer::PluginInstaller;
19pub use manifest::{MarketplaceManifest, PluginManifest};
20pub use registry::{MarketplaceRegistry, MarketplaceSource};
21
22/// Type alias for marketplace identifiers
23pub type MarketplaceId = String;
24
25/// Type alias for plugin identifiers
26pub type PluginId = String;
27
28/// Configuration for marketplace system
29#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct MarketplaceConfig {
31    /// Enable marketplace functionality
32    #[serde(default = "default_enabled")]
33    pub enabled: bool,
34
35    /// Auto-update marketplaces at startup
36    #[serde(default = "default_auto_update")]
37    pub auto_update: bool,
38
39    /// Default trust level for installed plugins
40    #[serde(default)]
41    pub default_trust: crate::config::PluginTrustLevel,
42
43    /// List of default marketplaces to include
44    #[serde(default)]
45    pub default_marketplaces: Vec<MarketplaceSource>,
46}
47
48impl Default for MarketplaceConfig {
49    fn default() -> Self {
50        Self {
51            enabled: true,
52            auto_update: true,
53            default_trust: crate::config::PluginTrustLevel::Sandbox,
54            default_marketplaces: vec![MarketplaceSource::Git {
55                id: "vtcode-official".to_string(),
56                url: "https://github.com/vinhnx/vtcode-marketplace".to_string(),
57                refspec: None,
58            }],
59        }
60    }
61}
62
63fn default_enabled() -> bool {
64    true
65}
66
67fn default_auto_update() -> bool {
68    true
69}
70
71/// Main marketplace system that coordinates all marketplace functionality
72pub struct MarketplaceSystem {
73    /// Registry for managing marketplaces
74    pub registry: MarketplaceRegistry,
75
76    /// Installer for managing plugin installations
77    pub installer: PluginInstaller,
78
79    /// Configuration for the marketplace system
80    pub config: MarketplaceConfig,
81}
82
83impl MarketplaceSystem {
84    /// Create a new marketplace system
85    pub fn new(
86        base_dir: PathBuf,
87        config: MarketplaceConfig,
88        plugin_runtime: Option<PluginRuntime>,
89    ) -> Self {
90        let registry = MarketplaceRegistry::new(base_dir.clone());
91        let installer = PluginInstaller::new(base_dir.join("plugins"), plugin_runtime);
92
93        Self {
94            registry,
95            installer,
96            config,
97        }
98    }
99
100    /// Initialize the marketplace system with default marketplaces
101    pub async fn initialize(&self) -> Result<()> {
102        // Add default marketplaces if enabled
103        for marketplace in &self.config.default_marketplaces {
104            self.registry.add_marketplace(marketplace.clone()).await?;
105        }
106
107        Ok(())
108    }
109}