






















@@ -123,6 +123,7 @@ const configMocks = vi.hoisted(() => ({
123123() => {
124124browser: Record<string, unknown>;
125125gateway?: { nodes?: { browser?: { node?: string } } };
126+agents?: { defaults?: { imageMaxDimensionPx?: number } };
126127}
127128>(() => ({ browser: {} })),
128129}));
@@ -185,6 +186,12 @@ vi.mock("./browser-tool.runtime.js", () => {
185186 ...gatewayMocks,
186187 ...sessionTabRegistryMocks,
187188getRuntimeConfig: configMocks.loadConfig,
189+resolveRuntimeImageSanitization: () => {
190+const configured = configMocks.loadConfig().agents?.defaults?.imageMaxDimensionPx;
191+return typeof configured === "number" && Number.isFinite(configured)
192+ ? { maxDimensionPx: Math.max(1, Math.floor(configured)) }
193+ : undefined;
194+},
188195applyBrowserProxyPaths: vi.fn(),
189196getBrowserProfileCapabilities: (profile: Record<string, unknown>) => ({
190197usesChromeMcp: profile.driver === "existing-session",
@@ -715,6 +722,29 @@ describe("browser tool snapshot maxChars", () => {
715722expect(opts.timeoutMs).toBe(12_345);
716723});
717724725+it("passes configured image sanitization to screenshot image results", async () => {
726+configMocks.loadConfig.mockReturnValue({
727+browser: {},
728+agents: { defaults: { imageMaxDimensionPx: 2000 } },
729+} as never);
730+toolCommonMocks.imageResultFromFile.mockResolvedValueOnce({
731+content: [{ type: "image", data: "base64", mimeType: "image/png" }],
732+details: { path: "/tmp/test.png" },
733+});
734+735+const tool = createBrowserTool();
736+await tool.execute?.("call-1", {
737+action: "screenshot",
738+target: "host",
739+targetId: "tab-1",
740+});
741+742+const imageParams = lastMockCallArg<{
743+imageSanitization?: { maxDimensionPx?: number };
744+}>(toolCommonMocks.imageResultFromFile, 0);
745+expect(imageParams.imageSanitization).toEqual({ maxDimensionPx: 2000 });
746+});
747+718748it("passes screenshot timeoutMs through the node browser proxy", async () => {
719749mockSingleBrowserProxyNode();
720750gatewayMocks.callGatewayTool.mockResolvedValueOnce({
@@ -1163,6 +1193,10 @@ describe("browser tool snapshot labels", () => {
11631193registerBrowserToolAfterEachReset();
1164119411651195it("returns image + text when labels are requested", async () => {
1196+configMocks.loadConfig.mockReturnValue({
1197+browser: {},
1198+agents: { defaults: { imageMaxDimensionPx: 2000 } },
1199+} as never);
11661200const tool = createBrowserTool();
11671201const imageResult = {
11681202content: [
@@ -1188,12 +1222,14 @@ describe("browser tool snapshot labels", () => {
11881222labels: true,
11891223});
119012241191-const imageParams = lastMockCallArg<{ path?: string; extraText?: string }>(
1192-toolCommonMocks.imageResultFromFile,
1193-0,
1194-);
1225+const imageParams = lastMockCallArg<{
1226+path?: string;
1227+extraText?: string;
1228+imageSanitization?: { maxDimensionPx?: number };
1229+}>(toolCommonMocks.imageResultFromFile, 0);
11951230expect(imageParams.path).toBe("/tmp/snap.png");
11961231expect(imageParams.extraText).toContain("<<<EXTERNAL_UNTRUSTED_CONTENT");
1232+expect(imageParams.imageSanitization).toEqual({ maxDimensionPx: 2000 });
11971233expect(result).toEqual(imageResult);
11981234expect(result?.content).toHaveLength(2);
11991235expect(result?.content?.[0]).toEqual({ type: "text", text: "label text" });
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。