@mendable/firecrawl-js 4.34.2 → 4.37.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/{chunk-PFIWJELS.js → chunk-LFX7WDGT.js} +1 -1
- package/dist/index.cjs +92 -15
- package/dist/index.d.cts +182 -2
- package/dist/index.d.ts +182 -2
- package/dist/index.js +93 -16
- package/dist/{package-H4IIQQQK.js → package-SHMK2LJE.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/v2/agent-effort-trace.unit.test.ts +140 -0
- package/src/__tests__/unit/v2/scrapeAutoResume.test.ts +145 -0
- package/src/__tests__/unit/v2/validation.test.ts +3 -2
- package/src/v1/index.ts +1 -0
- package/src/v2/client.ts +22 -4
- package/src/v2/methods/agent.ts +34 -1
- package/src/v2/methods/scrape.ts +123 -19
- package/src/v2/types.ts +173 -0
- package/src/v2/utils/httpClient.ts +6 -0
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";
|
|
@@ -129,6 +130,14 @@ type PDFParser = {
|
|
|
129
130
|
pageMarkdown?: boolean;
|
|
130
131
|
/** Include per-page typed layout blocks (bounding boxes, block types, reading order). */
|
|
131
132
|
blocks?: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Join PDF pages in `document.markdown` with `\n\n---\n\n<!-- page N -->\n\n`,
|
|
135
|
+
* where N is the 1-based physical page of the content that follows. Markers
|
|
136
|
+
* appear between pages only (no leading marker for page 1), and numbering may
|
|
137
|
+
* skip pages merged by cross-page stitching — use `pages: true` when every
|
|
138
|
+
* physical page is needed. No new response field.
|
|
139
|
+
*/
|
|
140
|
+
pageMarkers?: boolean;
|
|
132
141
|
};
|
|
133
142
|
interface PdfPage {
|
|
134
143
|
pageNumber: number;
|
|
@@ -1094,9 +1103,140 @@ interface AgentStatusResponse {
|
|
|
1094
1103
|
* names makes every future model a type error at the call site.
|
|
1095
1104
|
*/
|
|
1096
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";
|
|
1097
1111
|
expiresAt: string;
|
|
1098
1112
|
creditsUsed?: number;
|
|
1099
1113
|
}
|
|
1114
|
+
/** Reasoning effort for agent jobs. Every level runs spark-2. */
|
|
1115
|
+
type AgentEffort = "low" | "medium" | "high";
|
|
1116
|
+
type AgentTraceAgentRole = "orchestrator" | "subagent" | "browser" | "system";
|
|
1117
|
+
interface AgentTraceAgentIdentity {
|
|
1118
|
+
id: string;
|
|
1119
|
+
role: AgentTraceAgentRole;
|
|
1120
|
+
name: string;
|
|
1121
|
+
parentId?: string;
|
|
1122
|
+
}
|
|
1123
|
+
interface AgentTraceError {
|
|
1124
|
+
code: "cancelled" | "credit_limit_reached" | "parent_finished" | "refused" | "internal";
|
|
1125
|
+
source: "agent" | "tool" | "billing" | "system";
|
|
1126
|
+
retryable: boolean;
|
|
1127
|
+
message: string;
|
|
1128
|
+
}
|
|
1129
|
+
interface AgentTraceArtifactChange {
|
|
1130
|
+
kind: "json" | "markdown" | "html" | "screenshot" | "text";
|
|
1131
|
+
artifactId: string;
|
|
1132
|
+
path?: string;
|
|
1133
|
+
/** Fetch the full content via getAgentSnapshot(jobId, snapshotId). */
|
|
1134
|
+
snapshotId: string;
|
|
1135
|
+
change: "init" | "partial" | "append" | "modify" | "update";
|
|
1136
|
+
changedFields?: string[];
|
|
1137
|
+
itemCount?: number;
|
|
1138
|
+
sourceToolCallId?: string;
|
|
1139
|
+
}
|
|
1140
|
+
interface AgentTraceEventBase {
|
|
1141
|
+
schemaVersion: 1;
|
|
1142
|
+
eventId: string;
|
|
1143
|
+
runId: string;
|
|
1144
|
+
occurredAt: string;
|
|
1145
|
+
producerSequence: number;
|
|
1146
|
+
agent: AgentTraceAgentIdentity;
|
|
1147
|
+
}
|
|
1148
|
+
interface AgentTraceRunStartedEvent extends AgentTraceEventBase {
|
|
1149
|
+
type: "run.started";
|
|
1150
|
+
}
|
|
1151
|
+
interface AgentTraceRunCancelRequestedEvent extends AgentTraceEventBase {
|
|
1152
|
+
type: "run.cancel_requested";
|
|
1153
|
+
reason: "user";
|
|
1154
|
+
}
|
|
1155
|
+
interface AgentTraceRunFinishedEvent extends AgentTraceEventBase {
|
|
1156
|
+
type: "run.finished";
|
|
1157
|
+
outcome: "succeeded" | "failed" | "cancelled" | "refused" | "credit_limit_reached";
|
|
1158
|
+
/** The canonical schema always writes this key (nullable), but older rows may omit it. */
|
|
1159
|
+
error?: AgentTraceError | null;
|
|
1160
|
+
}
|
|
1161
|
+
interface AgentTraceAgentStartedEvent extends AgentTraceEventBase {
|
|
1162
|
+
type: "agent.started";
|
|
1163
|
+
}
|
|
1164
|
+
interface AgentTraceAgentFinishedEvent extends AgentTraceEventBase {
|
|
1165
|
+
type: "agent.finished";
|
|
1166
|
+
outcome: "succeeded" | "failed" | "cancelled" | "refused";
|
|
1167
|
+
durationMs: number;
|
|
1168
|
+
/** The canonical schema always writes this key (nullable), but older rows may omit it. */
|
|
1169
|
+
error?: AgentTraceError | null;
|
|
1170
|
+
}
|
|
1171
|
+
interface AgentTraceBrowserSessionStartedEvent extends AgentTraceEventBase {
|
|
1172
|
+
type: "browser.session.started";
|
|
1173
|
+
sessionId: string;
|
|
1174
|
+
}
|
|
1175
|
+
interface AgentTraceBrowserSessionFinishedEvent extends AgentTraceEventBase {
|
|
1176
|
+
type: "browser.session.finished";
|
|
1177
|
+
sessionId: string;
|
|
1178
|
+
durationMs: number;
|
|
1179
|
+
}
|
|
1180
|
+
interface AgentTraceProgressReportedEvent extends AgentTraceEventBase {
|
|
1181
|
+
type: "progress.reported";
|
|
1182
|
+
phase: "planning" | "working" | "finalizing";
|
|
1183
|
+
message: string;
|
|
1184
|
+
}
|
|
1185
|
+
interface AgentTraceReasoningSummaryEvent extends AgentTraceEventBase {
|
|
1186
|
+
type: "reasoning.summary";
|
|
1187
|
+
text: string;
|
|
1188
|
+
}
|
|
1189
|
+
interface AgentTraceToolCallStartedEvent extends AgentTraceEventBase {
|
|
1190
|
+
type: "tool_call.started";
|
|
1191
|
+
toolCallId: string;
|
|
1192
|
+
toolName: string;
|
|
1193
|
+
parameters: unknown;
|
|
1194
|
+
}
|
|
1195
|
+
interface AgentTraceToolCallFinishedEvent extends AgentTraceEventBase {
|
|
1196
|
+
type: "tool_call.finished";
|
|
1197
|
+
toolCallId: string;
|
|
1198
|
+
toolName: string;
|
|
1199
|
+
result: unknown;
|
|
1200
|
+
}
|
|
1201
|
+
interface AgentTraceArtifactUpdatedEvent extends AgentTraceEventBase {
|
|
1202
|
+
type: "artifact.updated";
|
|
1203
|
+
artifact: AgentTraceArtifactChange;
|
|
1204
|
+
}
|
|
1205
|
+
interface AgentTraceErrorOccurredEvent extends AgentTraceEventBase {
|
|
1206
|
+
type: "error.occurred";
|
|
1207
|
+
error: AgentTraceError;
|
|
1208
|
+
}
|
|
1209
|
+
/**
|
|
1210
|
+
* One event in an agent job's trace. Mirrors the canonical event schema of
|
|
1211
|
+
* the agent service (schemaVersion 1); `usage.recorded` events are withheld
|
|
1212
|
+
* server-side and `agent.started` carries no model name.
|
|
1213
|
+
*/
|
|
1214
|
+
type AgentTraceEvent = AgentTraceRunStartedEvent | AgentTraceRunCancelRequestedEvent | AgentTraceRunFinishedEvent | AgentTraceAgentStartedEvent | AgentTraceAgentFinishedEvent | AgentTraceBrowserSessionStartedEvent | AgentTraceBrowserSessionFinishedEvent | AgentTraceProgressReportedEvent | AgentTraceReasoningSummaryEvent | AgentTraceToolCallStartedEvent | AgentTraceToolCallFinishedEvent | AgentTraceArtifactUpdatedEvent | AgentTraceErrorOccurredEvent;
|
|
1215
|
+
interface AgentTraceActiveBrowserSession {
|
|
1216
|
+
id: string;
|
|
1217
|
+
liveViewUrl: string;
|
|
1218
|
+
viewport: {
|
|
1219
|
+
width: number;
|
|
1220
|
+
height: number;
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
interface AgentTraceResponse {
|
|
1224
|
+
success: boolean;
|
|
1225
|
+
id?: string;
|
|
1226
|
+
events?: AgentTraceEvent[];
|
|
1227
|
+
creditsUsed?: number;
|
|
1228
|
+
/** Present only when the trace was requested with liveView: true. */
|
|
1229
|
+
activeBrowserSessions?: AgentTraceActiveBrowserSession[];
|
|
1230
|
+
error?: string;
|
|
1231
|
+
}
|
|
1232
|
+
interface AgentSnapshotResponse {
|
|
1233
|
+
success: boolean;
|
|
1234
|
+
id?: string;
|
|
1235
|
+
snapshotId?: string;
|
|
1236
|
+
/** Full artifact content as a JSON/string blob. */
|
|
1237
|
+
snapshot?: string;
|
|
1238
|
+
error?: string;
|
|
1239
|
+
}
|
|
1100
1240
|
interface AgentOptions$1 {
|
|
1101
1241
|
model: "FIRE-1" | "v3-beta";
|
|
1102
1242
|
}
|
|
@@ -1416,6 +1556,9 @@ declare class HttpClient {
|
|
|
1416
1556
|
constructor(options: HttpClientOptions);
|
|
1417
1557
|
getApiUrl(): string;
|
|
1418
1558
|
getApiKey(): string;
|
|
1559
|
+
/** The client-wide default request timeout, for callers that need to
|
|
1560
|
+
* extend a specific request beyond it (e.g. scrape auto-resume). */
|
|
1561
|
+
getTimeoutMs(): number;
|
|
1419
1562
|
private request;
|
|
1420
1563
|
private sleep;
|
|
1421
1564
|
post<T = any>(endpoint: string, body: Record<string, unknown>, options?: RequestOptions): Promise<AxiosResponse<T, any, {}>>;
|
|
@@ -1426,6 +1569,27 @@ declare class HttpClient {
|
|
|
1426
1569
|
prepareHeaders(idempotencyKey?: string): Record<string, string>;
|
|
1427
1570
|
}
|
|
1428
1571
|
|
|
1572
|
+
/**
|
|
1573
|
+
* Options for a direct scrape call. `autoResume` lives here — NOT on the
|
|
1574
|
+
* shared ScrapeOptions — because that type is reused verbatim inside
|
|
1575
|
+
* batch/crawl/search/extract payloads, where an SDK-only key would leak
|
|
1576
|
+
* onto the wire and fail strict endpoints.
|
|
1577
|
+
*/
|
|
1578
|
+
type ScrapeCallOptions = ScrapeOptions & {
|
|
1579
|
+
/**
|
|
1580
|
+
* SDK-only (never sent to the API). Large documents (big PDFs) that
|
|
1581
|
+
* outlive the request window keep processing server-side; the API's
|
|
1582
|
+
* timeout error then carries `details.state === "processing_continues"`
|
|
1583
|
+
* and a Retry-After. When this is not `false`, the SDK sleeps that
|
|
1584
|
+
* long and re-issues the same request — the retry attaches to the
|
|
1585
|
+
* in-flight job and returns the finished result, so a large document
|
|
1586
|
+
* behaves like one slow successful call. Bounded (at most 5 resumes /
|
|
1587
|
+
* 20 minutes total wait); set `false` to surface the timeout error
|
|
1588
|
+
* immediately instead.
|
|
1589
|
+
*/
|
|
1590
|
+
autoResume?: boolean;
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1429
1593
|
declare function prepareExtractPayload(args: {
|
|
1430
1594
|
urls?: string[];
|
|
1431
1595
|
prompt?: string;
|
|
@@ -1457,6 +1621,7 @@ declare function prepareAgentPayload(args: {
|
|
|
1457
1621
|
maxCredits?: number;
|
|
1458
1622
|
strictConstrainToURLs?: boolean;
|
|
1459
1623
|
model?: "spark-1-pro" | "spark-1-mini" | "spark-2";
|
|
1624
|
+
effort?: AgentEffort;
|
|
1460
1625
|
webhook?: string | AgentWebhookConfig;
|
|
1461
1626
|
threatProtection?: ThreatProtectionOptions;
|
|
1462
1627
|
auditMetadata?: AuditMetadata$1;
|
|
@@ -1628,7 +1793,7 @@ declare class FirecrawlClient {
|
|
|
1628
1793
|
scrape<Opts extends ScrapeOptions>(url: string, options: Opts): Promise<Omit<Document, "json"> & {
|
|
1629
1794
|
json?: InferredJsonFromOptions<Opts>;
|
|
1630
1795
|
}>;
|
|
1631
|
-
scrape(url: string, options?:
|
|
1796
|
+
scrape(url: string, options?: ScrapeCallOptions): Promise<Document>;
|
|
1632
1797
|
/**
|
|
1633
1798
|
* Interact with the browser session associated with a scrape job.
|
|
1634
1799
|
* @param jobId Scrape job id.
|
|
@@ -1876,6 +2041,20 @@ declare class FirecrawlClient {
|
|
|
1876
2041
|
* @returns True if cancelled.
|
|
1877
2042
|
*/
|
|
1878
2043
|
cancelAgent(jobId: string): Promise<boolean>;
|
|
2044
|
+
/**
|
|
2045
|
+
* Get the execution trace of an agent job (spark-2 runs only).
|
|
2046
|
+
* @param jobId Agent job id.
|
|
2047
|
+
* @param options.liveView Also include currently active browser sessions with live view URLs.
|
|
2048
|
+
*/
|
|
2049
|
+
getAgentTrace(jobId: string, options?: {
|
|
2050
|
+
liveView?: boolean;
|
|
2051
|
+
}): Promise<AgentTraceResponse>;
|
|
2052
|
+
/**
|
|
2053
|
+
* Get the full content of an artifact snapshot referenced by a trace event.
|
|
2054
|
+
* @param jobId Agent job id.
|
|
2055
|
+
* @param snapshotId Snapshot id from an artifact.updated trace event.
|
|
2056
|
+
*/
|
|
2057
|
+
getAgentSnapshot(jobId: string, snapshotId: string): Promise<AgentSnapshotResponse>;
|
|
1879
2058
|
/**
|
|
1880
2059
|
* Create a new browser session.
|
|
1881
2060
|
* @param args Session options (ttl, activityTtl, streamWebView, profile).
|
|
@@ -2116,6 +2295,7 @@ interface ScrapeParams<LLMSchema extends zt.ZodSchema = any, ActionsSchema exten
|
|
|
2116
2295
|
prompt?: string;
|
|
2117
2296
|
schema?: LLMSchema;
|
|
2118
2297
|
systemPrompt?: string;
|
|
2298
|
+
checkPromptInjection?: boolean;
|
|
2119
2299
|
};
|
|
2120
2300
|
changeTrackingOptions?: {
|
|
2121
2301
|
prompt?: string;
|
|
@@ -2877,4 +3057,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
2877
3057
|
get v1(): FirecrawlApp;
|
|
2878
3058
|
}
|
|
2879
3059
|
|
|
2880
|
-
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 };
|
|
3060
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentEffort, 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-
|
|
3
|
+
} from "./chunk-LFX7WDGT.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
|
-
|
|
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
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
"
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
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;
|
|
@@ -1238,6 +1278,27 @@ async function agent(http, args) {
|
|
|
1238
1278
|
if (!jobId) return started;
|
|
1239
1279
|
return waitAgent(http, jobId, args.pollInterval ?? 2, args.timeout);
|
|
1240
1280
|
}
|
|
1281
|
+
async function getAgentTrace(http, jobId, options) {
|
|
1282
|
+
try {
|
|
1283
|
+
const query = options?.liveView ? "?liveView=true" : "";
|
|
1284
|
+
const res = await http.get(`/v2/agent/${jobId}/trace${query}`);
|
|
1285
|
+
if (res.status !== 200) throwForBadResponse(res, "agent trace");
|
|
1286
|
+
return res.data;
|
|
1287
|
+
} catch (err) {
|
|
1288
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "agent trace");
|
|
1289
|
+
throw err;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
async function getAgentSnapshot(http, jobId, snapshotId) {
|
|
1293
|
+
try {
|
|
1294
|
+
const res = await http.get(`/v2/agent/${jobId}/snapshots/${snapshotId}`);
|
|
1295
|
+
if (res.status !== 200) throwForBadResponse(res, "agent snapshot");
|
|
1296
|
+
return res.data;
|
|
1297
|
+
} catch (err) {
|
|
1298
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "agent snapshot");
|
|
1299
|
+
throw err;
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1241
1302
|
async function cancelAgent(http, jobId) {
|
|
1242
1303
|
try {
|
|
1243
1304
|
const res = await http.delete(`/v2/agent/${jobId}`);
|
|
@@ -2239,6 +2300,22 @@ var FirecrawlClient = class {
|
|
|
2239
2300
|
async cancelAgent(jobId) {
|
|
2240
2301
|
return cancelAgent(this.http, jobId);
|
|
2241
2302
|
}
|
|
2303
|
+
/**
|
|
2304
|
+
* Get the execution trace of an agent job (spark-2 runs only).
|
|
2305
|
+
* @param jobId Agent job id.
|
|
2306
|
+
* @param options.liveView Also include currently active browser sessions with live view URLs.
|
|
2307
|
+
*/
|
|
2308
|
+
async getAgentTrace(jobId, options) {
|
|
2309
|
+
return getAgentTrace(this.http, jobId, options);
|
|
2310
|
+
}
|
|
2311
|
+
/**
|
|
2312
|
+
* Get the full content of an artifact snapshot referenced by a trace event.
|
|
2313
|
+
* @param jobId Agent job id.
|
|
2314
|
+
* @param snapshotId Snapshot id from an artifact.updated trace event.
|
|
2315
|
+
*/
|
|
2316
|
+
async getAgentSnapshot(jobId, snapshotId) {
|
|
2317
|
+
return getAgentSnapshot(this.http, jobId, snapshotId);
|
|
2318
|
+
}
|
|
2242
2319
|
// Browser
|
|
2243
2320
|
/**
|
|
2244
2321
|
* Create a new browser session.
|
|
@@ -2381,7 +2458,7 @@ var FirecrawlApp = class {
|
|
|
2381
2458
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
2382
2459
|
return process.env.npm_package_version;
|
|
2383
2460
|
}
|
|
2384
|
-
const packageJson = await import("./package-
|
|
2461
|
+
const packageJson = await import("./package-SHMK2LJE.js");
|
|
2385
2462
|
return packageJson.default.version;
|
|
2386
2463
|
} catch (error) {
|
|
2387
2464
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mendable/firecrawl-js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.37.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
|
+
});
|