mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-10-15 12:15:11 +00:00
docs: 修正全部文档使其与源码实现一致
- Plugin.Start(sdk *PluginSDK) 接口签名改为指针 - 方法表重写: 移除 CallLLM/QueryKnowledge/SetMemory 等不存在方法 - IOInjector 参数顺序修正为 (source, channel, text) - 删除虚构 SDKConfig, 替换为实际 New() 构造函数签名 - .hmap 内容描述一致化 (plugin.so + plugin.dll + main.lua) - 添加 meta/ 包元数据文件
This commit is contained in:
19
tools/plugindev/templates/README.md.tmpl
Normal file
19
tools/plugindev/templates/README.md.tmpl
Normal file
@ -0,0 +1,19 @@
|
||||
# {{.Plg.Name}}
|
||||
|
||||
{{.Plg.Description}}
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
plugindev build
|
||||
```
|
||||
|
||||
## Install
|
||||
|
||||
Upload the `.hmap` file through the Plugin Manager API:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8080/api/v1/plugins \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary @dist/<name_en_snake>_linux_amd64.hmap
|
||||
```
|
||||
55
tools/plugindev/templates/main.go.tmpl
Normal file
55
tools/plugindev/templates/main.go.tmpl
Normal file
@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitcode.com/JianFeeeee/homeagent-sdk/sdk"
|
||||
)
|
||||
|
||||
type Plugin struct {
|
||||
name string
|
||||
sdk *sdk.PluginSDK
|
||||
}
|
||||
|
||||
func NewPlugin(name string, config map[string]interface{}) (sdk.Plugin, error) {
|
||||
return &Plugin{name: name}, nil
|
||||
}
|
||||
|
||||
func (p *Plugin) Name() string { return p.name }
|
||||
|
||||
func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
p.sdk = s
|
||||
|
||||
s.Settings().RegisterDef(sdk.ConfigDef{
|
||||
Key: "plugin.{{.Plg.Name}}.example",
|
||||
Default: "hello",
|
||||
Type: "string",
|
||||
DisplayName: "示例配置",
|
||||
Description: "An example configuration key",
|
||||
Category: "{{.Plg.Name}}",
|
||||
})
|
||||
|
||||
tp := p.name + "_"
|
||||
s.RegisterTool(tp+"hello", sdk.ToolDef{
|
||||
Name: tp + "hello",
|
||||
Description: "A hello world tool",
|
||||
Parameters: map[string]interface{}{
|
||||
"type": "object",
|
||||
"properties": map[string]interface{}{},
|
||||
},
|
||||
}, p.handleHello)
|
||||
|
||||
fmt.Printf("[%s] started\n", p.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) Stop() error {
|
||||
fmt.Printf("[%s] stopped\n", p.name)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) handleHello(args map[string]interface{}) (interface{}, error) {
|
||||
return map[string]interface{}{
|
||||
"content": "Hello from {{.Plg.Name}} plugin!",
|
||||
}, nil
|
||||
}
|
||||
45
tools/plugindev/templates/main.lua.tmpl
Normal file
45
tools/plugindev/templates/main.lua.tmpl
Normal file
@ -0,0 +1,45 @@
|
||||
local plugin = {
|
||||
name = "{{.Plg.Name}}",
|
||||
tools = {},
|
||||
stages = {},
|
||||
settings = {}
|
||||
}
|
||||
|
||||
function plugin:start(sdk)
|
||||
sdk.log("{{.Plg.Name}} plugin starting...")
|
||||
|
||||
-- Register a configuration setting
|
||||
-- sdk.settings.register({
|
||||
-- key = "{{.Plg.Name}}.example",
|
||||
-- default = "hello",
|
||||
-- type = "string",
|
||||
-- display_name = "Example Config",
|
||||
-- description = "An example configuration key"
|
||||
-- })
|
||||
|
||||
-- Register a tool
|
||||
local ok = sdk:register_tool("{{.Plg.Name}}_hello", {
|
||||
name = "{{.Plg.Name}}_hello",
|
||||
description = "A hello world tool",
|
||||
parameters = {
|
||||
type = "object",
|
||||
properties = {}
|
||||
}
|
||||
}, function(args)
|
||||
return { content = "Hello from {{.Plg.Name}} plugin!" }
|
||||
end)
|
||||
|
||||
if not ok then
|
||||
sdk.log("error: failed to register tool")
|
||||
return false
|
||||
end
|
||||
|
||||
sdk.log("{{.Plg.Name}} plugin started")
|
||||
return true
|
||||
end
|
||||
|
||||
function plugin:stop()
|
||||
return true
|
||||
end
|
||||
|
||||
return plugin
|
||||
11
tools/plugindev/templates/plg.json.tmpl
Normal file
11
tools/plugindev/templates/plg.json.tmpl
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "{{.Plg.Name}}",
|
||||
"name_zh": "{{.Plg.NameZh}}",
|
||||
"name_en": "{{.Plg.NameEn}}",
|
||||
"version": "{{.Plg.Version}}",
|
||||
"description": "{{.Plg.Description}}",
|
||||
"author": "{{.Plg.Author}}",
|
||||
"entry": "{{.Plg.Entry}}",
|
||||
"tags": {{.Plg.Tags}},
|
||||
"targets": "{{.Plg.Targets}}"
|
||||
}
|
||||
Reference in New Issue
Block a user