Skip to main content

tauri_plugin_modular_agent/
lib.rs

1#![recursion_limit = "256"]
2
3use modular_agent_kit::MAK;
4use tauri::{
5    plugin::{Builder, TauriPlugin},
6    Manager, RunEvent, Runtime,
7};
8
9mod commands;
10mod error;
11
12pub use error::{Error, Result};
13
14/// Extensions to [`tauri::App`], [`tauri::AppHandle`] and [`tauri::Window`] to access the mak APIs.
15pub trait MAKExt<R: Runtime> {
16    fn mak(&self) -> &MAK;
17}
18
19impl<R: Runtime, T: Manager<R>> crate::MAKExt<R> for T {
20    fn mak(&self) -> &MAK {
21        self.state::<MAK>().inner()
22    }
23}
24
25/// Initializes the plugin.
26pub fn init<R: Runtime>() -> TauriPlugin<R> {
27    Builder::new("modular-agent")
28        .invoke_handler(tauri::generate_handler![
29            // Preset management
30            commands::new_preset,
31            // commands::rename_preset,
32            // commands::unique_preset_name,
33            commands::add_preset,
34            commands::remove_preset,
35            commands::start_preset,
36            commands::stop_preset,
37            commands::open_preset_from_file,
38            commands::save_preset,
39            commands::save_preset_as,
40            commands::get_preset_path,
41            commands::set_preset_file_name,
42            commands::get_preset_spec,
43            commands::update_preset_spec,
44            commands::get_preset_info,
45            commands::get_preset_infos,
46            // Agent management
47            commands::get_agent_definition,
48            commands::get_agent_definitions,
49            commands::get_agent_spec,
50            commands::update_agent_spec,
51            commands::new_agent_spec,
52            commands::add_agent,
53            commands::remove_agent,
54            commands::add_connection,
55            commands::remove_connection,
56            commands::add_agents_and_connections,
57            commands::start_agent,
58            commands::stop_agent,
59            commands::set_agent_configs,
60            commands::get_global_configs,
61            commands::get_global_configs_map,
62            commands::set_global_configs,
63            commands::set_global_configs_map,
64            commands::write_board,
65        ])
66        .setup(|app, _api| {
67            let mak = MAK::init()?;
68            app.manage(mak);
69            Ok(())
70        })
71        .on_event(|app, event| match event {
72            RunEvent::Ready => {
73                tauri::async_runtime::block_on(async move {
74                    let mak = app.state::<MAK>();
75                    mak.ready().await.unwrap();
76                });
77            }
78            RunEvent::Exit => {
79                let mak = app.state::<MAK>();
80                mak.quit();
81            }
82            _ => {}
83        })
84        .build()
85}