firecrawl 4.35.0 → 4.38.0

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/index.d.ts CHANGED
@@ -16,6 +16,7 @@ interface JsonFormat extends Format {
16
16
  type: "json";
17
17
  prompt?: string;
18
18
  schema?: Record<string, unknown> | ZodTypeAny;
19
+ checkPromptInjection?: boolean;
19
20
  }
20
21
  interface ScreenshotFormat {
21
22
  type: "screenshot";
@@ -1102,9 +1103,181 @@ interface AgentStatusResponse {
1102
1103
  * names makes every future model a type error at the call site.
1103
1104
  */
1104
1105
  model?: "spark-1-pro" | "spark-1-mini" | "spark-2" | (string & {});
1106
+ /**
1107
+ * Reasoning effort the job ran with. Only set for runs that specified it;
1108
+ * older rows and default runs have no effort.
1109
+ */
1110
+ effort?: "low" | "medium" | "high";
1105
1111
  expiresAt: string;
1106
1112
  creditsUsed?: number;
1107
1113
  }
1114
+ /** Reasoning effort for agent jobs. Every level runs spark-2. */
1115
+ type AgentEffort = "low" | "medium" | "high";
1116
+ /** A single agent run as returned by the agent list endpoint. */
1117
+ interface AgentListItem {
1118
+ id: string;
1119
+ createdAt: string;
1120
+ targetHint: string;
1121
+ origin: string;
1122
+ integration?: string;
1123
+ settings: {
1124
+ hidden: boolean;
1125
+ starred: boolean;
1126
+ label?: string;
1127
+ };
1128
+ status: "processing" | "completed" | "failed";
1129
+ options?: {
1130
+ urls?: string[];
1131
+ prompt: string;
1132
+ schema?: unknown;
1133
+ /**
1134
+ * Server-provided model name. Widened past the request-side union on
1135
+ * purpose: new models ship without an SDK release, so pinning this to
1136
+ * known names makes every future model a type error at the call site.
1137
+ */
1138
+ model: "spark-1-pro" | "spark-1-mini" | "spark-2" | (string & {});
1139
+ effort?: AgentEffort;
1140
+ };
1141
+ }
1142
+ interface AgentListResponse {
1143
+ success: boolean;
1144
+ agents?: AgentListItem[];
1145
+ /**
1146
+ * Absolute URL of the next page (pass its `before` value to listAgents to
1147
+ * continue). Only present when more pages exist.
1148
+ */
1149
+ next?: string;
1150
+ error?: string;
1151
+ }
1152
+ /** Options for listing agent runs. */
1153
+ interface AgentListOptions {
1154
+ /** Only return agent runs created before this unix millisecond timestamp. */
1155
+ before?: number;
1156
+ }
1157
+ type AgentTraceAgentRole = "orchestrator" | "subagent" | "browser" | "system";
1158
+ interface AgentTraceAgentIdentity {
1159
+ id: string;
1160
+ role: AgentTraceAgentRole;
1161
+ name: string;
1162
+ parentId?: string;
1163
+ }
1164
+ interface AgentTraceError {
1165
+ code: "cancelled" | "credit_limit_reached" | "parent_finished" | "refused" | "internal";
1166
+ source: "agent" | "tool" | "billing" | "system";
1167
+ retryable: boolean;
1168
+ message: string;
1169
+ }
1170
+ interface AgentTraceArtifactChange {
1171
+ kind: "json" | "markdown" | "html" | "screenshot" | "text";
1172
+ artifactId: string;
1173
+ path?: string;
1174
+ /** Fetch the full content via getAgentSnapshot(jobId, snapshotId). */
1175
+ snapshotId: string;
1176
+ change: "init" | "partial" | "append" | "modify" | "update";
1177
+ changedFields?: string[];
1178
+ itemCount?: number;
1179
+ sourceToolCallId?: string;
1180
+ }
1181
+ interface AgentTraceEventBase {
1182
+ schemaVersion: 1;
1183
+ eventId: string;
1184
+ runId: string;
1185
+ occurredAt: string;
1186
+ producerSequence: number;
1187
+ agent: AgentTraceAgentIdentity;
1188
+ }
1189
+ interface AgentTraceRunStartedEvent extends AgentTraceEventBase {
1190
+ type: "run.started";
1191
+ }
1192
+ interface AgentTraceRunCancelRequestedEvent extends AgentTraceEventBase {
1193
+ type: "run.cancel_requested";
1194
+ reason: "user";
1195
+ }
1196
+ interface AgentTraceRunFinishedEvent extends AgentTraceEventBase {
1197
+ type: "run.finished";
1198
+ outcome: "succeeded" | "failed" | "cancelled" | "refused" | "credit_limit_reached";
1199
+ /** The canonical schema always writes this key (nullable), but older rows may omit it. */
1200
+ error?: AgentTraceError | null;
1201
+ }
1202
+ interface AgentTraceAgentStartedEvent extends AgentTraceEventBase {
1203
+ type: "agent.started";
1204
+ }
1205
+ interface AgentTraceAgentFinishedEvent extends AgentTraceEventBase {
1206
+ type: "agent.finished";
1207
+ outcome: "succeeded" | "failed" | "cancelled" | "refused";
1208
+ durationMs: number;
1209
+ /** The canonical schema always writes this key (nullable), but older rows may omit it. */
1210
+ error?: AgentTraceError | null;
1211
+ }
1212
+ interface AgentTraceBrowserSessionStartedEvent extends AgentTraceEventBase {
1213
+ type: "browser.session.started";
1214
+ sessionId: string;
1215
+ }
1216
+ interface AgentTraceBrowserSessionFinishedEvent extends AgentTraceEventBase {
1217
+ type: "browser.session.finished";
1218
+ sessionId: string;
1219
+ durationMs: number;
1220
+ }
1221
+ interface AgentTraceProgressReportedEvent extends AgentTraceEventBase {
1222
+ type: "progress.reported";
1223
+ phase: "planning" | "working" | "finalizing";
1224
+ message: string;
1225
+ }
1226
+ interface AgentTraceReasoningSummaryEvent extends AgentTraceEventBase {
1227
+ type: "reasoning.summary";
1228
+ text: string;
1229
+ }
1230
+ interface AgentTraceToolCallStartedEvent extends AgentTraceEventBase {
1231
+ type: "tool_call.started";
1232
+ toolCallId: string;
1233
+ toolName: string;
1234
+ parameters: unknown;
1235
+ }
1236
+ interface AgentTraceToolCallFinishedEvent extends AgentTraceEventBase {
1237
+ type: "tool_call.finished";
1238
+ toolCallId: string;
1239
+ toolName: string;
1240
+ result: unknown;
1241
+ }
1242
+ interface AgentTraceArtifactUpdatedEvent extends AgentTraceEventBase {
1243
+ type: "artifact.updated";
1244
+ artifact: AgentTraceArtifactChange;
1245
+ }
1246
+ interface AgentTraceErrorOccurredEvent extends AgentTraceEventBase {
1247
+ type: "error.occurred";
1248
+ error: AgentTraceError;
1249
+ }
1250
+ /**
1251
+ * One event in an agent job's trace. Mirrors the canonical event schema of
1252
+ * the agent service (schemaVersion 1); `usage.recorded` events are withheld
1253
+ * server-side and `agent.started` carries no model name.
1254
+ */
1255
+ type AgentTraceEvent = AgentTraceRunStartedEvent | AgentTraceRunCancelRequestedEvent | AgentTraceRunFinishedEvent | AgentTraceAgentStartedEvent | AgentTraceAgentFinishedEvent | AgentTraceBrowserSessionStartedEvent | AgentTraceBrowserSessionFinishedEvent | AgentTraceProgressReportedEvent | AgentTraceReasoningSummaryEvent | AgentTraceToolCallStartedEvent | AgentTraceToolCallFinishedEvent | AgentTraceArtifactUpdatedEvent | AgentTraceErrorOccurredEvent;
1256
+ interface AgentTraceActiveBrowserSession {
1257
+ id: string;
1258
+ liveViewUrl: string;
1259
+ viewport: {
1260
+ width: number;
1261
+ height: number;
1262
+ };
1263
+ }
1264
+ interface AgentTraceResponse {
1265
+ success: boolean;
1266
+ id?: string;
1267
+ events?: AgentTraceEvent[];
1268
+ creditsUsed?: number;
1269
+ /** Present only when the trace was requested with liveView: true. */
1270
+ activeBrowserSessions?: AgentTraceActiveBrowserSession[];
1271
+ error?: string;
1272
+ }
1273
+ interface AgentSnapshotResponse {
1274
+ success: boolean;
1275
+ id?: string;
1276
+ snapshotId?: string;
1277
+ /** Full artifact content as a JSON/string blob. */
1278
+ snapshot?: string;
1279
+ error?: string;
1280
+ }
1108
1281
  interface AgentOptions$1 {
1109
1282
  model: "FIRE-1" | "v3-beta";
1110
1283
  }
@@ -1424,6 +1597,9 @@ declare class HttpClient {
1424
1597
  constructor(options: HttpClientOptions);
1425
1598
  getApiUrl(): string;
1426
1599
  getApiKey(): string;
1600
+ /** The client-wide default request timeout, for callers that need to
1601
+ * extend a specific request beyond it (e.g. scrape auto-resume). */
1602
+ getTimeoutMs(): number;
1427
1603
  private request;
1428
1604
  private sleep;
1429
1605
  post<T = any>(endpoint: string, body: Record<string, unknown>, options?: RequestOptions): Promise<AxiosResponse<T, any, {}>>;
@@ -1434,6 +1610,27 @@ declare class HttpClient {
1434
1610
  prepareHeaders(idempotencyKey?: string): Record<string, string>;
1435
1611
  }
1436
1612
 
1613
+ /**
1614
+ * Options for a direct scrape call. `autoResume` lives here — NOT on the
1615
+ * shared ScrapeOptions — because that type is reused verbatim inside
1616
+ * batch/crawl/search/extract payloads, where an SDK-only key would leak
1617
+ * onto the wire and fail strict endpoints.
1618
+ */
1619
+ type ScrapeCallOptions = ScrapeOptions & {
1620
+ /**
1621
+ * SDK-only (never sent to the API). Large documents (big PDFs) that
1622
+ * outlive the request window keep processing server-side; the API's
1623
+ * timeout error then carries `details.state === "processing_continues"`
1624
+ * and a Retry-After. When this is not `false`, the SDK sleeps that
1625
+ * long and re-issues the same request — the retry attaches to the
1626
+ * in-flight job and returns the finished result, so a large document
1627
+ * behaves like one slow successful call. Bounded (at most 5 resumes /
1628
+ * 20 minutes total wait); set `false` to surface the timeout error
1629
+ * immediately instead.
1630
+ */
1631
+ autoResume?: boolean;
1632
+ };
1633
+
1437
1634
  declare function prepareExtractPayload(args: {
1438
1635
  urls?: string[];
1439
1636
  prompt?: string;
@@ -1465,6 +1662,7 @@ declare function prepareAgentPayload(args: {
1465
1662
  maxCredits?: number;
1466
1663
  strictConstrainToURLs?: boolean;
1467
1664
  model?: "spark-1-pro" | "spark-1-mini" | "spark-2";
1665
+ effort?: AgentEffort;
1468
1666
  webhook?: string | AgentWebhookConfig;
1469
1667
  threatProtection?: ThreatProtectionOptions;
1470
1668
  auditMetadata?: AuditMetadata$1;
@@ -1636,7 +1834,7 @@ declare class FirecrawlClient {
1636
1834
  scrape<Opts extends ScrapeOptions>(url: string, options: Opts): Promise<Omit<Document, "json"> & {
1637
1835
  json?: InferredJsonFromOptions<Opts>;
1638
1836
  }>;
1639
- scrape(url: string, options?: ScrapeOptions): Promise<Document>;
1837
+ scrape(url: string, options?: ScrapeCallOptions): Promise<Document>;
1640
1838
  /**
1641
1839
  * Interact with the browser session associated with a scrape job.
1642
1840
  * @param jobId Scrape job id.
@@ -1869,6 +2067,15 @@ declare class FirecrawlClient {
1869
2067
  * @param jobId Agent job id.
1870
2068
  */
1871
2069
  getAgentStatus(jobId: string): Promise<AgentStatusResponse>;
2070
+ /**
2071
+ * List agent runs, most recent first.
2072
+ *
2073
+ * Pages are fixed at 20 runs. To fetch the next page, pass the `before`
2074
+ * value from the previous page's `next` URL. This method does not
2075
+ * auto-paginate.
2076
+ * @param options.before Only return runs created before this unix ms timestamp.
2077
+ */
2078
+ listAgents(options?: AgentListOptions): Promise<AgentListResponse>;
1872
2079
  /**
1873
2080
  * Convenience waiter: start an agent and poll until it finishes.
1874
2081
  * @param args Agent request plus waiter controls (pollInterval, timeout seconds).
@@ -1884,6 +2091,20 @@ declare class FirecrawlClient {
1884
2091
  * @returns True if cancelled.
1885
2092
  */
1886
2093
  cancelAgent(jobId: string): Promise<boolean>;
2094
+ /**
2095
+ * Get the execution trace of an agent job (spark-2 runs only).
2096
+ * @param jobId Agent job id.
2097
+ * @param options.liveView Also include currently active browser sessions with live view URLs.
2098
+ */
2099
+ getAgentTrace(jobId: string, options?: {
2100
+ liveView?: boolean;
2101
+ }): Promise<AgentTraceResponse>;
2102
+ /**
2103
+ * Get the full content of an artifact snapshot referenced by a trace event.
2104
+ * @param jobId Agent job id.
2105
+ * @param snapshotId Snapshot id from an artifact.updated trace event.
2106
+ */
2107
+ getAgentSnapshot(jobId: string, snapshotId: string): Promise<AgentSnapshotResponse>;
1887
2108
  /**
1888
2109
  * Create a new browser session.
1889
2110
  * @param args Session options (ttl, activityTtl, streamWebView, profile).
@@ -2124,6 +2345,7 @@ interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchema exten
2124
2345
  prompt?: string;
2125
2346
  schema?: LLMSchema;
2126
2347
  systemPrompt?: string;
2348
+ checkPromptInjection?: boolean;
2127
2349
  };
2128
2350
  changeTrackingOptions?: {
2129
2351
  prompt?: string;
@@ -2885,4 +3107,4 @@ declare class Firecrawl extends FirecrawlClient {
2885
3107
  get v1(): FirecrawlApp;
2886
3108
  }
2887
3109
 
2888
- export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type AuditMetadata$1 as AuditMetadata, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type DeveloperSearchLicenseDisclosure, type DeveloperSearchOptions, type DeveloperSearchPassage, type DeveloperSearchRepoStatus, type DeveloperSearchResponse, type DeveloperSearchResult, type DeveloperSearchSourceStatus, type DeveloperSearchType, type Document, type DocumentMetadata, type EndpointFeedbackEndpoint, type EndpointFeedbackRequest, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, type FeedbackMissingContent, type FeedbackRating, type FeedbackResponse, type FeedbackValuableSource, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientInput, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type GetMonitorCheckOptions, type GetPaperOptions, type GitHubScoreBreakdown, type GitHubSearchItem, type GitHubSearchResponse, type HighlightsFormat, type IdMap, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type MenuAvailability, type MenuImage, type MenuItem, type MenuItemIdentifiers, type MenuMerchant, type MenuPrice, type MenuProfile, type MenuSection, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorCrawlTargetResult, type MonitorEmailNotification, type MonitorEmailRecipientSubscription, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorScrapeTargetResult, type MonitorSearchTarget, type MonitorSearchTargetResult, type MonitorSummary, type MonitorTarget, type MonitorTargetResult, type MonitorWebhookConfig, type PDFAction, type PDFParser, type PaginationConfig, type PaperMetadata, type PaperMetadataResponse, type PaperResult, type PaperSignals, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type Passage, type PdfBlockConfidence, type PdfBlockItem, type PdfPage, type PdfPageBlocks, type PressAction, type ProductAvailability, type ProductImage, type ProductPrice, type ProductProfile, type ProductSale, type ProductVariant, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ReadPaperResponse, type RedactPIIEntity, type RedactPIIOptions, ResearchClient, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchFeedbackRequest, type SearchGithubOptions, type SearchPapersOptions, type SearchPapersResponse, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type SimilarPapersOptions, type SimilarPapersResponse, type ThreatProtectionOptions, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
3110
+ export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentEffort, type AgentListItem, type AgentListOptions, type AgentListResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentSnapshotResponse, type AgentStatusResponse, type AgentTraceActiveBrowserSession, type AgentTraceAgentFinishedEvent, type AgentTraceAgentIdentity, type AgentTraceAgentRole, type AgentTraceAgentStartedEvent, type AgentTraceArtifactChange, type AgentTraceArtifactUpdatedEvent, type AgentTraceBrowserSessionFinishedEvent, type AgentTraceBrowserSessionStartedEvent, type AgentTraceError, type AgentTraceErrorOccurredEvent, type AgentTraceEvent, type AgentTraceProgressReportedEvent, type AgentTraceReasoningSummaryEvent, type AgentTraceResponse, type AgentTraceRunCancelRequestedEvent, type AgentTraceRunFinishedEvent, type AgentTraceRunStartedEvent, type AgentTraceToolCallFinishedEvent, type AgentTraceToolCallStartedEvent, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, type AuditMetadata$1 as AuditMetadata, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type BrandingProfile, type BrowserCreateResponse, type BrowserDeleteResponse, type BrowserExecuteResponse, type BrowserListResponse, type BrowserSession, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreateMonitorRequest, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type DeveloperSearchLicenseDisclosure, type DeveloperSearchOptions, type DeveloperSearchPassage, type DeveloperSearchRepoStatus, type DeveloperSearchResponse, type DeveloperSearchResult, type DeveloperSearchSourceStatus, type DeveloperSearchType, type Document, type DocumentMetadata, type EndpointFeedbackEndpoint, type EndpointFeedbackRequest, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, type FeedbackMissingContent, type FeedbackRating, type FeedbackResponse, type FeedbackValuableSource, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientInput, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type GetMonitorCheckOptions, type GetPaperOptions, type GitHubScoreBreakdown, type GitHubSearchItem, type GitHubSearchResponse, type HighlightsFormat, type IdMap, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type MenuAvailability, type MenuImage, type MenuItem, type MenuItemIdentifiers, type MenuMerchant, type MenuPrice, type MenuProfile, type MenuSection, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorCrawlTargetResult, type MonitorEmailNotification, type MonitorEmailRecipientSubscription, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorScrapeTargetResult, type MonitorSearchTarget, type MonitorSearchTargetResult, type MonitorSummary, type MonitorTarget, type MonitorTargetResult, type MonitorWebhookConfig, type PDFAction, type PDFParser, type PaginationConfig, type PaperMetadata, type PaperMetadataResponse, type PaperResult, type PaperSignals, type ParseFile, type ParseFileData, type ParseFormat, type ParseFormatOption, type ParseFormatString, type ParseOptions, type Passage, type PdfBlockConfidence, type PdfBlockItem, type PdfPage, type PdfPageBlocks, type PressAction, type ProductAvailability, type ProductImage, type ProductPrice, type ProductProfile, type ProductSale, type ProductVariant, type QueryFormat, type QuestionFormat, type QueueStatusResponse$1 as QueueStatusResponse, type ReadPaperResponse, type RedactPIIEntity, type RedactPIIOptions, ResearchClient, type ScrapeAction, type ScrapeBrowserDeleteResponse, type ScrapeExecuteRequest, type ScrapeExecuteResponse, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchFeedbackRequest, type SearchGithubOptions, type SearchPapersOptions, type SearchPapersResponse, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type SimilarPapersOptions, type SimilarPapersResponse, type ThreatProtectionOptions, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type UpdateMonitorRequest, type Viewport, type WaitAction, Watcher, type WatcherOptions, type WebhookConfig, type WriteAction, Firecrawl as default };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-666CR5HH.js";
3
+ } from "./chunk-KSTNOGOD.js";
4
4
 
5
5
  // src/v2/utils/httpClient.ts
6
6
  import axios from "axios";
@@ -48,6 +48,11 @@ var HttpClient = class {
48
48
  getApiKey() {
49
49
  return this.apiKey;
50
50
  }
51
+ /** The client-wide default request timeout, for callers that need to
52
+ * extend a specific request beyond it (e.g. scrape auto-resume). */
53
+ getTimeoutMs() {
54
+ return this.instance.defaults.timeout ?? 3e5;
55
+ }
51
56
  async request(config) {
52
57
  const version = getVersion();
53
58
  config.headers = {
@@ -428,26 +433,60 @@ function isRetryableError(err) {
428
433
  }
429
434
 
430
435
  // src/v2/methods/scrape.ts
431
- async function scrape(http, url, options) {
436
+ var RESUME_MAX_ATTEMPTS = 5;
437
+ var RESUME_MAX_TOTAL_WAIT_MS = 20 * 60 * 1e3;
438
+ var RESUME_MIN_DELAY_MS = 5 * 1e3;
439
+ var RESUME_MAX_DELAY_MS = 10 * 60 * 1e3;
440
+ function processingContinuesDelayMs(err) {
441
+ const response = err?.isAxiosError ? err.response : void 0;
442
+ if (!response || response.status !== 408) return void 0;
443
+ const body = response.data;
444
+ if (body?.code !== "SCRAPE_TIMEOUT" || body?.details?.state !== "processing_continues") {
445
+ return void 0;
446
+ }
447
+ const headerSeconds = Number(response.headers?.["retry-after"]);
448
+ const seconds = typeof body.details.retryAfterSeconds === "number" && Number.isFinite(body.details.retryAfterSeconds) ? body.details.retryAfterSeconds : Number.isFinite(headerSeconds) ? headerSeconds : 60;
449
+ return Math.min(RESUME_MAX_DELAY_MS, Math.max(RESUME_MIN_DELAY_MS, seconds * 1e3));
450
+ }
451
+ async function scrape(http, url, options, deps = {}) {
452
+ const sleep = deps.sleepImpl ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
432
453
  if (!url || !url.trim()) {
433
454
  throw new Error("URL cannot be empty");
434
455
  }
435
456
  if (options) ensureValidScrapeOptions(options);
457
+ const { autoResume, ...requestOptions } = options ?? {};
436
458
  const payload = { url: url.trim() };
437
- if (options) Object.assign(payload, options);
438
- try {
439
- const res = await http.post(
440
- "/v2/scrape",
441
- payload,
442
- typeof options?.timeout === "number" ? { timeoutMs: options.timeout + 5e3 } : {}
443
- );
444
- if (res.status !== 200 || !res.data?.success) {
445
- throwForBadResponse(res, "scrape");
459
+ Object.assign(payload, requestOptions);
460
+ const requestTimeout = autoResume === false ? typeof options?.timeout === "number" ? { timeoutMs: options.timeout + 5e3 } : {} : {
461
+ timeoutMs: Math.max(
462
+ typeof options?.timeout === "number" ? options.timeout : 3e5,
463
+ typeof http.getTimeoutMs === "function" ? http.getTimeoutMs() : 0
464
+ ) + 3e4
465
+ };
466
+ let resumes = 0;
467
+ let resumeWaitedMs = 0;
468
+ while (true) {
469
+ try {
470
+ const res = await http.post(
471
+ "/v2/scrape",
472
+ payload,
473
+ requestTimeout
474
+ );
475
+ if (res.status !== 200 || !res.data?.success) {
476
+ throwForBadResponse(res, "scrape");
477
+ }
478
+ return res.data.data || {};
479
+ } catch (err) {
480
+ const delayMs = autoResume !== false ? processingContinuesDelayMs(err) : void 0;
481
+ if (delayMs !== void 0 && resumes < RESUME_MAX_ATTEMPTS && resumeWaitedMs + delayMs <= RESUME_MAX_TOTAL_WAIT_MS) {
482
+ resumes += 1;
483
+ resumeWaitedMs += delayMs;
484
+ await sleep(delayMs);
485
+ continue;
486
+ }
487
+ if (err?.isAxiosError) return normalizeAxiosError(err, "scrape");
488
+ throw err;
446
489
  }
447
- return res.data.data || {};
448
- } catch (err) {
449
- if (err?.isAxiosError) return normalizeAxiosError(err, "scrape");
450
- throw err;
451
490
  }
452
491
  }
453
492
  async function interact(http, jobId, args) {
@@ -1195,6 +1234,7 @@ function prepareAgentPayload(args) {
1195
1234
  if (args.maxCredits !== null && args.maxCredits !== void 0) body.maxCredits = args.maxCredits;
1196
1235
  if (args.strictConstrainToURLs !== null && args.strictConstrainToURLs !== void 0) body.strictConstrainToURLs = args.strictConstrainToURLs;
1197
1236
  if (args.model !== null && args.model !== void 0) body.model = args.model;
1237
+ if (args.effort !== null && args.effort !== void 0) body.effort = args.effort;
1198
1238
  if (args.webhook != null) body.webhook = args.webhook;
1199
1239
  if (args.threatProtection != null)
1200
1240
  body.threatProtection = args.threatProtection;
@@ -1223,6 +1263,17 @@ async function getAgentStatus(http, jobId) {
1223
1263
  throw err;
1224
1264
  }
1225
1265
  }
1266
+ async function listAgents(http, options) {
1267
+ try {
1268
+ const query = options?.before !== void 0 ? `?before=${options.before}` : "";
1269
+ const res = await http.get(`/v2/agent${query}`);
1270
+ if (res.status !== 200) throwForBadResponse(res, "list agents");
1271
+ return res.data;
1272
+ } catch (err) {
1273
+ if (err?.isAxiosError) return normalizeAxiosError(err, "list agents");
1274
+ throw err;
1275
+ }
1276
+ }
1226
1277
  async function waitAgent(http, jobId, pollInterval = 2, timeout) {
1227
1278
  const start = Date.now();
1228
1279
  while (true) {
@@ -1238,6 +1289,27 @@ async function agent(http, args) {
1238
1289
  if (!jobId) return started;
1239
1290
  return waitAgent(http, jobId, args.pollInterval ?? 2, args.timeout);
1240
1291
  }
1292
+ async function getAgentTrace(http, jobId, options) {
1293
+ try {
1294
+ const query = options?.liveView ? "?liveView=true" : "";
1295
+ const res = await http.get(`/v2/agent/${jobId}/trace${query}`);
1296
+ if (res.status !== 200) throwForBadResponse(res, "agent trace");
1297
+ return res.data;
1298
+ } catch (err) {
1299
+ if (err?.isAxiosError) return normalizeAxiosError(err, "agent trace");
1300
+ throw err;
1301
+ }
1302
+ }
1303
+ async function getAgentSnapshot(http, jobId, snapshotId) {
1304
+ try {
1305
+ const res = await http.get(`/v2/agent/${jobId}/snapshots/${snapshotId}`);
1306
+ if (res.status !== 200) throwForBadResponse(res, "agent snapshot");
1307
+ return res.data;
1308
+ } catch (err) {
1309
+ if (err?.isAxiosError) return normalizeAxiosError(err, "agent snapshot");
1310
+ throw err;
1311
+ }
1312
+ }
1241
1313
  async function cancelAgent(http, jobId) {
1242
1314
  try {
1243
1315
  const res = await http.delete(`/v2/agent/${jobId}`);
@@ -2223,6 +2295,17 @@ var FirecrawlClient = class {
2223
2295
  async getAgentStatus(jobId) {
2224
2296
  return getAgentStatus(this.http, jobId);
2225
2297
  }
2298
+ /**
2299
+ * List agent runs, most recent first.
2300
+ *
2301
+ * Pages are fixed at 20 runs. To fetch the next page, pass the `before`
2302
+ * value from the previous page's `next` URL. This method does not
2303
+ * auto-paginate.
2304
+ * @param options.before Only return runs created before this unix ms timestamp.
2305
+ */
2306
+ async listAgents(options) {
2307
+ return listAgents(this.http, options);
2308
+ }
2226
2309
  /**
2227
2310
  * Convenience waiter: start an agent and poll until it finishes.
2228
2311
  * @param args Agent request plus waiter controls (pollInterval, timeout seconds).
@@ -2239,6 +2322,22 @@ var FirecrawlClient = class {
2239
2322
  async cancelAgent(jobId) {
2240
2323
  return cancelAgent(this.http, jobId);
2241
2324
  }
2325
+ /**
2326
+ * Get the execution trace of an agent job (spark-2 runs only).
2327
+ * @param jobId Agent job id.
2328
+ * @param options.liveView Also include currently active browser sessions with live view URLs.
2329
+ */
2330
+ async getAgentTrace(jobId, options) {
2331
+ return getAgentTrace(this.http, jobId, options);
2332
+ }
2333
+ /**
2334
+ * Get the full content of an artifact snapshot referenced by a trace event.
2335
+ * @param jobId Agent job id.
2336
+ * @param snapshotId Snapshot id from an artifact.updated trace event.
2337
+ */
2338
+ async getAgentSnapshot(jobId, snapshotId) {
2339
+ return getAgentSnapshot(this.http, jobId, snapshotId);
2340
+ }
2242
2341
  // Browser
2243
2342
  /**
2244
2343
  * Create a new browser session.
@@ -2381,7 +2480,7 @@ var FirecrawlApp = class {
2381
2480
  if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
2382
2481
  return process.env.npm_package_version;
2383
2482
  }
2384
- const packageJson = await import("./package-ZOVFJE7Z.js");
2483
+ const packageJson = await import("./package-OS7RONXY.js");
2385
2484
  return packageJson.default.version;
2386
2485
  } catch (error) {
2387
2486
  const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
@@ -1,4 +1,4 @@
1
1
  import {
2
2
  require_package
3
- } from "./chunk-666CR5HH.js";
3
+ } from "./chunk-KSTNOGOD.js";
4
4
  export default require_package();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firecrawl",
3
- "version": "4.35.0",
3
+ "version": "4.38.0",
4
4
  "description": "JavaScript SDK for the Firecrawl API: web scraping, crawling, web search, and scientific literature search over a research paper index of PubMed, bioRxiv, medRxiv and arXiv abstracts",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,140 @@
1
+ import { describe, expect, test } from "@jest/globals";
2
+ import {
3
+ startAgent,
4
+ getAgentTrace,
5
+ getAgentSnapshot,
6
+ } from "../../../v2/methods/agent";
7
+ import type { AgentTraceEvent } from "../../../v2/types";
8
+
9
+ describe("v2.agent unit", () => {
10
+ test("startAgent forwards effort in request payload", async () => {
11
+ const post = jest.fn().mockResolvedValue({
12
+ status: 200,
13
+ data: { success: true, id: "agent-job" },
14
+ });
15
+
16
+ await startAgent({ post } as any, {
17
+ prompt: "Find the pricing",
18
+ effort: "high",
19
+ });
20
+
21
+ expect(post).toHaveBeenCalledWith("/v2/agent", {
22
+ prompt: "Find the pricing",
23
+ effort: "high",
24
+ });
25
+ });
26
+
27
+ test("startAgent omits effort when unset", async () => {
28
+ const post = jest.fn().mockResolvedValue({
29
+ status: 200,
30
+ data: { success: true, id: "agent-job" },
31
+ });
32
+
33
+ await startAgent({ post } as any, { prompt: "Find the pricing" });
34
+
35
+ expect(post).toHaveBeenCalledWith("/v2/agent", {
36
+ prompt: "Find the pricing",
37
+ });
38
+ });
39
+
40
+ test("getAgentTrace hits the trace endpoint and returns typed events", async () => {
41
+ const runStarted: AgentTraceEvent = {
42
+ schemaVersion: 1,
43
+ eventId: "018f3c5e-0000-7000-8000-000000000000",
44
+ runId: "018f3c5e-0000-7000-8000-000000000001",
45
+ occurredAt: "2026-08-26T12:00:00+00:00",
46
+ producerSequence: 1,
47
+ agent: {
48
+ id: "018f3c5e-0000-7000-8000-000000000002",
49
+ role: "orchestrator",
50
+ name: "main",
51
+ },
52
+ type: "run.started",
53
+ };
54
+ const artifactUpdated: AgentTraceEvent = {
55
+ schemaVersion: 1,
56
+ eventId: "018f3c5e-0000-7000-8000-000000000010",
57
+ runId: "018f3c5e-0000-7000-8000-000000000001",
58
+ occurredAt: "2026-08-26T12:00:01+00:00",
59
+ producerSequence: 2,
60
+ agent: {
61
+ id: "018f3c5e-0000-7000-8000-000000000002",
62
+ role: "orchestrator",
63
+ name: "main",
64
+ },
65
+ type: "artifact.updated",
66
+ artifact: {
67
+ kind: "json",
68
+ artifactId: "result",
69
+ snapshotId: "018f3c5e-0000-7000-8000-000000000003",
70
+ change: "partial",
71
+ },
72
+ };
73
+ const get = jest.fn().mockResolvedValue({
74
+ status: 200,
75
+ data: {
76
+ success: true,
77
+ id: "agent-job",
78
+ events: [runStarted, artifactUpdated],
79
+ creditsUsed: 5,
80
+ },
81
+ });
82
+
83
+ const trace = await getAgentTrace({ get } as any, "agent-job");
84
+
85
+ expect(get).toHaveBeenCalledWith("/v2/agent/agent-job/trace");
86
+ expect(trace.events).toHaveLength(2);
87
+ expect(trace.events![0].type).toBe("run.started");
88
+ expect(trace.events![1].type).toBe("artifact.updated");
89
+ if (trace.events![1].type === "artifact.updated") {
90
+ expect(trace.events![1].artifact.snapshotId).toBe(
91
+ "018f3c5e-0000-7000-8000-000000000003",
92
+ );
93
+ }
94
+ expect(trace.creditsUsed).toBe(5);
95
+ });
96
+
97
+ test("getAgentTrace appends liveView query param when requested", async () => {
98
+ const get = jest.fn().mockResolvedValue({
99
+ status: 200,
100
+ data: {
101
+ success: true,
102
+ id: "agent-job",
103
+ events: [],
104
+ creditsUsed: 0,
105
+ activeBrowserSessions: [
106
+ {
107
+ id: "sess-1",
108
+ liveViewUrl: "https://browser.example.com/sess-1",
109
+ viewport: { width: 1280, height: 720 },
110
+ },
111
+ ],
112
+ },
113
+ });
114
+
115
+ const trace = await getAgentTrace({ get } as any, "agent-job", {
116
+ liveView: true,
117
+ });
118
+
119
+ expect(get).toHaveBeenCalledWith("/v2/agent/agent-job/trace?liveView=true");
120
+ expect(trace.activeBrowserSessions).toHaveLength(1);
121
+ expect(trace.activeBrowserSessions![0].viewport.width).toBe(1280);
122
+ });
123
+
124
+ test("getAgentSnapshot hits the snapshot endpoint", async () => {
125
+ const get = jest.fn().mockResolvedValue({
126
+ status: 200,
127
+ data: {
128
+ success: true,
129
+ id: "agent-job",
130
+ snapshotId: "snap-1",
131
+ snapshot: '{"price": 42}',
132
+ },
133
+ });
134
+
135
+ const snapshot = await getAgentSnapshot({ get } as any, "agent-job", "snap-1");
136
+
137
+ expect(get).toHaveBeenCalledWith("/v2/agent/agent-job/snapshots/snap-1");
138
+ expect(snapshot.snapshot).toBe('{"price": 42}');
139
+ });
140
+ });