tauri_plugin_askit/
lib.rs

1#![recursion_limit = "256"]
2
3use agent_stream_kit::ASKit;
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 askit APIs.
15pub trait ASKitExt<R: Runtime> {
16    fn askit(&self) -> &ASKit;
17}
18
19impl<R: Runtime, T: Manager<R>> crate::ASKitExt<R> for T {
20    fn askit(&self) -> &ASKit {
21        self.state::<ASKit>().inner()
22    }
23}
24
25/// Initializes the plugin.
26pub fn init<R: Runtime>() -> TauriPlugin<R> {
27    Builder::new("askit")
28        .invoke_handler(tauri::generate_handler![
29            commands::get_agent_definition,
30            commands::get_agent_definitions,
31            commands::get_agent_spec,
32            commands::update_agent_spec,
33            commands::get_agent_stream_info,
34            commands::get_agent_stream_infos,
35            commands::get_agent_stream_spec,
36            commands::update_agent_stream_spec,
37            commands::new_agent_stream,
38            commands::rename_agent_stream,
39            commands::unique_stream_name,
40            commands::add_agent_stream,
41            commands::remove_agent_stream,
42            commands::add_agents_and_channels,
43            commands::start_agent_stream,
44            commands::stop_agent_stream,
45            commands::new_agent_spec,
46            commands::add_agent,
47            commands::remove_agent,
48            commands::add_channel,
49            commands::remove_channel,
50            commands::start_agent,
51            commands::stop_agent,
52            commands::write_board,
53            commands::set_agent_configs,
54            commands::get_global_configs,
55            commands::get_global_configs_map,
56            commands::set_global_configs,
57            commands::set_global_configs_map,
58        ])
59        .setup(|app, _api| {
60            let askit = ASKit::init()?;
61            app.manage(askit);
62            Ok(())
63        })
64        .on_event(|app, event| match event {
65            RunEvent::Ready => {
66                tauri::async_runtime::block_on(async move {
67                    let askit = app.state::<ASKit>();
68                    askit.ready().await.unwrap();
69                });
70            }
71            RunEvent::Exit => {
72                let askit = app.state::<ASKit>();
73                askit.quit();
74            }
75            _ => {}
76        })
77        .build()
78}