插件与 API
本页是 RelayCraft 插件能力与 RelayCraft.api 的统一参考页。
插件可扩展范围
Section titled “插件可扩展范围”- 左侧导航页面(
api.ui.registerPage) - 标准 UI 插槽(
api.ui.registerSlot) - 流量右键菜单动作(
api.ui.registerContextMenuItem) - 规则自动化(
api.rules.createMock) - 流量分析(
api.traffic.listFlows、api.traffic.getFlow) - 运行时状态感知(
api.host.getRuntime)
插件 UI 代码会收到:
RelayCraft.api:插件作用域 APIRelayCraft.components:宿主提供的组件集合RelayCraft.icons:宿主提供的图标集合
ProxyPilot 保留为 RelayCraft 的兼容别名。
Manifest 基础结构
Section titled “Manifest 基础结构”每个插件通过 plugin.yaml 声明元信息、能力与权限。
manifestVersion: "1.0"id: "com.example.my-plugin"name: "我的插件"version: "0.1.0"entry: ui: "dist/index.js"permissions: - traffic:read - rules:writecapabilities: ui: pages: - id: "my-page" title: "我的页面" icon: "Puzzle" path: "/my-page"受限 API 在 permissions 未声明时会被宿主拦截。
| API 方法 | 所需权限 |
|---|---|
stats.getProcessStats | stats:read |
rules.list | rules:read |
rules.get | rules:read |
rules.createMock | rules:write |
traffic.listFlows | traffic:read |
traffic.getFlow | traffic:read |
host.getRuntime 不需要额外权限。
命名空间总览
Section titled “命名空间总览”t(key, options?)changeLanguage(lng)getCurrentLanguage()
register(theme)remove(themeName)list()
registerPage(page)unregisterPage(pageId)registerSlot(slotName, component, props?)unregisterSlot(slotId)registerContextMenuItem(item)unregisterContextMenuItem(itemId)toast(message, type?)
chat(messages)complete(prompt, options?)
getProcessStats()
getStatus()start()stop()restart()
settings
Section titled “settings”get(key?)set(key, value)watch(key, cb)
info(message, context?)warn(message, context?)error(message, context?)debug(message, context?)
send(request)
storage
Section titled “storage”get(key)set(key, value)remove(key)clear()list()
events
Section titled “events”on(eventName, callback)off(eventName, callback)emit(eventName, payload)
list(filter?)get(id)createMock(config)
traffic
Section titled “traffic”listFlows(filter?)getFlow(id, options?)
getRuntime()
标准插槽名称:
sidebar-topsidebar-bottomstatus-bar-leftstatus-bar-centerstatus-bar-rightflow-detail-tabsflow-detail-actions
Traffic API 数据结构
Section titled “Traffic API 数据结构”listFlows(filter?)
Section titled “listFlows(filter?)”过滤字段:
sessionId、method、host、urlPattern、statusoffset、limit
返回字段:
flows[]total、offset、limit、hasMore
getFlow(id, options?)
Section titled “getFlow(id, options?)”可选参数:
includeBodies(默认false)maxBodyBytes(默认128KB,宿主硬上限2MB)
返回值包含 request/response 元数据与规则命中信息。
- RelayCraft 保持 v1 向后兼容。
- 新能力以增量方式扩展。
- 权限检查由宿主桥在运行时强制执行。