跳转到内容
EN

插件与 API

本页是 RelayCraft 插件能力与 RelayCraft.api 的统一参考页。

  • 左侧导航页面(api.ui.registerPage)
  • 标准 UI 插槽(api.ui.registerSlot)
  • 流量右键菜单动作(api.ui.registerContextMenuItem)
  • 规则自动化——创建、编辑、停用插件自己拥有的 mock(api.rules.createMock、getOwnMock、disableMock)
  • 流量分析(api.traffic.listFlows、api.traffic.getFlow)
  • 运行时状态感知(api.host.getRuntime)

插件 UI 代码会收到:

  • RelayCraft.api:插件作用域 API
  • RelayCraft.components:宿主提供的组件集合
  • RelayCraft.icons:宿主提供的图标集合

ProxyPilot 保留为 RelayCraft 的兼容别名。

每个插件通过 plugin.yaml 声明元信息、能力与权限。

manifestVersion: "1.0"
id: "com.example.my-plugin"
name: "我的插件"
version: "0.1.0"
entry:
ui: "dist/index.js"
permissions:
- traffic:read
- rules:write
capabilities:
ui:
pages:
- id: "my-page"
title: "我的页面"
icon: "Puzzle"
path: "/my-page"

受限 API 在 permissions 未声明时会被宿主拦截。

API 方法所需权限
ai.chat、ai.chatStreamai:chat
http.sendnetwork:outbound
proxy.getStatusproxy:read
stats.getProcessStatsstats:read
storage.get、storage.liststorage:read
storage.set、storage.delete、storage.clearstorage:write
rules.list、rules.getrules:read
rules.createMock、rules.disableMock、rules.getOwnMockrules:write
traffic.listFlows、traffic.getFlowtraffic:read

host.getRuntime 以及 ui/theme/i18n/log/events/settings 调用不需要额外权限。

  • t(key, options?)
  • language
  • onLanguageChange(callback)——返回取消订阅函数
  • registerLocale(lang, resources)
  • register(theme)
  • set(themeId)
  • registerPage(page)
  • registerSlot(slotId, options)——options.component
  • registerContextMenuItem(config)
  • toast(message, type?)
  • components——宿主共享组件:Editor、DiffEditor、Markdown
  • chat(messages)
  • chatStream(messages, onChunk, options?)
  • isEnabled()
  • getProcessStats()
  • getStatus()
  • get(key?)——读取插件自身的设置
  • info(message, context?)
  • warn(message, context?)
  • error(message, error?)
  • send(request)
  • get(key)
  • set(key, value)
  • delete(key)
  • list(prefix?)
  • clear()
  • on(eventName, callback)——返回取消订阅函数
  • list(filter?)
  • get(id)
  • createMock(config)——返回新规则 ID
  • getOwnMock(ruleId)——获取本插件创建的 mock,用于编辑
  • disableMock(ruleId)——停用本插件创建的 mock
  • listFlows(filter?)
  • getFlow(id, options?)
  • getRuntime()

标准插槽名称:

  • sidebar-top
  • sidebar-bottom
  • status-bar-left
  • status-bar-center
  • status-bar-right
  • flow-detail-tabs
  • flow-detail-actions

过滤字段:

  • sessionId、method、host、urlPattern、status
  • offset、limit

返回字段:

  • flows[]
  • total、offset、limit、hasMore

可选参数:

  • includeBodies(默认 false)
  • maxBodyBytes(默认 128KB,宿主硬上限 2MB)

返回值包含 request/response 元数据与规则命中信息。

  • RelayCraft 保持 v1 向后兼容。
  • 新能力以增量方式扩展。
  • 权限检查由宿主桥在运行时强制执行。