@thynker-labs/tools-firecrawl 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +16 -0
- package/dist/index.js +119 -0
- package/package.json +31 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ToolProvider } from '@thynker-labs/core';
|
|
2
|
+
|
|
3
|
+
interface FirecrawlToolProviderConfig {
|
|
4
|
+
apiKeyEnv: string;
|
|
5
|
+
/** Required scopes (default: ["web:scrape"]). */
|
|
6
|
+
requiredScopes?: string[];
|
|
7
|
+
/** Default scrape output formats. */
|
|
8
|
+
defaultFormats?: Array<"markdown" | "html" | "links">;
|
|
9
|
+
}
|
|
10
|
+
type FirecrawlFetch = typeof fetch;
|
|
11
|
+
/**
|
|
12
|
+
* Firecrawl ToolProvider — scrape, map, and search via Firecrawl API.
|
|
13
|
+
*/
|
|
14
|
+
declare function createFirecrawlToolProvider(config: FirecrawlToolProviderConfig, fetchImpl?: FirecrawlFetch): ToolProvider;
|
|
15
|
+
|
|
16
|
+
export { type FirecrawlFetch, type FirecrawlToolProviderConfig, createFirecrawlToolProvider };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var FIRECRAWL_API = "https://api.firecrawl.dev/v1";
|
|
3
|
+
var TOOLS = [
|
|
4
|
+
{
|
|
5
|
+
name: "firecrawl_scrape",
|
|
6
|
+
description: "Scrape a single URL and return page content (markdown by default). Use for reading a specific page.",
|
|
7
|
+
requiredScopes: ["web:scrape"],
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: "object",
|
|
10
|
+
properties: {
|
|
11
|
+
url: { type: "string", description: "URL to scrape" },
|
|
12
|
+
formats: {
|
|
13
|
+
type: "array",
|
|
14
|
+
items: { type: "string", enum: ["markdown", "html", "links"] },
|
|
15
|
+
description: "Output formats (default: markdown)"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
required: ["url"]
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "firecrawl_map",
|
|
23
|
+
description: "Map a website and return discovered URLs (fast site structure discovery).",
|
|
24
|
+
requiredScopes: ["web:scrape"],
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: "object",
|
|
27
|
+
properties: {
|
|
28
|
+
url: { type: "string", description: "Root URL to map" },
|
|
29
|
+
limit: { type: "number", description: "Max URLs to return (default 50)" }
|
|
30
|
+
},
|
|
31
|
+
required: ["url"]
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "firecrawl_search",
|
|
36
|
+
description: "Search the web via Firecrawl and return relevant page snippets (alternative to Brave search).",
|
|
37
|
+
requiredScopes: ["web:search"],
|
|
38
|
+
inputSchema: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: {
|
|
41
|
+
query: { type: "string", description: "Search query" },
|
|
42
|
+
limit: { type: "number", description: "Max results (default 5)" }
|
|
43
|
+
},
|
|
44
|
+
required: ["query"]
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
];
|
|
48
|
+
function resolveApiKey(config) {
|
|
49
|
+
const key = process.env[config.apiKeyEnv];
|
|
50
|
+
if (!key) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`Missing ${config.apiKeyEnv}. Set it in .env to enable Firecrawl tools.`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return key;
|
|
56
|
+
}
|
|
57
|
+
function scopesFor(config, tool) {
|
|
58
|
+
if (config.requiredScopes) return config.requiredScopes;
|
|
59
|
+
return tool.requiredScopes ?? ["web:scrape"];
|
|
60
|
+
}
|
|
61
|
+
async function firecrawlPost(path, apiKey, body, fetchImpl) {
|
|
62
|
+
const res = await fetchImpl(`${FIRECRAWL_API}${path}`, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
Authorization: `Bearer ${apiKey}`,
|
|
66
|
+
"Content-Type": "application/json"
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify(body)
|
|
69
|
+
});
|
|
70
|
+
const data = await res.json();
|
|
71
|
+
if (!res.ok || data.success === false) {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Firecrawl ${path} failed (${res.status}): ${data.error ?? JSON.stringify(data)}`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
return data.data ?? data;
|
|
77
|
+
}
|
|
78
|
+
function createFirecrawlToolProvider(config, fetchImpl = fetch) {
|
|
79
|
+
const scopedTools = TOOLS.map((t) => ({
|
|
80
|
+
...t,
|
|
81
|
+
requiredScopes: scopesFor(config, t)
|
|
82
|
+
}));
|
|
83
|
+
return {
|
|
84
|
+
async list() {
|
|
85
|
+
resolveApiKey(config);
|
|
86
|
+
return scopedTools;
|
|
87
|
+
},
|
|
88
|
+
async execute(name, args, _authCtx) {
|
|
89
|
+
const apiKey = resolveApiKey(config);
|
|
90
|
+
if (name === "firecrawl_scrape") {
|
|
91
|
+
const url = String(args.url ?? "");
|
|
92
|
+
if (!url) throw new Error("url is required");
|
|
93
|
+
const formats = args.formats ?? config.defaultFormats ?? ["markdown"];
|
|
94
|
+
return firecrawlPost(
|
|
95
|
+
"/scrape",
|
|
96
|
+
apiKey,
|
|
97
|
+
{ url, formats },
|
|
98
|
+
fetchImpl
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (name === "firecrawl_map") {
|
|
102
|
+
const url = String(args.url ?? "");
|
|
103
|
+
if (!url) throw new Error("url is required");
|
|
104
|
+
const limit = Number(args.limit ?? 50);
|
|
105
|
+
return firecrawlPost("/map", apiKey, { url, limit }, fetchImpl);
|
|
106
|
+
}
|
|
107
|
+
if (name === "firecrawl_search") {
|
|
108
|
+
const query = String(args.query ?? "");
|
|
109
|
+
if (!query.trim()) throw new Error("query is required");
|
|
110
|
+
const limit = Number(args.limit ?? 5);
|
|
111
|
+
return firecrawlPost("/search", apiKey, { query, limit }, fetchImpl);
|
|
112
|
+
}
|
|
113
|
+
throw new Error(`Unknown Firecrawl tool: ${name}`);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
createFirecrawlToolProvider
|
|
119
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thynker-labs/tools-firecrawl",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Firecrawl ToolProvider for scrape, map, and search",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@thynker-labs/core": "0.0.1"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=20"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
}
|
|
31
|
+
}
|