This repository has been archived on 2026-08-12. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Cyrene/backend/plugins/README.md
T

63 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 第三方插件目录
将插件文件夹放入此目录,运行代码生成器即可自动注册——无需手动编辑 `plugins.json`
## 目录结构
```
plugins/
my-hello/
go.mod # Go 模块声明(module xxx
plugin.json # 插件声明(name, struct
main.go # 插件入口
...
```
## 注册(2 步)
**1. 放入插件**:将插件目录复制到 `backend/plugins/` 下。
**2. 运行生成器**
```bash
cd backend/ai-core/cmd && go run gen_plugins.go
```
生成器会自动:
- 扫描 `plugins/` 下所有子目录
- 读取每个目录的 `plugin.json``go.mod`
- 生成 `plugins_gen.go`(含 import + 注册代码)
- 自动向 `go.mod` 添加 `require` + `replace` 指令
**3. 重新编译**
```bash
cd backend/ai-core && go build -o main.exe ./cmd/
```
或使用 `go generate`
```bash
cd backend/ai-core && go generate ./cmd/...
```
## plugin.json 格式
```json
{
"name": "my-hello",
"struct": "HelloPlugin"
}
```
| 字段 | 必填 | 说明 |
|------|------|------|
| name | ✅ | 插件唯一名称 |
| struct | ✅ | 插件结构体名(实现 Plugin 接口的那个类型) |
`import` 路径自动从 `go.mod``module` 声明读取,无需手写。
## 插件开发
详见 [docs/api/plugin-development.md](../../docs/api/plugin-development.md)