Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Configurable {
    // Required methods
    fn init<'life0, 'life1, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        handle: Option<Arc<PluginHandle>>,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn query<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        query: &'life2 Query,
    ) -> Pin<Box<dyn Future<Output = Result<QueryResponse, PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn execute_action<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        ctx: &'life1 PluginContext,
        action_id: &'life2 str,
        payload: Value,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn interaction_policy(&self) -> PanelInteraction { ... }
    fn match_query<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        raw_query: &'life1 str,
        declared_trigger_keywords: &'life2 [String],
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

所有插件对象都需实现的核心契约。 服务于插件生命周期管理、查询处理与动作执行。 配置管理能力由 Configurable trait 提供。

Required Methods§

Source

fn init<'life0, 'life1, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, handle: Option<Arc<PluginHandle>>, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

插件初始化钩子。

handle 为宿主注入的平台服务句柄:进程内(内置)插件持有 Some(Arc<PluginHandle>);远端插件进程无宿主句柄(跨进程不可序列化), 收到 None,平台能力经 SDK host() 的 host/* RPC 访问。

Source

fn query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, query: &'life2 Query, ) -> Pin<Box<dyn Future<Output = Result<QueryResponse, PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Source

fn execute_action<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, ctx: &'life1 PluginContext, action_id: &'life2 str, payload: Value, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

执行插件动作。 action_id 为插件在 ListItem.actions / CustomPanel.actions / 面板按键 绑定中声明的动作标识;payload 形状由触发通道决定(插件应两种都兼容):

  • 候选确认通道(搜索栏结果列表 / 行内参数 / 参数面板确认): {"candidate_id": <u64>, "query_text": <str>, "user_args": [<str>]};
  • 面板动作通道(PanelKeyAction::Custom 面板按键绑定):插件自定义自由 JSON, 宿主原样透传。

Provided Methods§

Source

fn interaction_policy(&self) -> PanelInteraction

返回插件当前生效的交互策略(防抖延迟、提交行为等)。 这是一次快速、同步的调用,不涉及 IO 或网络。 默认返回无防抖、Execute 提交的交互策略。

Source

fn match_query<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, raw_query: &'life1 str, declared_trigger_keywords: &'life2 [String], ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

查询匹配:判定当前原始输入是否由本插件接管(行内插件路由的唯一判定入口)。

默认实现即框架的关键词判定:declared_trigger_keywords(宿主随判定请求传入的、 该插件在清单/代码中声明的触发词)中任一项等于输入首词且其后有内容时返回 true。 因此不覆盖本方法的插件行为与旧版关键词路由完全一致。

需要自定义判定的插件覆盖本方法即可(如形态检测器),自行决定何时返回 true。

契约:必须快速、不涉及 IO 或网络(每次按键都会执行,慢判定直接体现为输入延迟); 存在性/可达性等需要 IO 的判定放到 query() 内(那里是 async 且可自行超时)。 远端插件经 plugin/match_query RPC 调用;旧 SDK 未实现该方法时宿主按 METHOD_NOT_FOUND 用同一份关键词判定兜底,失败/超时按不命中处理。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§