Host SPI 索引与速查表
插件通过
self.host(即self._host_context)调用宿主。本页是导航 + 速查, 每个分组的详细契约在各自卡片里。
总览
| 分组 | 方法 | 详细 |
|---|---|---|
| 字幕与翻译 | feed_direct_caption · feed_caption · translate · translate_batch | 字幕与翻译 |
| 配置与数据 | get_plugin_config · set_plugin_config_value · save_plugin_config · get_plugin_data_dir · get_plugin_kv · set_plugin_kv · delete_plugin_kv | 配置与私有数据 |
| 会话与状态 | get_recent_conversation · get_history_as_text · get_pipeline_state · get_active_provider · list_installed_plugins · plugin_dir · has_plugin · runtime_dir · has_runtime · get_app_version · get_locale · log | 会话与宿主状态 |
| 热键 | register_plugin_hotkey · unregister_plugin_hotkeys · get_plugin_hotkeys | 全局热键 |
| 模型 | list_model_artifacts · inspect_model_artifact · download_model_artifact | 模型工件 |
| 事件 | subscribe_event · unsubscribe_event · unsubscribe_all_events | 事件总线 |
| 朗读与提示 | speak · stop_speak · is_speaking · show_toast · show_error · set_window_excluded_from_capture · set_copilot_visible · toggle_copilot_window | 朗读与提示 |
| 浮窗 | create_plugin_window · show_plugin_window · close_plugin_window · close_plugin_windows · move_plugin_window · resize_plugin_window · set_plugin_window_flags · list_plugin_windows · get_plugin_window | 插件浮窗 |
| 文件与进度 | pick_file · pick_files · pick_folder · pick_save_file · begin_progress · update_progress · end_progress · cancel_progress · is_progress_cancelled · get_progress | 文件选择与长任务 |
BasePlugin 提供的实例能力
子类可直接使用:
| 成员 | 说明 |
|---|---|
self.host | Host SPI 入口 |
self.manifest / self.id / self.name / self.plugin_type | 清单元数据 |
self._config | 当前配置字典(initialize / update_config 维护) |
initialize(config) / shutdown() / update_config(new_config) | 生命周期钩子 |
handle_action(action, params) | 分发到 action_<action>(**params) |
emit_event(name, payload) | 插件 → 前端事件 |
handle_host_event(name, payload) | 宿主 → 插件事件(可覆盖) |
subscribe_host_event(name, cb) / unsubscribe_host_event(name) | 实例级事件订阅 |
get_data_dir() | 私有数据目录(等价 host.get_plugin_data_dir(id)) |
show_toast(msg, level, timeout_ms) | 快捷方法 |
run_in_background(target, *args, **kwargs) | 守护线程执行耗时任务 |
model_artifacts() / check_ready() / requires_hf_runtime | 见 模型工件 |
ensure_loaded() / wait_async_init() | 惰性启动与异步 initialize 收敛,见 本地服务契约 |
TTS 专属:supports_voice_clone / supports_speed / list_voices() / register_voice() / remove_voice() | 见 tts |
命名约定
- 只使用蛇形名(新代码)。驼峰别名(
feedDirectCaption、registerPluginHotkey、getPluginConfig…)与本名并存 ≥ 1 个小版本,仅为兼容老插件而保留。 - bridge 上未在本文档列出的方法一律视为不稳定,不要用。
- 完整方法签名以
src/transbox/plugins/base.py的HostProtocol为准。
相关
- Provider 签名与数据类型
- 线程契约 — 哪些 API 能在哪个线程调
- 宿主实现清单
