Initial commit: Cyrene Plugins SDK + Plugin Manager
Extracted from Cyrene main repo (backend/pkg/plugins + backend/plugin-manager). Contains SDK interfaces (Plugin/Tool/HostAPI), 13 built-in plugins, ToolRegistry with call log ring buffer, and Plugin Manager REST API service. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/calculator"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/crypto"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/datetime"
|
||||
fileplugin "git.yeij.top/AskaEth/Cyrene-Plugins/file"
|
||||
httpplugin "git.yeij.top/AskaEth/Cyrene-Plugins/http"
|
||||
iotcontrol "git.yeij.top/AskaEth/Cyrene-Plugins/iot_control"
|
||||
iotquery "git.yeij.top/AskaEth/Cyrene-Plugins/iot_query"
|
||||
jsonplugin "git.yeij.top/AskaEth/Cyrene-Plugins/json"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/manager"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/markdown"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/random"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/sdk"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/text"
|
||||
webfetch "git.yeij.top/AskaEth/Cyrene-Plugins/web_fetch"
|
||||
websearch "git.yeij.top/AskaEth/Cyrene-Plugins/web_search"
|
||||
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/cmd/plugin-manager/internal/config"
|
||||
"git.yeij.top/AskaEth/Cyrene-Plugins/cmd/plugin-manager/internal/handler"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := config.Load()
|
||||
|
||||
var iotAPI iotquery.IoTClient
|
||||
if cfg.IoTSvcURL != "" {
|
||||
iotAPI = newIoTClient(cfg.IoTSvcURL)
|
||||
}
|
||||
|
||||
registry := manager.NewToolRegistry()
|
||||
host := newHostAPI(registry)
|
||||
mgr := manager.NewPluginManager(registry, host)
|
||||
|
||||
builtins := []sdk.Plugin{
|
||||
&calculator.CalculatorPlugin{},
|
||||
&datetime.DatetimePlugin{},
|
||||
&text.TextPlugin{},
|
||||
&crypto.CryptoPlugin{},
|
||||
&random.RandomPlugin{},
|
||||
&markdown.MarkdownPlugin{},
|
||||
&jsonplugin.JSONPlugin{},
|
||||
fileplugin.NewFilePlugin(cfg.DataDir),
|
||||
httpplugin.NewHTTPPlugin(),
|
||||
websearch.NewWebSearchPlugin(),
|
||||
webfetch.NewWebFetchPlugin(),
|
||||
iotquery.NewIoTQueryPlugin(iotAPI),
|
||||
}
|
||||
for _, p := range builtins {
|
||||
if err := mgr.Install(p); err != nil {
|
||||
println("WARN: install plugin failed:", err.Error())
|
||||
}
|
||||
}
|
||||
if iotAPI != nil {
|
||||
ctrlPlugin := iotcontrol.NewIoTControlPlugin(newIoTControllerAdapter(iotAPI, cfg.IoTSvcURL))
|
||||
if err := mgr.Install(ctrlPlugin); err != nil {
|
||||
println("WARN: install plugin failed:", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
errs := mgr.EnableAll(ctx)
|
||||
for _, e := range errs {
|
||||
println("WARN: enable plugin failed:", e.Error())
|
||||
}
|
||||
println("Plugin Manager: all built-in plugins enabled")
|
||||
|
||||
mux := http.NewServeMux()
|
||||
ph := handler.NewPluginHandler(mgr)
|
||||
ph.RegisterRoutes(mux)
|
||||
|
||||
println("Plugin Manager listening on port", cfg.Port)
|
||||
srv := &http.Server{Addr: ":" + cfg.Port, Handler: mux}
|
||||
|
||||
go func() {
|
||||
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||
println("FATAL:", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-quit
|
||||
println("Shutting down Plugin Manager...")
|
||||
|
||||
shutdownCtx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
mgr.Shutdown(shutdownCtx)
|
||||
srv.Shutdown(shutdownCtx)
|
||||
println("Plugin Manager stopped")
|
||||
}
|
||||
Reference in New Issue
Block a user