mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-11 20:48:58 +08:00
Nick:
This commit is contained in:
parent
acf1e60608
commit
7db2d25efa
@ -94,7 +94,7 @@ export async function performDeepResearch(options: DeepResearchServiceOptions) {
|
|||||||
teamId: options.teamId,
|
teamId: options.teamId,
|
||||||
plan: options.plan as PlanType,
|
plan: options.plan as PlanType,
|
||||||
origin: "deep-research",
|
origin: "deep-research",
|
||||||
timeout: 15000,
|
timeout: 10000,
|
||||||
scrapeOptions: {
|
scrapeOptions: {
|
||||||
formats: ["markdown"],
|
formats: ["markdown"],
|
||||||
onlyMainContent: true,
|
onlyMainContent: true,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mendable/firecrawl-js",
|
"name": "@mendable/firecrawl-js",
|
||||||
"version": "1.18.2",
|
"version": "1.18.3-beta.1",
|
||||||
"description": "JavaScript SDK for Firecrawl API",
|
"description": "JavaScript SDK for Firecrawl API",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -1391,10 +1391,22 @@ export default class FirecrawlApp {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates a deep research operation on a given topic and polls until completion.
|
* Initiates a deep research operation on a given topic and polls until completion.
|
||||||
|
* @param topic - The topic to research.
|
||||||
* @param params - Parameters for the deep research operation.
|
* @param params - Parameters for the deep research operation.
|
||||||
|
* @param onActivity - Optional callback to receive activity updates in real-time.
|
||||||
* @returns The final research results.
|
* @returns The final research results.
|
||||||
*/
|
*/
|
||||||
async __deepResearch(topic: string, params: DeepResearchParams): Promise<DeepResearchStatusResponse | ErrorResponse> {
|
async __deepResearch(
|
||||||
|
topic: string,
|
||||||
|
params: DeepResearchParams,
|
||||||
|
onActivity?: (activity: {
|
||||||
|
type: string;
|
||||||
|
status: string;
|
||||||
|
message: string;
|
||||||
|
timestamp: string;
|
||||||
|
depth: number;
|
||||||
|
}) => void
|
||||||
|
): Promise<DeepResearchStatusResponse | ErrorResponse> {
|
||||||
try {
|
try {
|
||||||
const response = await this.__asyncDeepResearch(topic, params);
|
const response = await this.__asyncDeepResearch(topic, params);
|
||||||
|
|
||||||
@ -1408,16 +1420,24 @@ export default class FirecrawlApp {
|
|||||||
|
|
||||||
const jobId = response.id;
|
const jobId = response.id;
|
||||||
let researchStatus;
|
let researchStatus;
|
||||||
|
let lastActivityCount = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// console.log("Checking research status...");
|
|
||||||
researchStatus = await this.__checkDeepResearchStatus(jobId);
|
researchStatus = await this.__checkDeepResearchStatus(jobId);
|
||||||
// console.log("Research status:", researchStatus);
|
|
||||||
|
|
||||||
if ('error' in researchStatus && !researchStatus.success) {
|
if ('error' in researchStatus && !researchStatus.success) {
|
||||||
return researchStatus;
|
return researchStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stream new activities through the callback if provided
|
||||||
|
if (onActivity && researchStatus.activities) {
|
||||||
|
const newActivities = researchStatus.activities.slice(lastActivityCount);
|
||||||
|
for (const activity of newActivities) {
|
||||||
|
onActivity(activity);
|
||||||
|
}
|
||||||
|
lastActivityCount = researchStatus.activities.length;
|
||||||
|
}
|
||||||
|
|
||||||
if (researchStatus.status === "completed") {
|
if (researchStatus.status === "completed") {
|
||||||
return researchStatus;
|
return researchStatus;
|
||||||
}
|
}
|
||||||
@ -1435,7 +1455,6 @@ export default class FirecrawlApp {
|
|||||||
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||||
}
|
}
|
||||||
// console.log("Research status finished:", researchStatus);
|
|
||||||
|
|
||||||
return { success: false, error: "Research job terminated unexpectedly" };
|
return { success: false, error: "Research job terminated unexpectedly" };
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user