18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package registry_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"code.tczkiot.com/wlw/ai-agent/internal/ai/runtime/registry"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
|
"code.tczkiot.com/wlw/ai-agent/internal/pkg/toolx"
|
|
|
|
einotool "github.com/cloudwego/eino/components/tool"
|
|
"github.com/cloudwego/eino/schema"
|
|
)
|
|
|
|
type stubTool struct {
|
|
name string
|
|
code string
|
|
}
|
|
|
|
func (t stubTool) Spec() toolx.ToolSpec {
|
|
return toolx.ToolSpec{
|
|
Code: t.code,
|
|
Name: t.name,
|
|
ServerCode: toolx.GraphHandoffConversation.ServerCode,
|
|
SourceType: toolx.GraphHandoffConversation.SourceType,
|
|
}
|
|
}
|
|
|
|
func (t stubTool) Name() string { return t.name }
|
|
func (t stubTool) Code() string { return t.code }
|
|
func (t stubTool) Enabled(registry.Context) bool {
|
|
return true
|
|
}
|
|
func (t stubTool) Build(registry.Context) (einotool.BaseTool, error) {
|
|
return stubBaseTool{name: t.name}, nil
|
|
}
|
|
|
|
type stubBaseTool struct {
|
|
name string
|
|
}
|
|
|
|
func (t stubBaseTool) Info(context.Context) (*schema.ToolInfo, error) {
|
|
return &schema.ToolInfo{Name: t.name}, nil
|
|
}
|
|
|
|
func TestResolveBuildsStaticToolMetadata(t *testing.T) {
|
|
r := registry.NewRegistry(stubTool{
|
|
name: toolx.GraphHandoffConversation.Name,
|
|
code: toolx.GraphHandoffConversation.Code,
|
|
})
|
|
toolSet, err := r.Resolve(registry.Context{
|
|
Conversation: models.Conversation{ID: 1},
|
|
AIAgent: models.AIAgent{ID: 1},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("resolve returned error: %v", err)
|
|
}
|
|
if toolSet == nil {
|
|
t.Fatalf("expected tool set")
|
|
}
|
|
if len(toolSet.StaticToolMetadata) != 1 {
|
|
t.Fatalf("expected 1 metadata item, got %d", len(toolSet.StaticToolMetadata))
|
|
}
|
|
item, ok := toolSet.StaticToolMetadata[toolx.GraphHandoffConversation.Name]
|
|
if !ok {
|
|
t.Fatalf("missing metadata for %s", toolx.GraphHandoffConversation.Name)
|
|
}
|
|
if item.ToolCode != toolx.GraphHandoffConversation.Code {
|
|
t.Fatalf("unexpected tool code: %s", item.ToolCode)
|
|
}
|
|
if item.ServerCode != toolx.GraphHandoffConversation.ServerCode {
|
|
t.Fatalf("unexpected server code: %s", item.ServerCode)
|
|
}
|
|
if item.ToolName != toolx.GraphHandoffConversation.Name {
|
|
t.Fatalf("unexpected tool name: %s", item.ToolName)
|
|
}
|
|
if item.SourceType != toolx.GraphHandoffConversation.SourceType {
|
|
t.Fatalf("unexpected source type: %s", item.SourceType)
|
|
}
|
|
}
|