1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::sync::Arc;
4
5pub const NAVI_PLUGIN_API_VERSION: u32 = 2;
6pub const NAVI_PLUGIN_ENTRYPOINT: &[u8] = b"navi_plugin_entrypoint";
7
8pub type PluginCreate = unsafe fn() -> Box<dyn NaviPlugin>;
9
10pub trait NaviPlugin: Send + Sync {
11 fn metadata(&self) -> PluginMetadata;
12 fn register(&self, registry: &mut dyn PluginRegistry) -> Result<(), String>;
13}
14
15pub trait PluginRegistry {
16 fn register_tool(&mut self, tool: Arc<dyn PluginTool>);
17 fn register_agent_policy(&mut self, name: &str);
18 fn register_tui_component(&mut self, name: &str);
19}
20
21pub trait PluginTool: Send + Sync {
24 fn definition(&self) -> PluginToolDefinition;
25 fn invoke(&self, invocation: PluginToolInvocation) -> Result<PluginToolResult, String>;
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct PluginToolDefinition {
30 pub name: String,
31 pub description: String,
32 pub kind: PluginToolKind,
33 #[serde(default)]
34 pub input_schema: Value,
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
38pub enum PluginToolKind {
39 Read,
40 Write,
41 Command,
42 Custom,
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46pub struct PluginToolInvocation {
47 pub id: String,
48 pub tool_name: String,
49 pub input: Value,
50}
51
52#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
53pub struct PluginToolResult {
54 pub invocation_id: String,
55 pub ok: bool,
56 pub output: Value,
57}
58
59#[derive(Debug, Clone)]
60pub struct PluginMetadata {
61 pub name: String,
62 pub version: String,
63 pub api_version: u32,
64 pub capabilities: Vec<PluginCapability>,
65}
66
67#[derive(Debug, Clone)]
68pub enum PluginCapability {
69 FileSystem,
70 Shell,
71 Network,
72 Tui,
73 Model,
74 Session,
75}