diff --git a/README.md b/README.md index 6b59c9d..cc40214 100644 --- a/README.md +++ b/README.md @@ -171,7 +171,7 @@ internal/ ## 项目状态 -**v0.7.2** — 核心可用,插件系统和 SDK 已就绪。内置 11 个插件,外部插件开发见 [homeagent-sdk](https://gitcode.com/JianFeeeee/homeagent-sdk) 仓库,使用 `plugindev` 工具链。输出通道系统、受限外部插件 API、EventAgentLLMChain 事件已上线。 +**v0.8.0** — 核心可用,插件系统增强。内置 20+ 插件,外部插件开发见 [homeagent-sdk](https://gitcode.com/JianFeeeee/homeagent-sdk) 仓库。新增输入通道 `NoMemory`/`Cleaner`、`ChannelDef`、插件禁用/启用系统(CLI + WebUI),`plugindev` 工具链完成 C ABI `ChannelDef` 传递。 ## 文档 diff --git a/README_EN.md b/README_EN.md index 896d68c..fdd3697 100644 --- a/README_EN.md +++ b/README_EN.md @@ -171,7 +171,7 @@ External plugin development: see [homeagent-sdk](https://gitcode.com/JianFeeeee/ ## Project Status -**v0.7.2** — Core is functional, plugin system and SDK are ready. 11 built-in plugins. External plugin development via [homeagent-sdk](https://gitcode.com/JianFeeeee/homeagent-sdk) repo using `plugindev` toolchain. Output channel system, restricted external plugin API, and EventAgentLLMChain event are live. +**v0.8.0** — Core is functional, plugin system enhanced. 20+ built-in plugins. External plugin development via [homeagent-sdk](https://gitcode.com/JianFeeeee/homeagent-sdk) repo. Added input channel `NoMemory`/`Cleaner`, `ChannelDef`, plugin disable/enable system (CLI + WebUI), `plugindev` toolchain C ABI `ChannelDef` support. ## Documentation diff --git a/assets/docs/en/PLUGIN_DEV.md b/assets/docs/en/PLUGIN_DEV.md index cde53d2..5d2aa23 100644 --- a/assets/docs/en/PLUGIN_DEV.md +++ b/assets/docs/en/PLUGIN_DEV.md @@ -361,6 +361,41 @@ s.InjectInterruptText(source, channel, text string) s.InjectTextNoMemory(source, channel, text string) ``` +#### Input Channel Registration — Declare External Message Sources + +```go +s.RegisterInputChannel("qq", sdk.ChannelDef{ + NoMemory: true, + Cleaner: func(text string) string { + return strings.TrimSpace(text) + }, +}) +``` + +`ChannelDef` controls channel behavior in the memory computation layer: + +| Field | Default | Description | +|-------|---------|-------------| +| `NoMemory` | `false` | Channel input/output skips vectorization/keyword/distillation; original text preserved in context | +| `Cleaner` | `nil` | `func(string) string` computation filter (does not modify original text) | + +Noisy sources (QQ group messages, RSS feeds, etc.) should set `NoMemory: true`. + +#### Output Channel Registration — Declare Output Destinations + +```go +s.RegisterOutputChannel("email", 1, "Send Email", sdk.ChannelDef{ + NoMemory: true, +}, func(args map[string]interface{}) (interface{}, error) { + to, _ := args["to"].(string) + subject, _ := args["subject"].(string) + body, _ := args["body"].(string) + return map[string]interface{}{"status": "sent"}, nil +}) +``` + +Parameters: `name` (route key), `caps` (1=text/2=rich/4=file/8=image), `desc`, `def` (ChannelDef), `handler` (callback). + #### Event Subscription ```go @@ -603,7 +638,42 @@ import ( : -## 6. Example Plugin Reference +## 6. Plugin Management + +### CLI Commands + +```bash +/plugin list # List all plugins with status (loaded/disabled) +/plugin disable # Disable plugin (immediate, no longer receives input) +/plugin enable # Enable plugin (restored after restart) +/plugin reload # Reload all plugins +``` + +### WebUI + +Dashboard plugin list provides "Disable/Enable" buttons in the actions column. Disabling WebUI itself shows a confirmation dialog to prevent misoperation. + +### Built-in Plugin API + +```go +pmgr := s.PluginMgr() +pmgr.DisablePlugin("qq", "admin") // Disable +pmgr.EnablePlugin("qq") // Enable +list := pmgr.ListDisabledPlugins() // List disabled plugins +loaded := pmgr.ListLoadedPlugins() // List loaded plugins +pmgr.IsPluginDisabled("qq") // Check if disabled +pmgr.ReloadPlugins() // Reload all plugins +``` + +Internal: records are stored in SQLite `disabled_plugins` table (`name`, `disabled_at`, `disabled_by`). Disabling takes effect immediately (plugin stops receiving input); full removal requires a restart. + +> **Note**: `PluginMgr()` is only available to built-in plugins; external dynamic plugins cannot call it directly. + +--- + + : + +## 7. Example Plugin Reference ### SDK Repository Examples (`homeagent-sdk/example/`) diff --git a/assets/docs/zh/PLUGIN_DEV.md b/assets/docs/zh/PLUGIN_DEV.md index c9884c4..c95780d 100644 --- a/assets/docs/zh/PLUGIN_DEV.md +++ b/assets/docs/zh/PLUGIN_DEV.md @@ -359,6 +359,41 @@ s.InjectInterruptText(source, channel, text string) s.InjectTextNoMemory(source, channel, text string) ``` +#### 输入通道注册 — 声明外部消息源 + +```go +s.RegisterInputChannel("qq", sdk.ChannelDef{ + NoMemory: true, + Cleaner: func(text string) string { + return strings.TrimSpace(text) + }, +}) +``` + +`ChannelDef` 控制通道在记忆计算层的行为: + +| 字段 | 默认 | 说明 | +|------|------|------| +| `NoMemory` | `false` | 通道输入/输出不参与向量化/关键词/蒸馏,原文保留 | +| `Cleaner` | `nil` | `func(string) string` 计算层过滤(不改原文) | + +噪声源通道(QQ 群消息、RSS 等)建议 `NoMemory: true`。 + +#### 输出通道注册 — 声明输出目的地 + +```go +s.RegisterOutputChannel("email", 1, "邮件发送", sdk.ChannelDef{ + NoMemory: true, +}, func(args map[string]interface{}) (interface{}, error) { + to, _ := args["to"].(string) + subject, _ := args["subject"].(string) + body, _ := args["body"].(string) + return map[string]interface{}{"status": "sent"}, nil +}) +``` + +参数:`name`(路由名)、`caps`(1=文本/2=富文本/4=文件/8=图片)、`desc`、`def`(ChannelDef)、`handler`(处理函数)。 + #### 事件订阅 ```go @@ -601,7 +636,42 @@ import ( : -## 六、示例插件参考 +## 六、插件管理 + +### CLI 命令 + +```bash +/plugin list # 列出所有插件及状态(已加载/已禁用) +/plugin disable # 禁用插件(立即生效,不再接收输入) +/plugin enable # 启用插件(重启后恢复加载) +/plugin reload # 重载所有插件 +``` + +### WebUI + +Dashboard 插件列表的操作列提供「禁用/启用」按钮。禁用 WebUI 自身时会弹出确认对话框,防止误操作。 + +### 内置插件 API + +```go +pmgr := s.PluginMgr() +pmgr.DisablePlugin("qq", "admin") // 禁用 +pmgr.EnablePlugin("qq") // 启用 +list := pmgr.ListDisabledPlugins() // 列出已禁用插件 +loaded := pmgr.ListLoadedPlugins() // 列出已加载插件 +pmgr.IsPluginDisabled("qq") // 检查是否已禁用 +pmgr.ReloadPlugins() // 重载所有插件 +``` + +内部机制:禁用记录存储在 SQLite `disabled_plugins` 表(`name`, `disabled_at`, `disabled_by`),禁用立即生效(插件不再接收输入),完全卸载需重启内核。 + +> **注意**:`PluginMgr()` 仅内置插件可用,外部动态插件无法直接调用。 + +--- + + : + +## 七、示例插件参考 ### SDK 仓库示例(`homeagent-sdk/example/`)