1use serde::{Deserialize, Serialize};
2use crate::permissions::Permission;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct PluginManifest {
7 pub id: String,
8 pub name: String,
9 pub version: String,
10 pub description: String,
11 #[serde(default)]
12 pub long_description: Option<String>,
13 pub author: String,
14 #[serde(default)]
15 pub author_url: Option<String>,
16 #[serde(default)]
17 pub homepage: Option<String>,
18 #[serde(default)]
19 pub license: Option<String>,
20 #[serde(default)]
21 pub keywords: Vec<String>,
22 #[serde(default)]
23 pub icon: Option<String>,
24
25 pub compatibility: CompatibilitySpec,
26
27 pub capability_levels: Vec<CapabilityLevel>,
29
30 #[serde(default)]
32 pub integration: IntegrationConfig,
33
34 #[serde(default)]
36 pub window: WindowPolicyConfig,
37
38 #[serde(default)]
40 pub entry: EntryConfig,
41
42 #[serde(default)]
44 pub dependencies: Vec<PluginDependency>,
45
46 #[serde(default)]
48 pub permissions: Vec<Permission>,
49
50 #[serde(default)]
53 pub host_capabilities: Vec<HostCapability>,
54
55 #[serde(default)]
57 pub settings_schema: Option<serde_json::Value>,
58
59 #[serde(default)]
61 pub commands: Vec<CommandDeclaration>,
62
63 #[serde(default)]
65 pub checksum: Option<String>,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct CompatibilitySpec {
70 pub min_app_version: String,
71 #[serde(default)]
72 pub min_host_api_version: Option<String>,
73 #[serde(default)]
74 pub max_app_version: Option<String>,
75 #[serde(default = "all_platforms")]
76 pub platforms: Vec<String>,
77}
78
79fn all_platforms() -> Vec<String> {
80 vec!["windows".into(), "macos".into(), "linux".into()]
81}
82
83#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
85#[serde(from = "u8", into = "u8")]
86pub enum CapabilityLevel {
87 Module = 0,
89 ModuleFeature = 1,
91 UiExtension = 2,
93 AiAssistant = 3,
95 Service = 4,
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
101#[serde(rename_all = "snake_case")]
102pub enum HostCapability {
103 Navigation,
104 AppState,
105 FileIntents,
106 FileDialogs,
107 #[serde(rename = "aichat")]
108 AiChat,
109 EnterpriseGateway,
110 DeepLinks,
111 ThemeRead,
112 EventSubscribe,
113}
114
115impl HostCapability {
116 pub fn as_str(&self) -> &'static str {
117 match self {
118 Self::Navigation => "navigation",
119 Self::AppState => "app_state",
120 Self::FileIntents => "file_intents",
121 Self::FileDialogs => "file_dialogs",
122 Self::AiChat => "aichat",
123 Self::EnterpriseGateway => "enterprise_gateway",
124 Self::DeepLinks => "deep_links",
125 Self::ThemeRead => "theme_read",
126 Self::EventSubscribe => "event_subscribe",
127 }
128 }
129}
130
131impl From<u8> for CapabilityLevel {
132 fn from(v: u8) -> Self {
133 match v {
134 0 => Self::Module,
135 1 => Self::ModuleFeature,
136 2 => Self::UiExtension,
137 3 => Self::AiAssistant,
138 4 => Self::Service,
139 _ => Self::Service,
140 }
141 }
142}
143
144impl From<CapabilityLevel> for u8 {
145 fn from(l: CapabilityLevel) -> u8 {
146 l as u8
147 }
148}
149
150#[derive(Debug, Clone, Default, Serialize, Deserialize)]
152pub struct IntegrationConfig {
153 #[serde(default)]
154 pub level0: Option<Level0Config>,
155 #[serde(default)]
156 pub level1: Option<Level1Config>,
157 #[serde(default)]
158 pub level2: Option<Level2Config>,
159 #[serde(default)]
160 pub level3: Option<Level3Config>,
161 #[serde(default)]
162 pub level4: Option<Level4Config>,
163}
164
165#[derive(Debug, Clone, Default, Serialize, Deserialize)]
171pub struct WindowPolicyConfig {
172 #[serde(default)]
175 pub default_open_mode: Option<String>,
176 #[serde(default)]
178 pub reuse_key: Option<String>,
179 #[serde(default)]
182 pub allow_multiple: Option<bool>,
183 #[serde(default)]
185 pub document_handlers: Vec<DocumentHandlerConfig>,
186}
187
188#[derive(Debug, Clone, Default, Serialize, Deserialize)]
190pub struct DocumentHandlerConfig {
191 #[serde(default)]
193 pub id: Option<String>,
194 #[serde(default)]
196 pub label: Option<String>,
197 #[serde(default)]
199 pub extensions: Vec<String>,
200 #[serde(default)]
202 pub mime_types: Vec<String>,
203 pub route: String,
205 #[serde(default)]
207 pub resource_param: Option<String>,
208 #[serde(default)]
210 pub open_mode: Option<String>,
211 #[serde(default)]
213 pub reuse_key: Option<String>,
214 #[serde(default)]
216 pub allow_multiple: Option<bool>,
217}
218
219#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct Level0Config {
222 pub module_id: String,
224 pub module_label: String,
225 pub module_icon: String,
227 #[serde(default = "default_sidebar_position")]
229 pub sidebar_position: String,
230 #[serde(default = "default_sidebar_order")]
232 pub sidebar_order: u32,
233 pub panel_entry: String,
235}
236
237fn default_sidebar_position() -> String { "main".into() }
238fn default_sidebar_order() -> u32 { 100 }
239
240#[derive(Debug, Clone, Serialize, Deserialize)]
242pub struct Level1Config {
243 pub parent_module: String,
245 pub tab_id: String,
247 pub tab_label: String,
248 pub tab_icon: String,
250 #[serde(default)]
252 pub tab_position: Option<String>,
253 pub panel_entry: String,
255}
256
257#[derive(Debug, Clone, Serialize, Deserialize)]
259pub struct Level2Config {
260 pub slots: Vec<String>,
262}
263
264#[derive(Debug, Clone, Serialize, Deserialize)]
266pub struct Level3Config {
267 pub assistant_id: String,
268 pub assistant_name: String,
269 #[serde(default)]
270 pub assistant_icon: Option<String>,
271 #[serde(default)]
272 pub assistant_description: Option<String>,
273 pub system_prompt_file: String,
275 #[serde(default)]
277 pub preferred_model: Option<String>,
278}
279
280#[derive(Debug, Clone, Default, Serialize, Deserialize)]
282pub struct Level4Config {
283 #[serde(default)]
285 pub workflow_step_types: Vec<String>,
286}
287
288#[derive(Debug, Clone, Default, Serialize, Deserialize)]
290pub struct EntryConfig {
291 #[serde(default)]
292 pub native: Option<NativeEntry>,
293 #[serde(default)]
294 pub frontend: Option<String>,
295 #[serde(default)]
296 pub frontend_styles: Option<String>,
297}
298
299#[derive(Debug, Clone, Default, Serialize, Deserialize)]
300pub struct NativeEntry {
301 #[serde(default)]
302 pub macos_arm64: Option<String>,
303 #[serde(default)]
304 pub macos_x64: Option<String>,
305 #[serde(default)]
306 pub windows_x64: Option<String>,
307 #[serde(default)]
308 pub windows_arm64: Option<String>,
309 #[serde(default)]
310 pub linux_x64: Option<String>,
311 #[serde(default)]
312 pub linux_arm64: Option<String>,
313}
314
315impl NativeEntry {
316 pub fn for_current_platform(&self) -> Option<&str> {
318 #[cfg(all(target_os = "macos", target_arch = "aarch64"))]
319 return self.macos_arm64.as_deref();
320
321 #[cfg(all(target_os = "macos", target_arch = "x86_64"))]
322 return self.macos_x64.as_deref();
323
324 #[cfg(all(target_os = "windows", target_arch = "x86_64"))]
325 return self.windows_x64.as_deref();
326
327 #[cfg(all(target_os = "windows", target_arch = "aarch64"))]
328 return self.windows_arm64.as_deref();
329
330 #[cfg(all(target_os = "linux", target_arch = "x86_64"))]
331 return self.linux_x64.as_deref();
332
333 #[cfg(all(target_os = "linux", target_arch = "aarch64"))]
334 return self.linux_arm64.as_deref();
335
336 #[allow(unreachable_code)]
337 None
338 }
339}
340
341#[derive(Debug, Clone, Serialize, Deserialize)]
342pub struct PluginDependency {
343 pub id: String,
344 pub version: String,
346}
347
348#[derive(Debug, Clone, Serialize, Deserialize)]
349pub struct CommandDeclaration {
350 pub id: String,
351 #[serde(default)]
352 pub description: Option<String>,
353}
354
355#[cfg(test)]
356mod tests {
357 use super::{HostCapability, PluginManifest};
358
359 #[test]
360 fn manifest_supports_public_host_api_fields() {
361 let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
362 "id": "dev.haloforge.example",
363 "name": "Example",
364 "version": "0.1.0",
365 "description": "Example plugin",
366 "author": "HaloForge Team",
367 "compatibility": {
368 "min_app_version": "0.1.0",
369 "min_host_api_version": "0.1.0",
370 "platforms": ["windows"]
371 },
372 "capability_levels": [2],
373 "host_capabilities": ["navigation", "aichat"],
374 "integration": {
375 "level2": { "slots": ["devkit.toolbar"] }
376 }
377 }))
378 .expect("manifest should deserialize");
379
380 assert_eq!(
381 manifest.compatibility.min_host_api_version.as_deref(),
382 Some("0.1.0")
383 );
384 assert_eq!(
385 manifest.host_capabilities,
386 vec![HostCapability::Navigation, HostCapability::AiChat]
387 );
388 }
389
390 #[test]
391 fn manifest_supports_window_policy_document_handlers() {
392 let manifest: PluginManifest = serde_json::from_value(serde_json::json!({
393 "id": "dev.haloforge.markdown",
394 "name": "Markdown",
395 "version": "0.2.13",
396 "description": "Markdown plugin",
397 "author": "HaloForge Team",
398 "compatibility": {
399 "min_app_version": "0.8.0",
400 "min_host_api_version": "0.2.16",
401 "platforms": ["windows", "macos", "linux"]
402 },
403 "capability_levels": [0],
404 "host_capabilities": ["navigation", "file_intents"],
405 "integration": {
406 "level0": {
407 "module_id": "markdown",
408 "module_label": "Markdown",
409 "module_icon": "FileText",
410 "panel_entry": "app/dist/index.js"
411 }
412 },
413 "window": {
414 "default_open_mode": "reuse_or_new",
415 "reuse_key": "resource",
416 "allow_multiple": true,
417 "document_handlers": [{
418 "id": "markdown",
419 "label": "Markdown",
420 "extensions": [".md", ".markdown"],
421 "mime_types": ["text/markdown"],
422 "route": "/document",
423 "resource_param": "path"
424 }]
425 }
426 }))
427 .expect("manifest should deserialize");
428
429 assert_eq!(manifest.window.default_open_mode.as_deref(), Some("reuse_or_new"));
430 assert_eq!(manifest.window.reuse_key.as_deref(), Some("resource"));
431 assert_eq!(manifest.window.allow_multiple, Some(true));
432 let handler = manifest
433 .window
434 .document_handlers
435 .first()
436 .expect("document handler should deserialize");
437 assert_eq!(handler.extensions, vec![".md", ".markdown"]);
438 assert_eq!(handler.mime_types, vec!["text/markdown"]);
439 assert_eq!(handler.route, "/document");
440 assert_eq!(handler.resource_param.as_deref(), Some("path"));
441 }
442
443 #[test]
444 fn host_capability_names_are_stable() {
445 assert_eq!(HostCapability::FileIntents.as_str(), "file_intents");
446 assert_eq!(HostCapability::FileDialogs.as_str(), "file_dialogs");
447 assert_eq!(HostCapability::DeepLinks.as_str(), "deep_links");
448 assert_eq!(HostCapability::ThemeRead.as_str(), "theme_read");
449 }
450}