fix: Phase 6联调 — 插件管理器端口修正 + 多模型配置系统整合 + 历史消息刷新修复
## 调试日志
### 1. 插件管理器启动失败
- **症状**: DevTools 显示插件管理器一直"已停止",手动启动正常
- **排查**: 对比 process-manager.js 传入的环境变量 vs plugin-manager config.go 读取的变量
- **根因**: config.js 传入 PLUGIN_MANAGER_PORT=8094,但 config.go 读取 os.Getenv("PORT"),env 名不匹配。且 process.env 中 PORT 泄露时被误读为 9090,与 DevTools 端口冲突
- **修复**: config.js 将 PLUGIN_MANAGER_PORT → PORT,使 env 名与代码一致 (c3055f4)
### 2. 历史消息刷新后消失
- **症状**: 浏览器刷新后聊天历史清空
- **排查**: WebSocket history_response handler 中 if (msg.messages) 对空数组 [] 为 truthy
- **根因**: 后端返回空的 history_response (缓存为空) 时,空数组覆盖了 HTTP 已加载的消息
- **修复**: useWebSocket.ts 改为 if (msg.messages && msg.messages.length > 0),空数组走 else-if 分支仅打日志,不覆盖已有消息
### 3. Phase 6 多模型配置系统
- Gateway: ModelsConfigStore (JSON文件持久化) + Admin CRUD API (providers/models/routing)
- ai-core: ModelSelector 支持按 purpose 选择 + fallback_chain,无配置时回退 .env
- DevTools: 模型配置管理面板 (Providers/Models/Routing 三Tab)、在线模型查询代理、路由表单 checkbox 多选、关键词搜索过滤
- .gitignore: models.json + platform_configs.json
### 4. 多端客户端追踪
- Hub 新增 knownClients 映射 (clientID → KnownClient),在线/离线状态追踪
- 客户端备注持久化到 PostgreSQL
- DevTools 客户端管理面板
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ProviderData mirrors the Gateway ProviderConfig JSON shape.
|
||||
type ProviderData struct {
|
||||
Name string `json:"name"`
|
||||
BaseURL string `json:"base_url"`
|
||||
APIKey string `json:"api_key"`
|
||||
TimeoutSec int `json:"timeout_sec"`
|
||||
MaxRetries int `json:"max_retries"`
|
||||
APIVersion string `json:"api_version,omitempty"`
|
||||
ExtraHeaders map[string]string `json:"extra_headers,omitempty"`
|
||||
}
|
||||
|
||||
// ModelData mirrors the Gateway ModelConfig JSON shape.
|
||||
type ModelData struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Provider string `json:"provider"`
|
||||
Description string `json:"description"`
|
||||
Priority int `json:"priority"`
|
||||
Tags []string `json:"tags"`
|
||||
Params map[string]interface{} `json:"params"`
|
||||
Enabled bool `json:"enabled"`
|
||||
}
|
||||
|
||||
// RoutingData mirrors the Gateway RoutingRule JSON shape.
|
||||
type RoutingData struct {
|
||||
Purpose string `json:"purpose"`
|
||||
FallbackChain []string `json:"fallback_chain"`
|
||||
Required bool `json:"required"`
|
||||
}
|
||||
|
||||
// ModelsConfigData is the top-level config document (read-only mirror).
|
||||
type ModelsConfigData struct {
|
||||
Version string `json:"version"`
|
||||
Providers map[string]*ProviderData `json:"providers"`
|
||||
Models map[string]*ModelData `json:"models"`
|
||||
Routing map[string]*RoutingData `json:"routing"`
|
||||
}
|
||||
|
||||
// Loader provides read-only access to models.json.
|
||||
type Loader struct {
|
||||
mu sync.RWMutex
|
||||
path string
|
||||
config *ModelsConfigData
|
||||
}
|
||||
|
||||
// NewLoader reads models.json and returns a Loader. Returns nil config if file doesn't exist.
|
||||
func NewLoader(path string) (*Loader, error) {
|
||||
l := &Loader{
|
||||
path: path,
|
||||
config: &ModelsConfigData{
|
||||
Version: "1.0",
|
||||
Providers: make(map[string]*ProviderData),
|
||||
Models: make(map[string]*ModelData),
|
||||
Routing: make(map[string]*RoutingData),
|
||||
},
|
||||
}
|
||||
if err := l.load(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return l, nil
|
||||
}
|
||||
|
||||
func (l *Loader) load() error {
|
||||
data, err := os.ReadFile(l.path)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
l.config = nil // Signal: use .env fallback.
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("read model config: %w", err)
|
||||
}
|
||||
if len(data) == 0 {
|
||||
l.config = nil
|
||||
return nil
|
||||
}
|
||||
var cfg ModelsConfigData
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return fmt.Errorf("parse model config: %w", err)
|
||||
}
|
||||
if cfg.Providers == nil {
|
||||
cfg.Providers = make(map[string]*ProviderData)
|
||||
}
|
||||
if cfg.Models == nil {
|
||||
cfg.Models = make(map[string]*ModelData)
|
||||
}
|
||||
if cfg.Routing == nil {
|
||||
cfg.Routing = make(map[string]*RoutingData)
|
||||
}
|
||||
l.config = &cfg
|
||||
return nil
|
||||
}
|
||||
|
||||
// HasConfig returns true if models.json exists and contains data.
|
||||
func (l *Loader) HasConfig() bool {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
return l.config != nil && (len(l.config.Providers) > 0 || len(l.config.Models) > 0)
|
||||
}
|
||||
|
||||
// Reload re-reads the config file. Used for config updates without restart.
|
||||
func (l *Loader) Reload() error {
|
||||
return l.load()
|
||||
}
|
||||
|
||||
// GetConfig returns the current config (read-only).
|
||||
func (l *Loader) GetConfig() *ModelsConfigData {
|
||||
l.mu.RLock()
|
||||
defer l.mu.RUnlock()
|
||||
return l.config
|
||||
}
|
||||
Reference in New Issue
Block a user