Skip to content

Commit 1e91710

Browse files
committed
fix(mcp): let addZoom take customScale without depth
addZoom's schema gave depth a default of 3. The MCP server, the in-app agent and addZooms all parse the arguments through that schema before the tool runs, so a call with customScale alone arrived with depth: 3 filled in, and the guard against passing both levels refused it. A free level could only be set by adding the zoom, then calling setZoom. The default moves into the handler, where it applies only when neither level is given.
1 parent 3c9bd5d commit 1e91710

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎electron/ai-edition/agent-tools.test.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ZOOM_DEPTH_SCALES } from "../../src/lib/ai-edition/timeline/zoom-scale"
1010
import { zoomScaleLimit } from "../../src/native/sceneDescription";
1111
import {
1212
type AgentToolOptions,
13+
addZoomArgs,
1314
executeAgentTool,
1415
isMutatingTool,
1516
MUTATING_TOOL_NAMES,
@@ -3342,6 +3343,23 @@ describe("region tools reach the inspector's settings (#1180)", () => {
33423343
expect(both.ok).toBe(false);
33433344
});
33443345

3346+
it("takes customScale alone wherever the arguments were parsed first", () => {
3347+
// The MCP server and the in-app agent hand the tool its arguments through the same schema,
3348+
// and addZooms hands each region to addZoom parsed. A default depth filled in there read as
3349+
// "depth and customScale both passed", so a free level could never be set in one call.
3350+
const zoomOnly = { startSec: 2, endSec: 4, customScale: 1.6 };
3351+
const parsed = run(fixtureDocument(), "addZoom", addZoomArgs.parse(zoomOnly));
3352+
expect(parsed.ok).toBe(true);
3353+
expect(parsed.document?.zoomRanges[0]).toMatchObject({ customScale: 1.6 });
3354+
const batch = run(fixtureDocument(), "addZooms", { regions: [zoomOnly] });
3355+
expect(batch.ok).toBe(true);
3356+
expect(batch.document?.zoomRanges[0]).toMatchObject({ customScale: 1.6 });
3357+
// Neither level given: the default depth still applies.
3358+
const plain = run(fixtureDocument(), "addZoom", addZoomArgs.parse({ startSec: 2, endSec: 4 }));
3359+
expect(plain.document?.zoomRanges[0]).toMatchObject({ depth: 3 });
3360+
expect(plain.document?.zoomRanges[0]).not.toHaveProperty("customScale");
3361+
});
3362+
33453363
it("reads an annotation back in the terms its writes take", () => {
33463364
const added = run(fixtureDocument(), "addAnnotation", {
33473365
startSec: 1,

‎electron/ai-edition/agent-tools.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,12 @@ const customScaleSchema = z
791791
export const addZoomArgs = z.object({
792792
startSec: secondsSchema,
793793
endSec: secondsSchema,
794-
depth: depthSchema.default(3),
794+
// No schema default: the MCP server, the in-app agent and addZooms all parse the arguments
795+
// before the tool runs, and a default filled in there reads as a depth passed next to
796+
// customScale. The handler applies 3 when neither level is given.
797+
depth: depthSchema
798+
.optional()
799+
.describe("Defaults to 3 when neither depth nor customScale is given."),
795800
focus: focusSchema.default({ cx: 0.5, cy: 0.5 }),
796801
rotationPreset: rotationPresetSchema.default("none"),
797802
focusMode: focusModeSchema.default("manual"),
@@ -2897,7 +2902,7 @@ export function executeAgentTool(
28972902
id: createId("zoom"),
28982903
startMs,
28992904
endMs,
2900-
depth: parsed.data.depth as 1 | 2 | 3 | 4 | 5 | 6,
2905+
depth: (parsed.data.depth ?? 3) as 1 | 2 | 3 | 4 | 5 | 6,
29012906
...level,
29022907
focus: parsed.data.focus,
29032908
focusMode: parsed.data.focusMode,

0 commit comments

Comments
 (0)