@mendable/firecrawl-js 1.18.0-beta.1 → 1.18.0-beta.3

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 CHANGED
@@ -852,11 +852,43 @@ var FirecrawlApp = class {
852
852
  }
853
853
  }
854
854
  /**
855
- * Initiates a deep research operation on a given topic.
855
+ * Initiates a deep research operation on a given topic and polls until completion.
856
856
  * @param params - Parameters for the deep research operation.
857
- * @returns The response containing the research job ID.
857
+ * @returns The final research results.
858
858
  */
859
859
  async __deepResearch(params) {
860
+ try {
861
+ const response = await this.__asyncDeepResearch(params);
862
+ if (!response.success || "error" in response) {
863
+ return { success: false, error: "error" in response ? response.error : "Unknown error" };
864
+ }
865
+ if (response.id) {
866
+ const jobId = response.id;
867
+ let researchStatus;
868
+ do {
869
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
870
+ if ("error" in researchStatus && !researchStatus.success) {
871
+ return researchStatus;
872
+ }
873
+ if (researchStatus.status === "completed" && researchStatus.data) {
874
+ return researchStatus;
875
+ } else if (researchStatus.status === "failed") {
876
+ throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
877
+ }
878
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
879
+ } while (researchStatus.status === "processing" || researchStatus.status === "completed");
880
+ }
881
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
882
+ } catch (error) {
883
+ throw new FirecrawlError(error.message, 500, error.response?.data?.details);
884
+ }
885
+ }
886
+ /**
887
+ * Initiates a deep research operation on a given topic without polling.
888
+ * @param params - Parameters for the deep research operation.
889
+ * @returns The response containing the research job ID.
890
+ */
891
+ async __asyncDeepResearch(params) {
860
892
  const headers = this.prepareHeaders();
861
893
  try {
862
894
  const response = await this.postRequest(
package/dist/index.d.cts CHANGED
@@ -557,11 +557,17 @@ declare class FirecrawlApp {
557
557
  */
558
558
  handleError(response: AxiosResponse, action: string): void;
559
559
  /**
560
- * Initiates a deep research operation on a given topic.
560
+ * Initiates a deep research operation on a given topic and polls until completion.
561
+ * @param params - Parameters for the deep research operation.
562
+ * @returns The final research results.
563
+ */
564
+ __deepResearch(params: DeepResearchParams): Promise<DeepResearchStatusResponse | ErrorResponse>;
565
+ /**
566
+ * Initiates a deep research operation on a given topic without polling.
561
567
  * @param params - Parameters for the deep research operation.
562
568
  * @returns The response containing the research job ID.
563
569
  */
564
- __deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
570
+ __asyncDeepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
565
571
  /**
566
572
  * Checks the status of a deep research operation.
567
573
  * @param id - The ID of the deep research operation.
package/dist/index.d.ts CHANGED
@@ -557,11 +557,17 @@ declare class FirecrawlApp {
557
557
  */
558
558
  handleError(response: AxiosResponse, action: string): void;
559
559
  /**
560
- * Initiates a deep research operation on a given topic.
560
+ * Initiates a deep research operation on a given topic and polls until completion.
561
+ * @param params - Parameters for the deep research operation.
562
+ * @returns The final research results.
563
+ */
564
+ __deepResearch(params: DeepResearchParams): Promise<DeepResearchStatusResponse | ErrorResponse>;
565
+ /**
566
+ * Initiates a deep research operation on a given topic without polling.
561
567
  * @param params - Parameters for the deep research operation.
562
568
  * @returns The response containing the research job ID.
563
569
  */
564
- __deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
570
+ __asyncDeepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse>;
565
571
  /**
566
572
  * Checks the status of a deep research operation.
567
573
  * @param id - The ID of the deep research operation.
package/dist/index.js CHANGED
@@ -816,11 +816,43 @@ var FirecrawlApp = class {
816
816
  }
817
817
  }
818
818
  /**
819
- * Initiates a deep research operation on a given topic.
819
+ * Initiates a deep research operation on a given topic and polls until completion.
820
820
  * @param params - Parameters for the deep research operation.
821
- * @returns The response containing the research job ID.
821
+ * @returns The final research results.
822
822
  */
823
823
  async __deepResearch(params) {
824
+ try {
825
+ const response = await this.__asyncDeepResearch(params);
826
+ if (!response.success || "error" in response) {
827
+ return { success: false, error: "error" in response ? response.error : "Unknown error" };
828
+ }
829
+ if (response.id) {
830
+ const jobId = response.id;
831
+ let researchStatus;
832
+ do {
833
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
834
+ if ("error" in researchStatus && !researchStatus.success) {
835
+ return researchStatus;
836
+ }
837
+ if (researchStatus.status === "completed" && researchStatus.data) {
838
+ return researchStatus;
839
+ } else if (researchStatus.status === "failed") {
840
+ throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
841
+ }
842
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
843
+ } while (researchStatus.status === "processing" || researchStatus.status === "completed");
844
+ }
845
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
846
+ } catch (error) {
847
+ throw new FirecrawlError(error.message, 500, error.response?.data?.details);
848
+ }
849
+ }
850
+ /**
851
+ * Initiates a deep research operation on a given topic without polling.
852
+ * @param params - Parameters for the deep research operation.
853
+ * @returns The response containing the research job ID.
854
+ */
855
+ async __asyncDeepResearch(params) {
824
856
  const headers = this.prepareHeaders();
825
857
  try {
826
858
  const response = await this.postRequest(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mendable/firecrawl-js",
3
- "version": "1.18.0-beta.1",
3
+ "version": "1.18.0-beta.3",
4
4
  "description": "JavaScript SDK for Firecrawl API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -1350,11 +1350,48 @@ export default class FirecrawlApp {
1350
1350
  }
1351
1351
 
1352
1352
  /**
1353
- * Initiates a deep research operation on a given topic.
1353
+ * Initiates a deep research operation on a given topic and polls until completion.
1354
+ * @param params - Parameters for the deep research operation.
1355
+ * @returns The final research results.
1356
+ */
1357
+ async __deepResearch(params: DeepResearchParams): Promise<DeepResearchStatusResponse | ErrorResponse> {
1358
+ try {
1359
+ const response = await this.__asyncDeepResearch(params);
1360
+
1361
+ if (!response.success || 'error' in response) {
1362
+ return { success: false, error: 'error' in response ? response.error : 'Unknown error' };
1363
+ }
1364
+
1365
+ if (response.id) {
1366
+ const jobId = response.id;
1367
+ let researchStatus;
1368
+ do {
1369
+ researchStatus = await this.__checkDeepResearchStatus(jobId);
1370
+
1371
+ if ('error' in researchStatus && !researchStatus.success) {
1372
+ return researchStatus;
1373
+ }
1374
+
1375
+ if (researchStatus.status === "completed" && researchStatus.data) {
1376
+ return researchStatus;
1377
+ } else if (researchStatus.status === "failed") {
1378
+ throw new FirecrawlError(`Research job failed. Error: ${researchStatus.error}`, 500);
1379
+ }
1380
+ await new Promise(resolve => setTimeout(resolve, 1000)); // Polling interval
1381
+ } while (researchStatus.status === "processing" || researchStatus.status === "completed");
1382
+ }
1383
+ throw new FirecrawlError(`Failed to start research. No job ID returned.`, 500);
1384
+ } catch (error: any) {
1385
+ throw new FirecrawlError(error.message, 500, error.response?.data?.details);
1386
+ }
1387
+ }
1388
+
1389
+ /**
1390
+ * Initiates a deep research operation on a given topic without polling.
1354
1391
  * @param params - Parameters for the deep research operation.
1355
1392
  * @returns The response containing the research job ID.
1356
1393
  */
1357
- async __deepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse> {
1394
+ async __asyncDeepResearch(params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse> {
1358
1395
  const headers = this.prepareHeaders();
1359
1396
  try {
1360
1397
  const response: AxiosResponse = await this.postRequest(