Skip to main content

zeph_commands/handlers/
model.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Model and provider command handlers: `/model`, `/provider`.
5
6use std::future::Future;
7use std::pin::Pin;
8
9use crate::context::CommandContext;
10use crate::{CommandError, CommandHandler, CommandOutput, SlashCategory};
11
12/// Show or switch the active LLM model.
13///
14/// - `/model` — list available models.
15/// - `/model refresh` — clear cache and re-fetch from remote.
16/// - `/model <id>` — switch to the given model.
17pub struct ModelCommand;
18
19impl CommandHandler<CommandContext<'_>> for ModelCommand {
20    fn name(&self) -> &'static str {
21        "/model"
22    }
23
24    fn description(&self) -> &'static str {
25        "Show or switch the active model"
26    }
27
28    fn args_hint(&self) -> &'static str {
29        "[id|refresh]"
30    }
31
32    fn category(&self) -> SlashCategory {
33        SlashCategory::Configuration
34    }
35
36    fn handle<'a>(
37        &'a self,
38        ctx: &'a mut CommandContext<'_>,
39        args: &'a str,
40    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
41        Box::pin(async move {
42            let result = ctx.agent.handle_model(args).await;
43            if result.is_empty() {
44                Ok(CommandOutput::Silent)
45            } else {
46                Ok(CommandOutput::Message(result))
47            }
48        })
49    }
50}
51
52/// List configured providers or switch to one by name.
53///
54/// - `/provider` or `/provider status` — list all configured providers and their status.
55/// - `/provider <name>` — switch to the named provider.
56pub struct ProviderCommand;
57
58impl CommandHandler<CommandContext<'_>> for ProviderCommand {
59    fn name(&self) -> &'static str {
60        "/provider"
61    }
62
63    fn description(&self) -> &'static str {
64        "List configured providers or switch to one by name"
65    }
66
67    fn args_hint(&self) -> &'static str {
68        "[name|status]"
69    }
70
71    fn category(&self) -> SlashCategory {
72        SlashCategory::Configuration
73    }
74
75    fn handle<'a>(
76        &'a self,
77        ctx: &'a mut CommandContext<'_>,
78        args: &'a str,
79    ) -> Pin<Box<dyn Future<Output = Result<CommandOutput, CommandError>> + Send + 'a>> {
80        Box::pin(async move {
81            let result = ctx.agent.handle_provider(args).await;
82            if result.is_empty() {
83                Ok(CommandOutput::Silent)
84            } else {
85                Ok(CommandOutput::Message(result))
86            }
87        })
88    }
89}