fix(*): 创作工作台 - 修复 Agent、资源引用、附件交互与 Agnes 视频协议
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
|
||||
import { collectUpstreamVideoNodes } from "../src/lib/canvas/canvas-resource-references";
|
||||
import { buildNodeMentionReferences, canvasResourceMentionToken, collectUpstreamVideoNodes } from "../src/lib/canvas/canvas-resource-references";
|
||||
import { CanvasNodeType, type CanvasConnection, type CanvasNodeData } from "../src/types/canvas";
|
||||
|
||||
function videoNode(id: string): CanvasNodeData {
|
||||
@@ -27,6 +27,30 @@ function textNode(id: string): CanvasNodeData {
|
||||
};
|
||||
}
|
||||
|
||||
function imageNode(id: string): CanvasNodeData {
|
||||
return {
|
||||
id,
|
||||
type: CanvasNodeType.Image,
|
||||
title: id,
|
||||
position: { x: 0, y: 0 },
|
||||
width: 100,
|
||||
height: 100,
|
||||
metadata: { content: `data:image/png;base64,${id}` },
|
||||
};
|
||||
}
|
||||
|
||||
function audioNode(id: string): CanvasNodeData {
|
||||
return {
|
||||
id,
|
||||
type: CanvasNodeType.Audio,
|
||||
title: id,
|
||||
position: { x: 0, y: 0 },
|
||||
width: 100,
|
||||
height: 60,
|
||||
metadata: { content: `data:audio/mpeg;base64,${id}` },
|
||||
};
|
||||
}
|
||||
|
||||
function connection(fromNodeId: string, toNodeId: string): CanvasConnection {
|
||||
return { id: `conn-${fromNodeId}-${toNodeId}`, fromNodeId, toNodeId };
|
||||
}
|
||||
@@ -50,3 +74,35 @@ describe("collectUpstreamVideoNodes", () => {
|
||||
expect(collectUpstreamVideoNodes("a", nodes, connections).length).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("canvas resource mention slots", () => {
|
||||
test("画布节点引用只保存类型位置,不保存节点 ID", () => {
|
||||
const target = videoNode("target");
|
||||
const image = imageNode("image-a");
|
||||
const [reference] = buildNodeMentionReferences(target, [image, target], [connection(image.id, target.id)]);
|
||||
|
||||
expect(reference.label).toBe("图片1");
|
||||
expect(canvasResourceMentionToken(reference)).toBe("@图片1");
|
||||
expect(canvasResourceMentionToken(reference)).not.toContain(image.id);
|
||||
});
|
||||
|
||||
test("图片、音频和文本分别按各自类型顺序编号", () => {
|
||||
const target = videoNode("target");
|
||||
const nodes = [imageNode("image-a"), audioNode("audio-a"), imageNode("image-b"), textNode("text-a"), target];
|
||||
const connections = nodes.slice(0, -1).map((node) => connection(node.id, target.id));
|
||||
|
||||
expect(buildNodeMentionReferences(target, nodes, connections).map((reference) => reference.label)).toEqual(["图片1", "音频1", "图片2", "文本1"]);
|
||||
});
|
||||
|
||||
test("素材库身份 token 保持稳定", () => {
|
||||
expect(canvasResourceMentionToken({
|
||||
id: "asset:asset-a",
|
||||
nodeId: "",
|
||||
assetId: "asset-a",
|
||||
kind: "image",
|
||||
label: "场景图",
|
||||
title: "场景图",
|
||||
active: false,
|
||||
})).toBe("@[asset:asset-a]");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user