vtcode_core/marketplace/
mod.rs1use 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
22pub type MarketplaceId = String;
24
25pub type PluginId = String;
27
28#[derive(Debug, Clone, Deserialize, Serialize)]
30pub struct MarketplaceConfig {
31 #[serde(default = "default_enabled")]
33 pub enabled: bool,
34
35 #[serde(default = "default_auto_update")]
37 pub auto_update: bool,
38
39 #[serde(default)]
41 pub default_trust: crate::config::PluginTrustLevel,
42
43 #[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
71pub struct MarketplaceSystem {
73 pub registry: MarketplaceRegistry,
75
76 pub installer: PluginInstaller,
78
79 pub config: MarketplaceConfig,
81}
82
83impl MarketplaceSystem {
84 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 pub async fn initialize(&self) -> Result<()> {
102 for marketplace in &self.config.default_marketplaces {
104 self.registry.add_marketplace(marketplace.clone()).await?;
105 }
106
107 Ok(())
108 }
109}