ai_agent/utils/plugins/
plugin_identifier.rs1#![allow(dead_code)]
3
4use super::schemas::PluginScope;
5
6pub struct ParsedPluginIdentifier {
8 pub name: String,
9 pub marketplace: Option<String>,
10}
11
12pub fn parse_plugin_identifier(plugin: &str) -> ParsedPluginIdentifier {
14 if let Some(at_pos) = plugin.find('@') {
15 let name = plugin[..at_pos].to_string();
16 let marketplace = plugin[at_pos + 1..].to_string();
17 ParsedPluginIdentifier {
18 name,
19 marketplace: Some(marketplace),
20 }
21 } else {
22 ParsedPluginIdentifier {
23 name: plugin.to_string(),
24 marketplace: None,
25 }
26 }
27}
28
29pub fn build_plugin_id(name: &str, marketplace: Option<&str>) -> String {
31 match marketplace {
32 Some(m) => format!("{}@{}", name, m),
33 None => name.to_string(),
34 }
35}
36
37pub fn is_official_marketplace_name(marketplace: Option<&str>) -> bool {
39 match marketplace {
40 Some(m) => {
41 let lowercase = m.to_lowercase();
42 super::schemas::allowed_official_marketplace_names()
43 .iter()
44 .any(|&s| s == lowercase)
45 }
46 None => false,
47 }
48}
49
50pub fn scope_to_setting_source(
52 scope: &PluginScope,
53) -> Result<&'static str, Box<dyn std::error::Error + Send + Sync>> {
54 match scope {
55 PluginScope::User => Ok("userSettings"),
56 PluginScope::Project => Ok("projectSettings"),
57 PluginScope::Local => Ok("localSettings"),
58 PluginScope::Managed => Err("Cannot install plugins to managed scope".into()),
59 }
60}
61
62pub fn setting_source_to_scope(source: &str) -> Option<PluginScope> {
64 match source {
65 "userSettings" => Some(PluginScope::User),
66 "projectSettings" => Some(PluginScope::Project),
67 "localSettings" => Some(PluginScope::Local),
68 "policySettings" => Some(PluginScope::Managed),
69 _ => None,
70 }
71}