Skip to content

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.hostHost 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 为准。

相关 ​

TransBox - 赋能全人类无界限跨语言交流