概览
此包提供了类型定义和显示验证符,用于 任务控制代理 (AMC)插件. 它是插件工程的 dev 依赖性 — 它为沙盒提供 TypeScript 接口 PluginContext 您的后端代码收到 AgentMC 浏览器连接您使用的 UI 代码, 以及用于构建时检查的 Zod 动力显示验证器 .
安装
npm install @agent-mc/plugin-sdk --save-dev
使用量
后端类型
import type { PluginActivate, PluginContext } from '@agent-mc/plugin-sdk'
const activate: PluginActivate = (ctx) => {
return {
async onEnable() {
const data = await ctx.storage.get('config')
ctx.log.info('Plugin enabled', data)
},
async onShutdown() {
ctx.log.info('Goodbye')
},
}
}
export default activate
浏览器桥型
import type { AgentMC } from '@agent-mc/plugin-sdk/browser'
declare global {
interface Window { AgentMC: AgentMC }
}
const settings = await window.AgentMC.settings.getAll()
表面验证
import { validateManifest } from '@agent-mc/plugin-sdk/validators'
const result = validateManifest(manifest)
if (!result.valid) {
console.error(result.errors)
}
插件连接 API
每个后端插件都收到一个 PluginContext 具有这些沙箱能力:
| 能力 | 接口 | 权限 | 说明 |
|---|---|---|---|
storage | PluginStorage | storage | 钥匙价值商店get, (中文(简体) ), set, (中文(简体) ), delete, (中文(简体) ), list(中文(简体) ) |
db | PluginDb | storage | SQLite 收藏库 (insert, (中文(简体) ), query, (中文(简体) ), getById, (中文(简体) ), update, (中文(简体) ), delete(中文(简体) ) |
fs | PluginFs | storage | 沙盒文件系统( S)readFile, (中文(简体) ), writeFile, (中文(简体) ), exists, (中文(简体) ), listDir(中文(简体) ) |
sessions | PluginSessions | sessions | 创建和管理 Claude 代码会话 |
ai | PluginAi | ai | 直接 AI 文本生成( R)generateMessage, (中文(简体) ), generateTitle(中文(简体) ) |
http | PluginHttp | network | 输出的 HTTP 请求( E)fetch(中文(简体) ) |
cron | PluginCron | cron | 排定的经常性任务 |
cli | PluginCli | cli | AMC 控制服务器上的 HTTP 端点 |
toast | PluginToast | notifications* 联合国 | 草签和操作系统通知 |
sidebar | PluginSidebar | —— 说 | 徽章计数和导航项目 |
settings | PluginSettings | —— 说 | 读取插件设置( N)getAll, (中文(简体) ), get(中文(简体) ) |
log | PluginLogger | —— 说 | 范围伐木info, (中文(简体) ), warn, (中文(简体) ), error, (中文(简体) ), debug(中文(简体) ) |
events | PluginEvents | —— 说 | Pub/子事件系统(emit, (中文(简体) ), on(中文(简体) ) |
* 联合国 toast.show() 总是有的;只有 toast.notify() (OS级)要求 notifications 允许.
权限
宣布为 manifest.json AMC在安装和运行时显示:
{
"permissions": ["storage", "network", "ai"]
}
| 权限 | 赠款 |
|---|---|
storage | ctx.storage, (中文(简体) ), ctx.db, (中文(简体) ), ctx.fs |
sessions | ctx.sessions |
ai | ctx.ai |
network | ctx.http |
cron | ctx.cron |
cli | ctx.cli |
notifications | ctx.toast.notify() |
rss | 访问 AMC 内置的 RSS 种子数据 |
出口
该套装提供了五个切入点:
| 导入路径 | 它提供的东西 |
|---|---|
@agent-mc/plugin-sdk | 所有类型脚本类型 + validateManifest() + 键 manifestSchema + 键 checkCommandTables() |
@agent-mc/plugin-sdk/browser | AgentMC 用户界面插件的浏览器桥型 |
@agent-mc/plugin-sdk/validators | Zod 显示计划和验证功能 |
@agent-mc/plugin-sdk/commands | createCommandChannel (后端)和 createCommandClient (平面板):私人命令频道代理无法写入 |
@agent-mc/plugin-sdk/testing | createTestContext, (中文(简体) ), createRpcDouble 财务报告和审定财务报表 describeForgedRowsAreInert 用于插件测试 |
后端生命周期
interface PluginBackend {
onEnable?(): Promise<void> | void
onDisable?(): Promise<void> | void
onSettingsChanged?(settings: Record<string, unknown>): Promise<void> | void
onAppReady?(): Promise<void> | void
onShutdown?(): Promise<void> | void
}
文档
完整指南、 API 参考和实例 : Omniscio 插件 SDK 文档