2026-04-13 19:23:53 +08:00
|
|
|
package registry_test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-08-21 00:41:07 +08:00
|
|
|
"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"
|
2026-04-13 19:23:53 +08:00
|
|
|
|
|
|
|
|
einotool "github.com/cloudwego/eino/components/tool"
|
|
|
|
|
"github.com/cloudwego/eino/schema"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type stubTool struct {
|
|
|
|
|
name string
|
|
|
|
|
code string
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-14 09:56:37 +08:00
|
|
|
func (t stubTool) Spec() toolx.ToolSpec {
|
|
|
|
|
return toolx.ToolSpec{
|
|
|
|
|
Code: t.code,
|
|
|
|
|
Name: t.name,
|
2026-08-28 22:23:13 +08:00
|
|
|
ServerCode: toolx.GraphHandoffConversation.ServerCode,
|
|
|
|
|
SourceType: toolx.GraphHandoffConversation.SourceType,
|
2026-04-14 09:56:37 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-13 19:23:53 +08:00
|
|
|
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{
|
2026-08-28 22:23:13 +08:00
|
|
|
name: toolx.GraphHandoffConversation.Name,
|
|
|
|
|
code: toolx.GraphHandoffConversation.Code,
|
2026-04-13 19:23:53 +08:00
|
|
|
})
|
|
|
|
|
toolSet, err := r.Resolve(registry.Context{
|
2026-04-17 18:48:45 +08:00
|
|
|
Conversation: models.Conversation{ID: 1},
|
2026-04-17 17:57:01 +08:00
|
|
|
AIAgent: models.AIAgent{ID: 1},
|
2026-04-13 19:23:53 +08:00
|
|
|
})
|
|
|
|
|
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))
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
item, ok := toolSet.StaticToolMetadata[toolx.GraphHandoffConversation.Name]
|
2026-04-13 19:23:53 +08:00
|
|
|
if !ok {
|
2026-08-28 22:23:13 +08:00
|
|
|
t.Fatalf("missing metadata for %s", toolx.GraphHandoffConversation.Name)
|
2026-04-13 19:23:53 +08:00
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
if item.ToolCode != toolx.GraphHandoffConversation.Code {
|
2026-04-13 19:23:53 +08:00
|
|
|
t.Fatalf("unexpected tool code: %s", item.ToolCode)
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
if item.ServerCode != toolx.GraphHandoffConversation.ServerCode {
|
2026-04-13 19:23:53 +08:00
|
|
|
t.Fatalf("unexpected server code: %s", item.ServerCode)
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
if item.ToolName != toolx.GraphHandoffConversation.Name {
|
2026-04-13 19:23:53 +08:00
|
|
|
t.Fatalf("unexpected tool name: %s", item.ToolName)
|
|
|
|
|
}
|
2026-08-28 22:23:13 +08:00
|
|
|
if item.SourceType != toolx.GraphHandoffConversation.SourceType {
|
2026-04-13 19:23:53 +08:00
|
|
|
t.Fatalf("unexpected source type: %s", item.SourceType)
|
|
|
|
|
}
|
|
|
|
|
}
|