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:
JianFeeeee
2026-07-25 11:17:21 +08:00
parent 34f91ebd1a
commit cb7999ca71
54 changed files with 682 additions and 475 deletions

View File

@ -2,6 +2,7 @@ package main
import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"log"
@ -38,6 +39,17 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
"language": map[string]interface{}{"type": "string", "description": "识别语言,默认 chi_sim+eng中文简体+英文),可选 chi_sim / eng / chi_sim+eng"},
},
},
Cleaner: func(output string) string {
var r struct{ Text string }
if json.Unmarshal([]byte(output), &r) == nil && r.Text != "" {
return r.Text
}
var r2 struct{ Content string }
if json.Unmarshal([]byte(output), &r2) == nil && r2.Content != "" {
return r2.Content
}
return output
},
}, p.handleOcrImage)
log.Printf("[%s] plugin started", p.name)
@ -128,7 +140,6 @@ func (p *Plugin) handleOcrImage(args map[string]interface{}) (interface{}, error
}, nil
}
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}, nil
}
}