refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/contract"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/ai"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"github.com/mlogclub/simple/sqls"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type evaluationPlatformAIProvider struct{}
|
||||
|
||||
func (evaluationPlatformAIProvider) ModelSource(context.Context) (string, error) {
|
||||
return contract.ModelSourcePlatform, nil
|
||||
}
|
||||
|
||||
func (evaluationPlatformAIProvider) Config(context.Context) (*contract.PlatformAIConfig, error) {
|
||||
return &contract.PlatformAIConfig{
|
||||
APIKey: "license-signed",
|
||||
BaseURL: "https://platform.example/v1",
|
||||
ModelName: "platform-default",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (evaluationPlatformAIProvider) Status(context.Context) (*contract.PlatformAIStatus, error) {
|
||||
return &contract.PlatformAIStatus{Enabled: true}, nil
|
||||
}
|
||||
|
||||
func TestRunAgentEvaluationResolvesPlatformWithoutCustomConfig(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open("file:"+strings.ReplaceAll(t.Name(), "/", "_")+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&models.AIAgent{}); err != nil {
|
||||
t.Fatalf("auto migrate: %v", err)
|
||||
}
|
||||
sqls.SetDB(db)
|
||||
agent := &models.AIAgent{Name: "platform-agent", Status: enums.StatusOk, AIConfigID: 0}
|
||||
if err := db.Create(agent).Error; err != nil {
|
||||
t.Fatalf("create agent: %v", err)
|
||||
}
|
||||
|
||||
ai.SetPlatformAIProvider(evaluationPlatformAIProvider{})
|
||||
t.Cleanup(func() { ai.SetPlatformAIProvider(nil) })
|
||||
|
||||
report, err := RunAgentEvaluation(context.Background(), request.RunAgentEvaluationRequest{AIAgentID: agent.ID})
|
||||
if err != nil {
|
||||
t.Fatalf("RunAgentEvaluation() error = %v", err)
|
||||
}
|
||||
if report.Total != 0 || !strings.Contains(report.CSV, "case_id") {
|
||||
t.Fatalf("RunAgentEvaluation() = %+v", report)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user