zerolaunch_plugin_api/host/
plugin_host.rs1use std::collections::HashMap;
13use std::path::Path;
14use std::time::Duration;
15
16use async_trait::async_trait;
17
18use crate::host::{CacheLevel, HostApiError, OpenTarget};
19use crate::services::app::AppInfo;
20use crate::services::focus_monitor::FocusCallback;
21use crate::services::hotkey::types::{HotkeyCallback, HotkeyEventFilter};
22use crate::services::installation_monitor::types::InstallationCallback;
23use crate::services::model::{
24 ModelChatRequest, ModelChatResponse, ModelEmbeddingRequest, ModelEmbeddingResponse, ModelError,
25 ModelInfo, ModelSimilarityRequest, ModelSimilarityResponse,
26};
27use crate::services::parameter::types::ParameterSnapshot;
28use crate::services::path::path_resolver::KnownPath;
29use crate::services::shell::CommandRunMode;
30use crate::services::theme::Theme;
31use crate::services::timer::types::{TimerCallback, TimerId};
32use crate::services::IconRequest;
33
34#[async_trait]
36pub trait PluginHost: Send + Sync {
37 async fn get_icon(
43 &self,
44 request: &IconRequest,
45 level: CacheLevel,
46 ) -> Result<Vec<u8>, HostApiError>;
47
48 async fn get_icon_or_default(&self, request: &IconRequest, level: CacheLevel) -> Vec<u8>;
50
51 async fn get_icon_and_update_cache(
53 &self,
54 request: &IconRequest,
55 level: CacheLevel,
56 ) -> Result<Vec<u8>, HostApiError>;
57
58 async fn override_icon_cache(
62 &self,
63 original_request: &IconRequest,
64 custom_icon_path: &str,
65 ) -> Result<(), HostApiError>;
66
67 async fn shell_open(&self, target: OpenTarget) -> Result<(), HostApiError>;
71
72 async fn shell_open_folder(&self, path: &str) -> Result<(), HostApiError>;
74
75 async fn shell_execute_elevation(&self, path: &str) -> Result<(), HostApiError>;
77
78 async fn shell_execute_command(
81 &self,
82 command: &str,
83 mode: CommandRunMode,
84 ) -> Result<(), HostApiError>;
85
86 async fn activate_window_by_process(&self, process_name: &str) -> Result<bool, HostApiError>;
91
92 async fn activate_window_by_title(&self, title: &str) -> Result<bool, HostApiError>;
94
95 async fn activate_window_by_pid(&self, pid: u32) -> Result<bool, HostApiError>;
97
98 fn resolve_path(&self, path: KnownPath) -> Result<String, HostApiError>;
102
103 fn set_clipboard_text(&self, text: &str) -> Result<(), HostApiError>;
107
108 async fn enumerate_apps(&self) -> Vec<AppInfo>;
112
113 async fn launch_app(&self, app_id: &str, args: Option<&[String]>) -> Result<u32, HostApiError>;
115
116 fn get_app_icon_path(&self, name: &str) -> Option<String>;
120
121 fn resolve_lnk_target(&self, lnk_path: &str) -> Option<String>;
125
126 fn parse_localized_names_from_dir(&self, dir_path: &Path) -> HashMap<String, String>;
128
129 fn get_theme(&self) -> Result<Theme, HostApiError>;
134
135 fn get_system_theme(&self) -> Result<Theme, HostApiError>;
137
138 fn model_list(&self) -> Vec<ModelInfo>;
142
143 async fn model_chat(&self, req: ModelChatRequest) -> Result<ModelChatResponse, ModelError>;
145
146 async fn model_embedding(
148 &self,
149 req: ModelEmbeddingRequest,
150 ) -> Result<ModelEmbeddingResponse, ModelError>;
151
152 async fn model_similarity(
154 &self,
155 req: ModelSimilarityRequest,
156 ) -> Result<ModelSimilarityResponse, ModelError>;
157
158 async fn resolve_parameters(
162 &self,
163 template: &str,
164 user_args: &[String],
165 snapshot: &ParameterSnapshot,
166 ) -> Result<String, HostApiError>;
167
168 fn count_user_parameters(&self, template: &str) -> usize;
170
171 fn has_system_parameters(&self, template: &str) -> bool;
173
174 async fn set_timeout(
180 &self,
181 plugin_id: &str,
182 delay: Duration,
183 callback: TimerCallback,
184 ) -> Result<TimerId, HostApiError>;
185
186 async fn set_interval(
190 &self,
191 plugin_id: &str,
192 interval: Duration,
193 callback: TimerCallback,
194 ) -> Result<TimerId, HostApiError>;
195
196 async fn cancel_timer(&self, plugin_id: &str, id: TimerId) -> Result<(), HostApiError>;
199
200 async fn cancel_all_timers(&self, plugin_id: &str) -> Result<(), HostApiError>;
202
203 async fn resource_upload(
208 &self,
209 plugin_id: &str,
210 resource_id: &str,
211 file_path: &str,
212 max_size: Option<u64>,
213 ) -> Result<String, HostApiError>;
214
215 async fn resource_put(
217 &self,
218 plugin_id: &str,
219 resource_id: &str,
220 data: &[u8],
221 ) -> Result<(), HostApiError>;
222
223 async fn resource_get(
225 &self,
226 plugin_id: &str,
227 resource_id: &str,
228 ) -> Result<Vec<u8>, HostApiError>;
229
230 async fn resource_delete(&self, plugin_id: &str, resource_id: &str)
232 -> Result<(), HostApiError>;
233
234 async fn resource_list(&self, plugin_id: &str) -> Result<Vec<String>, HostApiError>;
236
237 async fn cache_put(
241 &self,
242 plugin_id: &str,
243 domain: &str,
244 key: &str,
245 data: &[u8],
246 ) -> Result<(), HostApiError>;
247
248 async fn cache_get(
250 &self,
251 plugin_id: &str,
252 domain: &str,
253 key: &str,
254 ) -> Result<Option<Vec<u8>>, HostApiError>;
255
256 async fn cache_delete(
258 &self,
259 plugin_id: &str,
260 domain: &str,
261 key: &str,
262 ) -> Result<(), HostApiError>;
263
264 async fn cache_cleanup(
266 &self,
267 plugin_id: &str,
268 domain: &str,
269 max_entries: usize,
270 ) -> Result<(), HostApiError>;
271
272 fn register_hotkey_callback(
276 &self,
277 plugin_id: &str,
278 id: &str,
279 filter: HotkeyEventFilter,
280 callback: HotkeyCallback,
281 );
282
283 fn unregister_hotkey_callback(&self, plugin_id: &str, id: &str);
285
286 fn register_installation_callback(
288 &self,
289 plugin_id: &str,
290 id: &str,
291 callback: InstallationCallback,
292 );
293
294 fn unregister_installation_callback(&self, plugin_id: &str, id: &str);
296
297 fn register_focus_callback(&self, plugin_id: &str, id: &str, callback: FocusCallback);
299
300 fn unregister_focus_callback(&self, plugin_id: &str, id: &str);
302}