Skip to main content

systemprompt_cli/commands/plugins/capabilities/
llm_providers.rs

1//! `plugins capabilities llm-providers` 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::{LlmProviderWithExtension, LlmProvidersListOutput};
11use crate::shared::CommandOutput;
12
13#[derive(Debug, Clone, Args)]
14pub struct LlmProvidersArgs {
15    #[arg(long, help = "Filter by extension ID")]
16    pub extension: Option<String>,
17}
18
19pub fn execute(args: &LlmProvidersArgs, _config: &CliConfig) -> CommandOutput {
20    let registry = discover_registry();
21
22    let providers: Vec<LlmProviderWithExtension> = 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            ext.llm_providers()
28                .iter()
29                .enumerate()
30                .map(|(i, _provider)| LlmProviderWithExtension {
31                    extension_id: systemprompt_identifiers::PluginId::new(ext.id()),
32                    extension_name: ext.name().to_owned(),
33                    provider_name: format!("llm_provider_{}", i),
34                })
35                .collect::<Vec<_>>()
36        })
37        .collect();
38
39    let total = providers.len();
40
41    let output = LlmProvidersListOutput { providers, total };
42
43    CommandOutput::table_of(vec!["extension_id", "provider_name"], &output.providers)
44        .with_title("LLM Providers Across Extensions")
45}