@howells/fieldwork-sdk 0.5.1 → 0.5.2

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/exa.js CHANGED
@@ -1,24 +1,32 @@
1
1
  import { t as defineAdapter } from "./adapter-DWYJys20.js";
2
- import { r as invalidRequest, t as FieldworkError } from "./errors-Yvk42oZH.js";
3
- import { B as requireJobId, C as createRawClient, E as segment, F as parseJson, M as compact, N as hours, P as meta, R as record, S as withOriginal, T as requireKey, V as uniqueCitations, _ as optionalStructure, a as looseObject, b as warningEntry, d as optionalId, f as optionalNumber, g as optionalStringOrNumber, h as optionalString, i as both, j as citationsOf, k as callSettings, l as optionalBoolean, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source } from "./parse-n8MmaK1x.js";
4
- import { t as runJob } from "./job-BGTwH3F-.js";
5
- import { n as jsonSchemaOf, t as checkOutput } from "./schema-DbSIABP0.js";
2
+ import { r as invalidRequest, t as FieldworkError } from "./errors-DROZyb9T.js";
3
+ import { B as requireJobId, C as createRawClient, E as segment, F as parseJson, M as compact, N as hours, P as meta, R as record, S as withOriginal, T as requireKey, V as uniqueCitations, _ as optionalStructure, a as looseObject, b as warningEntry, d as optionalId, f as optionalNumber, g as optionalStringOrNumber, h as optionalString, i as both, j as citationsOf, k as callSettings, l as optionalBoolean, m as optionalScalar, n as anything, r as arrayOf, s as optionalAnyString, t as Source } from "./parse-BY3R0oWO.js";
4
+ import { t as runJob } from "./job-DVsmQMKP.js";
5
+ import { n as jsonSchemaOf, t as checkOutput } from "./schema-BYcXgfuZ.js";
6
6
  import * as z from "zod/mini";
7
7
  const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/u;
8
+ /** The search types that take `additionalQueries`. */
8
9
  const DEEP_TYPES = /* @__PURE__ */ new Set([
9
10
  "deep-lite",
10
11
  "deep",
11
12
  "deep-reasoning"
12
13
  ]);
14
+ /**
15
+ * A `YYYY-MM-DD` date as a UTC date-time, at the start of the day or (for an
16
+ * upper bound) its last millisecond, so the filter covers the whole day. Any
17
+ * other value passes through.
18
+ */
13
19
  const dateTime = (value, endOfDay) => {
14
20
  if (value === void 0 || !DATE_ONLY.test(value)) return value;
15
21
  return endOfDay ? `${value}T23:59:59.999Z` : `${value}T00:00:00.000Z`;
16
22
  };
23
+ /** The cost and request id Exa reports, with any warnings. */
17
24
  const responseMeta = (body, warnings) => meta({
18
25
  costUsd: body.costDollars.total,
19
26
  requestId: body.requestId,
20
27
  warnings
21
28
  });
29
+ /** Exa's `summary` content option. A schema asks for a structured summary and is sent even when `summary` is off. */
22
30
  const summaryOption = (summary, schema) => {
23
31
  if (summary === void 0 || summary === false) return schema ? compact({ schema }) : void 0;
24
32
  return compact({
@@ -26,6 +34,7 @@ const summaryOption = (summary, schema) => {
26
34
  schema
27
35
  });
28
36
  };
37
+ /** Refuses option combinations Exa does not accept, before the request is sent. */
29
38
  const checkSearch = (o) => {
30
39
  if (o.type === "lite") {
31
40
  const unsupported = [
@@ -42,10 +51,15 @@ const checkSearch = (o) => {
42
51
  if ((o.category === "company" || o.category === "people") && dated) throw invalidRequest("exa", `category "${o.category}" does not accept publishedAfter or publishedBefore`);
43
52
  if (o.category === "people" && o.excludeDomains !== void 0) throw invalidRequest("exa", "category \"people\" does not accept excludeDomains");
44
53
  };
54
+ /** Exa's `highlights` option: `true`, or the query and length limit that steer the passages. */
45
55
  const highlightsOption = (highlights) => typeof highlights === "object" ? compact({
46
56
  maxCharacters: highlights.maxCharacters,
47
57
  query: highlights.query
48
58
  }) : true;
59
+ /**
60
+ * The `contents` of a search request. Highlights are on unless `highlights` is
61
+ * false. Undefined when nothing is asked for.
62
+ */
49
63
  const searchContents = (o) => {
50
64
  const contents = compact({
51
65
  highlights: o.highlights === false ? void 0 : highlightsOption(o.highlights),
@@ -55,6 +69,10 @@ const searchContents = (o) => {
55
69
  });
56
70
  return Object.keys(contents).length > 0 ? contents : void 0;
57
71
  };
72
+ /**
73
+ * A search result. `snippet` joins the highlights with " … ". Exa's `summary`
74
+ * is not mapped; it stays in `raw`.
75
+ */
58
76
  const searchResult = (result) => compact({
59
77
  author: result.author,
60
78
  content: result.text,
@@ -66,11 +84,21 @@ const searchResult = (result) => compact({
66
84
  title: result.title,
67
85
  url: result.url ?? ""
68
86
  });
87
+ /**
88
+ * The answer Exa generated from the results: text as it is (none when empty),
89
+ * or an object serialized as JSON text. Undefined when Exa sent none; the
90
+ * object itself stays in `raw`.
91
+ */
69
92
  const generatedAnswer = (output) => {
70
93
  const { text, value } = output.content;
71
94
  if (text !== void 0) return text === "" ? void 0 : text;
72
95
  return value === void 0 || value === null ? void 0 : JSON.stringify(value);
73
96
  };
97
+ /**
98
+ * The `/contents` options for a read. Page text is always requested (capped
99
+ * when `maxCharacters` is set); `query` asks for highlights; links and image
100
+ * links default to 100 each, and `0` leaves them out.
101
+ */
74
102
  const readBody = (o) => {
75
103
  const links = o.linkLimit ?? 100;
76
104
  const images = o.imageLimit ?? 100;
@@ -87,16 +115,23 @@ const readBody = (o) => {
87
115
  text: o.maxCharacters === void 0 ? true : { maxCharacters: o.maxCharacters }
88
116
  });
89
117
  };
118
+ /**
119
+ * The error code for a URL Exa failed to read. Exa reports this per URL in the
120
+ * response, not as an HTTP error: its `tag` decides first, then the HTTP
121
+ * status it saw.
122
+ */
90
123
  const failureCode = (tag, httpStatus) => {
91
124
  if (tag === "CRAWL_NOT_FOUND" || tag === "CONTENT_NOT_CACHED") return "NotFound";
92
125
  if (tag === "CRAWL_TIMEOUT") return "Timeout";
93
126
  if (httpStatus === 404 || httpStatus === 410) return "NotFound";
94
127
  return httpStatus === 408 || httpStatus === 504 ? "Timeout" : "ProviderError";
95
128
  };
129
+ /** Why a URL failed, for an error message: Exa's tag, else its HTTP status, else the status text. */
96
130
  const statusReason = (status) => {
97
131
  const { httpStatusCode, tag } = status.error;
98
132
  return tag ?? (httpStatusCode === void 0 ? void 0 : `HTTP ${httpStatusCode}`) ?? status.status.text ?? "unknown";
99
133
  };
134
+ /** The URLs Exa reported with a status other than `success`. A status left out is not a failure. */
100
135
  const failedStatuses = (statuses) => statuses.filter(({ status }) => status.value !== void 0 && status.value !== "success");
101
136
  /** A page from a result; the caller adds `raw`. */
102
137
  const pageFrom = (url, result) => compact({
@@ -112,6 +147,7 @@ const pageFrom = (url, result) => compact({
112
147
  title: result.title,
113
148
  url: result.url ?? url
114
149
  });
150
+ /** Whether a run has the output asked for: the structured value, or the text. */
115
151
  const hasOutput = (run, structured) => structured ? run.output.structured !== void 0 && run.output.structured !== null : run.output.text !== void 0;
116
152
  const runMeta = (run) => {
117
153
  const { usage } = run;
@@ -125,11 +161,13 @@ const runMeta = (run) => {
125
161
  }
126
162
  });
127
163
  };
164
+ /** Refuses a budget the chosen `effort` does not take, before the run starts. */
128
165
  const checkResearch = (o) => {
129
166
  const effort = o.effort ?? "auto";
130
167
  if (o.maxCostDollars !== void 0 && effort !== "auto" && effort !== "ultra") throw invalidRequest("exa", `maxCostDollars needs effort "auto" or "ultra", not "${effort}"`);
131
168
  if (o.maxDurationSeconds !== void 0 && effort !== "ultra") throw invalidRequest("exa", `maxDurationSeconds needs effort "ultra", not "${effort}"`);
132
169
  };
170
+ /** The body that starts an agent run. `continueFrom` is sent as `previousRunId`. */
133
171
  const researchBody = (question, o) => {
134
172
  const budget = compact({
135
173
  maxCostDollars: o.maxCostDollars,
@@ -149,6 +187,13 @@ const researchBody = (question, o) => {
149
187
  systemPrompt: o.systemPrompt
150
188
  });
151
189
  };
190
+ /**
191
+ * The result of a finished run. A run that did not complete and has no output
192
+ * throws `JobFailed` with Exa's error. Otherwise the result is `completed`
193
+ * only when the run completed and stopped for no reason or with
194
+ * `schema_satisfied`; any other finish is `partial`, with the stop reason.
195
+ * `continuationId` is the run's id once it has completed.
196
+ */
152
197
  const researchResult = (id, entry, structured) => {
153
198
  const run = entry.value;
154
199
  const { stopReason } = run;
@@ -180,6 +225,7 @@ const researchResult = (id, entry, structured) => {
180
225
  stopReason: finished ? void 0 : stopReason ?? status
181
226
  });
182
227
  };
228
+ /** Exa's trigger period for an interval schedule: `hour`, `day` and `week` become `1h`, `1d` and `7d`. Exa has no cron. */
183
229
  const intervalPeriod = (schedule) => {
184
230
  const { every } = record(schedule);
185
231
  if (typeof every !== "string") throw invalidRequest("exa", "monitors run on an interval of whole hours or days; Exa has no cron");
@@ -190,7 +236,9 @@ const intervalPeriod = (schedule) => {
190
236
  if (!/^[1-9]\d*[hd]$/u.test(value)) throw invalidRequest("exa", `monitor schedule "${every}" is not whole hours or days, at least 1h`);
191
237
  return value;
192
238
  };
239
+ /** The trigger period for a monitor's schedule; undefined for a monitor with none. */
193
240
  const period = (schedule) => schedule === void 0 ? void 0 : intervalPeriod(schedule);
241
+ /** A monitor from Exa's entry; `schedule` is its trigger period and `watch` its search query. */
194
242
  const monitorInfo = (entry) => {
195
243
  const found = entry.value;
196
244
  return compact({
@@ -203,11 +251,16 @@ const monitorInfo = (entry) => {
203
251
  webhookUrl: found.webhook.url
204
252
  });
205
253
  };
254
+ /** What a run found: its generated text, or the failure when it failed. Undefined otherwise. */
206
255
  const eventSummary = (run) => {
207
256
  const { text } = run.output.content;
208
257
  if (text !== void 0) return text === "" ? void 0 : text;
209
258
  if (run.status === "failed") return `Run failed${run.failReason === void 0 ? "" : `: ${run.failReason}`}`;
210
259
  };
260
+ /**
261
+ * One run of a monitor as an event. `output` is set only when the run's
262
+ * content is a structured value rather than text.
263
+ */
211
264
  const monitorEvent = (entry) => {
212
265
  const run = entry.value;
213
266
  const { text, value } = run.output.content;
@@ -289,6 +342,7 @@ const SearchResponse = looseObject({
289
342
  results: arrayOf(Result),
290
343
  warnings: arrayOf(warningEntry)
291
344
  });
345
+ /** The sources behind one field of a run's output, with Exa's confidence in it. */
292
346
  const Grounding = looseObject({
293
347
  citations: arrayOf(Source),
294
348
  confidence: optionalStringOrNumber,
@@ -321,6 +375,7 @@ const Run = looseObject({
321
375
  const RunEntry = withOriginal(Run);
322
376
  /** The reply to starting a run. */
323
377
  const RunStart = looseObject({ id: withOriginal(optionalId) });
378
+ /** A monitor. `trigger.period` is its schedule and `search.query` what it watches. */
324
379
  const Monitor = looseObject({
325
380
  createdAt: optionalString,
326
381
  id: withOriginal(optionalId),
@@ -337,6 +392,7 @@ const MonitorsPage = looseObject({
337
392
  hasMore: optionalBoolean,
338
393
  nextCursor: optionalString
339
394
  });
395
+ /** One run of a monitor; `output.content` is its generated report, text or a value. */
340
396
  const MonitorRun = looseObject({
341
397
  completedAt: optionalString,
342
398
  createdAt: optionalString,
@@ -368,6 +424,7 @@ const exa = (config = {}) => {
368
424
  provider: "exa",
369
425
  retries: config.retries
370
426
  });
427
+ /** Calls `/contents` for these URLs. A URL Exa could not read is in `statuses`, not an error. */
371
428
  const fetchContents = async (urls, body, call) => {
372
429
  const response = await raw.request("POST", "/contents", {
373
430
  ...call,
@@ -381,6 +438,7 @@ const exa = (config = {}) => {
381
438
  response
382
439
  };
383
440
  };
441
+ /** Reads one URL. Throws when Exa reports a failure for it or returns no result. */
384
442
  const readOne = async (url, body, call) => {
385
443
  const { body: parsed, response } = await fetchContents([url], body, call);
386
444
  const [failed] = failedStatuses(parsed.statuses);
@@ -1,4 +1,4 @@
1
- import { m as Capability, n as AnyAdapter } from "./adapter-BgdfLBs-.js";
1
+ import { m as Capability, n as AnyAdapter } from "./adapter-BhTK51Yj.js";
2
2
  /** Why a call failed. Branch on this, not on the message, which can change. */
3
3
  type FieldworkErrorCode =
4
4
  /** The adapter's provider does not offer this capability. */
@@ -6,15 +6,24 @@ type FieldworkErrorCode =
6
6
  /** The API key is missing or the provider rejected it. */
7
7
  "Unauthorized" |
8
8
  /** The provider refused the request because of a rate or plan limit. */
9
- "RateLimited" | "NotFound" |
10
- /** The provider rejected the request as malformed. */
9
+ "RateLimited" |
10
+ /** A 404, or a page read that answered 404 or 410. */
11
+ "NotFound" |
12
+ /** The request is malformed or combines options the provider rejects: its 400 or 422, or Fieldwork refusing it before sending. */
11
13
  "InvalidRequest" |
12
14
  /** An asynchronous job finished without a result. */
13
- "JobFailed" | "Timeout" | "Aborted" |
15
+ "JobFailed" |
16
+ /** The call's `timeout` ran out, a job did not finish within it, or the provider answered 408. */
17
+ "Timeout" |
18
+ /** The caller's `signal` cancelled the call. */
19
+ "Aborted" |
14
20
  /** Any other provider failure. */
15
21
  "ProviderError";
22
+ /** What a `FieldworkError` carries besides its code and message. */
16
23
  interface FieldworkErrorOptions {
24
+ /** The provider the call was for, such as "exa". */
17
25
  provider?: string;
26
+ /** The HTTP status the provider answered with. */
18
27
  status?: number;
19
28
  /** Seconds the provider asked to wait before retrying. */
20
29
  retryAfter?: number;
@@ -22,14 +31,18 @@ interface FieldworkErrorOptions {
22
31
  jobId?: string;
23
32
  /** Overrides the default, which follows from the code and status. */
24
33
  retryable?: boolean;
34
+ /** What the failure came from, such as the provider's parsed error body or the underlying fetch error. */
25
35
  cause?: unknown;
26
36
  }
27
37
  /** The one error type every adapter throws, with a normalized code. */
28
38
  declare class FieldworkError extends Error {
29
39
  readonly name = "FieldworkError";
30
40
  readonly code: FieldworkErrorCode;
41
+ /** The provider the call was for, when the error came from one. */
31
42
  readonly provider?: string;
43
+ /** The HTTP status the provider answered with, when there was a response. */
32
44
  readonly status?: number;
45
+ /** Seconds the provider asked to wait before retrying, from its `Retry-After` header. */
33
46
  readonly retryAfter?: number;
34
47
  /**
35
48
  * The provider's id for an asynchronous job that was already created when
@@ -55,7 +68,9 @@ declare class FieldworkError extends Error {
55
68
  status: number | undefined;
56
69
  };
57
70
  }
71
+ /** What `new Fieldwork` takes. */
58
72
  interface FieldworkOptions<A extends AnyAdapter> {
73
+ /** The provider to call, such as `exa()`, or a `router` over several. */
59
74
  adapter: A;
60
75
  }
61
76
  interface FieldworkBase<A extends AnyAdapter> {
@@ -65,6 +80,7 @@ interface FieldworkBase<A extends AnyAdapter> {
65
80
  readonly capabilities: Readonly<Record<Capability, boolean>>;
66
81
  /** The provider's HTTP API, for anything Fieldwork does not wrap. */
67
82
  readonly raw: A["raw"];
83
+ /** Whether the capability can be called. Same as `capabilities[capability]`. */
68
84
  supports: (capability: Capability) => boolean;
69
85
  /** The provider that serves a capability, or undefined when none does. */
70
86
  providerFor: (capability: Capability) => string | undefined;
@@ -1,9 +1,12 @@
1
- import { B as ParsedDocument, C as DocumentInput, E as Extraction, F as MonitorEvents, I as MonitorInfo, K as Recency, L as MonitorSchedule, Q as SiteMap, R as Page, U as Product, Y as SearchResponse, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, j as ImageSearch, p as CallOptions, q as Research, s as AccountUsage, t as Adapter, z as PageBatch } from "./adapter-BgdfLBs-.js";
2
- import { t as OutputSchema } from "./schema-Cupy7-7q.js";
1
+ import { B as ParsedDocument, C as DocumentInput, E as Extraction, F as MonitorEvents, I as MonitorInfo, K as Recency, L as MonitorSchedule, Q as SiteMap, R as Page, U as Product, Y as SearchResponse, _ as Crawl, a as RawClient, c as ActResult, d as BrowserSession, j as ImageSearch, p as CallOptions, q as Research, s as AccountUsage, t as Adapter, z as PageBatch } from "./adapter-BhTK51Yj.js";
2
+ import { t as OutputSchema } from "./schema-CNd51xdD.js";
3
+ /** Settings for the Firecrawl adapter. */
3
4
  interface FirecrawlConfig {
4
5
  /** Defaults to the FIRECRAWL_API_KEY environment variable. */
5
6
  apiKey?: string;
7
+ /** Defaults to https://api.firecrawl.dev/v2. */
6
8
  baseUrl?: string;
9
+ /** Sends every request instead of the global `fetch`. */
7
10
  fetch?: typeof fetch;
8
11
  /** Repeats of a request that can succeed on repeat; 2 unless set. `0` turns retrying off. */
9
12
  retries?: number;
@@ -54,6 +57,7 @@ type FirecrawlAction = {
54
57
  type FirecrawlParser = "pdf" | "image" | FirecrawlPdfParser | {
55
58
  type: "image";
56
59
  };
60
+ /** Settings for Firecrawl's PDF parser. */
57
61
  interface FirecrawlPdfParser {
58
62
  type: "pdf";
59
63
  /** "fast" reads embedded text only, "ocr" always runs OCR, "auto" falls back to OCR. */
@@ -71,7 +75,7 @@ interface FirecrawlPageSettings {
71
75
  onlyMainContent?: boolean;
72
76
  includeTags?: string[];
73
77
  excludeTags?: string[];
74
- /** Seconds a cached copy may be old; 0 always fetches fresh. */
78
+ /** Seconds a cached copy may be old; 0 always fetches fresh. Sent to Firecrawl in milliseconds. */
75
79
  maxAge?: number;
76
80
  /** Milliseconds to wait for the page before reading it. */
77
81
  waitFor?: number;
@@ -92,6 +96,7 @@ interface FirecrawlPageSettings {
92
96
  actions?: FirecrawlAction[];
93
97
  parsers?: FirecrawlParser[];
94
98
  }
99
+ /** A format `include` can ask for beside Markdown. */
95
100
  type FirecrawlFormat = "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary";
96
101
  /** What to read from each page, beside its Markdown. */
97
102
  interface FirecrawlReadSettings extends FirecrawlPageSettings {
@@ -106,9 +111,17 @@ interface FirecrawlReadSettings extends FirecrawlPageSettings {
106
111
  */
107
112
  queryFormat?: "highlights" | "question";
108
113
  }
114
+ /** Options for `product`, and the page settings `extract` takes. */
109
115
  interface FirecrawlPageOptions extends CallOptions, FirecrawlPageSettings {}
116
+ /** Options for `read`. With `query`, the page has `excerpts`. */
110
117
  interface FirecrawlReadOptions extends CallOptions, FirecrawlReadSettings {}
118
+ /**
119
+ * Options for `readMany`, which runs one Firecrawl batch scrape as an
120
+ * asynchronous job. URLs Firecrawl rejects at the start, and pages that
121
+ * failed or answered 404 or 410, are listed in `failed`.
122
+ */
111
123
  interface FirecrawlReadManyOptions extends FirecrawlReadOptions {
124
+ /** Most pages Firecrawl scrapes at the same time. */
112
125
  maxConcurrency?: number;
113
126
  /** Firecrawl defaults to true: invalid URLs go to `failed` instead of failing the job. */
114
127
  ignoreInvalidURLs?: boolean;
@@ -121,9 +134,16 @@ interface FirecrawlReadManyOptions extends FirecrawlReadOptions {
121
134
  */
122
135
  resume?: string;
123
136
  }
137
+ /**
138
+ * Options for `search`. `tbs` and `recency` cannot be combined with each other
139
+ * or with the published dates, and `includeDomains` cannot be combined with
140
+ * `excludeDomains`; the adapter throws `InvalidRequest` before sending when
141
+ * they are.
142
+ */
124
143
  interface FirecrawlSearchOptions extends CallOptions {
125
144
  /** Results per source; Firecrawl allows up to 100. */
126
145
  limit?: number;
146
+ /** Which result lists to ask for. `images` fills `images` on the response. */
127
147
  sources?: ("web" | "news" | "images")[];
128
148
  /** "gov" cannot be combined with another category. */
129
149
  categories?: ("developer" | "gov" | "research" | "pdf")[];
@@ -140,7 +160,7 @@ interface FirecrawlSearchOptions extends CallOptions {
140
160
  country?: string;
141
161
  /** A place name such as "San Francisco,California,United States". */
142
162
  location?: string;
143
- /** Google time filter such as "sbd:1,qdr:w", for when the named options do not fit. */
163
+ /** Google time filter such as "sbd:1,qdr:w", for when the named options do not fit. Not with `recency`, `publishedAfter` or `publishedBefore`. */
144
164
  tbs?: string;
145
165
  /** Include each result's page text as Markdown. */
146
166
  content?: boolean;
@@ -148,16 +168,22 @@ interface FirecrawlSearchOptions extends CallOptions {
148
168
  safe?: boolean;
149
169
  ignoreInvalidURLs?: boolean;
150
170
  }
171
+ /** Options for `images`, which searches Firecrawl's image source only. */
151
172
  interface FirecrawlImagesOptions extends CallOptions {
152
173
  limit?: number;
153
174
  country?: string;
154
175
  location?: string;
155
176
  safe?: boolean;
156
177
  }
178
+ /**
179
+ * Options for `extract`: a scrape that asks Firecrawl for JSON in the shape of
180
+ * `schema`, which is checked on return.
181
+ */
157
182
  interface FirecrawlExtractOptions<T = unknown> extends FirecrawlPageOptions {
158
183
  schema: OutputSchema<T>;
159
184
  prompt?: string;
160
185
  }
186
+ /** Options for `map`. */
161
187
  interface FirecrawlMapOptions extends CallOptions {
162
188
  limit?: number;
163
189
  /** Order links by relevance to this text. */
@@ -173,6 +199,11 @@ interface FirecrawlMapOptions extends CallOptions {
173
199
  languages?: string[];
174
200
  };
175
201
  }
202
+ /**
203
+ * Options for `crawl`, which runs a Firecrawl crawl as an asynchronous job and
204
+ * returns every page. Pages that failed are in `failed` and pages robots.txt
205
+ * blocked in `robotsBlocked`.
206
+ */
176
207
  interface FirecrawlCrawlOptions extends CallOptions {
177
208
  limit?: number;
178
209
  /** Plain-words crawl instructions; the options you set override it. */
@@ -202,7 +233,13 @@ interface FirecrawlCrawlOptions extends CallOptions {
202
233
  */
203
234
  resume?: string;
204
235
  }
236
+ /**
237
+ * Options for `research`, which starts a Firecrawl agent run and waits for it
238
+ * as an asynchronous job. A run that fails but leaves partial output is
239
+ * returned with status `partial` and a `stopReason`.
240
+ */
205
241
  interface FirecrawlResearchOptions<T = unknown> extends CallOptions {
242
+ /** Output in the shape of this schema, checked on return. */
206
243
  schema?: OutputSchema<T>;
207
244
  /** Pages to start from. */
208
245
  urls?: string[];
@@ -224,6 +261,7 @@ interface FirecrawlResearchOptions<T = unknown> extends CallOptions {
224
261
  */
225
262
  resume?: string;
226
263
  }
264
+ /** How a new browser session is set up. */
227
265
  interface FirecrawlSessionSettings {
228
266
  /** Seconds the browser session may live (30 to 3600). */
229
267
  ttl?: number;
@@ -237,7 +275,13 @@ interface FirecrawlSessionSettings {
237
275
  /** ISO 3166-1 alpha-2 country the browser connects from. */
238
276
  country?: string;
239
277
  }
278
+ /**
279
+ * Options for `act`, which runs a script in a browser session. The call's
280
+ * `timeout` also limits the script, to at most 300 seconds. Session settings
281
+ * (`ttl`, `activityTtl`, `profile`, `country`) are refused together with `session`.
282
+ */
240
283
  interface FirecrawlActOptions extends CallOptions, FirecrawlSessionSettings {
284
+ /** Defaults to "node". */
241
285
  language?: "node" | "python" | "bash";
242
286
  /**
243
287
  * Run in this open session (from `browser.open` or an earlier `act` with
@@ -251,7 +295,13 @@ interface FirecrawlActOptions extends CallOptions, FirecrawlSessionSettings {
251
295
  */
252
296
  keepSession?: boolean;
253
297
  }
298
+ /** Options for `browser.open`. */
254
299
  type FirecrawlBrowserOptions = CallOptions & FirecrawlSessionSettings;
300
+ /**
301
+ * Options for `parse`, which reads a local file to Markdown. The adapter sends
302
+ * these as Firecrawl's PDF parser settings, and refuses a file type it does
303
+ * not know, a file over 50 MB, and a `timeout` over 300 seconds.
304
+ */
255
305
  interface FirecrawlParseOptions extends CallOptions {
256
306
  /** "fast" reads embedded text only, "ocr" always runs OCR, "auto" falls back to OCR. */
257
307
  mode?: "auto" | "fast" | "ocr";
@@ -263,6 +313,11 @@ interface FirecrawlParseOptions extends CallOptions {
263
313
  /** Mark page breaks in the Markdown. */
264
314
  pageMarkers?: boolean;
265
315
  }
316
+ /**
317
+ * Options for `monitor.create`. A monitor either watches `urls` or runs a
318
+ * search for `query`; one of the two is required. `searchWindow`, `maxResults`
319
+ * and the domain lists apply to search monitors and are refused with `urls`.
320
+ */
266
321
  interface FirecrawlMonitorOptions extends CallOptions {
267
322
  /** A name for the monitor; defaults to the query or first URL. */
268
323
  name?: string;
@@ -289,6 +344,11 @@ interface FirecrawlMonitorOptions extends CallOptions {
289
344
  /** Search monitors only. */
290
345
  excludeDomains?: string[];
291
346
  }
347
+ /**
348
+ * What Firecrawl can do: search, images, read, readMany, extract, product,
349
+ * map, crawl, research, act, browser, parse, monitor and usage. `readMany`,
350
+ * `crawl` and `research` are asynchronous jobs and accept `resume`.
351
+ */
292
352
  interface FirecrawlOperations {
293
353
  search: (query: string, options?: FirecrawlSearchOptions) => Promise<SearchResponse>;
294
354
  images: (query: string, options?: FirecrawlImagesOptions) => Promise<ImageSearch>;