mirror of
https://gitcode.com/JianFeeeee/homeagent-sdk.git
synced 2026-09-21 01:18:02 +00:00
feat: sdk NoMemory/Cleaner + example build fixes
- sdk/plugin.go: ToolDef adds NoMemory/Cleaner fields - sdk/plugin_test.go: unit tests for NoMemory/Cleaner - all example plugins: NoMemory/Cleaner annotated for each tool - plugindev/templates.go: template shows NoMemory/Cleaner pattern - plugindev/cmd_build.go: fix ensureGoMod, buildBundle/buildTarget sdkPath param, NewPluginFactory - example/go.mod: add external dependency declarations (chromedp, gofeed) - add main.go stubs for all example plugins
This commit is contained in:
@ -51,7 +51,7 @@ type BrowserSession struct {
|
||||
currentURL string
|
||||
}
|
||||
|
||||
func NewPlugin(name string, config map[string]interface{}) (sdk.Plugin, error) {
|
||||
func NewPluginFactory(name string, config map[string]interface{}) (sdk.Plugin, error) {
|
||||
return &Plugin{name: name, stopCh: make(chan struct{}), sessions: make(map[string]*BrowserSession)}, nil
|
||||
}
|
||||
|
||||
@ -188,6 +188,14 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
|
||||
tp := p.name + "_"
|
||||
|
||||
cleaner := func(output string) string {
|
||||
var r struct{ Content string }
|
||||
if json.Unmarshal([]byte(output), &r) == nil && r.Content != "" {
|
||||
return r.Content
|
||||
}
|
||||
return output
|
||||
}
|
||||
|
||||
s.RegisterTool(tp+"search", sdk.ToolDef{
|
||||
Name: tp + "search",
|
||||
Description: "使用 Bing 搜索网页。返回标题、URL 和摘要。",
|
||||
@ -199,6 +207,7 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
},
|
||||
"required": []string{"query"},
|
||||
},
|
||||
Cleaner: cleaner,
|
||||
}, p.handleSearch)
|
||||
|
||||
s.RegisterTool(tp+"fetch", sdk.ToolDef{
|
||||
@ -213,6 +222,7 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
},
|
||||
"required": []string{"url"},
|
||||
},
|
||||
Cleaner: cleaner,
|
||||
}, p.handleFetch)
|
||||
|
||||
s.RegisterTool(tp+"render", sdk.ToolDef{
|
||||
@ -226,6 +236,7 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
|
||||
},
|
||||
"required": []string{"url"},
|
||||
},
|
||||
Cleaner: cleaner,
|
||||
}, p.handleRender)
|
||||
|
||||
s.RegisterTool(tp+"start", sdk.ToolDef{
|
||||
|
||||
Reference in New Issue
Block a user