@howells/fieldwork-sdk 0.2.0 → 0.3.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.
@@ -1,53 +1,161 @@
1
- import { C as SearchResponse, E as SiteMap, S as Research, _ as JsonSchema, a as RawClient, b as Product, f as Crawl, h as Extraction, l as CallOptions, p as DocumentInput, s as ActResult, t as Adapter, v as Page, y as ParsedDocument } from "./adapter-C_kRm6TT.js";
2
- import { t as Json } from "./util-D0PLE6Rl.js";
3
- export interface FirecrawlConfig {
1
+ import { A as JsonSchema, F as MonitorSchedule, G as Research, I as Page, L as PageBatch, N as MonitorEvents, P as MonitorInfo, R as ParsedDocument, V as Product, W as Recency, X as SiteMap, a as RawClient, c as ActResult, f as CallOptions, g as Crawl, k as ImageSearch, q as SearchResponse, s as AccountUsage, t as Adapter, u as BrowserSession, w as Extraction, x as DocumentInput } from "./adapter-DGehHCMo.js";
2
+ interface FirecrawlConfig {
4
3
  /** Defaults to the FIRECRAWL_API_KEY environment variable. */
5
4
  apiKey?: string;
6
5
  baseUrl?: string;
7
6
  fetch?: typeof fetch;
8
7
  }
8
+ /** A step Firecrawl runs in the browser before it reads the page. */
9
+ type FirecrawlAction = {
10
+ type: "wait";
11
+ milliseconds: number;
12
+ } | {
13
+ type: "wait";
14
+ selector: string;
15
+ } | {
16
+ type: "screenshot";
17
+ fullPage?: boolean;
18
+ quality?: number;
19
+ viewport?: {
20
+ width: number;
21
+ height: number;
22
+ };
23
+ } | {
24
+ type: "click";
25
+ selector: string;
26
+ all?: boolean;
27
+ } |
28
+ /** Click the field first: Firecrawl types into the focused element. */
29
+ {
30
+ type: "write";
31
+ text: string;
32
+ } | {
33
+ type: "press";
34
+ key: string;
35
+ } | {
36
+ type: "scroll";
37
+ direction?: "up" | "down";
38
+ selector?: string;
39
+ } | {
40
+ type: "scrape";
41
+ } | {
42
+ type: "executeJavascript";
43
+ script: string;
44
+ } | {
45
+ type: "pdf";
46
+ format?: "A0" | "A1" | "A2" | "A3" | "A4" | "A5" | "A6" | "Letter" | "Legal" | "Tabloid" | "Ledger";
47
+ landscape?: boolean;
48
+ scale?: number;
49
+ };
50
+ /** How Firecrawl reads files it meets while scraping. Parsers left out are off. */
51
+ type FirecrawlParser = "pdf" | "image" | FirecrawlPdfParser | {
52
+ type: "image";
53
+ };
54
+ interface FirecrawlPdfParser {
55
+ type: "pdf";
56
+ /** "fast" reads embedded text only, "ocr" always runs OCR, "auto" falls back to OCR. */
57
+ mode?: "fast" | "auto" | "ocr";
58
+ maxPages?: number;
59
+ /** Return one Markdown entry per physical page. */
60
+ pages?: boolean;
61
+ /** Return layout blocks with positions. */
62
+ blocks?: boolean;
63
+ /** Mark page breaks in the Markdown. */
64
+ pageMarkers?: boolean;
65
+ }
9
66
  /** Page-fetching settings Firecrawl applies before reading. */
10
- export interface FirecrawlPageOptions extends CallOptions {
67
+ interface FirecrawlPageSettings {
11
68
  onlyMainContent?: boolean;
12
69
  includeTags?: string[];
13
70
  excludeTags?: string[];
14
- /** Milliseconds of cache Firecrawl may use; 0 forces a live fetch. */
71
+ /** Seconds a cached copy may be old; 0 always fetches fresh. */
15
72
  maxAge?: number;
16
73
  /** Milliseconds to wait for the page before reading it. */
17
74
  waitFor?: number;
18
75
  mobile?: boolean;
76
+ /**
77
+ * Which proxies fetch the page. `basic` is fast and suits sites with little
78
+ * anti-bot protection; `enhanced` is slower and gets past stronger bot
79
+ * walls; `auto` retries with `enhanced` when `basic` fails. Both cost the
80
+ * same credits.
81
+ */
19
82
  proxy?: "basic" | "enhanced" | "auto";
83
+ /** Where the request comes from; `country` is ISO 3166-1 alpha-2. */
20
84
  location?: {
21
85
  country?: string;
22
86
  languages?: string[];
23
87
  };
24
88
  /** Clicks, scrolls, waits and scripts to run before reading. */
25
- actions?: Json[];
89
+ actions?: FirecrawlAction[];
90
+ parsers?: FirecrawlParser[];
91
+ }
92
+ type FirecrawlFormat = "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary";
93
+ /** What to read from each page, beside its Markdown. */
94
+ interface FirecrawlReadSettings extends FirecrawlPageSettings {
95
+ /** Extra formats beside Markdown. */
96
+ include?: FirecrawlFormat[];
97
+ /** Return passages that answer this as `excerpts`. */
98
+ query?: string;
99
+ /**
100
+ * How `query` is answered: "highlights" (the default) returns the page's
101
+ * relevant passages, "question" returns one written answer. Each costs
102
+ * 4 extra credits per page.
103
+ */
104
+ queryFormat?: "highlights" | "question";
105
+ }
106
+ interface FirecrawlPageOptions extends CallOptions, FirecrawlPageSettings {}
107
+ interface FirecrawlReadOptions extends CallOptions, FirecrawlReadSettings {}
108
+ interface FirecrawlReadManyOptions extends FirecrawlReadOptions {
109
+ maxConcurrency?: number;
110
+ /** Firecrawl defaults to true: invalid URLs go to `failed` instead of failing the job. */
111
+ ignoreInvalidURLs?: boolean;
112
+ /** Milliseconds between status checks. */
113
+ interval?: number;
114
+ /**
115
+ * The id of a job that timed out or was cancelled, from the error's
116
+ * `jobId`. Waits for that job instead of starting a new one; `urls` is then
117
+ * ignored.
118
+ */
119
+ resume?: string;
26
120
  }
27
- export interface FirecrawlSearchOptions extends CallOptions {
121
+ interface FirecrawlSearchOptions extends CallOptions {
28
122
  /** Results per source; Firecrawl allows up to 100. */
29
123
  limit?: number;
30
124
  sources?: ("web" | "news" | "images")[];
31
- categories?: ("github" | "research" | "pdf")[];
32
- /** Hosts only; Firecrawl does not filter by path. */
125
+ /** "gov" cannot be combined with another category. */
126
+ categories?: ("developer" | "gov" | "research" | "pdf")[];
127
+ /** Hosts only; Firecrawl does not filter by path. Not with `excludeDomains`. */
33
128
  includeDomains?: string[];
34
129
  excludeDomains?: string[];
130
+ /** YYYY-MM-DD. Firecrawl applies dates and recency to web results only. */
131
+ publishedAfter?: string;
132
+ /** YYYY-MM-DD. */
133
+ publishedBefore?: string;
134
+ /** Not with `publishedAfter` or `publishedBefore`. */
135
+ recency?: Recency;
136
+ /** ISO 3166-1 alpha-2 country code. */
35
137
  country?: string;
138
+ /** A place name such as "San Francisco,California,United States". */
36
139
  location?: string;
37
- /** Google time filter, such as "qdr:w" for the past week. */
140
+ /** Google time filter such as "sbd:1,qdr:w", for when the named options do not fit. */
38
141
  tbs?: string;
39
142
  /** Include each result's page text as Markdown. */
40
143
  content?: boolean;
144
+ /** Filter explicit content (SafeSearch). */
145
+ safe?: boolean;
146
+ ignoreInvalidURLs?: boolean;
41
147
  }
42
- export interface FirecrawlReadOptions extends FirecrawlPageOptions {
43
- /** Extra formats beside Markdown. */
44
- include?: ("html" | "rawHtml" | "links" | "images" | "screenshot" | "summary")[];
148
+ interface FirecrawlImagesOptions extends CallOptions {
149
+ limit?: number;
150
+ country?: string;
151
+ location?: string;
152
+ safe?: boolean;
45
153
  }
46
- export interface FirecrawlExtractOptions extends FirecrawlPageOptions {
154
+ interface FirecrawlExtractOptions extends FirecrawlPageOptions {
47
155
  schema: JsonSchema;
48
156
  prompt?: string;
49
157
  }
50
- export interface FirecrawlMapOptions extends CallOptions {
158
+ interface FirecrawlMapOptions extends CallOptions {
51
159
  limit?: number;
52
160
  /** Order links by relevance to this text. */
53
161
  search?: string;
@@ -55,22 +163,34 @@ export interface FirecrawlMapOptions extends CallOptions {
55
163
  includeSubdomains?: boolean;
56
164
  /** Firecrawl defaults to true, which merges URLs that differ only by query. */
57
165
  ignoreQueryParameters?: boolean;
166
+ /** Skip the sitemap cache, which can be up to 7 days old. */
167
+ ignoreCache?: boolean;
168
+ location?: {
169
+ country?: string;
170
+ languages?: string[];
171
+ };
58
172
  }
59
- export interface FirecrawlCrawlOptions extends CallOptions {
173
+ interface FirecrawlCrawlOptions extends CallOptions {
60
174
  limit?: number;
61
- /** Plain-words crawl instructions. */
175
+ /** Plain-words crawl instructions; the options you set override it. */
62
176
  prompt?: string;
177
+ /** Regular expressions on the URL path (not hosts); a page must match one. */
63
178
  includePaths?: string[];
179
+ /** Regular expressions on the URL path; a page matching one is skipped. */
64
180
  excludePaths?: string[];
181
+ /** Match the two lists above against the full URL instead of the path. */
182
+ regexOnFullURL?: boolean;
65
183
  maxDiscoveryDepth?: number;
66
184
  sitemap?: "skip" | "include" | "only";
67
185
  crawlEntireDomain?: boolean;
68
186
  allowSubdomains?: boolean;
69
187
  allowExternalLinks?: boolean;
70
188
  ignoreQueryParameters?: boolean;
189
+ /** Seconds between page requests; forces one page at a time. */
71
190
  delay?: number;
72
191
  maxConcurrency?: number;
73
- scrapeOptions?: Json;
192
+ /** How each crawled page is read. */
193
+ scrapeOptions?: FirecrawlReadSettings;
74
194
  /** Milliseconds between status checks. */
75
195
  interval?: number;
76
196
  /**
@@ -79,16 +199,21 @@ export interface FirecrawlCrawlOptions extends CallOptions {
79
199
  */
80
200
  resume?: string;
81
201
  }
82
- export interface FirecrawlResearchOptions extends CallOptions {
202
+ interface FirecrawlResearchOptions extends CallOptions {
83
203
  schema?: JsonSchema;
84
204
  /** Pages to start from. */
85
205
  urls?: string[];
86
206
  /** Visit only `urls`. */
87
207
  strictConstrainToURLs?: boolean;
88
- /** Credit cap for the run. */
208
+ /** Credit cap for the run; Firecrawl defaults to 2500. */
89
209
  maxCredits?: number;
90
- model?: "spark-2" | "spark-1-mini" | "spark-1-pro";
210
+ model?: "spark-2";
91
211
  effort?: "low" | "medium" | "high";
212
+ /** The `continuationId` of an earlier run: this run is the next turn of its thread. */
213
+ continueFrom?: string;
214
+ /** ISO 3166-1 alpha-2 country the agent browses from. */
215
+ country?: string;
216
+ /** Milliseconds between status checks. */
92
217
  interval?: number;
93
218
  /**
94
219
  * The id of a job that timed out or was cancelled, from the error's
@@ -96,16 +221,35 @@ export interface FirecrawlResearchOptions extends CallOptions {
96
221
  */
97
222
  resume?: string;
98
223
  }
99
- export interface FirecrawlActOptions extends CallOptions {
100
- language?: "node" | "python" | "bash";
101
- /** Seconds the browser session may live. */
224
+ interface FirecrawlSessionSettings {
225
+ /** Seconds the browser session may live (30 to 3600). */
102
226
  ttl?: number;
227
+ /** Seconds the session may sit idle; defaults to `ttl`. */
228
+ activityTtl?: number;
229
+ /** Keeps cookies and storage between sessions that share the name. */
103
230
  profile?: {
104
231
  name: string;
105
232
  saveChanges?: boolean;
106
233
  };
234
+ /** ISO 3166-1 alpha-2 country the browser connects from. */
235
+ country?: string;
236
+ }
237
+ interface FirecrawlActOptions extends CallOptions, FirecrawlSessionSettings {
238
+ language?: "node" | "python" | "bash";
239
+ /**
240
+ * Run in this open session (from `browser.open` or an earlier `act` with
241
+ * `keepSession`) instead of a new one. Not with the session settings.
242
+ */
243
+ session?: string;
244
+ /**
245
+ * Leave the session open and return its id as `sessionId`. Defaults to true
246
+ * when `session` is given and false otherwise. A session left open bills
247
+ * until it expires or you close it.
248
+ */
249
+ keepSession?: boolean;
107
250
  }
108
- export interface FirecrawlParseOptions extends CallOptions {
251
+ type FirecrawlBrowserOptions = CallOptions & FirecrawlSessionSettings;
252
+ interface FirecrawlParseOptions extends CallOptions {
109
253
  /** "fast" reads embedded text only, "ocr" always runs OCR, "auto" falls back to OCR. */
110
254
  mode?: "auto" | "fast" | "ocr";
111
255
  maxPages?: number;
@@ -113,18 +257,66 @@ export interface FirecrawlParseOptions extends CallOptions {
113
257
  pages?: boolean;
114
258
  /** Return layout blocks with positions. */
115
259
  blocks?: boolean;
260
+ /** Mark page breaks in the Markdown. */
261
+ pageMarkers?: boolean;
262
+ }
263
+ interface FirecrawlMonitorOptions extends CallOptions {
264
+ /** A name for the monitor; defaults to the query or first URL. */
265
+ name?: string;
266
+ /**
267
+ * What counts as a meaningful change, in plain words. With `urls` it judges
268
+ * their changes; without `urls` it is also the search the monitor runs.
269
+ */
270
+ query?: string;
271
+ /** Pages to watch. */
272
+ urls?: string[];
273
+ /** A cron expression (five fields, at least 5 minutes apart) or a named interval. */
274
+ schedule: MonitorSchedule;
275
+ /** IANA time zone for the schedule. Defaults to UTC. */
276
+ timezone?: string;
277
+ webhookUrl?: string;
278
+ /** Days Firecrawl keeps check history, 1 to 365. */
279
+ retentionDays?: number;
280
+ /** Search monitors only: how far back results may be published. */
281
+ searchWindow?: "5m" | "15m" | "1h" | "6h" | "24h" | "7d";
282
+ /** Search monitors only: results to judge per check, 1 to 50. */
283
+ maxResults?: number;
284
+ /** Search monitors only. */
285
+ includeDomains?: string[];
286
+ /** Search monitors only. */
287
+ excludeDomains?: string[];
116
288
  }
117
- export interface FirecrawlOperations {
289
+ interface FirecrawlOperations {
118
290
  search(query: string, options?: FirecrawlSearchOptions): Promise<SearchResponse>;
291
+ images(query: string, options?: FirecrawlImagesOptions): Promise<ImageSearch>;
119
292
  read(url: string, options?: FirecrawlReadOptions): Promise<Page>;
293
+ /** Reads many pages in one background job. */
294
+ readMany(urls: string[], options?: FirecrawlReadManyOptions): Promise<PageBatch>;
120
295
  extract<T = unknown>(url: string, options: FirecrawlExtractOptions): Promise<Extraction<T>>;
121
296
  /** Reads product and variant data from the page's structured data, without a model. */
122
297
  product(url: string, options?: FirecrawlPageOptions): Promise<Product>;
123
298
  map(url: string, options?: FirecrawlMapOptions): Promise<SiteMap>;
124
299
  crawl(url: string, options?: FirecrawlCrawlOptions): Promise<Crawl>;
125
300
  research<T = unknown>(question: string, options?: FirecrawlResearchOptions): Promise<Research<T>>;
126
- /** Runs a script in a fresh browser session, then closes it. */
301
+ /** Runs a script in a browser session; closes the session unless `keepSession` is set. */
127
302
  act(code: string, options?: FirecrawlActOptions): Promise<ActResult>;
303
+ browser: {
304
+ /** Opens a remote browser you drive over CDP; it bills until it expires or you close it. */
305
+ open(options?: FirecrawlBrowserOptions): Promise<BrowserSession>;
306
+ close(id: string, options?: CallOptions): Promise<void>;
307
+ };
128
308
  parse(document: DocumentInput, options?: FirecrawlParseOptions): Promise<ParsedDocument>;
309
+ monitor: {
310
+ create(options: FirecrawlMonitorOptions): Promise<MonitorInfo>;
311
+ get(id: string, options?: CallOptions): Promise<MonitorInfo>;
312
+ list(options?: CallOptions): Promise<MonitorInfo[]>;
313
+ delete(id: string, options?: CallOptions): Promise<void>;
314
+ /** One event per check the monitor ran, newest first. */
315
+ events(id: string, options?: CallOptions & {
316
+ cursor?: string;
317
+ }): Promise<MonitorEvents>;
318
+ };
319
+ usage(options?: CallOptions): Promise<AccountUsage>;
129
320
  }
130
- export declare function firecrawl(config?: FirecrawlConfig): Adapter<"firecrawl", FirecrawlOperations, RawClient>;
321
+ export declare const firecrawl: (config?: FirecrawlConfig) => Adapter<"firecrawl", FirecrawlOperations, RawClient>;
322
+ export type { FirecrawlActOptions, FirecrawlAction, FirecrawlBrowserOptions, FirecrawlConfig, FirecrawlCrawlOptions, FirecrawlExtractOptions, FirecrawlFormat, FirecrawlImagesOptions, FirecrawlMapOptions, FirecrawlMonitorOptions, FirecrawlOperations, FirecrawlPageOptions, FirecrawlPageSettings, FirecrawlParseOptions, FirecrawlParser, FirecrawlPdfParser, FirecrawlReadManyOptions, FirecrawlReadOptions, FirecrawlReadSettings, FirecrawlResearchOptions, FirecrawlSearchOptions, FirecrawlSessionSettings };