feat(server): provider switching API, WS/REST cancel, summarize endpoints

This commit is contained in:
OpenClaw Dev 2026-10-25 04:48:09 +01:00
parent f1b2093b22
commit 49fdc5a189
7 changed files with 463 additions and 28 deletions

View file

@ -17,6 +17,7 @@ import (
"github.com/crypto/byteclaw/internal/agent"
"github.com/crypto/byteclaw/internal/config"
"github.com/crypto/byteclaw/internal/llm"
"github.com/crypto/byteclaw/internal/providers"
"github.com/crypto/byteclaw/internal/server"
"github.com/crypto/byteclaw/internal/store"
"github.com/crypto/byteclaw/internal/tools"
@ -71,10 +72,16 @@ func run(cfgPath string, log *slog.Logger) error {
reg.Register(sh)
log.Warn("shell tool enabled", "allowed", sc.AllowedCommands)
}
prov := llm.NewOpenAI(cfg.LLM.BaseURL, cfg.LLM.APIKey, cfg.LLM.Model, cfg.LLM.Temperature, time.Duration(cfg.LLM.TimeoutSec)*time.Second)
ag := &agent.Agent{LLM: prov, Tools: reg, Store: st, SystemPrompt: cfg.Agent.SystemPrompt,
MaxIterations: cfg.Agent.MaxIterations, HistoryLimit: cfg.Agent.HistoryLimit}
srv := &server.Server{Agent: ag, Store: st, Token: cfg.AuthToken, AllowedOrigins: cfg.AllowedOrigins, Log: log,
pm := providers.New(cfg.LLM, os.Getenv, st)
sm := cfg.Agent.Summarize
ag := &agent.Agent{Tools: reg, Store: st, SystemPrompt: cfg.Agent.SystemPrompt,
MaxIterations: cfg.Agent.MaxIterations, HistoryLimit: cfg.Agent.HistoryLimit,
Summarize: agent.SummarizeConfig{Enabled: sm.Enabled, MaxMessages: sm.MaxMessages, MaxTokens: sm.MaxTokens, KeepRecent: sm.KeepRecent},
Resolve: func(ctx context.Context, sid string) (llm.Provider, error) {
p, _, err := pm.ForSession(ctx, sid)
return p, err
}}
srv := &server.Server{Agent: ag, Store: st, Token: cfg.AuthToken, AllowedOrigins: cfg.AllowedOrigins, Log: log, Providers: pm,
Info: server.Info{Version: version, Provider: cfg.LLM.Provider, Model: cfg.LLM.Model, BaseURL: cfg.LLM.BaseURL},
RunTimeout: time.Duration(cfg.LLM.TimeoutSec*cfg.Agent.MaxIterations) * time.Second}
@ -83,7 +90,7 @@ func run(cfgPath string, log *slog.Logger) error {
defer stop()
errc := make(chan error, 1)
go func() {
log.Info("byteclaw listening", "addr", cfg.Listen, "provider", cfg.LLM.Provider, "model", cfg.LLM.Model, "tools", len(reg.Specs()), "version", version)
log.Info("byteclaw listening", "addr", cfg.Listen, "provider", pm.Active().Provider, "model", pm.Active().Model, "tools", len(reg.Specs()), "version", version)
errc <- hs.ListenAndServe()
}()
select {