Skip to main content

agent_hub_runtime/commands/
agent_launch.rs

1use crate::core::{agent_launch_config as config, error::AppError};
2
3#[tauri::command]
4pub async fn agent_launch_settings() -> Result<config::Snapshot, AppError> {
5    tauri::async_runtime::spawn_blocking(|| config::load().map_err(AppError::io)).await?
6}
7
8#[tauri::command]
9pub async fn agent_launch_config_path() -> Result<String, AppError> {
10    tauri::async_runtime::spawn_blocking(|| config::file_path().map_err(AppError::io)).await?
11}
12/// Resolve the same literal argv used by launchers, without starting a process.
13#[tauri::command]
14pub async fn agent_launch_plan(
15    agent: String,
16    scheme_id: Option<String>,
17) -> Result<config::Launch, AppError> {
18    tauri::async_runtime::spawn_blocking(move || {
19        config::resolve_scheme(&agent, scheme_id.as_deref()).map_err(AppError::io)
20    })
21    .await?
22}
23#[tauri::command]
24pub async fn save_agent_launch_settings(
25    document: config::Document,
26    revision: String,
27) -> Result<config::Snapshot, AppError> {
28    tauri::async_runtime::spawn_blocking(move || {
29        config::save(document, &revision).map_err(AppError::io)
30    })
31    .await?
32}
33
34#[derive(serde::Serialize)]
35pub struct NativeLaunchOutcome {
36    pub receipt: crate::core::agent_launcher::external_terminal::Receipt,
37    pub warning: Option<String>,
38}
39/// Return None when Herdr is installed. Never fall back after a submitted Herdr request.
40#[tauri::command]
41pub async fn task_native_agent_launch(
42    store: tauri::State<'_, std::sync::Arc<crate::core::skill_store::SkillStore>>,
43    project_id: String,
44    path: String,
45    kind: String,
46    prompt: String,
47) -> Result<Option<NativeLaunchOutcome>, AppError> {
48    let store = store.inner().clone();
49    tauri::async_runtime::spawn_blocking(move || {
50        #[cfg(feature = "herdr")]
51        if crate::core::agent_execution::core_available() { return Ok(None); }
52        let cwd = crate::core::project_worktrees::directory(&store, &project_id, Some(&path)).map_err(AppError::io)?;
53        let launch = config::resolve(&kind).map_err(AppError::io)?;
54        let mut submitted = None;
55        let opened = crate::core::agent_launcher::external_terminal::open(&launch, &cwd, Some(&prompt), |receipt| { submitted = Some(receipt.clone()); Ok(()) });
56        match (opened, submitted) {
57            (Ok(receipt), _) => Ok(Some(NativeLaunchOutcome { receipt, warning: None })),
58            (Err(error), Some(receipt)) => Ok(Some(NativeLaunchOutcome { receipt, warning: Some(format!("{error}; terminal launch was submitted. Inspect the native terminal before retrying")) })),
59            (Err(error), None) => Err(AppError::io(error)),
60        }
61    }).await?
62}