feat(platform): Agent 能力 - 扩展画布读取与模型路由能力
This commit is contained in:
@@ -3,6 +3,8 @@ package app
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -366,6 +368,49 @@ func TestCloudAgentProjectionRejectsMissingAdapterAndOpaqueMetadata(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentTextResourceProjectionHidesLocator(t *testing.T) {
|
||||
node := map[string]any{"id": "novel", "type": "text", "title": "小说原文"}
|
||||
meta := map[string]any{"content": "/api/resources/novel-res/file", "storageKey": "resource:novel-res", "mimeType": "text/plain"}
|
||||
descriptor, _ := cloudAgentNodeCapabilityForType("text")
|
||||
projected, err := cloudAgentProjectNodeFields(node, meta, descriptor, descriptor.DetailFields, 16000, true, 0)
|
||||
if err != nil || projected["content"] != nil || projected["contentAvailable"] != true || projected["contentSource"] != "resource" {
|
||||
t.Fatalf("resource locator leaked or content availability missing: %v, %v", projected, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentReadTextLoadsOwnedResource(t *testing.T) {
|
||||
s, db, _, _ := creationTestService(t)
|
||||
content := "第一章\n林逸在石殿中醒来。"
|
||||
objectKey := "users/user-1/file/novel.txt"
|
||||
resource := model.Resource{ID: "novel-res", UserID: "user", Kind: "file", Status: model.ResourceStatusReady, Provider: "local", ObjectKey: objectKey, MimeType: "text/plain", Size: int64(len(content))}
|
||||
if err := db.Create(&resource).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Join(s.dataDir, "resources", filepath.Dir(objectKey)), 0700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(s.dataDir, "resources", objectKey), []byte(content), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
doc := map[string]any{"nodes": []map[string]any{{"id": "novel", "type": "text", "title": "小说原文", "metadata": map[string]any{"storageKey": "resource:novel-res", "content": "/api/resources/novel-res/file", "mimeType": "text/plain"}}}, "connections": []any{}}
|
||||
raw, _ := json.Marshal(doc)
|
||||
if err := db.Create(&model.CanvasProject{ID: "agent-canvas", UserID: "user", PayloadJSON: string(raw)}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
state := &cloudAgentRuntime{Request: CloudAgentRequest{CanvasID: "agent-canvas"}}
|
||||
call := cloudAgentCall{ID: "read-text"}
|
||||
call.Function.Name = "canvas_read_text"
|
||||
call.Function.Arguments = `{"nodeId":"novel"}`
|
||||
result, err := cloudAgentReadTool(s.repo, "user", state, call, s)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
view, ok := result.(map[string]any)
|
||||
if !ok || view["content"] != content || view["hasMore"] != false {
|
||||
t.Fatalf("unexpected text resource result: %#v", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCloudAgentCanvasStateBoundsDefaultBodyProjection(t *testing.T) {
|
||||
body := strings.Repeat("长正文 ", 999) + "长正文"
|
||||
doc := map[string]any{"nodes": []map[string]any{{"id": "markdown", "type": "markdown", "title": "长文档", "metadata": map[string]any{"content": body}}}, "connections": []map[string]any{}}
|
||||
|
||||
Reference in New Issue
Block a user