ai_agent/utils/plugins/
plugin_autoupdate.rs1#![allow(dead_code)]
3
4use std::collections::HashSet;
5use std::sync::Mutex;
6
7use once_cell::sync::Lazy;
8
9use super::installed_plugins_manager::{
10 get_pending_updates_details, has_pending_updates, is_installation_relevant_to_current_project,
11 load_installed_plugins_from_disk,
12};
13use super::plugin_identifier::parse_plugin_identifier;
14
15type PluginAutoUpdateCallback = Box<dyn Fn(Vec<String>) + Send + Sync>;
17
18static PLUGIN_UPDATE_CALLBACK: Lazy<Mutex<Option<PluginAutoUpdateCallback>>> =
19 Lazy::new(|| Mutex::new(None));
20static PENDING_NOTIFICATION: Lazy<Mutex<Option<Vec<String>>>> = Lazy::new(|| Mutex::new(None));
21
22pub fn on_plugins_auto_updated(
24 callback: impl Fn(Vec<String>) + Send + Sync + 'static,
25) -> Box<dyn FnOnce()> {
26 let cb: PluginAutoUpdateCallback = Box::new(callback);
27
28 {
29 let mut pending = PENDING_NOTIFICATION.lock().unwrap();
30 if let Some(ref updates) = *pending {
31 if !updates.is_empty() {
32 cb(updates.clone());
33 *pending = None;
34 }
35 }
36 }
37
38 {
39 let mut callback_lock = PLUGIN_UPDATE_CALLBACK.lock().unwrap();
40 *callback_lock = Some(cb);
41 }
42
43 Box::new(|| {
44 let mut callback_lock = PLUGIN_UPDATE_CALLBACK.lock().unwrap();
45 *callback_lock = None;
46 })
47}
48
49pub fn get_auto_updated_plugin_names() -> Vec<String> {
51 if !has_pending_updates() {
52 return Vec::new();
53 }
54
55 get_pending_updates_details()
56 .into_iter()
57 .map(|d| parse_plugin_identifier(&d.plugin_id).name)
58 .collect()
59}
60
61async fn get_auto_update_enabled_marketplaces() -> HashSet<String> {
63 HashSet::new()
64}
65
66pub async fn update_plugins_for_marketplaces(_marketplace_names: &HashSet<String>) -> Vec<String> {
68 Vec::new()
69}
70
71pub fn auto_update_marketplaces_and_plugins_in_background() {
73 }