@narumitw/pi-firecrawl 0.50.2 → 0.50.4

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/src/tools.ts CHANGED
@@ -1,9 +1,4 @@
1
- import {
2
- DEFAULT_MAX_BYTES,
3
- DEFAULT_MAX_LINES,
4
- defineTool,
5
- formatSize,
6
- } from "@earendil-works/pi-coding-agent";
1
+ import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, defineTool, formatSize } from "@earendil-works/pi-coding-agent";
7
2
  import { Type } from "typebox";
8
3
  import { cleanObject, firecrawlRequest, jsonResult, withStatus } from "./client.js";
9
4
  import { FIRECRAWL_TOOL_NAMES } from "./tool-names.js";
@@ -12,189 +7,135 @@ const StringArray = Type.Array(Type.String());
12
7
  const OUTPUT_LIMIT_DESCRIPTION = `Output is truncated to ${DEFAULT_MAX_LINES} lines or ${formatSize(DEFAULT_MAX_BYTES)}; complete truncated responses are saved temporarily and their path is returned.`;
13
8
 
14
9
  export const scrapeTool = defineTool({
15
- name: FIRECRAWL_TOOL_NAMES[0],
16
- label: "Firecrawl: Scrape",
17
- description: `Scrape a single URL through Firecrawl and return requested formats. ${OUTPUT_LIMIT_DESCRIPTION}`,
18
- parameters: Type.Object({
19
- url: Type.String({ description: "URL to scrape." }),
20
- formats: Type.Optional(
21
- Type.Array(
22
- Type.String({
23
- description:
24
- "Requested Firecrawl output format, such as markdown, html, rawHtml, links, screenshot, or json.",
25
- }),
26
- { description: "Firecrawl output formats. Defaults to Firecrawl's API default." },
27
- ),
28
- ),
29
- onlyMainContent: Type.Optional(
30
- Type.Boolean({ description: "Return only the main page content when supported." }),
31
- ),
32
- includeTags: Type.Optional(StringArray),
33
- excludeTags: Type.Optional(StringArray),
34
- waitFor: Type.Optional(Type.Number({ description: "Milliseconds to wait before scraping." })),
35
- timeout: Type.Optional(
36
- Type.Number({ description: "Firecrawl request timeout in milliseconds." }),
37
- ),
38
- mobile: Type.Optional(Type.Boolean({ description: "Use a mobile user agent when supported." })),
39
- skipTlsVerification: Type.Optional(
40
- Type.Boolean({ description: "Skip TLS certificate verification when supported." }),
41
- ),
42
- removeBase64Images: Type.Optional(
43
- Type.Boolean({ description: "Remove base64 image data from the response when supported." }),
44
- ),
45
- blockAds: Type.Optional(
46
- Type.Boolean({ description: "Block ads while scraping when supported." }),
47
- ),
48
- headers: Type.Optional(
49
- Type.Record(Type.String(), Type.String(), {
50
- description: "Additional HTTP headers Firecrawl should use while fetching the target URL.",
51
- }),
52
- ),
53
- jsonOptions: Type.Optional(
54
- Type.Any({ description: "Firecrawl jsonOptions for structured extraction." }),
55
- ),
56
- actions: Type.Optional(
57
- Type.Array(Type.Any(), {
58
- description: "Firecrawl browser actions to perform before scraping.",
59
- }),
60
- ),
61
- location: Type.Optional(Type.Any({ description: "Firecrawl location options." })),
62
- }),
63
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
64
- return withStatus(ctx, "scrape", async () => {
65
- const payload = await firecrawlRequest(
66
- "POST",
67
- "/scrape",
68
- cleanObject(params),
69
- signal,
70
- ctx.sessionManager,
71
- );
72
- return await jsonResult(payload, ctx.sessionManager);
73
- });
74
- },
10
+ name: FIRECRAWL_TOOL_NAMES[0],
11
+ label: "Firecrawl: Scrape",
12
+ description: `Scrape a single URL through Firecrawl and return requested formats. ${OUTPUT_LIMIT_DESCRIPTION}`,
13
+ parameters: Type.Object({
14
+ url: Type.String({ description: "URL to scrape." }),
15
+ formats: Type.Optional(
16
+ Type.Array(
17
+ Type.String({
18
+ description:
19
+ "Requested Firecrawl output format, such as markdown, html, rawHtml, links, screenshot, or json.",
20
+ }),
21
+ { description: "Firecrawl output formats. Defaults to Firecrawl's API default." },
22
+ ),
23
+ ),
24
+ onlyMainContent: Type.Optional(Type.Boolean({ description: "Return only the main page content when supported." })),
25
+ includeTags: Type.Optional(StringArray),
26
+ excludeTags: Type.Optional(StringArray),
27
+ waitFor: Type.Optional(Type.Number({ description: "Milliseconds to wait before scraping." })),
28
+ timeout: Type.Optional(Type.Number({ description: "Firecrawl request timeout in milliseconds." })),
29
+ mobile: Type.Optional(Type.Boolean({ description: "Use a mobile user agent when supported." })),
30
+ skipTlsVerification: Type.Optional(
31
+ Type.Boolean({ description: "Skip TLS certificate verification when supported." }),
32
+ ),
33
+ removeBase64Images: Type.Optional(
34
+ Type.Boolean({ description: "Remove base64 image data from the response when supported." }),
35
+ ),
36
+ blockAds: Type.Optional(Type.Boolean({ description: "Block ads while scraping when supported." })),
37
+ headers: Type.Optional(
38
+ Type.Record(Type.String(), Type.String(), {
39
+ description: "Additional HTTP headers Firecrawl should use while fetching the target URL.",
40
+ }),
41
+ ),
42
+ jsonOptions: Type.Optional(Type.Any({ description: "Firecrawl jsonOptions for structured extraction." })),
43
+ actions: Type.Optional(
44
+ Type.Array(Type.Any(), {
45
+ description: "Firecrawl browser actions to perform before scraping.",
46
+ }),
47
+ ),
48
+ location: Type.Optional(Type.Any({ description: "Firecrawl location options." })),
49
+ }),
50
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
51
+ return withStatus(ctx, "scrape", async () => {
52
+ const payload = await firecrawlRequest("POST", "/scrape", cleanObject(params), signal, ctx.sessionManager);
53
+ return await jsonResult(payload, ctx.sessionManager);
54
+ });
55
+ },
75
56
  });
76
57
 
77
58
  export const crawlTool = defineTool({
78
- name: FIRECRAWL_TOOL_NAMES[1],
79
- label: "Firecrawl: Crawl",
80
- description: `Start a Firecrawl crawl job for a website. ${OUTPUT_LIMIT_DESCRIPTION}`,
81
- parameters: Type.Object({
82
- url: Type.String({ description: "Starting URL for the crawl." }),
83
- limit: Type.Optional(Type.Number({ description: "Maximum number of pages to crawl." })),
84
- maxDepth: Type.Optional(Type.Number({ description: "Maximum crawl depth when supported." })),
85
- includePaths: Type.Optional(
86
- Type.Array(Type.String(), { description: "URL path patterns to include." }),
87
- ),
88
- excludePaths: Type.Optional(
89
- Type.Array(Type.String(), { description: "URL path patterns to exclude." }),
90
- ),
91
- allowBackwardLinks: Type.Optional(
92
- Type.Boolean({ description: "Allow crawling backward links when supported." }),
93
- ),
94
- allowExternalLinks: Type.Optional(
95
- Type.Boolean({ description: "Allow crawling external links when supported." }),
96
- ),
97
- ignoreSitemap: Type.Optional(Type.Boolean({ description: "Ignore sitemap discovery." })),
98
- deduplicateSimilarURLs: Type.Optional(
99
- Type.Boolean({ description: "Deduplicate similar URLs when supported." }),
100
- ),
101
- scrapeOptions: Type.Optional(
102
- Type.Any({ description: "Firecrawl scrapeOptions applied to crawled pages." }),
103
- ),
104
- webhook: Type.Optional(Type.Any({ description: "Firecrawl webhook configuration." })),
105
- }),
106
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
107
- return withStatus(ctx, "crawl", async () => {
108
- const payload = await firecrawlRequest(
109
- "POST",
110
- "/crawl",
111
- cleanObject(params),
112
- signal,
113
- ctx.sessionManager,
114
- );
115
- return await jsonResult(payload, ctx.sessionManager);
116
- });
117
- },
59
+ name: FIRECRAWL_TOOL_NAMES[1],
60
+ label: "Firecrawl: Crawl",
61
+ description: `Start a Firecrawl crawl job for a website. ${OUTPUT_LIMIT_DESCRIPTION}`,
62
+ parameters: Type.Object({
63
+ url: Type.String({ description: "Starting URL for the crawl." }),
64
+ limit: Type.Optional(Type.Number({ description: "Maximum number of pages to crawl." })),
65
+ maxDepth: Type.Optional(Type.Number({ description: "Maximum crawl depth when supported." })),
66
+ includePaths: Type.Optional(Type.Array(Type.String(), { description: "URL path patterns to include." })),
67
+ excludePaths: Type.Optional(Type.Array(Type.String(), { description: "URL path patterns to exclude." })),
68
+ allowBackwardLinks: Type.Optional(Type.Boolean({ description: "Allow crawling backward links when supported." })),
69
+ allowExternalLinks: Type.Optional(Type.Boolean({ description: "Allow crawling external links when supported." })),
70
+ ignoreSitemap: Type.Optional(Type.Boolean({ description: "Ignore sitemap discovery." })),
71
+ deduplicateSimilarURLs: Type.Optional(Type.Boolean({ description: "Deduplicate similar URLs when supported." })),
72
+ scrapeOptions: Type.Optional(Type.Any({ description: "Firecrawl scrapeOptions applied to crawled pages." })),
73
+ webhook: Type.Optional(Type.Any({ description: "Firecrawl webhook configuration." })),
74
+ }),
75
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
76
+ return withStatus(ctx, "crawl", async () => {
77
+ const payload = await firecrawlRequest("POST", "/crawl", cleanObject(params), signal, ctx.sessionManager);
78
+ return await jsonResult(payload, ctx.sessionManager);
79
+ });
80
+ },
118
81
  });
119
82
 
120
83
  export const crawlStatusTool = defineTool({
121
- name: FIRECRAWL_TOOL_NAMES[2],
122
- label: "Firecrawl: Crawl Status",
123
- description: `Check a Firecrawl crawl job status and retrieve completed crawl data. ${OUTPUT_LIMIT_DESCRIPTION}`,
124
- parameters: Type.Object({
125
- id: Type.String({ description: "Crawl job id returned by firecrawl_crawl." }),
126
- }),
127
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
128
- return withStatus(ctx, "crawl status", async () => {
129
- const payload = await firecrawlRequest(
130
- "GET",
131
- `/crawl/${encodeURIComponent(params.id)}`,
132
- undefined,
133
- signal,
134
- ctx.sessionManager,
135
- );
136
- return await jsonResult(payload, ctx.sessionManager);
137
- });
138
- },
84
+ name: FIRECRAWL_TOOL_NAMES[2],
85
+ label: "Firecrawl: Crawl Status",
86
+ description: `Check a Firecrawl crawl job status and retrieve completed crawl data. ${OUTPUT_LIMIT_DESCRIPTION}`,
87
+ parameters: Type.Object({
88
+ id: Type.String({ description: "Crawl job id returned by firecrawl_crawl." }),
89
+ }),
90
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
91
+ return withStatus(ctx, "crawl status", async () => {
92
+ const payload = await firecrawlRequest(
93
+ "GET",
94
+ `/crawl/${encodeURIComponent(params.id)}`,
95
+ undefined,
96
+ signal,
97
+ ctx.sessionManager,
98
+ );
99
+ return await jsonResult(payload, ctx.sessionManager);
100
+ });
101
+ },
139
102
  });
140
103
 
141
104
  export const mapTool = defineTool({
142
- name: FIRECRAWL_TOOL_NAMES[3],
143
- label: "Firecrawl: Map",
144
- description: `Discover URLs for a site through Firecrawl's map endpoint. ${OUTPUT_LIMIT_DESCRIPTION}`,
145
- parameters: Type.Object({
146
- url: Type.String({ description: "Website URL to map." }),
147
- search: Type.Optional(
148
- Type.String({ description: "Optional search term to filter discovered URLs." }),
149
- ),
150
- ignoreSitemap: Type.Optional(Type.Boolean({ description: "Ignore sitemap discovery." })),
151
- sitemapOnly: Type.Optional(
152
- Type.Boolean({ description: "Only use sitemap URLs when supported." }),
153
- ),
154
- includeSubdomains: Type.Optional(
155
- Type.Boolean({ description: "Include subdomains when supported." }),
156
- ),
157
- limit: Type.Optional(Type.Number({ description: "Maximum number of URLs to return." })),
158
- }),
159
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
160
- return withStatus(ctx, "map", async () => {
161
- const payload = await firecrawlRequest(
162
- "POST",
163
- "/map",
164
- cleanObject(params),
165
- signal,
166
- ctx.sessionManager,
167
- );
168
- return await jsonResult(payload, ctx.sessionManager);
169
- });
170
- },
105
+ name: FIRECRAWL_TOOL_NAMES[3],
106
+ label: "Firecrawl: Map",
107
+ description: `Discover URLs for a site through Firecrawl's map endpoint. ${OUTPUT_LIMIT_DESCRIPTION}`,
108
+ parameters: Type.Object({
109
+ url: Type.String({ description: "Website URL to map." }),
110
+ search: Type.Optional(Type.String({ description: "Optional search term to filter discovered URLs." })),
111
+ ignoreSitemap: Type.Optional(Type.Boolean({ description: "Ignore sitemap discovery." })),
112
+ sitemapOnly: Type.Optional(Type.Boolean({ description: "Only use sitemap URLs when supported." })),
113
+ includeSubdomains: Type.Optional(Type.Boolean({ description: "Include subdomains when supported." })),
114
+ limit: Type.Optional(Type.Number({ description: "Maximum number of URLs to return." })),
115
+ }),
116
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
117
+ return withStatus(ctx, "map", async () => {
118
+ const payload = await firecrawlRequest("POST", "/map", cleanObject(params), signal, ctx.sessionManager);
119
+ return await jsonResult(payload, ctx.sessionManager);
120
+ });
121
+ },
171
122
  });
172
123
 
173
124
  export const searchTool = defineTool({
174
- name: FIRECRAWL_TOOL_NAMES[4],
175
- label: "Firecrawl: Search",
176
- description: `Search the web through Firecrawl and optionally scrape search results. ${OUTPUT_LIMIT_DESCRIPTION}`,
177
- parameters: Type.Object({
178
- query: Type.String({ description: "Search query." }),
179
- limit: Type.Optional(Type.Number({ description: "Maximum number of search results." })),
180
- tbs: Type.Optional(
181
- Type.String({ description: "Google-style time based search filter when supported." }),
182
- ),
183
- location: Type.Optional(Type.String({ description: "Search location when supported." })),
184
- scrapeOptions: Type.Optional(
185
- Type.Any({ description: "Firecrawl scrapeOptions for search result pages." }),
186
- ),
187
- }),
188
- async execute(_toolCallId, params, signal, _onUpdate, ctx) {
189
- return withStatus(ctx, "search", async () => {
190
- const payload = await firecrawlRequest(
191
- "POST",
192
- "/search",
193
- cleanObject(params),
194
- signal,
195
- ctx.sessionManager,
196
- );
197
- return await jsonResult(payload, ctx.sessionManager);
198
- });
199
- },
125
+ name: FIRECRAWL_TOOL_NAMES[4],
126
+ label: "Firecrawl: Search",
127
+ description: `Search the web through Firecrawl and optionally scrape search results. ${OUTPUT_LIMIT_DESCRIPTION}`,
128
+ parameters: Type.Object({
129
+ query: Type.String({ description: "Search query." }),
130
+ limit: Type.Optional(Type.Number({ description: "Maximum number of search results." })),
131
+ tbs: Type.Optional(Type.String({ description: "Google-style time based search filter when supported." })),
132
+ location: Type.Optional(Type.String({ description: "Search location when supported." })),
133
+ scrapeOptions: Type.Optional(Type.Any({ description: "Firecrawl scrapeOptions for search result pages." })),
134
+ }),
135
+ async execute(_toolCallId, params, signal, _onUpdate, ctx) {
136
+ return withStatus(ctx, "search", async () => {
137
+ const payload = await firecrawlRequest("POST", "/search", cleanObject(params), signal, ctx.sessionManager);
138
+ return await jsonResult(payload, ctx.sessionManager);
139
+ });
140
+ },
200
141
  });