Skip to content

Commit cfe24e7

Browse files
fix(tavily): reject blank extract URLs
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
1 parent 2a6fd77 commit cfe24e7

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

extensions/tavily/src/tavily-extract-tool.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function createTavilyExtractTool(api: OpenClawPluginApi, ctx?: TavilyTool
5050
parameters: TavilyExtractToolSchema,
5151
execute: async (_toolCallId: string, rawParams: Record<string, unknown>) => {
5252
const urls = Array.isArray(rawParams.urls)
53-
? (rawParams.urls as string[]).filter(Boolean)
53+
? rawParams.urls.map((url) => (typeof url === "string" ? url.trim() : "")).filter(Boolean)
5454
: [];
5555
if (urls.length === 0) {
5656
throw new Error("tavily_extract requires at least one URL.");

extensions/tavily/src/tavily-tools.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,28 @@ describe("tavily tools", () => {
351351
expect(runTavilyExtract).not.toHaveBeenCalled();
352352
});
353353

354+
it("rejects blank extract URLs before Tavily calls and trims valid URLs", async () => {
355+
const tool = createTavilyExtractTool(fakeApi());
356+
357+
await expect(
358+
tool.execute("extract-call", {
359+
urls: [" "],
360+
}),
361+
).rejects.toThrow("tavily_extract requires at least one URL.");
362+
363+
expect(runTavilyExtract).not.toHaveBeenCalled();
364+
365+
await tool.execute("extract-call", {
366+
urls: [" https://example.com/article "],
367+
});
368+
369+
const extractParams = requireFirstMockArg(
370+
runTavilyExtract,
371+
"Tavily extract params",
372+
) as TavilyExtractParams;
373+
expect(extractParams.urls).toEqual(["https://example.com/article"]);
374+
});
375+
354376
it("rejects fractional and out-of-range integer options before Tavily calls", async () => {
355377
const searchTool = createTavilySearchTool(fakeApi());
356378
await expect(

0 commit comments

Comments
 (0)