webcrawlerapi-js 2.2.1 → 2.2.5
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/@types/api.d.ts +4 -3
- package/dist/@types/model.d.ts +11 -1
- package/dist/api.js +14 -7
- package/package.json +1 -1
package/dist/@types/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CrawlRequest, Job, JobId, ScrapeRequest, ScrapeResponse, ScrapeResponseError, ScrapeId,
|
|
1
|
+
import { CrawlRequest, Job, JobId, ScrapeRequest, ScrapeResponse, ScrapeResponseError, ScrapeId, JobMarkdownResponse, MarkdownRequest, MarkdownResponse, AgentRunRequest, AgentRun } from "./model";
|
|
2
2
|
import { JobStatus, ErrorCode } from "./constants";
|
|
3
3
|
import { WebcrawlerApiError } from "./errors";
|
|
4
4
|
export { WebcrawlerApiError, JobStatus, ErrorCode };
|
|
@@ -15,10 +15,11 @@ export declare class WebcrawlerClient {
|
|
|
15
15
|
runAgent(request: AgentRunRequest, maxPolls?: number): Promise<AgentRun>;
|
|
16
16
|
getScrape(scrapeId: string): Promise<ScrapeResponse | ScrapeResponseError>;
|
|
17
17
|
scrape(request: ScrapeRequest, maxPolls?: number): Promise<ScrapeResponse | ScrapeResponseError>;
|
|
18
|
-
crawl(crawlRequest: CrawlRequest,
|
|
19
|
-
crawlAsync(crawlRequest: CrawlRequest
|
|
18
|
+
crawl(crawlRequest: CrawlRequest, maxPolls?: number): Promise<Job>;
|
|
19
|
+
crawlAsync(crawlRequest: CrawlRequest): Promise<JobId>;
|
|
20
20
|
getJob(jobID: string): Promise<Job>;
|
|
21
21
|
getJobMarkdown(jobID: string): Promise<JobMarkdownResponse>;
|
|
22
22
|
getJobMarkdownContent(jobID: string): Promise<string>;
|
|
23
|
+
markdown(request: MarkdownRequest): Promise<MarkdownResponse>;
|
|
23
24
|
private sendRequest;
|
|
24
25
|
}
|
package/dist/@types/model.d.ts
CHANGED
|
@@ -53,7 +53,6 @@ export interface CrawlRequest {
|
|
|
53
53
|
blacklist_regexp?: string;
|
|
54
54
|
/** URL where the server will send a POST request once the job is completed. */
|
|
55
55
|
webhook_url?: string;
|
|
56
|
-
actions?: Action[];
|
|
57
56
|
/** If true, the crawler will respect the website's robots.txt and skip disallowed pages. Default is false. */
|
|
58
57
|
respect_robots_txt?: boolean;
|
|
59
58
|
/** Extract only the main content of the page. Works best for articles, blog posts, news. */
|
|
@@ -62,6 +61,8 @@ export interface CrawlRequest {
|
|
|
62
61
|
max_depth?: number;
|
|
63
62
|
/** Maximum age of cached content in seconds. Set to 0 to always fetch fresh content. */
|
|
64
63
|
max_age?: number;
|
|
64
|
+
/** If true, keeps query parameters in crawled URLs instead of stripping them. Default is false. */
|
|
65
|
+
keep_query_params?: boolean;
|
|
65
66
|
}
|
|
66
67
|
export interface Job {
|
|
67
68
|
id: string;
|
|
@@ -119,6 +120,15 @@ export interface UploadS3Action extends Action {
|
|
|
119
120
|
export interface JobMarkdownResponse {
|
|
120
121
|
content_url: string;
|
|
121
122
|
}
|
|
123
|
+
export interface MarkdownRequest {
|
|
124
|
+
/** The URL of the webpage to extract the article markdown from. */
|
|
125
|
+
url: string;
|
|
126
|
+
}
|
|
127
|
+
export interface MarkdownResponse {
|
|
128
|
+
success: boolean;
|
|
129
|
+
/** Cleaned article markdown (main content only). */
|
|
130
|
+
markdown?: string;
|
|
131
|
+
}
|
|
122
132
|
export interface AgentRunRequest {
|
|
123
133
|
/** Natural-language task for the agent to complete. */
|
|
124
134
|
prompt: string;
|
package/dist/api.js
CHANGED
|
@@ -211,12 +211,11 @@ class WebcrawlerClient {
|
|
|
211
211
|
// Return the last known state if maxPolls is reached
|
|
212
212
|
return result;
|
|
213
213
|
}
|
|
214
|
-
async crawl(crawlRequest,
|
|
214
|
+
async crawl(crawlRequest, maxPolls = MaxPullRetries) {
|
|
215
215
|
const url = `${this.basePath}/${this.apiVersion}/crawl`;
|
|
216
216
|
const requestBody = {
|
|
217
217
|
output_formats: ['markdown'],
|
|
218
|
-
...crawlRequest
|
|
219
|
-
actions: actions ? (Array.isArray(actions) ? actions : [actions]) : undefined
|
|
218
|
+
...crawlRequest
|
|
220
219
|
};
|
|
221
220
|
const requestOptions = {
|
|
222
221
|
'method': 'POST',
|
|
@@ -235,7 +234,7 @@ class WebcrawlerClient {
|
|
|
235
234
|
throw new errors_1.WebcrawlerApiError('invalid_response', 'Failed to fetch job status', 0);
|
|
236
235
|
}
|
|
237
236
|
let delayIntervalMs = initialPullDelayMs;
|
|
238
|
-
for (let i = 0; i <
|
|
237
|
+
for (let i = 0; i < maxPolls; i++) {
|
|
239
238
|
await new Promise(resolve => setTimeout(resolve, delayIntervalMs));
|
|
240
239
|
const timestamp = new Date().getTime();
|
|
241
240
|
const job = await this.getJob(`${jobIdResponse.id}?t=${timestamp}`);
|
|
@@ -248,12 +247,11 @@ class WebcrawlerClient {
|
|
|
248
247
|
}
|
|
249
248
|
throw new errors_1.WebcrawlerApiError('timeout', 'Crawling took too long, please retry or increase the number of polling retries', 0);
|
|
250
249
|
}
|
|
251
|
-
async crawlAsync(crawlRequest
|
|
250
|
+
async crawlAsync(crawlRequest) {
|
|
252
251
|
const url = `${this.basePath}/${this.apiVersion}/crawl`;
|
|
253
252
|
const requestBody = {
|
|
254
253
|
output_formats: ['markdown'],
|
|
255
|
-
...crawlRequest
|
|
256
|
-
actions: actions ? (Array.isArray(actions) ? actions : [actions]) : undefined
|
|
254
|
+
...crawlRequest
|
|
257
255
|
};
|
|
258
256
|
const requestOptions = {
|
|
259
257
|
'method': 'POST',
|
|
@@ -330,6 +328,15 @@ class WebcrawlerClient {
|
|
|
330
328
|
}
|
|
331
329
|
return response.text();
|
|
332
330
|
}
|
|
331
|
+
async markdown(request) {
|
|
332
|
+
const url = `${this.basePath}/markdown`;
|
|
333
|
+
const requestOptions = {
|
|
334
|
+
'method': 'POST',
|
|
335
|
+
'headers': this.getDefaultHeaders(),
|
|
336
|
+
'body': JSON.stringify(request),
|
|
337
|
+
};
|
|
338
|
+
return this.sendRequest(url, requestOptions);
|
|
339
|
+
}
|
|
333
340
|
async sendRequest(url, requestOptions) {
|
|
334
341
|
let response;
|
|
335
342
|
try {
|