feat: add Firecrawl provider support
This commit is contained in:
@@ -2,69 +2,37 @@ import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createWebFetchTool } from "./web-fetch.ts";
|
||||
|
||||
test("web_fetch prepareArguments folds a single url into urls", () => {
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async () => {
|
||||
throw new Error("not used");
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(tool.prepareArguments?.({ url: "https://exa.ai/docs" }), {
|
||||
url: "https://exa.ai/docs",
|
||||
urls: ["https://exa.ai/docs"],
|
||||
});
|
||||
});
|
||||
|
||||
test("web_fetch forwards nested Tavily extract options to the runtime", async () => {
|
||||
let capturedRequest: any;
|
||||
test("createWebFetchTool passes Firecrawl fetch options through to the runtime", async () => {
|
||||
let captured: any;
|
||||
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async (request) => {
|
||||
capturedRequest = request;
|
||||
async executeFetch(request) {
|
||||
captured = request;
|
||||
return {
|
||||
providerName: "tavily-main",
|
||||
results: [
|
||||
{
|
||||
url: "https://pi.dev",
|
||||
title: "Docs",
|
||||
text: "Body",
|
||||
},
|
||||
],
|
||||
execution: { actualProviderName: "tavily-main" },
|
||||
providerName: "firecrawl-main",
|
||||
results: [],
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const result = await tool.execute(
|
||||
"tool-1",
|
||||
{
|
||||
urls: ["https://pi.dev"],
|
||||
tavily: {
|
||||
query: "installation",
|
||||
extractDepth: "advanced",
|
||||
includeImages: true,
|
||||
},
|
||||
await tool.execute("tool-call", {
|
||||
urls: ["https://pi.dev"],
|
||||
provider: "firecrawl-main",
|
||||
firecrawl: {
|
||||
formats: ["markdown", "summary", "images"],
|
||||
},
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
} as any);
|
||||
|
||||
assert.equal(capturedRequest.tavily.query, "installation");
|
||||
assert.equal(capturedRequest.tavily.extractDepth, "advanced");
|
||||
assert.equal(capturedRequest.text, true);
|
||||
assert.match((result.content[0] as { text: string }).text, /Body/);
|
||||
});
|
||||
|
||||
test("web_fetch rejects malformed URLs", async () => {
|
||||
const tool = createWebFetchTool({
|
||||
executeFetch: async () => {
|
||||
throw new Error("should not execute fetch for invalid URLs");
|
||||
assert.deepEqual(captured, {
|
||||
urls: ["https://pi.dev/"],
|
||||
text: true,
|
||||
highlights: false,
|
||||
summary: false,
|
||||
textMaxCharacters: undefined,
|
||||
provider: "firecrawl-main",
|
||||
tavily: undefined,
|
||||
firecrawl: {
|
||||
formats: ["markdown", "summary", "images"],
|
||||
},
|
||||
});
|
||||
|
||||
await assert.rejects(
|
||||
() => tool.execute("tool-1", { urls: ["not-a-url"] }, undefined, undefined, undefined),
|
||||
/Invalid URL/,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user