@mendable/firecrawl 1.19.2 → 1.21.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.cjs +19 -3
- package/dist/index.d.cts +39 -8
- package/dist/index.d.ts +39 -8
- package/dist/index.js +19 -3
- package/package.json +1 -1
- package/src/index.ts +64 -10
package/dist/index.cjs
CHANGED
|
@@ -419,6 +419,7 @@ var FirecrawlApp = class {
|
|
|
419
419
|
* @param pollInterval - Time in seconds for job status checks.
|
|
420
420
|
* @param idempotencyKey - Optional idempotency key for the request.
|
|
421
421
|
* @param webhook - Optional webhook for the batch scrape.
|
|
422
|
+
* @param ignoreInvalidURLs - Optional flag to ignore invalid URLs.
|
|
422
423
|
* @returns The response from the crawl operation.
|
|
423
424
|
*/
|
|
424
425
|
async batchScrapeUrls(urls, params, pollInterval = 2, idempotencyKey, webhook, ignoreInvalidURLs) {
|
|
@@ -607,7 +608,7 @@ var FirecrawlApp = class {
|
|
|
607
608
|
/**
|
|
608
609
|
* Extracts information from URLs using the Firecrawl API.
|
|
609
610
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
610
|
-
* @param
|
|
611
|
+
* @param urls - The URLs to extract information from. Optional if using other methods for data extraction.
|
|
611
612
|
* @param params - Additional parameters for the extract request.
|
|
612
613
|
* @returns The response from the extract operation.
|
|
613
614
|
*/
|
|
@@ -841,7 +842,7 @@ var FirecrawlApp = class {
|
|
|
841
842
|
* @param {string} action - The action being performed when the error occurred.
|
|
842
843
|
*/
|
|
843
844
|
handleError(response, action) {
|
|
844
|
-
if ([400, 402, 408, 409, 500].includes(response.status)) {
|
|
845
|
+
if ([400, 402, 403, 408, 409, 500].includes(response.status)) {
|
|
845
846
|
const errorMessage = response.data.error || "Unknown error occurred";
|
|
846
847
|
const details = response.data.details ? ` - ${JSON.stringify(response.data.details)}` : "";
|
|
847
848
|
throw new FirecrawlError(
|
|
@@ -922,10 +923,25 @@ var FirecrawlApp = class {
|
|
|
922
923
|
*/
|
|
923
924
|
async asyncDeepResearch(query, params) {
|
|
924
925
|
const headers = this.prepareHeaders();
|
|
926
|
+
let jsonData = { query, ...params };
|
|
927
|
+
if (jsonData?.jsonOptions?.schema) {
|
|
928
|
+
let schema = jsonData.jsonOptions.schema;
|
|
929
|
+
try {
|
|
930
|
+
schema = (0, import_zod_to_json_schema.zodToJsonSchema)(schema);
|
|
931
|
+
} catch (error) {
|
|
932
|
+
}
|
|
933
|
+
jsonData = {
|
|
934
|
+
...jsonData,
|
|
935
|
+
jsonOptions: {
|
|
936
|
+
...jsonData.jsonOptions,
|
|
937
|
+
schema
|
|
938
|
+
}
|
|
939
|
+
};
|
|
940
|
+
}
|
|
925
941
|
try {
|
|
926
942
|
const response = await this.postRequest(
|
|
927
943
|
`${this.apiUrl}/v1/deep-research`,
|
|
928
|
-
|
|
944
|
+
jsonData,
|
|
929
945
|
headers
|
|
930
946
|
);
|
|
931
947
|
if (response.status === 200) {
|
package/dist/index.d.cts
CHANGED
|
@@ -65,6 +65,11 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
65
65
|
screenshot?: string;
|
|
66
66
|
metadata?: FirecrawlDocumentMetadata;
|
|
67
67
|
actions: ActionsSchema;
|
|
68
|
+
compare?: {
|
|
69
|
+
previousScrapeAt: string | null;
|
|
70
|
+
changeStatus: "new" | "same" | "changed" | "removed";
|
|
71
|
+
visibility: "visible" | "hidden";
|
|
72
|
+
};
|
|
68
73
|
title?: string;
|
|
69
74
|
description?: string;
|
|
70
75
|
}
|
|
@@ -73,7 +78,7 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
73
78
|
* Defines the options and configurations available for scraping web content.
|
|
74
79
|
*/
|
|
75
80
|
interface CrawlScrapeOptions {
|
|
76
|
-
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json")[];
|
|
81
|
+
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json" | "compare")[];
|
|
77
82
|
headers?: Record<string, string>;
|
|
78
83
|
includeTags?: string[];
|
|
79
84
|
excludeTags?: string[];
|
|
@@ -97,6 +102,7 @@ type Action = {
|
|
|
97
102
|
} | {
|
|
98
103
|
type: "click";
|
|
99
104
|
selector: string;
|
|
105
|
+
all?: boolean;
|
|
100
106
|
} | {
|
|
101
107
|
type: "screenshot";
|
|
102
108
|
fullPage?: boolean;
|
|
@@ -131,6 +137,14 @@ interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchema exten
|
|
|
131
137
|
}
|
|
132
138
|
interface ActionsResult {
|
|
133
139
|
screenshots: string[];
|
|
140
|
+
scrapes: ({
|
|
141
|
+
url: string;
|
|
142
|
+
html: string;
|
|
143
|
+
})[];
|
|
144
|
+
javascriptReturns: {
|
|
145
|
+
type: string;
|
|
146
|
+
value: unknown;
|
|
147
|
+
}[];
|
|
134
148
|
}
|
|
135
149
|
/**
|
|
136
150
|
* Response interface for scraping operations.
|
|
@@ -325,7 +339,7 @@ interface CrawlErrorsResponse {
|
|
|
325
339
|
* Parameters for deep research operations.
|
|
326
340
|
* Defines options for conducting deep research on a query.
|
|
327
341
|
*/
|
|
328
|
-
interface DeepResearchParams {
|
|
342
|
+
interface DeepResearchParams<LLMSchema extends zt.ZodSchema = any> {
|
|
329
343
|
/**
|
|
330
344
|
* Maximum depth of research iterations (1-10)
|
|
331
345
|
* @default 7
|
|
@@ -342,9 +356,25 @@ interface DeepResearchParams {
|
|
|
342
356
|
*/
|
|
343
357
|
maxUrls?: number;
|
|
344
358
|
/**
|
|
345
|
-
*
|
|
359
|
+
* The prompt to use for the final analysis
|
|
360
|
+
*/
|
|
361
|
+
analysisPrompt?: string;
|
|
362
|
+
/**
|
|
363
|
+
* The system prompt to use for the research agent
|
|
364
|
+
*/
|
|
365
|
+
systemPrompt?: string;
|
|
366
|
+
/**
|
|
367
|
+
* The formats to use for the final analysis
|
|
368
|
+
*/
|
|
369
|
+
formats?: ("markdown" | "json")[];
|
|
370
|
+
/**
|
|
371
|
+
* The JSON options to use for the final analysis
|
|
346
372
|
*/
|
|
347
|
-
|
|
373
|
+
jsonOptions?: {
|
|
374
|
+
prompt?: string;
|
|
375
|
+
schema?: LLMSchema;
|
|
376
|
+
systemPrompt?: string;
|
|
377
|
+
};
|
|
348
378
|
}
|
|
349
379
|
/**
|
|
350
380
|
* Response interface for deep research operations.
|
|
@@ -512,6 +542,7 @@ declare class FirecrawlApp {
|
|
|
512
542
|
* @param pollInterval - Time in seconds for job status checks.
|
|
513
543
|
* @param idempotencyKey - Optional idempotency key for the request.
|
|
514
544
|
* @param webhook - Optional webhook for the batch scrape.
|
|
545
|
+
* @param ignoreInvalidURLs - Optional flag to ignore invalid URLs.
|
|
515
546
|
* @returns The response from the crawl operation.
|
|
516
547
|
*/
|
|
517
548
|
batchScrapeUrls(urls: string[], params?: ScrapeParams, pollInterval?: number, idempotencyKey?: string, webhook?: CrawlParams["webhook"], ignoreInvalidURLs?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
|
|
@@ -543,11 +574,11 @@ declare class FirecrawlApp {
|
|
|
543
574
|
/**
|
|
544
575
|
* Extracts information from URLs using the Firecrawl API.
|
|
545
576
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
546
|
-
* @param
|
|
577
|
+
* @param urls - The URLs to extract information from. Optional if using other methods for data extraction.
|
|
547
578
|
* @param params - Additional parameters for the extract request.
|
|
548
579
|
* @returns The response from the extract operation.
|
|
549
580
|
*/
|
|
550
|
-
extract<T extends zt.ZodSchema = any>(urls
|
|
581
|
+
extract<T extends zt.ZodSchema = any>(urls?: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse>;
|
|
551
582
|
/**
|
|
552
583
|
* Initiates an asynchronous extract job for a URL using the Firecrawl API.
|
|
553
584
|
* @param url - The URL to extract data from.
|
|
@@ -613,7 +644,7 @@ declare class FirecrawlApp {
|
|
|
613
644
|
* @param onSource - Optional callback to receive source updates in real-time.
|
|
614
645
|
* @returns The final research results.
|
|
615
646
|
*/
|
|
616
|
-
deepResearch(query: string, params: DeepResearchParams
|
|
647
|
+
deepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>, onActivity?: (activity: {
|
|
617
648
|
type: string;
|
|
618
649
|
status: string;
|
|
619
650
|
message: string;
|
|
@@ -630,7 +661,7 @@ declare class FirecrawlApp {
|
|
|
630
661
|
* @param params - Parameters for the deep research operation.
|
|
631
662
|
* @returns The response containing the research job ID.
|
|
632
663
|
*/
|
|
633
|
-
asyncDeepResearch(query: string, params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
|
|
664
|
+
asyncDeepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>): Promise<DeepResearchResponse | ErrorResponse>;
|
|
634
665
|
/**
|
|
635
666
|
* Checks the status of a deep research operation.
|
|
636
667
|
* @param id - The ID of the deep research operation.
|
package/dist/index.d.ts
CHANGED
|
@@ -65,6 +65,11 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
65
65
|
screenshot?: string;
|
|
66
66
|
metadata?: FirecrawlDocumentMetadata;
|
|
67
67
|
actions: ActionsSchema;
|
|
68
|
+
compare?: {
|
|
69
|
+
previousScrapeAt: string | null;
|
|
70
|
+
changeStatus: "new" | "same" | "changed" | "removed";
|
|
71
|
+
visibility: "visible" | "hidden";
|
|
72
|
+
};
|
|
68
73
|
title?: string;
|
|
69
74
|
description?: string;
|
|
70
75
|
}
|
|
@@ -73,7 +78,7 @@ interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult | neve
|
|
|
73
78
|
* Defines the options and configurations available for scraping web content.
|
|
74
79
|
*/
|
|
75
80
|
interface CrawlScrapeOptions {
|
|
76
|
-
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json")[];
|
|
81
|
+
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json" | "compare")[];
|
|
77
82
|
headers?: Record<string, string>;
|
|
78
83
|
includeTags?: string[];
|
|
79
84
|
excludeTags?: string[];
|
|
@@ -97,6 +102,7 @@ type Action = {
|
|
|
97
102
|
} | {
|
|
98
103
|
type: "click";
|
|
99
104
|
selector: string;
|
|
105
|
+
all?: boolean;
|
|
100
106
|
} | {
|
|
101
107
|
type: "screenshot";
|
|
102
108
|
fullPage?: boolean;
|
|
@@ -131,6 +137,14 @@ interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchema exten
|
|
|
131
137
|
}
|
|
132
138
|
interface ActionsResult {
|
|
133
139
|
screenshots: string[];
|
|
140
|
+
scrapes: ({
|
|
141
|
+
url: string;
|
|
142
|
+
html: string;
|
|
143
|
+
})[];
|
|
144
|
+
javascriptReturns: {
|
|
145
|
+
type: string;
|
|
146
|
+
value: unknown;
|
|
147
|
+
}[];
|
|
134
148
|
}
|
|
135
149
|
/**
|
|
136
150
|
* Response interface for scraping operations.
|
|
@@ -325,7 +339,7 @@ interface CrawlErrorsResponse {
|
|
|
325
339
|
* Parameters for deep research operations.
|
|
326
340
|
* Defines options for conducting deep research on a query.
|
|
327
341
|
*/
|
|
328
|
-
interface DeepResearchParams {
|
|
342
|
+
interface DeepResearchParams<LLMSchema extends zt.ZodSchema = any> {
|
|
329
343
|
/**
|
|
330
344
|
* Maximum depth of research iterations (1-10)
|
|
331
345
|
* @default 7
|
|
@@ -342,9 +356,25 @@ interface DeepResearchParams {
|
|
|
342
356
|
*/
|
|
343
357
|
maxUrls?: number;
|
|
344
358
|
/**
|
|
345
|
-
*
|
|
359
|
+
* The prompt to use for the final analysis
|
|
360
|
+
*/
|
|
361
|
+
analysisPrompt?: string;
|
|
362
|
+
/**
|
|
363
|
+
* The system prompt to use for the research agent
|
|
364
|
+
*/
|
|
365
|
+
systemPrompt?: string;
|
|
366
|
+
/**
|
|
367
|
+
* The formats to use for the final analysis
|
|
368
|
+
*/
|
|
369
|
+
formats?: ("markdown" | "json")[];
|
|
370
|
+
/**
|
|
371
|
+
* The JSON options to use for the final analysis
|
|
346
372
|
*/
|
|
347
|
-
|
|
373
|
+
jsonOptions?: {
|
|
374
|
+
prompt?: string;
|
|
375
|
+
schema?: LLMSchema;
|
|
376
|
+
systemPrompt?: string;
|
|
377
|
+
};
|
|
348
378
|
}
|
|
349
379
|
/**
|
|
350
380
|
* Response interface for deep research operations.
|
|
@@ -512,6 +542,7 @@ declare class FirecrawlApp {
|
|
|
512
542
|
* @param pollInterval - Time in seconds for job status checks.
|
|
513
543
|
* @param idempotencyKey - Optional idempotency key for the request.
|
|
514
544
|
* @param webhook - Optional webhook for the batch scrape.
|
|
545
|
+
* @param ignoreInvalidURLs - Optional flag to ignore invalid URLs.
|
|
515
546
|
* @returns The response from the crawl operation.
|
|
516
547
|
*/
|
|
517
548
|
batchScrapeUrls(urls: string[], params?: ScrapeParams, pollInterval?: number, idempotencyKey?: string, webhook?: CrawlParams["webhook"], ignoreInvalidURLs?: boolean): Promise<BatchScrapeStatusResponse | ErrorResponse>;
|
|
@@ -543,11 +574,11 @@ declare class FirecrawlApp {
|
|
|
543
574
|
/**
|
|
544
575
|
* Extracts information from URLs using the Firecrawl API.
|
|
545
576
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
546
|
-
* @param
|
|
577
|
+
* @param urls - The URLs to extract information from. Optional if using other methods for data extraction.
|
|
547
578
|
* @param params - Additional parameters for the extract request.
|
|
548
579
|
* @returns The response from the extract operation.
|
|
549
580
|
*/
|
|
550
|
-
extract<T extends zt.ZodSchema = any>(urls
|
|
581
|
+
extract<T extends zt.ZodSchema = any>(urls?: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse>;
|
|
551
582
|
/**
|
|
552
583
|
* Initiates an asynchronous extract job for a URL using the Firecrawl API.
|
|
553
584
|
* @param url - The URL to extract data from.
|
|
@@ -613,7 +644,7 @@ declare class FirecrawlApp {
|
|
|
613
644
|
* @param onSource - Optional callback to receive source updates in real-time.
|
|
614
645
|
* @returns The final research results.
|
|
615
646
|
*/
|
|
616
|
-
deepResearch(query: string, params: DeepResearchParams
|
|
647
|
+
deepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>, onActivity?: (activity: {
|
|
617
648
|
type: string;
|
|
618
649
|
status: string;
|
|
619
650
|
message: string;
|
|
@@ -630,7 +661,7 @@ declare class FirecrawlApp {
|
|
|
630
661
|
* @param params - Parameters for the deep research operation.
|
|
631
662
|
* @returns The response containing the research job ID.
|
|
632
663
|
*/
|
|
633
|
-
asyncDeepResearch(query: string, params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
|
|
664
|
+
asyncDeepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>): Promise<DeepResearchResponse | ErrorResponse>;
|
|
634
665
|
/**
|
|
635
666
|
* Checks the status of a deep research operation.
|
|
636
667
|
* @param id - The ID of the deep research operation.
|
package/dist/index.js
CHANGED
|
@@ -383,6 +383,7 @@ var FirecrawlApp = class {
|
|
|
383
383
|
* @param pollInterval - Time in seconds for job status checks.
|
|
384
384
|
* @param idempotencyKey - Optional idempotency key for the request.
|
|
385
385
|
* @param webhook - Optional webhook for the batch scrape.
|
|
386
|
+
* @param ignoreInvalidURLs - Optional flag to ignore invalid URLs.
|
|
386
387
|
* @returns The response from the crawl operation.
|
|
387
388
|
*/
|
|
388
389
|
async batchScrapeUrls(urls, params, pollInterval = 2, idempotencyKey, webhook, ignoreInvalidURLs) {
|
|
@@ -571,7 +572,7 @@ var FirecrawlApp = class {
|
|
|
571
572
|
/**
|
|
572
573
|
* Extracts information from URLs using the Firecrawl API.
|
|
573
574
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
574
|
-
* @param
|
|
575
|
+
* @param urls - The URLs to extract information from. Optional if using other methods for data extraction.
|
|
575
576
|
* @param params - Additional parameters for the extract request.
|
|
576
577
|
* @returns The response from the extract operation.
|
|
577
578
|
*/
|
|
@@ -805,7 +806,7 @@ var FirecrawlApp = class {
|
|
|
805
806
|
* @param {string} action - The action being performed when the error occurred.
|
|
806
807
|
*/
|
|
807
808
|
handleError(response, action) {
|
|
808
|
-
if ([400, 402, 408, 409, 500].includes(response.status)) {
|
|
809
|
+
if ([400, 402, 403, 408, 409, 500].includes(response.status)) {
|
|
809
810
|
const errorMessage = response.data.error || "Unknown error occurred";
|
|
810
811
|
const details = response.data.details ? ` - ${JSON.stringify(response.data.details)}` : "";
|
|
811
812
|
throw new FirecrawlError(
|
|
@@ -886,10 +887,25 @@ var FirecrawlApp = class {
|
|
|
886
887
|
*/
|
|
887
888
|
async asyncDeepResearch(query, params) {
|
|
888
889
|
const headers = this.prepareHeaders();
|
|
890
|
+
let jsonData = { query, ...params };
|
|
891
|
+
if (jsonData?.jsonOptions?.schema) {
|
|
892
|
+
let schema = jsonData.jsonOptions.schema;
|
|
893
|
+
try {
|
|
894
|
+
schema = zodToJsonSchema(schema);
|
|
895
|
+
} catch (error) {
|
|
896
|
+
}
|
|
897
|
+
jsonData = {
|
|
898
|
+
...jsonData,
|
|
899
|
+
jsonOptions: {
|
|
900
|
+
...jsonData.jsonOptions,
|
|
901
|
+
schema
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
}
|
|
889
905
|
try {
|
|
890
906
|
const response = await this.postRequest(
|
|
891
907
|
`${this.apiUrl}/v1/deep-research`,
|
|
892
|
-
|
|
908
|
+
jsonData,
|
|
893
909
|
headers
|
|
894
910
|
);
|
|
895
911
|
if (response.status === 200) {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -69,6 +69,11 @@ export interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult
|
|
|
69
69
|
screenshot?: string;
|
|
70
70
|
metadata?: FirecrawlDocumentMetadata;
|
|
71
71
|
actions: ActionsSchema;
|
|
72
|
+
compare?: {
|
|
73
|
+
previousScrapeAt: string | null;
|
|
74
|
+
changeStatus: "new" | "same" | "changed" | "removed";
|
|
75
|
+
visibility: "visible" | "hidden";
|
|
76
|
+
};
|
|
72
77
|
// v1 search only
|
|
73
78
|
title?: string;
|
|
74
79
|
description?: string;
|
|
@@ -79,7 +84,7 @@ export interface FirecrawlDocument<T = any, ActionsSchema extends (ActionsResult
|
|
|
79
84
|
* Defines the options and configurations available for scraping web content.
|
|
80
85
|
*/
|
|
81
86
|
export interface CrawlScrapeOptions {
|
|
82
|
-
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json")[];
|
|
87
|
+
formats?: ("markdown" | "html" | "rawHtml" | "content" | "links" | "screenshot" | "screenshot@fullPage" | "extract" | "json" | "compare")[];
|
|
83
88
|
headers?: Record<string, string>;
|
|
84
89
|
includeTags?: string[];
|
|
85
90
|
excludeTags?: string[];
|
|
@@ -104,6 +109,7 @@ export type Action = {
|
|
|
104
109
|
} | {
|
|
105
110
|
type: "click",
|
|
106
111
|
selector: string,
|
|
112
|
+
all?: boolean,
|
|
107
113
|
} | {
|
|
108
114
|
type: "screenshot",
|
|
109
115
|
fullPage?: boolean,
|
|
@@ -140,6 +146,14 @@ export interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchem
|
|
|
140
146
|
|
|
141
147
|
export interface ActionsResult {
|
|
142
148
|
screenshots: string[];
|
|
149
|
+
scrapes: ({
|
|
150
|
+
url: string;
|
|
151
|
+
html: string;
|
|
152
|
+
})[];
|
|
153
|
+
javascriptReturns: {
|
|
154
|
+
type: string;
|
|
155
|
+
value: unknown
|
|
156
|
+
}[];
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
/**
|
|
@@ -355,7 +369,7 @@ export interface CrawlErrorsResponse {
|
|
|
355
369
|
* Parameters for deep research operations.
|
|
356
370
|
* Defines options for conducting deep research on a query.
|
|
357
371
|
*/
|
|
358
|
-
export interface DeepResearchParams {
|
|
372
|
+
export interface DeepResearchParams<LLMSchema extends zt.ZodSchema = any> {
|
|
359
373
|
/**
|
|
360
374
|
* Maximum depth of research iterations (1-10)
|
|
361
375
|
* @default 7
|
|
@@ -372,9 +386,29 @@ export interface DeepResearchParams {
|
|
|
372
386
|
*/
|
|
373
387
|
maxUrls?: number;
|
|
374
388
|
/**
|
|
389
|
+
* The prompt to use for the final analysis
|
|
390
|
+
*/
|
|
391
|
+
analysisPrompt?: string;
|
|
392
|
+
/**
|
|
393
|
+
* The system prompt to use for the research agent
|
|
394
|
+
*/
|
|
395
|
+
systemPrompt?: string;
|
|
396
|
+
/**
|
|
397
|
+
* The formats to use for the final analysis
|
|
398
|
+
*/
|
|
399
|
+
formats?: ("markdown" | "json")[];
|
|
400
|
+
/**
|
|
401
|
+
* The JSON options to use for the final analysis
|
|
402
|
+
*/
|
|
403
|
+
jsonOptions?:{
|
|
404
|
+
prompt?: string;
|
|
405
|
+
schema?: LLMSchema;
|
|
406
|
+
systemPrompt?: string;
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
375
409
|
* Experimental flag for streaming steps
|
|
376
410
|
*/
|
|
377
|
-
__experimental_streamSteps?: boolean;
|
|
411
|
+
// __experimental_streamSteps?: boolean;
|
|
378
412
|
}
|
|
379
413
|
|
|
380
414
|
/**
|
|
@@ -893,6 +927,7 @@ export default class FirecrawlApp {
|
|
|
893
927
|
* @param pollInterval - Time in seconds for job status checks.
|
|
894
928
|
* @param idempotencyKey - Optional idempotency key for the request.
|
|
895
929
|
* @param webhook - Optional webhook for the batch scrape.
|
|
930
|
+
* @param ignoreInvalidURLs - Optional flag to ignore invalid URLs.
|
|
896
931
|
* @returns The response from the crawl operation.
|
|
897
932
|
*/
|
|
898
933
|
async batchScrapeUrls(
|
|
@@ -1119,14 +1154,14 @@ export default class FirecrawlApp {
|
|
|
1119
1154
|
/**
|
|
1120
1155
|
* Extracts information from URLs using the Firecrawl API.
|
|
1121
1156
|
* Currently in Beta. Expect breaking changes on future minor versions.
|
|
1122
|
-
* @param
|
|
1157
|
+
* @param urls - The URLs to extract information from. Optional if using other methods for data extraction.
|
|
1123
1158
|
* @param params - Additional parameters for the extract request.
|
|
1124
1159
|
* @returns The response from the extract operation.
|
|
1125
1160
|
*/
|
|
1126
|
-
async extract<T extends zt.ZodSchema = any>(urls
|
|
1161
|
+
async extract<T extends zt.ZodSchema = any>(urls?: string[], params?: ExtractParams<T>): Promise<ExtractResponse<zt.infer<T>> | ErrorResponse> {
|
|
1127
1162
|
const headers = this.prepareHeaders();
|
|
1128
1163
|
|
|
1129
|
-
let jsonData: { urls
|
|
1164
|
+
let jsonData: { urls?: string[] } & ExtractParams<T> = { urls: urls, ...params };
|
|
1130
1165
|
let jsonSchema: any;
|
|
1131
1166
|
try {
|
|
1132
1167
|
if (!params?.schema) {
|
|
@@ -1388,7 +1423,7 @@ export default class FirecrawlApp {
|
|
|
1388
1423
|
* @param {string} action - The action being performed when the error occurred.
|
|
1389
1424
|
*/
|
|
1390
1425
|
handleError(response: AxiosResponse, action: string): void {
|
|
1391
|
-
if ([400, 402, 408, 409, 500].includes(response.status)) {
|
|
1426
|
+
if ([400, 402, 403, 408, 409, 500].includes(response.status)) {
|
|
1392
1427
|
const errorMessage: string =
|
|
1393
1428
|
response.data.error || "Unknown error occurred";
|
|
1394
1429
|
const details = response.data.details ? ` - ${JSON.stringify(response.data.details)}` : '';
|
|
@@ -1415,7 +1450,7 @@ export default class FirecrawlApp {
|
|
|
1415
1450
|
*/
|
|
1416
1451
|
async deepResearch(
|
|
1417
1452
|
query: string,
|
|
1418
|
-
params: DeepResearchParams
|
|
1453
|
+
params: DeepResearchParams<zt.ZodSchema>,
|
|
1419
1454
|
onActivity?: (activity: {
|
|
1420
1455
|
type: string;
|
|
1421
1456
|
status: string;
|
|
@@ -1500,12 +1535,31 @@ export default class FirecrawlApp {
|
|
|
1500
1535
|
* @param params - Parameters for the deep research operation.
|
|
1501
1536
|
* @returns The response containing the research job ID.
|
|
1502
1537
|
*/
|
|
1503
|
-
async asyncDeepResearch(query: string, params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse> {
|
|
1538
|
+
async asyncDeepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>): Promise<DeepResearchResponse | ErrorResponse> {
|
|
1504
1539
|
const headers = this.prepareHeaders();
|
|
1540
|
+
let jsonData: any = { query, ...params };
|
|
1541
|
+
|
|
1542
|
+
if (jsonData?.jsonOptions?.schema) {
|
|
1543
|
+
let schema = jsonData.jsonOptions.schema;
|
|
1544
|
+
// Try parsing the schema as a Zod schema
|
|
1545
|
+
try {
|
|
1546
|
+
schema = zodToJsonSchema(schema);
|
|
1547
|
+
} catch (error) {
|
|
1548
|
+
|
|
1549
|
+
}
|
|
1550
|
+
jsonData = {
|
|
1551
|
+
...jsonData,
|
|
1552
|
+
jsonOptions: {
|
|
1553
|
+
...jsonData.jsonOptions,
|
|
1554
|
+
schema: schema,
|
|
1555
|
+
},
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1505
1559
|
try {
|
|
1506
1560
|
const response: AxiosResponse = await this.postRequest(
|
|
1507
1561
|
`${this.apiUrl}/v1/deep-research`,
|
|
1508
|
-
|
|
1562
|
+
jsonData,
|
|
1509
1563
|
headers
|
|
1510
1564
|
);
|
|
1511
1565
|
|