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
22crate::id_newtype::define_id_newtype! {
23    /// Identifier for a marketplace.
24    pub struct MarketplaceId
25}
26
27/// Configuration for marketplace system
28#[derive(Debug, Clone, Deserialize, Serialize)]
29pub struct MarketplaceConfig {
30    /// Enable marketplace functionality
31    #[serde(default = "default_enabled")]
32    pub enabled: bool,
33
34    /// Auto-update marketplaces at startup
35    #[serde(default = "default_auto_update")]
36    pub auto_update: bool,
37
38    /// Default trust level for installed plugins
39    #[serde(default)]
40    pub default_trust: crate::config::PluginTrustLevel,
41
42    /// List of default marketplaces to include
43    #[serde(default)]
44    pub default_marketplaces: Vec<MarketplaceSource>,
45}
46
47impl Default for MarketplaceConfig {
48    fn default() -> Self {
49        Self {
50            enabled: true,
51            auto_update: true,
52            default_trust: crate::config::PluginTrustLevel::Sandbox,
53            default_marketplaces: vec![MarketplaceSource::Git {
54                id: "vtcode-official".to_string(),
55                url: "https://github.com/vinhnx/vtcode-marketplace".to_string(),
56                refspec: None,
57            }],
58        }
59    }
60}
61
62fn default_enabled() -> bool {
63    true
64}
65
66fn default_auto_update() -> bool {
67    true
68}
69
70/// Main marketplace system that coordinates all marketplace functionality
71pub struct MarketplaceSystem {
72    /// Registry for managing marketplaces
73    pub registry: MarketplaceRegistry,
74
75    /// Installer for managing plugin installations
76    pub installer: PluginInstaller,
77
78    /// Configuration for the marketplace system
79    pub config: MarketplaceConfig,
80}
81
82impl MarketplaceSystem {
83    /// Create a new marketplace system
84    pub fn new(base_dir: PathBuf, config: MarketplaceConfig, plugin_runtime: Option<PluginRuntime>) -> Self {
85        let registry = MarketplaceRegistry::new(base_dir.clone());
86        let installer = PluginInstaller::new(base_dir.join("plugins"), plugin_runtime);
87
88        Self { registry, installer, config }
89    }
90
91    /// Initialize the marketplace system with default marketplaces
92    pub async fn initialize(&self) -> Result<()> {
93        // Add default marketplaces if enabled
94        for marketplace in &self.config.default_marketplaces {
95            self.registry.add_marketplace(marketplace.clone()).await?;
96        }
97
98        Ok(())
99    }
100}