refactor: 将客服后端重构为宿主可嵌入模块
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"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/enums"
|
||||
|
||||
@@ -12,6 +16,48 @@ import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type runtimePlatformAIProvider struct{}
|
||||
|
||||
func (runtimePlatformAIProvider) ModelSource(context.Context) (string, error) {
|
||||
return contract.ModelSourcePlatform, nil
|
||||
}
|
||||
|
||||
type runtimeVisionOnlyPlatformAIProvider struct{}
|
||||
|
||||
func (runtimeVisionOnlyPlatformAIProvider) ModelSource(context.Context) (string, error) {
|
||||
return contract.ModelSourcePlatform, nil
|
||||
}
|
||||
|
||||
func (runtimeVisionOnlyPlatformAIProvider) Config(context.Context) (*contract.PlatformAIConfig, error) {
|
||||
return &contract.PlatformAIConfig{
|
||||
APIKey: "platform-managed",
|
||||
BaseURL: "https://platform.example/v1",
|
||||
ChatEnabled: false,
|
||||
ChatModel: "qwen-plus",
|
||||
VisionEnabled: true,
|
||||
VisionModel: "qwen3-vl-plus",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (runtimeVisionOnlyPlatformAIProvider) Status(context.Context) (*contract.PlatformAIStatus, error) {
|
||||
return &contract.PlatformAIStatus{VisionEnabled: true, VisionModel: "qwen3-vl-plus"}, nil
|
||||
}
|
||||
|
||||
func (runtimePlatformAIProvider) Config(context.Context) (*contract.PlatformAIConfig, error) {
|
||||
return &contract.PlatformAIConfig{
|
||||
APIKey: "license-signed",
|
||||
BaseURL: "https://platform.example/v1",
|
||||
ModelName: "platform-default",
|
||||
TimeoutMS: 30000,
|
||||
MaxRetryCount: 1,
|
||||
HTTPClient: &http.Client{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (runtimePlatformAIProvider) Status(context.Context) (*contract.PlatformAIStatus, error) {
|
||||
return &contract.PlatformAIStatus{Enabled: true}, nil
|
||||
}
|
||||
|
||||
func TestAgentApplicationServiceLoadsConsistentPersistedRequest(t *testing.T) {
|
||||
db, err := gorm.Open(sqlite.Open("file:"+strings.ReplaceAll(t.Name(), "/", "_")+"?mode=memory&cache=shared"), &gorm.Config{})
|
||||
if err != nil {
|
||||
@@ -52,3 +98,32 @@ func TestAgentApplicationServiceRejectsMismatchedMessage(t *testing.T) {
|
||||
t.Fatal("expected invalid identifiers error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveRuntimeAIConfigUsesPlatformWithoutCustomConfig(t *testing.T) {
|
||||
ai.SetPlatformAIProvider(runtimePlatformAIProvider{})
|
||||
t.Cleanup(func() { ai.SetPlatformAIProvider(nil) })
|
||||
|
||||
config, err := ResolveRuntimeAIConfig(context.Background(), 0)
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveRuntimeAIConfig() error = %v", err)
|
||||
}
|
||||
if !config.Platform || config.ModelName != "platform-default" || config.APIKey != "license-signed" {
|
||||
t.Fatalf("ResolveRuntimeAIConfig() = %+v", config)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveRuntimeAIConfigForImageUsesVisionWhenChatIsDisabled(t *testing.T) {
|
||||
ai.SetPlatformAIProvider(runtimeVisionOnlyPlatformAIProvider{})
|
||||
t.Cleanup(func() { ai.SetPlatformAIProvider(nil) })
|
||||
|
||||
config, err := ResolveRuntimeAIConfigForMessage(context.Background(), 0, enums.IMMessageTypeImage)
|
||||
if err != nil {
|
||||
t.Fatalf("ResolveRuntimeAIConfigForMessage(image) error = %v", err)
|
||||
}
|
||||
if config.ModelName != "qwen3-vl-plus" || !config.VisionEnabled {
|
||||
t.Fatalf("ResolveRuntimeAIConfigForMessage(image) = %+v", config)
|
||||
}
|
||||
if _, err := ResolveRuntimeAIConfigForMessage(context.Background(), 0, enums.IMMessageTypeText); err == nil || !strings.Contains(err.Error(), "chat model is not enabled") {
|
||||
t.Fatalf("text must still require chat capability, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user