feat(llm): 大模型双协议(OpenAI+Anthropic)接入 + SSH凭证修复 + 容量预测AI解读

后端双协议: 新增 anthropic.go(Complete/Stream/工具转换) + client.go 工厂按 Protocol 路由; llm.Client 加 Stream; llm_chat 三方法收敛复用 llm.Client; resolveProtocol 按 provider 路由; Agent CLI 注入协议。编码套餐(GLM-5.2/Kimi/MiMo/Anthropic)走 Anthropic /v1/messages。

SSH凭证修复: applyCredential 正确解析凭证 JSON 的 private_key(旧实现把整个 JSON 当私钥 → ssh.ParsePrivateKey 失败 → ssh-key 登录不通); AssignCredential/批量导入/单台 CRUD 三处统一; 单台补齐 credential_id 字段(原被忽略)。

容量预测: 新增 AI 深度解读(buildCapacityInsightPrompt + PredictiveCapacityTab 按钮, 复用 aiApi.chat)。

其他: DeepSeek 模型名更新为 deepseek-v4-flash/pro; 智能助手去掉重复模型配置按钮; LLMConfig 精简生成参数(Claude Code 式)。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
LoganandClaude committed 2026-06-28 22:37:46 +08:00
1 parent c0ee8e4ddd
commit 0b2e43ea9e
16 files changed
+689 -296

No files matched your search

+13 -14
View File
@@ -30,26 +30,24 @@ func (h *ServerHandler) BatchCreateServers(c *gin.Context) {
authType = "password"
}
// 如果指定了凭据,提前解密 // Logan.Li
var decryptedPwd, decryptedKey string
// 如果指定了凭据,提前解密(plain 在循环内由 applyCredential 解析填充) // Logan.Li
var (
hasCred bool
cred model.Credential
credPlain string
)
if req.CredentialID != nil && *req.CredentialID > 0 {
var cred model.Credential
if err := h.db.First(&cred, *req.CredentialID).Error; err != nil {
c.JSON(http.StatusBadRequest, model.Response{Code: 400, Message: "凭据不存在"})
return
}
plain, err := h.crypt.Decrypt(cred.Content)
p, err := h.crypt.Decrypt(cred.Content)
if err != nil {
c.JSON(http.StatusInternalServerError, model.Response{Code: 500, Message: "凭据解密失败"})
return
}
if cred.SecretType == "ssh" {
decryptedKey = plain
authType = "key"
} else {
decryptedPwd = plain
authType = "password"
}
credPlain = p
hasCred = true
}
result := model.BatchCreateResult{Errors: []string{}}
@@ -84,9 +82,7 @@ func (h *ServerHandler) BatchCreateServers(c *gin.Context) {
IP: ip,
Port: port,
Username: username,
AuthType: authType,
Password: decryptedPwd,
SSHKey: decryptedKey,
AuthType: authType, // 无凭证时用请求 authType(默认 password)
OS: item.OS,
CPU: item.CPU,
Memory: item.Memory * 1024, // GB → MB
@@ -95,6 +91,9 @@ func (h *ServerHandler) BatchCreateServers(c *gin.Context) {
RegionID: req.RegionID,
Status: "stopped",
}
if hasCred {
applyCredential(cred, credPlain, &server) // 有凭证则覆盖认证字段(ssh→私钥/ssh_user/ssh_port) // Logan.Li
}
if err := h.db.Create(&server).Error; err != nil {
result.Failed++
result.Errors = append(result.Errors, fmt.Sprintf("%s(%s): %s", hostname, ip, err.Error()))