firecrawl 4.1.0 → 4.2.0
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/{chunk-EX7LNARR.js → chunk-MKEZ44MR.js} +1 -1
- package/dist/index.cjs +40 -1
- package/dist/index.d.cts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +41 -2
- package/dist/{package-MVCQF4ZJ.js → package-7YDUGTZ6.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/e2e/v2/usage.test.ts +8 -0
- package/src/v1/index.ts +44 -1
- package/src/v2/client.ts +6 -1
- package/src/v2/methods/usage.ts +11 -1
- package/src/v2/types.ts +8 -0
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@mendable/firecrawl-js",
|
|
11
|
-
version: "4.
|
|
11
|
+
version: "4.2.0",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@mendable/firecrawl-js",
|
|
38
|
-
version: "4.
|
|
38
|
+
version: "4.2.0",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -756,6 +756,16 @@ async function getTokenUsage(http) {
|
|
|
756
756
|
throw err;
|
|
757
757
|
}
|
|
758
758
|
}
|
|
759
|
+
async function getQueueStatus(http) {
|
|
760
|
+
try {
|
|
761
|
+
const res = await http.get("/v2/team/queue-status");
|
|
762
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
763
|
+
return res.data;
|
|
764
|
+
} catch (err) {
|
|
765
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
766
|
+
throw err;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
759
769
|
|
|
760
770
|
// src/v2/watcher.ts
|
|
761
771
|
var import_events = require("events");
|
|
@@ -1063,6 +1073,10 @@ var FirecrawlClient = class {
|
|
|
1063
1073
|
async getTokenUsage() {
|
|
1064
1074
|
return getTokenUsage(this.http);
|
|
1065
1075
|
}
|
|
1076
|
+
/** Metrics about the team's scrape queue. */
|
|
1077
|
+
async getQueueStatus() {
|
|
1078
|
+
return getQueueStatus(this.http);
|
|
1079
|
+
}
|
|
1066
1080
|
// Watcher
|
|
1067
1081
|
/**
|
|
1068
1082
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
@@ -2309,6 +2323,31 @@ var FirecrawlApp = class {
|
|
|
2309
2323
|
}
|
|
2310
2324
|
return { success: false, error: "Internal server error." };
|
|
2311
2325
|
}
|
|
2326
|
+
/**
|
|
2327
|
+
* Gets metrics about the team's scrape queue.
|
|
2328
|
+
* @returns The current queue status.
|
|
2329
|
+
*/
|
|
2330
|
+
async getQueueStatus() {
|
|
2331
|
+
const headers = this.prepareHeaders();
|
|
2332
|
+
try {
|
|
2333
|
+
const response = await this.getRequest(
|
|
2334
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2335
|
+
headers
|
|
2336
|
+
);
|
|
2337
|
+
if (response.status === 200) {
|
|
2338
|
+
return response.data;
|
|
2339
|
+
} else {
|
|
2340
|
+
this.handleError(response, "get queue status");
|
|
2341
|
+
}
|
|
2342
|
+
} catch (error) {
|
|
2343
|
+
if (error.response?.data?.error) {
|
|
2344
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2345
|
+
} else {
|
|
2346
|
+
throw new FirecrawlError(error.message, 500);
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
return { success: false, error: "Internal server error." };
|
|
2350
|
+
}
|
|
2312
2351
|
};
|
|
2313
2352
|
var CrawlWatcher = class extends e {
|
|
2314
2353
|
ws;
|
package/dist/index.d.cts
CHANGED
|
@@ -324,6 +324,14 @@ declare class SdkError extends Error {
|
|
|
324
324
|
details?: unknown;
|
|
325
325
|
constructor(message: string, status?: number, code?: string, details?: unknown);
|
|
326
326
|
}
|
|
327
|
+
interface QueueStatusResponse$1 {
|
|
328
|
+
success: boolean;
|
|
329
|
+
jobsInQueue: number;
|
|
330
|
+
activeJobsInQueue: number;
|
|
331
|
+
waitingJobsInQueue: number;
|
|
332
|
+
maxConcurrency: number;
|
|
333
|
+
mostRecentSuccess: string | null;
|
|
334
|
+
}
|
|
327
335
|
|
|
328
336
|
interface HttpClientOptions {
|
|
329
337
|
apiKey: string;
|
|
@@ -544,6 +552,8 @@ declare class FirecrawlClient {
|
|
|
544
552
|
getCreditUsage(): Promise<CreditUsage>;
|
|
545
553
|
/** Recent token usage. */
|
|
546
554
|
getTokenUsage(): Promise<TokenUsage>;
|
|
555
|
+
/** Metrics about the team's scrape queue. */
|
|
556
|
+
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
547
557
|
/**
|
|
548
558
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
549
559
|
* @param jobId Job id.
|
|
@@ -1068,6 +1078,20 @@ interface GenerateLLMsTextStatusResponse {
|
|
|
1068
1078
|
error?: string;
|
|
1069
1079
|
expiresAt: string;
|
|
1070
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Response interface for queue status operations.
|
|
1083
|
+
*/
|
|
1084
|
+
interface QueueStatusResponse {
|
|
1085
|
+
success: boolean;
|
|
1086
|
+
jobsInQueue: number;
|
|
1087
|
+
activeJobsInQueue: number;
|
|
1088
|
+
waitingJobsInQueue: number;
|
|
1089
|
+
maxConcurrency: number;
|
|
1090
|
+
/**
|
|
1091
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
1092
|
+
*/
|
|
1093
|
+
mostRecentSuccess: string | null;
|
|
1094
|
+
}
|
|
1071
1095
|
/**
|
|
1072
1096
|
* Main class for interacting with the Firecrawl API.
|
|
1073
1097
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1251,7 +1275,7 @@ declare class FirecrawlApp {
|
|
|
1251
1275
|
* @param {AxiosResponse} response - The response from the API.
|
|
1252
1276
|
* @param {string} action - The action being performed when the error occurred.
|
|
1253
1277
|
*/
|
|
1254
|
-
handleError(response: AxiosResponse, action: string):
|
|
1278
|
+
handleError(response: AxiosResponse, action: string): never;
|
|
1255
1279
|
/**
|
|
1256
1280
|
* Initiates a deep research operation on a given query and polls until completion.
|
|
1257
1281
|
* @param query - The query to research.
|
|
@@ -1333,6 +1357,11 @@ declare class FirecrawlApp {
|
|
|
1333
1357
|
* @returns The current status and results of the generation operation.
|
|
1334
1358
|
*/
|
|
1335
1359
|
checkGenerateLLMsTextStatus(id: string): Promise<GenerateLLMsTextStatusResponse | ErrorResponse>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Gets metrics about the team's scrape queue.
|
|
1362
|
+
* @returns The current queue status.
|
|
1363
|
+
*/
|
|
1364
|
+
getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse>;
|
|
1336
1365
|
}
|
|
1337
1366
|
interface CrawlWatcherEvents {
|
|
1338
1367
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1374,4 +1403,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1374
1403
|
get v1(): FirecrawlApp;
|
|
1375
1404
|
}
|
|
1376
1405
|
|
|
1377
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1406
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -324,6 +324,14 @@ declare class SdkError extends Error {
|
|
|
324
324
|
details?: unknown;
|
|
325
325
|
constructor(message: string, status?: number, code?: string, details?: unknown);
|
|
326
326
|
}
|
|
327
|
+
interface QueueStatusResponse$1 {
|
|
328
|
+
success: boolean;
|
|
329
|
+
jobsInQueue: number;
|
|
330
|
+
activeJobsInQueue: number;
|
|
331
|
+
waitingJobsInQueue: number;
|
|
332
|
+
maxConcurrency: number;
|
|
333
|
+
mostRecentSuccess: string | null;
|
|
334
|
+
}
|
|
327
335
|
|
|
328
336
|
interface HttpClientOptions {
|
|
329
337
|
apiKey: string;
|
|
@@ -544,6 +552,8 @@ declare class FirecrawlClient {
|
|
|
544
552
|
getCreditUsage(): Promise<CreditUsage>;
|
|
545
553
|
/** Recent token usage. */
|
|
546
554
|
getTokenUsage(): Promise<TokenUsage>;
|
|
555
|
+
/** Metrics about the team's scrape queue. */
|
|
556
|
+
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
547
557
|
/**
|
|
548
558
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
549
559
|
* @param jobId Job id.
|
|
@@ -1068,6 +1078,20 @@ interface GenerateLLMsTextStatusResponse {
|
|
|
1068
1078
|
error?: string;
|
|
1069
1079
|
expiresAt: string;
|
|
1070
1080
|
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Response interface for queue status operations.
|
|
1083
|
+
*/
|
|
1084
|
+
interface QueueStatusResponse {
|
|
1085
|
+
success: boolean;
|
|
1086
|
+
jobsInQueue: number;
|
|
1087
|
+
activeJobsInQueue: number;
|
|
1088
|
+
waitingJobsInQueue: number;
|
|
1089
|
+
maxConcurrency: number;
|
|
1090
|
+
/**
|
|
1091
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
1092
|
+
*/
|
|
1093
|
+
mostRecentSuccess: string | null;
|
|
1094
|
+
}
|
|
1071
1095
|
/**
|
|
1072
1096
|
* Main class for interacting with the Firecrawl API.
|
|
1073
1097
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1251,7 +1275,7 @@ declare class FirecrawlApp {
|
|
|
1251
1275
|
* @param {AxiosResponse} response - The response from the API.
|
|
1252
1276
|
* @param {string} action - The action being performed when the error occurred.
|
|
1253
1277
|
*/
|
|
1254
|
-
handleError(response: AxiosResponse, action: string):
|
|
1278
|
+
handleError(response: AxiosResponse, action: string): never;
|
|
1255
1279
|
/**
|
|
1256
1280
|
* Initiates a deep research operation on a given query and polls until completion.
|
|
1257
1281
|
* @param query - The query to research.
|
|
@@ -1333,6 +1357,11 @@ declare class FirecrawlApp {
|
|
|
1333
1357
|
* @returns The current status and results of the generation operation.
|
|
1334
1358
|
*/
|
|
1335
1359
|
checkGenerateLLMsTextStatus(id: string): Promise<GenerateLLMsTextStatusResponse | ErrorResponse>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Gets metrics about the team's scrape queue.
|
|
1362
|
+
* @returns The current queue status.
|
|
1363
|
+
*/
|
|
1364
|
+
getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse>;
|
|
1336
1365
|
}
|
|
1337
1366
|
interface CrawlWatcherEvents {
|
|
1338
1367
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1374,4 +1403,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1374
1403
|
get v1(): FirecrawlApp;
|
|
1375
1404
|
}
|
|
1376
1405
|
|
|
1377
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1406
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
require_package
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MKEZ44MR.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -640,6 +640,16 @@ async function getTokenUsage(http) {
|
|
|
640
640
|
throw err;
|
|
641
641
|
}
|
|
642
642
|
}
|
|
643
|
+
async function getQueueStatus(http) {
|
|
644
|
+
try {
|
|
645
|
+
const res = await http.get("/v2/team/queue-status");
|
|
646
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
647
|
+
return res.data;
|
|
648
|
+
} catch (err) {
|
|
649
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
650
|
+
throw err;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
643
653
|
|
|
644
654
|
// src/v2/watcher.ts
|
|
645
655
|
import { EventEmitter } from "events";
|
|
@@ -947,6 +957,10 @@ var FirecrawlClient = class {
|
|
|
947
957
|
async getTokenUsage() {
|
|
948
958
|
return getTokenUsage(this.http);
|
|
949
959
|
}
|
|
960
|
+
/** Metrics about the team's scrape queue. */
|
|
961
|
+
async getQueueStatus() {
|
|
962
|
+
return getQueueStatus(this.http);
|
|
963
|
+
}
|
|
950
964
|
// Watcher
|
|
951
965
|
/**
|
|
952
966
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
@@ -992,7 +1006,7 @@ var FirecrawlApp = class {
|
|
|
992
1006
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
993
1007
|
return process.env.npm_package_version;
|
|
994
1008
|
}
|
|
995
|
-
const packageJson = await import("./package-
|
|
1009
|
+
const packageJson = await import("./package-7YDUGTZ6.js");
|
|
996
1010
|
return packageJson.default.version;
|
|
997
1011
|
} catch (error) {
|
|
998
1012
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -2193,6 +2207,31 @@ var FirecrawlApp = class {
|
|
|
2193
2207
|
}
|
|
2194
2208
|
return { success: false, error: "Internal server error." };
|
|
2195
2209
|
}
|
|
2210
|
+
/**
|
|
2211
|
+
* Gets metrics about the team's scrape queue.
|
|
2212
|
+
* @returns The current queue status.
|
|
2213
|
+
*/
|
|
2214
|
+
async getQueueStatus() {
|
|
2215
|
+
const headers = this.prepareHeaders();
|
|
2216
|
+
try {
|
|
2217
|
+
const response = await this.getRequest(
|
|
2218
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2219
|
+
headers
|
|
2220
|
+
);
|
|
2221
|
+
if (response.status === 200) {
|
|
2222
|
+
return response.data;
|
|
2223
|
+
} else {
|
|
2224
|
+
this.handleError(response, "get queue status");
|
|
2225
|
+
}
|
|
2226
|
+
} catch (error) {
|
|
2227
|
+
if (error.response?.data?.error) {
|
|
2228
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2229
|
+
} else {
|
|
2230
|
+
throw new FirecrawlError(error.message, 500);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
return { success: false, error: "Internal server error." };
|
|
2234
|
+
}
|
|
2196
2235
|
};
|
|
2197
2236
|
var CrawlWatcher = class extends e {
|
|
2198
2237
|
ws;
|
package/package.json
CHANGED
|
@@ -32,5 +32,13 @@ describe("v2.usage e2e", () => {
|
|
|
32
32
|
const resp = await client.getTokenUsage();
|
|
33
33
|
expect(typeof resp.remainingTokens).toBe("number");
|
|
34
34
|
}, 60_000);
|
|
35
|
+
|
|
36
|
+
test("get_queue_status", async () => {
|
|
37
|
+
const resp = await client.getQueueStatus();
|
|
38
|
+
expect(typeof resp.jobsInQueue).toBe("number");
|
|
39
|
+
expect(typeof resp.activeJobsInQueue).toBe("number");
|
|
40
|
+
expect(typeof resp.waitingJobsInQueue).toBe("number");
|
|
41
|
+
expect(typeof resp.maxConcurrency).toBe("number");
|
|
42
|
+
}, 60_000);
|
|
35
43
|
});
|
|
36
44
|
|
package/src/v1/index.ts
CHANGED
|
@@ -568,6 +568,22 @@ export interface GenerateLLMsTextStatusResponse {
|
|
|
568
568
|
expiresAt: string;
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Response interface for queue status operations.
|
|
573
|
+
*/
|
|
574
|
+
export interface QueueStatusResponse {
|
|
575
|
+
success: boolean;
|
|
576
|
+
jobsInQueue: number;
|
|
577
|
+
activeJobsInQueue: number;
|
|
578
|
+
waitingJobsInQueue: number;
|
|
579
|
+
maxConcurrency: number;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
583
|
+
*/
|
|
584
|
+
mostRecentSuccess: string | null;
|
|
585
|
+
}
|
|
586
|
+
|
|
571
587
|
/**
|
|
572
588
|
* Main class for interacting with the Firecrawl API.
|
|
573
589
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1586,7 +1602,7 @@ export default class FirecrawlApp {
|
|
|
1586
1602
|
* @param {AxiosResponse} response - The response from the API.
|
|
1587
1603
|
* @param {string} action - The action being performed when the error occurred.
|
|
1588
1604
|
*/
|
|
1589
|
-
handleError(response: AxiosResponse, action: string):
|
|
1605
|
+
handleError(response: AxiosResponse, action: string): never {
|
|
1590
1606
|
if (!response) {
|
|
1591
1607
|
throw new FirecrawlError(
|
|
1592
1608
|
`No response received while trying to ${action}. This may be a network error or the server is unreachable.`,
|
|
@@ -2027,6 +2043,33 @@ export default class FirecrawlApp {
|
|
|
2027
2043
|
}
|
|
2028
2044
|
return { success: false, error: "Internal server error." };
|
|
2029
2045
|
}
|
|
2046
|
+
|
|
2047
|
+
/**
|
|
2048
|
+
* Gets metrics about the team's scrape queue.
|
|
2049
|
+
* @returns The current queue status.
|
|
2050
|
+
*/
|
|
2051
|
+
async getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse> {
|
|
2052
|
+
const headers = this.prepareHeaders();
|
|
2053
|
+
try {
|
|
2054
|
+
const response: AxiosResponse = await this.getRequest(
|
|
2055
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2056
|
+
headers
|
|
2057
|
+
);
|
|
2058
|
+
|
|
2059
|
+
if (response.status === 200) {
|
|
2060
|
+
return response.data;
|
|
2061
|
+
} else {
|
|
2062
|
+
this.handleError(response, "get queue status");
|
|
2063
|
+
}
|
|
2064
|
+
} catch (error: any) {
|
|
2065
|
+
if (error.response?.data?.error) {
|
|
2066
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2067
|
+
} else {
|
|
2068
|
+
throw new FirecrawlError(error.message, 500);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
return { success: false, error: "Internal server error." };
|
|
2072
|
+
}
|
|
2030
2073
|
}
|
|
2031
2074
|
|
|
2032
2075
|
interface CrawlWatcherEvents {
|
package/src/v2/client.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
batchScrape as batchWaiter,
|
|
20
20
|
} from "./methods/batch";
|
|
21
21
|
import { startExtract, getExtractStatus, extract as extractWaiter } from "./methods/extract";
|
|
22
|
-
import { getConcurrency, getCreditUsage, getTokenUsage } from "./methods/usage";
|
|
22
|
+
import { getConcurrency, getCreditUsage, getQueueStatus, getTokenUsage } from "./methods/usage";
|
|
23
23
|
import type {
|
|
24
24
|
Document,
|
|
25
25
|
ScrapeOptions,
|
|
@@ -269,6 +269,11 @@ export class FirecrawlClient {
|
|
|
269
269
|
return getTokenUsage(this.http);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/** Metrics about the team's scrape queue. */
|
|
273
|
+
async getQueueStatus() {
|
|
274
|
+
return getQueueStatus(this.http);
|
|
275
|
+
}
|
|
276
|
+
|
|
272
277
|
// Watcher
|
|
273
278
|
/**
|
|
274
279
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
package/src/v2/methods/usage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConcurrencyCheck, CreditUsage, TokenUsage } from "../types";
|
|
1
|
+
import type { ConcurrencyCheck, CreditUsage, QueueStatusResponse, TokenUsage } from "../types";
|
|
2
2
|
import { HttpClient } from "../utils/httpClient";
|
|
3
3
|
import { normalizeAxiosError, throwForBadResponse } from "../utils/errorHandler";
|
|
4
4
|
|
|
@@ -37,3 +37,13 @@ export async function getTokenUsage(http: HttpClient): Promise<TokenUsage> {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
export async function getQueueStatus(http: HttpClient): Promise<QueueStatusResponse> {
|
|
41
|
+
try {
|
|
42
|
+
const res = await http.get<QueueStatusResponse>("/v2/team/queue-status");
|
|
43
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
44
|
+
return res.data;
|
|
45
|
+
} catch (err: any) {
|
|
46
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/v2/types.ts
CHANGED
|
@@ -388,3 +388,11 @@ export class SdkError extends Error {
|
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
390
|
|
|
391
|
+
export interface QueueStatusResponse {
|
|
392
|
+
success: boolean;
|
|
393
|
+
jobsInQueue: number;
|
|
394
|
+
activeJobsInQueue: number;
|
|
395
|
+
waitingJobsInQueue: number;
|
|
396
|
+
maxConcurrency: number;
|
|
397
|
+
mostRecentSuccess: string | null;
|
|
398
|
+
}
|