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
22crate::id_newtype::define_id_newtype! {
23 pub struct MarketplaceId
25}
26
27#[derive(Debug, Clone, Deserialize, Serialize)]
29pub struct MarketplaceConfig {
30 #[serde(default = "default_enabled")]
32 pub enabled: bool,
33
34 #[serde(default = "default_auto_update")]
36 pub auto_update: bool,
37
38 #[serde(default)]
40 pub default_trust: crate::config::PluginTrustLevel,
41
42 #[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
70pub struct MarketplaceSystem {
72 pub registry: MarketplaceRegistry,
74
75 pub installer: PluginInstaller,
77
78 pub config: MarketplaceConfig,
80}
81
82impl MarketplaceSystem {
83 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 pub async fn initialize(&self) -> Result<()> {
93 for marketplace in &self.config.default_marketplaces {
95 self.registry.add_marketplace(marketplace.clone()).await?;
96 }
97
98 Ok(())
99 }
100}