Skip to main content

systemprompt_cli/commands/plugins/capabilities/
templates.rs

1//! `plugins capabilities templates` command.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use clap::Args;
7
8use crate::CliConfig;
9use crate::commands::plugins::discover_registry;
10use crate::commands::plugins::types::{TemplateWithExtension, TemplatesListOutput};
11use crate::shared::CommandOutput;
12
13#[derive(Debug, Clone, Args)]
14pub struct TemplatesArgs {
15    #[arg(long, help = "Filter by extension ID")]
16    pub extension: Option<String>,
17}
18
19pub fn execute(args: &TemplatesArgs, _config: &CliConfig) -> CommandOutput {
20    let registry = discover_registry();
21
22    let templates: Vec<TemplateWithExtension> = registry
23        .extensions()
24        .iter()
25        .filter(|ext| args.extension.as_ref().is_none_or(|f| ext.id().contains(f)))
26        .flat_map(|ext| {
27            let ext_id = ext.id().to_owned();
28            let ext_name = ext.name().to_owned();
29
30            ext.template_providers()
31                .iter()
32                .flat_map(|provider| {
33                    provider
34                        .templates()
35                        .iter()
36                        .map(|t| (t.name.clone(), t.content_types.join(", ")))
37                        .collect::<Vec<_>>()
38                })
39                .map(|(name, desc)| TemplateWithExtension {
40                    extension_id: systemprompt_identifiers::PluginId::new(ext_id.clone()),
41                    extension_name: ext_name.clone(),
42                    template_name: name,
43                    description: desc,
44                })
45                .collect::<Vec<_>>()
46        })
47        .collect();
48
49    let total = templates.len();
50
51    let output = TemplatesListOutput { templates, total };
52
53    CommandOutput::table_of(
54        vec!["extension_id", "template_name", "description"],
55        &output.templates,
56    )
57    .with_title("Templates Across Extensions")
58}