fix: include all visible canvas nodes in agent fit-all view

This commit is contained in:
134 2026-06-23 15:18:54 +08:00
parent 8ee7eb1f0a
commit 0bb134d3b8
2 changed files with 19 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import type { CanvasViewOperationPlan } from "@/types/canvas/agent-protocol"; import type { CanvasViewOperationPlan } from "@/types/canvas/agent-protocol";
import type { NodeType } from "@/types/canvas";
export type CanvasAgentViewNodeLike = { export type CanvasAgentViewNodeLike = {
id: string; id: string;
@ -28,6 +29,18 @@ export type ResolvedCanvasViewOperation = {
const VIEWPORT_ANCHOR_X_RATIO = 0.52; const VIEWPORT_ANCHOR_X_RATIO = 0.52;
const VIEWPORT_ANCHOR_Y_RATIO = 0.46; const VIEWPORT_ANCHOR_Y_RATIO = 0.46;
const FIT_ALL_VISIBLE_NODE_TYPES = new Set([
"message",
"image",
"video",
"text",
"ui-screen",
"workflow",
"scene-fusion",
"model3d",
"world3d",
"agent-slot",
] satisfies NodeType[]);
function toFiniteNumber(value: unknown, fallback = 0) { function toFiniteNumber(value: unknown, fallback = 0) {
const numericValue = Number(value); const numericValue = Number(value);
@ -213,8 +226,9 @@ function computeCanvasAgentFocusNodesViewport(params: {
} }
function getFitAllViewNodes(nodes: CanvasAgentViewNodeLike[]) { function getFitAllViewNodes(nodes: CanvasAgentViewNodeLike[]) {
const visibleNodeTypes = new Set(["image", "video", "agent-slot", "ui-screen", "text"]); return nodes.filter((node) =>
return nodes.filter((node) => visibleNodeTypes.has(String(node.type))); FIT_ALL_VISIBLE_NODE_TYPES.has(String(node.type) as NodeType)
);
} }
export function resolveCanvasViewOperation(params: { export function resolveCanvasViewOperation(params: {

View File

@ -1822,9 +1822,9 @@ test.describe("canvas chat pure helpers", () => {
}); });
expect(fitAll?.targetNodeIds).toEqual([]); expect(fitAll?.targetNodeIds).toEqual([]);
expect(fitAll?.viewport.zoom).toBeCloseTo(0.675); expect(fitAll?.viewport.zoom).toBeCloseTo(0.1784615385);
expect(fitAll?.viewport.x).toBeCloseTo(317.5); expect(fitAll?.viewport.x).toBeCloseTo(305.8461538);
expect(fitAll?.viewport.y).toBeCloseTo(266.75); expect(fitAll?.viewport.y).toBeCloseTo(153.8461538);
}); });
test("resolves grid media placements to the right of an anchor node", () => { test("resolves grid media placements to the right of an anchor node", () => {