@mendable/firecrawl-js 1.16.0 → 1.18.0-beta.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 +57 -1
- package/dist/index.d.cts +80 -1
- package/dist/index.d.ts +80 -1
- package/dist/index.js +57 -1
- package/package.json +1 -1
- package/src/index.ts +131 -1
package/dist/index.cjs
CHANGED
|
@@ -647,7 +647,8 @@ var FirecrawlApp = class {
|
|
|
647
647
|
success: true,
|
|
648
648
|
data: extractStatus.data,
|
|
649
649
|
warning: extractStatus.warning,
|
|
650
|
-
error: extractStatus.error
|
|
650
|
+
error: extractStatus.error,
|
|
651
|
+
sources: extractStatus?.sources || void 0
|
|
651
652
|
};
|
|
652
653
|
} else {
|
|
653
654
|
throw new FirecrawlError(`Failed to extract data. Error: ${extractStatus.error}`, statusResponse.status);
|
|
@@ -850,6 +851,61 @@ var FirecrawlApp = class {
|
|
|
850
851
|
);
|
|
851
852
|
}
|
|
852
853
|
}
|
|
854
|
+
/**
|
|
855
|
+
* Initiates a deep research operation on a given topic.
|
|
856
|
+
* @param params - Parameters for the deep research operation.
|
|
857
|
+
* @returns The response containing the research job ID.
|
|
858
|
+
*/
|
|
859
|
+
async __deepResearch(params) {
|
|
860
|
+
const headers = this.prepareHeaders();
|
|
861
|
+
try {
|
|
862
|
+
const response = await this.postRequest(
|
|
863
|
+
`${this.apiUrl}/v1/deep-research`,
|
|
864
|
+
params,
|
|
865
|
+
headers
|
|
866
|
+
);
|
|
867
|
+
if (response.status === 200) {
|
|
868
|
+
return response.data;
|
|
869
|
+
} else {
|
|
870
|
+
this.handleError(response, "start deep research");
|
|
871
|
+
}
|
|
872
|
+
} catch (error) {
|
|
873
|
+
if (error.response?.data?.error) {
|
|
874
|
+
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);
|
|
875
|
+
} else {
|
|
876
|
+
throw new FirecrawlError(error.message, 500);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return { success: false, error: "Internal server error." };
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Checks the status of a deep research operation.
|
|
883
|
+
* @param id - The ID of the deep research operation.
|
|
884
|
+
* @returns The current status and results of the research operation.
|
|
885
|
+
*/
|
|
886
|
+
async __checkDeepResearchStatus(id) {
|
|
887
|
+
const headers = this.prepareHeaders();
|
|
888
|
+
try {
|
|
889
|
+
const response = await this.getRequest(
|
|
890
|
+
`${this.apiUrl}/v1/deep-research/${id}`,
|
|
891
|
+
headers
|
|
892
|
+
);
|
|
893
|
+
if (response.status === 200) {
|
|
894
|
+
return response.data;
|
|
895
|
+
} else if (response.status === 404) {
|
|
896
|
+
throw new FirecrawlError("Deep research job not found", 404);
|
|
897
|
+
} else {
|
|
898
|
+
this.handleError(response, "check deep research status");
|
|
899
|
+
}
|
|
900
|
+
} catch (error) {
|
|
901
|
+
if (error.response?.data?.error) {
|
|
902
|
+
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);
|
|
903
|
+
} else {
|
|
904
|
+
throw new FirecrawlError(error.message, 500);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
return { success: false, error: "Internal server error." };
|
|
908
|
+
}
|
|
853
909
|
};
|
|
854
910
|
var CrawlWatcher = class extends import_typescript_event_target.TypedEventTarget {
|
|
855
911
|
ws;
|
package/dist/index.d.cts
CHANGED
|
@@ -244,6 +244,7 @@ interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
|
244
244
|
enableWebSearch?: boolean;
|
|
245
245
|
includeSubdomains?: boolean;
|
|
246
246
|
origin?: string;
|
|
247
|
+
showSources?: boolean;
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
249
250
|
* Response interface for extracting information from URLs.
|
|
@@ -254,6 +255,7 @@ interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
|
|
|
254
255
|
data: LLMSchema;
|
|
255
256
|
error?: string;
|
|
256
257
|
warning?: string;
|
|
258
|
+
sources?: string[];
|
|
257
259
|
}
|
|
258
260
|
/**
|
|
259
261
|
* Error response interface.
|
|
@@ -315,6 +317,71 @@ interface CrawlErrorsResponse {
|
|
|
315
317
|
*/
|
|
316
318
|
robotsBlocked: string[];
|
|
317
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Parameters for deep research operations.
|
|
322
|
+
* Defines options for conducting deep research on a topic.
|
|
323
|
+
*/
|
|
324
|
+
interface DeepResearchParams {
|
|
325
|
+
/**
|
|
326
|
+
* The topic or question to research
|
|
327
|
+
*/
|
|
328
|
+
topic: string;
|
|
329
|
+
/**
|
|
330
|
+
* Maximum depth of research iterations (1-10)
|
|
331
|
+
* @default 7
|
|
332
|
+
*/
|
|
333
|
+
maxDepth?: number;
|
|
334
|
+
/**
|
|
335
|
+
* Time limit in seconds (30-300)
|
|
336
|
+
* @default 270
|
|
337
|
+
*/
|
|
338
|
+
timeLimit?: number;
|
|
339
|
+
/**
|
|
340
|
+
* Experimental flag for streaming steps
|
|
341
|
+
*/
|
|
342
|
+
__experimental_streamSteps?: boolean;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Response interface for deep research operations.
|
|
346
|
+
*/
|
|
347
|
+
interface DeepResearchResponse {
|
|
348
|
+
success: boolean;
|
|
349
|
+
id: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Status response interface for deep research operations.
|
|
353
|
+
*/
|
|
354
|
+
interface DeepResearchStatusResponse {
|
|
355
|
+
success: boolean;
|
|
356
|
+
data: {
|
|
357
|
+
findings: Array<{
|
|
358
|
+
text: string;
|
|
359
|
+
source: string;
|
|
360
|
+
}>;
|
|
361
|
+
finalAnalysis: string;
|
|
362
|
+
analysis: string;
|
|
363
|
+
completedSteps: number;
|
|
364
|
+
totalSteps: number;
|
|
365
|
+
};
|
|
366
|
+
status: "processing" | "completed" | "failed";
|
|
367
|
+
error?: string;
|
|
368
|
+
expiresAt: string;
|
|
369
|
+
currentDepth: number;
|
|
370
|
+
maxDepth: number;
|
|
371
|
+
activities: Array<{
|
|
372
|
+
type: string;
|
|
373
|
+
status: string;
|
|
374
|
+
message: string;
|
|
375
|
+
timestamp: string;
|
|
376
|
+
depth: number;
|
|
377
|
+
}>;
|
|
378
|
+
sources: Array<{
|
|
379
|
+
url: string;
|
|
380
|
+
title: string;
|
|
381
|
+
description: string;
|
|
382
|
+
}>;
|
|
383
|
+
summaries: string[];
|
|
384
|
+
}
|
|
318
385
|
/**
|
|
319
386
|
* Main class for interacting with the Firecrawl API.
|
|
320
387
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -489,6 +556,18 @@ declare class FirecrawlApp {
|
|
|
489
556
|
* @param {string} action - The action being performed when the error occurred.
|
|
490
557
|
*/
|
|
491
558
|
handleError(response: AxiosResponse, action: string): void;
|
|
559
|
+
/**
|
|
560
|
+
* Initiates a deep research operation on a given topic.
|
|
561
|
+
* @param params - Parameters for the deep research operation.
|
|
562
|
+
* @returns The response containing the research job ID.
|
|
563
|
+
*/
|
|
564
|
+
__deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
|
|
565
|
+
/**
|
|
566
|
+
* Checks the status of a deep research operation.
|
|
567
|
+
* @param id - The ID of the deep research operation.
|
|
568
|
+
* @returns The current status and results of the research operation.
|
|
569
|
+
*/
|
|
570
|
+
__checkDeepResearchStatus(id: string): Promise<DeepResearchStatusResponse | ErrorResponse>;
|
|
492
571
|
}
|
|
493
572
|
interface CrawlWatcherEvents {
|
|
494
573
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -511,4 +590,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
511
590
|
close(): void;
|
|
512
591
|
}
|
|
513
592
|
|
|
514
|
-
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlErrorsResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type ExtractParams, type ExtractResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, type SearchParams, type SearchResponse, FirecrawlApp as default };
|
|
593
|
+
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlErrorsResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type DeepResearchParams, type DeepResearchResponse, type DeepResearchStatusResponse, type ErrorResponse, type ExtractParams, type ExtractResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, type SearchParams, type SearchResponse, FirecrawlApp as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -244,6 +244,7 @@ interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
|
244
244
|
enableWebSearch?: boolean;
|
|
245
245
|
includeSubdomains?: boolean;
|
|
246
246
|
origin?: string;
|
|
247
|
+
showSources?: boolean;
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
249
250
|
* Response interface for extracting information from URLs.
|
|
@@ -254,6 +255,7 @@ interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
|
|
|
254
255
|
data: LLMSchema;
|
|
255
256
|
error?: string;
|
|
256
257
|
warning?: string;
|
|
258
|
+
sources?: string[];
|
|
257
259
|
}
|
|
258
260
|
/**
|
|
259
261
|
* Error response interface.
|
|
@@ -315,6 +317,71 @@ interface CrawlErrorsResponse {
|
|
|
315
317
|
*/
|
|
316
318
|
robotsBlocked: string[];
|
|
317
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Parameters for deep research operations.
|
|
322
|
+
* Defines options for conducting deep research on a topic.
|
|
323
|
+
*/
|
|
324
|
+
interface DeepResearchParams {
|
|
325
|
+
/**
|
|
326
|
+
* The topic or question to research
|
|
327
|
+
*/
|
|
328
|
+
topic: string;
|
|
329
|
+
/**
|
|
330
|
+
* Maximum depth of research iterations (1-10)
|
|
331
|
+
* @default 7
|
|
332
|
+
*/
|
|
333
|
+
maxDepth?: number;
|
|
334
|
+
/**
|
|
335
|
+
* Time limit in seconds (30-300)
|
|
336
|
+
* @default 270
|
|
337
|
+
*/
|
|
338
|
+
timeLimit?: number;
|
|
339
|
+
/**
|
|
340
|
+
* Experimental flag for streaming steps
|
|
341
|
+
*/
|
|
342
|
+
__experimental_streamSteps?: boolean;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Response interface for deep research operations.
|
|
346
|
+
*/
|
|
347
|
+
interface DeepResearchResponse {
|
|
348
|
+
success: boolean;
|
|
349
|
+
id: string;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Status response interface for deep research operations.
|
|
353
|
+
*/
|
|
354
|
+
interface DeepResearchStatusResponse {
|
|
355
|
+
success: boolean;
|
|
356
|
+
data: {
|
|
357
|
+
findings: Array<{
|
|
358
|
+
text: string;
|
|
359
|
+
source: string;
|
|
360
|
+
}>;
|
|
361
|
+
finalAnalysis: string;
|
|
362
|
+
analysis: string;
|
|
363
|
+
completedSteps: number;
|
|
364
|
+
totalSteps: number;
|
|
365
|
+
};
|
|
366
|
+
status: "processing" | "completed" | "failed";
|
|
367
|
+
error?: string;
|
|
368
|
+
expiresAt: string;
|
|
369
|
+
currentDepth: number;
|
|
370
|
+
maxDepth: number;
|
|
371
|
+
activities: Array<{
|
|
372
|
+
type: string;
|
|
373
|
+
status: string;
|
|
374
|
+
message: string;
|
|
375
|
+
timestamp: string;
|
|
376
|
+
depth: number;
|
|
377
|
+
}>;
|
|
378
|
+
sources: Array<{
|
|
379
|
+
url: string;
|
|
380
|
+
title: string;
|
|
381
|
+
description: string;
|
|
382
|
+
}>;
|
|
383
|
+
summaries: string[];
|
|
384
|
+
}
|
|
318
385
|
/**
|
|
319
386
|
* Main class for interacting with the Firecrawl API.
|
|
320
387
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -489,6 +556,18 @@ declare class FirecrawlApp {
|
|
|
489
556
|
* @param {string} action - The action being performed when the error occurred.
|
|
490
557
|
*/
|
|
491
558
|
handleError(response: AxiosResponse, action: string): void;
|
|
559
|
+
/**
|
|
560
|
+
* Initiates a deep research operation on a given topic.
|
|
561
|
+
* @param params - Parameters for the deep research operation.
|
|
562
|
+
* @returns The response containing the research job ID.
|
|
563
|
+
*/
|
|
564
|
+
__deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
|
|
565
|
+
/**
|
|
566
|
+
* Checks the status of a deep research operation.
|
|
567
|
+
* @param id - The ID of the deep research operation.
|
|
568
|
+
* @returns The current status and results of the research operation.
|
|
569
|
+
*/
|
|
570
|
+
__checkDeepResearchStatus(id: string): Promise<DeepResearchStatusResponse | ErrorResponse>;
|
|
492
571
|
}
|
|
493
572
|
interface CrawlWatcherEvents {
|
|
494
573
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -511,4 +590,4 @@ declare class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|
|
511
590
|
close(): void;
|
|
512
591
|
}
|
|
513
592
|
|
|
514
|
-
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlErrorsResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type ErrorResponse, type ExtractParams, type ExtractResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, type SearchParams, type SearchResponse, FirecrawlApp as default };
|
|
593
|
+
export { type Action, type ActionsResult, type BatchScrapeResponse, type BatchScrapeStatusResponse, type CrawlErrorsResponse, type CrawlParams, type CrawlResponse, type CrawlScrapeOptions, type CrawlStatusResponse, CrawlWatcher, type DeepResearchParams, type DeepResearchResponse, type DeepResearchStatusResponse, type ErrorResponse, type ExtractParams, type ExtractResponse, type FirecrawlAppConfig, type FirecrawlDocument, type FirecrawlDocumentMetadata, FirecrawlError, type MapParams, type MapResponse, type ScrapeParams, type ScrapeResponse, type SearchParams, type SearchResponse, FirecrawlApp as default };
|
package/dist/index.js
CHANGED
|
@@ -611,7 +611,8 @@ var FirecrawlApp = class {
|
|
|
611
611
|
success: true,
|
|
612
612
|
data: extractStatus.data,
|
|
613
613
|
warning: extractStatus.warning,
|
|
614
|
-
error: extractStatus.error
|
|
614
|
+
error: extractStatus.error,
|
|
615
|
+
sources: extractStatus?.sources || void 0
|
|
615
616
|
};
|
|
616
617
|
} else {
|
|
617
618
|
throw new FirecrawlError(`Failed to extract data. Error: ${extractStatus.error}`, statusResponse.status);
|
|
@@ -814,6 +815,61 @@ var FirecrawlApp = class {
|
|
|
814
815
|
);
|
|
815
816
|
}
|
|
816
817
|
}
|
|
818
|
+
/**
|
|
819
|
+
* Initiates a deep research operation on a given topic.
|
|
820
|
+
* @param params - Parameters for the deep research operation.
|
|
821
|
+
* @returns The response containing the research job ID.
|
|
822
|
+
*/
|
|
823
|
+
async __deepResearch(params) {
|
|
824
|
+
const headers = this.prepareHeaders();
|
|
825
|
+
try {
|
|
826
|
+
const response = await this.postRequest(
|
|
827
|
+
`${this.apiUrl}/v1/deep-research`,
|
|
828
|
+
params,
|
|
829
|
+
headers
|
|
830
|
+
);
|
|
831
|
+
if (response.status === 200) {
|
|
832
|
+
return response.data;
|
|
833
|
+
} else {
|
|
834
|
+
this.handleError(response, "start deep research");
|
|
835
|
+
}
|
|
836
|
+
} catch (error) {
|
|
837
|
+
if (error.response?.data?.error) {
|
|
838
|
+
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);
|
|
839
|
+
} else {
|
|
840
|
+
throw new FirecrawlError(error.message, 500);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return { success: false, error: "Internal server error." };
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Checks the status of a deep research operation.
|
|
847
|
+
* @param id - The ID of the deep research operation.
|
|
848
|
+
* @returns The current status and results of the research operation.
|
|
849
|
+
*/
|
|
850
|
+
async __checkDeepResearchStatus(id) {
|
|
851
|
+
const headers = this.prepareHeaders();
|
|
852
|
+
try {
|
|
853
|
+
const response = await this.getRequest(
|
|
854
|
+
`${this.apiUrl}/v1/deep-research/${id}`,
|
|
855
|
+
headers
|
|
856
|
+
);
|
|
857
|
+
if (response.status === 200) {
|
|
858
|
+
return response.data;
|
|
859
|
+
} else if (response.status === 404) {
|
|
860
|
+
throw new FirecrawlError("Deep research job not found", 404);
|
|
861
|
+
} else {
|
|
862
|
+
this.handleError(response, "check deep research status");
|
|
863
|
+
}
|
|
864
|
+
} catch (error) {
|
|
865
|
+
if (error.response?.data?.error) {
|
|
866
|
+
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);
|
|
867
|
+
} else {
|
|
868
|
+
throw new FirecrawlError(error.message, 500);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
return { success: false, error: "Internal server error." };
|
|
872
|
+
}
|
|
817
873
|
};
|
|
818
874
|
var CrawlWatcher = class extends TypedEventTarget {
|
|
819
875
|
ws;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -262,6 +262,7 @@ export interface ExtractParams<LLMSchema extends zt.ZodSchema = any> {
|
|
|
262
262
|
enableWebSearch?: boolean;
|
|
263
263
|
includeSubdomains?: boolean;
|
|
264
264
|
origin?: string;
|
|
265
|
+
showSources?: boolean;
|
|
265
266
|
}
|
|
266
267
|
|
|
267
268
|
/**
|
|
@@ -273,6 +274,7 @@ export interface ExtractResponse<LLMSchema extends zt.ZodSchema = any> {
|
|
|
273
274
|
data: LLMSchema;
|
|
274
275
|
error?: string;
|
|
275
276
|
warning?: string;
|
|
277
|
+
sources?: string[];
|
|
276
278
|
}
|
|
277
279
|
|
|
278
280
|
/**
|
|
@@ -345,6 +347,74 @@ export interface CrawlErrorsResponse {
|
|
|
345
347
|
robotsBlocked: string[];
|
|
346
348
|
};
|
|
347
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Parameters for deep research operations.
|
|
352
|
+
* Defines options for conducting deep research on a topic.
|
|
353
|
+
*/
|
|
354
|
+
export interface DeepResearchParams {
|
|
355
|
+
/**
|
|
356
|
+
* The topic or question to research
|
|
357
|
+
*/
|
|
358
|
+
topic: string;
|
|
359
|
+
/**
|
|
360
|
+
* Maximum depth of research iterations (1-10)
|
|
361
|
+
* @default 7
|
|
362
|
+
*/
|
|
363
|
+
maxDepth?: number;
|
|
364
|
+
/**
|
|
365
|
+
* Time limit in seconds (30-300)
|
|
366
|
+
* @default 270
|
|
367
|
+
*/
|
|
368
|
+
timeLimit?: number;
|
|
369
|
+
/**
|
|
370
|
+
* Experimental flag for streaming steps
|
|
371
|
+
*/
|
|
372
|
+
__experimental_streamSteps?: boolean;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Response interface for deep research operations.
|
|
377
|
+
*/
|
|
378
|
+
export interface DeepResearchResponse {
|
|
379
|
+
success: boolean;
|
|
380
|
+
id: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Status response interface for deep research operations.
|
|
385
|
+
*/
|
|
386
|
+
export interface DeepResearchStatusResponse {
|
|
387
|
+
success: boolean;
|
|
388
|
+
data: {
|
|
389
|
+
findings: Array<{
|
|
390
|
+
text: string;
|
|
391
|
+
source: string;
|
|
392
|
+
}>;
|
|
393
|
+
finalAnalysis: string;
|
|
394
|
+
analysis: string;
|
|
395
|
+
completedSteps: number;
|
|
396
|
+
totalSteps: number;
|
|
397
|
+
};
|
|
398
|
+
status: "processing" | "completed" | "failed";
|
|
399
|
+
error?: string;
|
|
400
|
+
expiresAt: string;
|
|
401
|
+
currentDepth: number;
|
|
402
|
+
maxDepth: number;
|
|
403
|
+
activities: Array<{
|
|
404
|
+
type: string;
|
|
405
|
+
status: string;
|
|
406
|
+
message: string;
|
|
407
|
+
timestamp: string;
|
|
408
|
+
depth: number;
|
|
409
|
+
}>;
|
|
410
|
+
sources: Array<{
|
|
411
|
+
url: string;
|
|
412
|
+
title: string;
|
|
413
|
+
description: string;
|
|
414
|
+
}>;
|
|
415
|
+
summaries: string[];
|
|
416
|
+
}
|
|
417
|
+
|
|
348
418
|
/**
|
|
349
419
|
* Main class for interacting with the Firecrawl API.
|
|
350
420
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1041,7 +1111,8 @@ export default class FirecrawlApp {
|
|
|
1041
1111
|
success: true,
|
|
1042
1112
|
data: extractStatus.data,
|
|
1043
1113
|
warning: extractStatus.warning,
|
|
1044
|
-
error: extractStatus.error
|
|
1114
|
+
error: extractStatus.error,
|
|
1115
|
+
sources: extractStatus?.sources || undefined,
|
|
1045
1116
|
};
|
|
1046
1117
|
} else {
|
|
1047
1118
|
throw new FirecrawlError(`Failed to extract data. Error: ${extractStatus.error}`, statusResponse.status);
|
|
@@ -1277,6 +1348,65 @@ export default class FirecrawlApp {
|
|
|
1277
1348
|
);
|
|
1278
1349
|
}
|
|
1279
1350
|
}
|
|
1351
|
+
|
|
1352
|
+
/**
|
|
1353
|
+
* Initiates a deep research operation on a given topic.
|
|
1354
|
+
* @param params - Parameters for the deep research operation.
|
|
1355
|
+
* @returns The response containing the research job ID.
|
|
1356
|
+
*/
|
|
1357
|
+
async __deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse> {
|
|
1358
|
+
const headers = this.prepareHeaders();
|
|
1359
|
+
try {
|
|
1360
|
+
const response: AxiosResponse = await this.postRequest(
|
|
1361
|
+
`${this.apiUrl}/v1/deep-research`,
|
|
1362
|
+
params,
|
|
1363
|
+
headers
|
|
1364
|
+
);
|
|
1365
|
+
|
|
1366
|
+
if (response.status === 200) {
|
|
1367
|
+
return response.data;
|
|
1368
|
+
} else {
|
|
1369
|
+
this.handleError(response, "start deep research");
|
|
1370
|
+
}
|
|
1371
|
+
} catch (error: any) {
|
|
1372
|
+
if (error.response?.data?.error) {
|
|
1373
|
+
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);
|
|
1374
|
+
} else {
|
|
1375
|
+
throw new FirecrawlError(error.message, 500);
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
return { success: false, error: "Internal server error." };
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Checks the status of a deep research operation.
|
|
1383
|
+
* @param id - The ID of the deep research operation.
|
|
1384
|
+
* @returns The current status and results of the research operation.
|
|
1385
|
+
*/
|
|
1386
|
+
async __checkDeepResearchStatus(id: string): Promise<DeepResearchStatusResponse | ErrorResponse> {
|
|
1387
|
+
const headers = this.prepareHeaders();
|
|
1388
|
+
try {
|
|
1389
|
+
const response: AxiosResponse = await this.getRequest(
|
|
1390
|
+
`${this.apiUrl}/v1/deep-research/${id}`,
|
|
1391
|
+
headers
|
|
1392
|
+
);
|
|
1393
|
+
|
|
1394
|
+
if (response.status === 200) {
|
|
1395
|
+
return response.data;
|
|
1396
|
+
} else if (response.status === 404) {
|
|
1397
|
+
throw new FirecrawlError("Deep research job not found", 404);
|
|
1398
|
+
} else {
|
|
1399
|
+
this.handleError(response, "check deep research status");
|
|
1400
|
+
}
|
|
1401
|
+
} catch (error: any) {
|
|
1402
|
+
if (error.response?.data?.error) {
|
|
1403
|
+
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);
|
|
1404
|
+
} else {
|
|
1405
|
+
throw new FirecrawlError(error.message, 500);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
return { success: false, error: "Internal server error." };
|
|
1409
|
+
}
|
|
1280
1410
|
}
|
|
1281
1411
|
|
|
1282
1412
|
interface CrawlWatcherEvents {
|