example: 新增 acp(ACP 代理通信)、vanblog(VanBlog 博客管理) 插件; 多插件工具调用检测与清理改进; weather 移除 onRemove/文本记忆; plugindev 精简

This commit is contained in:
JianFeeeee
2026-08-15 09:03:05 +08:00
parent b6e30f9279
commit cca9fdce9c
30 changed files with 2408 additions and 228 deletions

View File

@ -5,8 +5,6 @@ import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strconv"
"strings"
"time"
@ -19,7 +17,6 @@ type Plugin struct {
sdk *sdk.PluginSDK
client *http.Client
defaultLoc string
dataDir string
}
func NewPluginFactory(name string, config map[string]interface{}) (sdk.Plugin, error) {
@ -45,16 +42,6 @@ func (p *Plugin) Start(s *sdk.PluginSDK) error {
}
}
dataHome := os.Getenv("HOME")
if dataHome == "" {
dataHome = "/tmp"
}
p.dataDir = filepath.Join(dataHome, ".homeagent", "weather")
os.MkdirAll(p.dataDir, 0755)
// 卸载(删除)时清理天气缓存目录;重载不触发
s.RegisterOnRemoveHandler(p.cleanupData)
tp := p.name + "_"
s.RegisterTool(tp+"current", sdk.ToolDef{
Name: tp + "current", Description: "Get current weather for a city",
@ -299,15 +286,6 @@ func (p *Plugin) handleCurrent(args map[string]interface{}) (interface{}, error)
cc.Humidity, cc.WindspeedKmph, windUnit, cc.Winddir16Point,
obsTime)
// 文本记忆每次查询写入一条历史记录role=tool 便于追溯)
if p.sdk.TextMemory() != nil {
_ = p.sdk.TextMemory().Append(sdk.TextEvent{
Role: "tool",
Content: fmt.Sprintf("weather %s: %s", place, desc),
Channel: p.name,
})
}
return map[string]interface{}{
"content": result,
"location": place,
@ -395,7 +373,11 @@ func (p *Plugin) handleForecast(args map[string]interface{}) (interface{}, error
sunset = day.Astronomy[0].Sunset
}
line := fmt.Sprintf(" %s %s/%s — %s~%s%s %s", weekday, day.Date[5:], day.Date[8:], minT, maxT, unitStr, desc)
datePart := ""
if len(day.Date) >= 8 {
datePart = day.Date[5:7] + "/" + day.Date[8:]
}
line := fmt.Sprintf(" %s %s — %s~%s%s %s", weekday, datePart, minT, maxT, unitStr, desc)
if precip != "" {
line += precip
}
@ -428,10 +410,3 @@ func (p *Plugin) handleSetLocation(args map[string]interface{}) (interface{}, er
p.defaultLoc = loc
return map[string]interface{}{"content": fmt.Sprintf("Default location set to: %s", loc)}, nil
}
// cleanupData 卸载时清理天气缓存目录
func (p *Plugin) cleanupData() {
if p.dataDir != "" {
os.RemoveAll(p.dataDir)
}
}