diff --git a/src/agents/tools/embedded-gateway-stub.test.ts b/src/agents/tools/embedded-gateway-stub.test.ts index cab2cbb22fc3..e85ab4ca1166 100644 --- a/src/agents/tools/embedded-gateway-stub.test.ts +++ b/src/agents/tools/embedded-gateway-stub.test.ts @@ -504,6 +504,14 @@ describe("embedded gateway stub", () => { params: { sessionKey: "agent:main:main", offset: 1.5 }, }), ).rejects.toThrow("offset must be a non-negative integer"); + await expect( + callGateway({ + method: "chat.history", + params: { sessionKey: "agent:main:main", offset: "1abc" }, + }), + ).rejects.toThrow("offset must be a non-negative integer"); expect(runtime.readSessionMessagesAsync).not.toHaveBeenCalled(); + expect(runtime.readRecentSessionMessagesWithStatsAsync).not.toHaveBeenCalled(); + expect(runtime.readSessionMessagesPageWithStatsAsync).not.toHaveBeenCalled(); }); }); diff --git a/src/agents/tools/embedded-gateway-stub.ts b/src/agents/tools/embedded-gateway-stub.ts index 23f648c4d620..69b53aa6775c 100644 --- a/src/agents/tools/embedded-gateway-stub.ts +++ b/src/agents/tools/embedded-gateway-stub.ts @@ -17,7 +17,7 @@ import type { import type { SessionsListResult } from "../../gateway/session-utils.types.js"; import type { SessionsResolveResult } from "../../gateway/sessions-resolve.js"; import { parseAgentSessionKey } from "../../routing/session-key.js"; -import { readNumberParam, readPositiveIntegerParam } from "./common.js"; +import { readNonNegativeIntegerParam, readPositiveIntegerParam } from "./common.js"; type EmbeddedCallGateway = >(opts: CallGatewayOptions) => Promise; @@ -109,10 +109,7 @@ async function getRuntime(): Promise { } function readOffsetParam(params: Record): number | undefined { - const offset = readNumberParam(params, "offset", { - integer: true, - nonNegativeInteger: true, - }); + const offset = readNonNegativeIntegerParam(params, "offset"); if (params.offset !== undefined && offset === undefined) { throw new Error("offset must be a non-negative integer"); } diff --git a/src/agents/tools/sessions-history-tool.test.ts b/src/agents/tools/sessions-history-tool.test.ts index 1cb5af60bbf0..c22426d54ab9 100644 --- a/src/agents/tools/sessions-history-tool.test.ts +++ b/src/agents/tools/sessions-history-tool.test.ts @@ -118,12 +118,20 @@ describe("sessions_history redaction", () => { ); }); - it.each([-1, 1.5])("rejects invalid offset value %s", async (offset) => { - const tool = createHistoryToolWithMessage("hello"); + it.each([-1, 1.5, "1abc"])("rejects invalid offset value %s", async (offset) => { + const requests: CallGatewayRequest[] = []; + const tool = createSessionsHistoryTool({ + config: {}, + callGateway: async >(request: CallGatewayRequest): Promise => { + requests.push(request); + return { messages: [] } as T; + }, + }); await expect(tool.execute("call-1", { sessionKey: "main", offset })).rejects.toThrow( "offset must be a non-negative integer", ); + expect(requests).toEqual([]); }); it("preserves the bounded default history request", async () => { diff --git a/src/agents/tools/sessions-history-tool.ts b/src/agents/tools/sessions-history-tool.ts index edbb134d12e3..e9f6a66e30a0 100644 --- a/src/agents/tools/sessions-history-tool.ts +++ b/src/agents/tools/sessions-history-tool.ts @@ -21,7 +21,7 @@ import { stripToolMessages } from "./chat-history-text.js"; import type { AnyAgentTool } from "./common.js"; import { jsonResult, - readNumberParam, + readNonNegativeIntegerParam, readPositiveIntegerParam, readStringParam, ToolInputError, @@ -53,10 +53,7 @@ type ChatHistoryPaginationMetadata = { }; function readOffsetParam(params: Record): number | undefined { - const offset = readNumberParam(params, "offset", { - integer: true, - nonNegativeInteger: true, - }); + const offset = readNonNegativeIntegerParam(params, "offset"); if (params.offset !== undefined && offset === undefined) { throw new ToolInputError("offset must be a non-negative integer"); }