hide unavailable channels in webui

This commit is contained in:
lpf
2026-03-10 14:46:34 +08:00
parent 4a1b5f27e4
commit 594897c9bb
20 changed files with 110 additions and 30 deletions

View File

@@ -1188,9 +1188,10 @@ func (s *Server) handleWebUIVersion(w http.ResponseWriter, r *http.Request) {
return
}
_ = json.NewEncoder(w).Encode(map[string]interface{}{
"ok": true,
"gateway_version": firstNonEmptyString(s.gatewayVersion, gatewayBuildVersion()),
"webui_version": firstNonEmptyString(s.webuiVersion, detectWebUIVersion(strings.TrimSpace(s.webUIDir))),
"ok": true,
"gateway_version": firstNonEmptyString(s.gatewayVersion, gatewayBuildVersion()),
"webui_version": firstNonEmptyString(s.webuiVersion, detectWebUIVersion(strings.TrimSpace(s.webUIDir))),
"compiled_channels": channels.CompiledChannelKeys(),
})
}
@@ -1523,8 +1524,9 @@ func (s *Server) webUISubagentsRuntimePayload(ctx context.Context) map[string]in
func (s *Server) webUIVersionPayload() map[string]interface{} {
return map[string]interface{}{
"gateway_version": firstNonEmptyString(s.gatewayVersion, gatewayBuildVersion()),
"webui_version": firstNonEmptyString(s.webuiVersion, detectWebUIVersion(strings.TrimSpace(s.webUIDir))),
"gateway_version": firstNonEmptyString(s.gatewayVersion, gatewayBuildVersion()),
"webui_version": firstNonEmptyString(s.webuiVersion, detectWebUIVersion(strings.TrimSpace(s.webUIDir))),
"compiled_channels": channels.CompiledChannelKeys(),
}
}

View File

@@ -0,0 +1,30 @@
package channels
import "sort"
func CompiledChannelKeys() []string {
out := make([]string, 0, 7)
if telegramCompiled {
out = append(out, "telegram")
}
if whatsappCompiled {
out = append(out, "whatsapp")
}
if discordCompiled {
out = append(out, "discord")
}
if feishuCompiled {
out = append(out, "feishu")
}
if qqCompiled {
out = append(out, "qq")
}
if dingtalkCompiled {
out = append(out, "dingtalk")
}
if maixcamCompiled {
out = append(out, "maixcam")
}
sort.Strings(out)
return out
}

View File

@@ -30,6 +30,8 @@ type DingTalkChannel struct {
sessionWebhooks sync.Map // chatID -> sessionWebhook
}
const dingtalkCompiled = true
// NewDingTalkChannel creates a new DingTalk channel instance
func NewDingTalkChannel(cfg config.DingTalkConfig, messageBus *bus.MessageBus) (*DingTalkChannel, error) {
if cfg.ClientID == "" || cfg.ClientSecret == "" {

View File

@@ -9,6 +9,8 @@ import (
type DingTalkChannel struct{ disabledChannel }
const dingtalkCompiled = false
func NewDingTalkChannel(cfg config.DingTalkConfig, bus *bus.MessageBus) (*DingTalkChannel, error) {
return nil, errChannelDisabled("dingtalk")
}

View File

@@ -23,6 +23,8 @@ type DiscordChannel struct {
config config.DiscordConfig
}
const discordCompiled = true
func NewDiscordChannel(cfg config.DiscordConfig, bus *bus.MessageBus) (*DiscordChannel, error) {
session, err := discordgo.New("Bot " + cfg.Token)
if err != nil {

View File

@@ -9,6 +9,8 @@ import (
type DiscordChannel struct{ disabledChannel }
const discordCompiled = false
func NewDiscordChannel(cfg config.DiscordConfig, bus *bus.MessageBus) (*DiscordChannel, error) {
return nil, errChannelDisabled("discord")
}

View File

@@ -45,6 +45,8 @@ type FeishuChannel struct {
tenantTokenErr error
}
const feishuCompiled = true
func (c *FeishuChannel) SupportsAction(action string) bool {
switch strings.ToLower(strings.TrimSpace(action)) {
case "", "send":

View File

@@ -9,6 +9,8 @@ import (
type FeishuChannel struct{ disabledChannel }
const feishuCompiled = false
func NewFeishuChannel(cfg config.FeishuConfig, bus *bus.MessageBus) (*FeishuChannel, error) {
return nil, errChannelDisabled("feishu")
}

View File

@@ -22,6 +22,8 @@ type MaixCamChannel struct {
clientsMux sync.RWMutex
}
const maixcamCompiled = true
type MaixCamMessage struct {
Type string `json:"type"`
Tips string `json:"tips"`

View File

@@ -9,6 +9,8 @@ import (
type MaixCamChannel struct{ disabledChannel }
const maixcamCompiled = false
func NewMaixCamChannel(cfg config.MaixCamConfig, bus *bus.MessageBus) (*MaixCamChannel, error) {
return nil, errChannelDisabled("maixcam")
}

View File

@@ -31,6 +31,8 @@ type QQChannel struct {
mu sync.RWMutex
}
const qqCompiled = true
func NewQQChannel(cfg config.QQConfig, messageBus *bus.MessageBus) (*QQChannel, error) {
base := NewBaseChannel("qq", cfg, messageBus, cfg.AllowFrom)

View File

@@ -9,6 +9,8 @@ import (
type QQChannel struct{ disabledChannel }
const qqCompiled = false
func NewQQChannel(cfg config.QQConfig, bus *bus.MessageBus) (*QQChannel, error) {
return nil, errChannelDisabled("qq")
}

View File

@@ -38,6 +38,8 @@ const (
telegramStreamMaxRetries = 4
)
const telegramCompiled = true
type TelegramChannel struct {
*BaseChannel
bot *telego.Bot

View File

@@ -9,6 +9,8 @@ import (
type TelegramChannel struct{ disabledChannel }
const telegramCompiled = false
func NewTelegramChannel(cfg config.TelegramConfig, bus *bus.MessageBus) (*TelegramChannel, error) {
return nil, errChannelDisabled("telegram")
}

View File

@@ -30,6 +30,8 @@ type WhatsAppChannel struct {
connected bool
}
const whatsappCompiled = true
func NewWhatsAppChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus) (*WhatsAppChannel, error) {
base := NewBaseChannel("whatsapp", cfg, bus, cfg.AllowFrom)

View File

@@ -9,6 +9,8 @@ import (
type WhatsAppChannel struct{ disabledChannel }
const whatsappCompiled = false
func NewWhatsAppChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus) (*WhatsAppChannel, error) {
return nil, errChannelDisabled("whatsapp")
}