mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-14 05:05:55 +08:00
Merge pull request #994 from mendableai/feat/added-id-to-ws-sdks
feat-SDK/added crawl id to ws
This commit is contained in:
commit
d67db99791
@ -935,9 +935,11 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|||||||
private ws: WebSocket;
|
private ws: WebSocket;
|
||||||
public data: FirecrawlDocument<undefined>[];
|
public data: FirecrawlDocument<undefined>[];
|
||||||
public status: CrawlStatusResponse["status"];
|
public status: CrawlStatusResponse["status"];
|
||||||
|
public id: string;
|
||||||
|
|
||||||
constructor(id: string, app: FirecrawlApp) {
|
constructor(id: string, app: FirecrawlApp) {
|
||||||
super();
|
super();
|
||||||
|
this.id = id;
|
||||||
this.ws = new WebSocket(`${app.apiUrl}/v1/crawl/${id}`, app.apiKey);
|
this.ws = new WebSocket(`${app.apiUrl}/v1/crawl/${id}`, app.apiKey);
|
||||||
this.status = "scraping";
|
this.status = "scraping";
|
||||||
this.data = [];
|
this.data = [];
|
||||||
@ -968,6 +970,7 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|||||||
detail: {
|
detail: {
|
||||||
status: this.status,
|
status: this.status,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
|
id: this.id,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
} else if (msg.type === "error") {
|
} else if (msg.type === "error") {
|
||||||
@ -977,6 +980,7 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|||||||
status: this.status,
|
status: this.status,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
error: msg.error,
|
error: msg.error,
|
||||||
|
id: this.id,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
} else if (msg.type === "catchup") {
|
} else if (msg.type === "catchup") {
|
||||||
@ -984,12 +988,18 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|||||||
this.data.push(...(msg.data.data ?? []));
|
this.data.push(...(msg.data.data ?? []));
|
||||||
for (const doc of this.data) {
|
for (const doc of this.data) {
|
||||||
this.dispatchTypedEvent("document", new CustomEvent("document", {
|
this.dispatchTypedEvent("document", new CustomEvent("document", {
|
||||||
detail: doc,
|
detail: {
|
||||||
|
...doc,
|
||||||
|
id: this.id,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} else if (msg.type === "document") {
|
} else if (msg.type === "document") {
|
||||||
this.dispatchTypedEvent("document", new CustomEvent("document", {
|
this.dispatchTypedEvent("document", new CustomEvent("document", {
|
||||||
detail: msg.data,
|
detail: {
|
||||||
|
...msg.data,
|
||||||
|
id: this.id,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1016,6 +1026,7 @@ export class CrawlWatcher extends TypedEventTarget<CrawlWatcherEvents> {
|
|||||||
status: this.status,
|
status: this.status,
|
||||||
data: this.data,
|
data: this.data,
|
||||||
error: "WebSocket error",
|
error: "WebSocket error",
|
||||||
|
id: this.id,
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
}).bind(this);
|
}).bind(this);
|
||||||
|
@ -13,7 +13,7 @@ import os
|
|||||||
|
|
||||||
from .firecrawl import FirecrawlApp # noqa
|
from .firecrawl import FirecrawlApp # noqa
|
||||||
|
|
||||||
__version__ = "1.6.4"
|
__version__ = "1.6.5"
|
||||||
|
|
||||||
# Define the logger for the Firecrawl project
|
# Define the logger for the Firecrawl project
|
||||||
logger: logging.Logger = logging.getLogger("firecrawl")
|
logger: logging.Logger = logging.getLogger("firecrawl")
|
||||||
|
@ -704,15 +704,15 @@ class CrawlWatcher:
|
|||||||
async def _handle_message(self, msg: Dict[str, Any]):
|
async def _handle_message(self, msg: Dict[str, Any]):
|
||||||
if msg['type'] == 'done':
|
if msg['type'] == 'done':
|
||||||
self.status = 'completed'
|
self.status = 'completed'
|
||||||
self.dispatch_event('done', {'status': self.status, 'data': self.data})
|
self.dispatch_event('done', {'status': self.status, 'data': self.data, 'id': self.id})
|
||||||
elif msg['type'] == 'error':
|
elif msg['type'] == 'error':
|
||||||
self.status = 'failed'
|
self.status = 'failed'
|
||||||
self.dispatch_event('error', {'status': self.status, 'data': self.data, 'error': msg['error']})
|
self.dispatch_event('error', {'status': self.status, 'data': self.data, 'error': msg['error'], 'id': self.id})
|
||||||
elif msg['type'] == 'catchup':
|
elif msg['type'] == 'catchup':
|
||||||
self.status = msg['data']['status']
|
self.status = msg['data']['status']
|
||||||
self.data.extend(msg['data'].get('data', []))
|
self.data.extend(msg['data'].get('data', []))
|
||||||
for doc in self.data:
|
for doc in self.data:
|
||||||
self.dispatch_event('document', doc)
|
self.dispatch_event('document', {'data': doc, 'id': self.id})
|
||||||
elif msg['type'] == 'document':
|
elif msg['type'] == 'document':
|
||||||
self.data.append(msg['data'])
|
self.data.append(msg['data'])
|
||||||
self.dispatch_event('document', msg['data'])
|
self.dispatch_event('document', {'data': msg['data'], 'id': self.id})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user