firecrawl 4.47.0 → 4.48.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/README.md +10 -0
- package/dist/{chunk-H75FJ6LW.js → chunk-GD463K4D.js} +1 -1
- package/dist/index.cjs +112 -26
- package/dist/index.d.cts +17 -2
- package/dist/index.d.ts +17 -2
- package/dist/index.js +113 -27
- package/dist/{package-NZI5TDUV.js → package-WONXBIJS.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/unit/v2/agent-hints.test.ts +1 -0
- package/src/__tests__/unit/v2/origin.test.ts +132 -0
- package/src/__tests__/unit/v2/research.test.ts +1 -0
- package/src/index.ts +1 -0
- package/src/utils/callerOrigin.ts +74 -0
- package/src/v1/index.ts +28 -13
- package/src/v2/client.ts +10 -1
- package/src/v2/methods/parse.ts +1 -6
- package/src/v2/methods/research.ts +20 -7
- package/src/v2/utils/httpClient.ts +10 -3
package/src/v1/index.ts
CHANGED
|
@@ -4,15 +4,18 @@ import { zodSchemaToJsonSchema } from "../utils/zodSchemaToJson";
|
|
|
4
4
|
import { TypedEventTarget } from "typescript-event-target";
|
|
5
5
|
import type { RequiresAction } from "../v2/types";
|
|
6
6
|
import { pinToApiOrigin } from "../utils/apiOrigin";
|
|
7
|
+
import { detectCallerPackage } from "../utils/callerOrigin";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Configuration interface for FirecrawlApp.
|
|
10
11
|
* @param apiKey - Optional API key for authentication.
|
|
11
12
|
* @param apiUrl - Optional base URL of the API; defaults to 'https://api.firecrawl.dev'.
|
|
13
|
+
* @param origin - Optional attribution tag stamped into request bodies.
|
|
12
14
|
*/
|
|
13
15
|
export interface FirecrawlAppConfig {
|
|
14
16
|
apiKey?: string | null;
|
|
15
17
|
apiUrl?: string | null;
|
|
18
|
+
origin?: string;
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
/**
|
|
@@ -666,6 +669,8 @@ export default class FirecrawlApp {
|
|
|
666
669
|
public apiKey: string;
|
|
667
670
|
public apiUrl: string;
|
|
668
671
|
public version: string = "1.25.1";
|
|
672
|
+
private readonly clientOrigin?: string;
|
|
673
|
+
private readonly callerPackage: string | null;
|
|
669
674
|
|
|
670
675
|
private isCloudService(url: string): boolean {
|
|
671
676
|
return url.includes('api.firecrawl.dev');
|
|
@@ -698,7 +703,7 @@ export default class FirecrawlApp {
|
|
|
698
703
|
* Initializes a new instance of the FirecrawlApp class.
|
|
699
704
|
* @param config - Configuration options for the FirecrawlApp instance.
|
|
700
705
|
*/
|
|
701
|
-
constructor({ apiKey = null, apiUrl = null }: FirecrawlAppConfig) {
|
|
706
|
+
constructor({ apiKey = null, apiUrl = null, origin }: FirecrawlAppConfig) {
|
|
702
707
|
const baseUrl = apiUrl || "https://api.firecrawl.dev";
|
|
703
708
|
|
|
704
709
|
if (this.isCloudService(baseUrl) && typeof apiKey !== "string") {
|
|
@@ -707,9 +712,19 @@ export default class FirecrawlApp {
|
|
|
707
712
|
|
|
708
713
|
this.apiKey = apiKey || '';
|
|
709
714
|
this.apiUrl = baseUrl;
|
|
715
|
+
this.clientOrigin = origin || undefined;
|
|
716
|
+
this.callerPackage = this.clientOrigin ? null : detectCallerPackage();
|
|
710
717
|
this.init();
|
|
711
718
|
}
|
|
712
719
|
|
|
720
|
+
private resolveOrigin(params?: any): string {
|
|
721
|
+
if (typeof params?.origin === "string" && params.origin) return params.origin;
|
|
722
|
+
if (this.clientOrigin) return this.clientOrigin;
|
|
723
|
+
return this.callerPackage
|
|
724
|
+
? `js-sdk.${this.callerPackage}@${this.version}`
|
|
725
|
+
: `js-sdk@${this.version}`;
|
|
726
|
+
}
|
|
727
|
+
|
|
713
728
|
/**
|
|
714
729
|
* Scrapes a URL using the Firecrawl API.
|
|
715
730
|
* @param url - The URL to scrape.
|
|
@@ -724,7 +739,7 @@ export default class FirecrawlApp {
|
|
|
724
739
|
"Content-Type": "application/json",
|
|
725
740
|
Authorization: `Bearer ${this.apiKey}`,
|
|
726
741
|
} as AxiosRequestHeaders;
|
|
727
|
-
let jsonData: any = { url, ...params, origin:
|
|
742
|
+
let jsonData: any = { url, ...params, origin: this.resolveOrigin(params) };
|
|
728
743
|
if (jsonData?.extract?.schema) {
|
|
729
744
|
jsonData = {
|
|
730
745
|
...jsonData,
|
|
@@ -791,7 +806,7 @@ export default class FirecrawlApp {
|
|
|
791
806
|
lang: params?.lang ?? "en",
|
|
792
807
|
country: params?.country ?? "us",
|
|
793
808
|
location: params?.location,
|
|
794
|
-
origin:
|
|
809
|
+
origin: this.resolveOrigin(params),
|
|
795
810
|
timeout: params?.timeout ?? 60000,
|
|
796
811
|
scrapeOptions: params?.scrapeOptions ?? { formats: [] },
|
|
797
812
|
};
|
|
@@ -855,7 +870,7 @@ export default class FirecrawlApp {
|
|
|
855
870
|
idempotencyKey?: string
|
|
856
871
|
): Promise<CrawlStatusResponse | ErrorResponse> {
|
|
857
872
|
const headers = this.prepareHeaders(idempotencyKey);
|
|
858
|
-
let jsonData: any = { url, ...params, origin:
|
|
873
|
+
let jsonData: any = { url, ...params, origin: this.resolveOrigin(params) };
|
|
859
874
|
try {
|
|
860
875
|
const response: AxiosResponse = await this.postRequest(
|
|
861
876
|
this.apiUrl + `/v1/crawl`,
|
|
@@ -884,7 +899,7 @@ export default class FirecrawlApp {
|
|
|
884
899
|
idempotencyKey?: string
|
|
885
900
|
): Promise<CrawlResponse | ErrorResponse> {
|
|
886
901
|
const headers = this.prepareHeaders(idempotencyKey);
|
|
887
|
-
let jsonData: any = { url, ...params, origin:
|
|
902
|
+
let jsonData: any = { url, ...params, origin: this.resolveOrigin(params) };
|
|
888
903
|
try {
|
|
889
904
|
const response: AxiosResponse = await this.postRequest(
|
|
890
905
|
this.apiUrl + `/v1/crawl`,
|
|
@@ -1060,7 +1075,7 @@ export default class FirecrawlApp {
|
|
|
1060
1075
|
*/
|
|
1061
1076
|
async mapUrl(url: string, params?: MapParams): Promise<MapResponse | ErrorResponse> {
|
|
1062
1077
|
const headers = this.prepareHeaders();
|
|
1063
|
-
let jsonData: any = { url, ...params, origin:
|
|
1078
|
+
let jsonData: any = { url, ...params, origin: this.resolveOrigin(params) };
|
|
1064
1079
|
|
|
1065
1080
|
try {
|
|
1066
1081
|
const response: AxiosResponse = await this.postRequest(
|
|
@@ -1099,7 +1114,7 @@ export default class FirecrawlApp {
|
|
|
1099
1114
|
maxConcurrency?: number,
|
|
1100
1115
|
): Promise<BatchScrapeStatusResponse | ErrorResponse> {
|
|
1101
1116
|
const headers = this.prepareHeaders(idempotencyKey);
|
|
1102
|
-
let jsonData: any = { urls, webhook, ignoreInvalidURLs, maxConcurrency, ...params, origin:
|
|
1117
|
+
let jsonData: any = { urls, webhook, ignoreInvalidURLs, maxConcurrency, ...params, origin: this.resolveOrigin(params) };
|
|
1103
1118
|
if (jsonData?.extract?.schema) {
|
|
1104
1119
|
jsonData = {
|
|
1105
1120
|
...jsonData,
|
|
@@ -1148,7 +1163,7 @@ export default class FirecrawlApp {
|
|
|
1148
1163
|
ignoreInvalidURLs?: boolean,
|
|
1149
1164
|
): Promise<BatchScrapeResponse | ErrorResponse> {
|
|
1150
1165
|
const headers = this.prepareHeaders(idempotencyKey);
|
|
1151
|
-
let jsonData: any = { urls, webhook, ignoreInvalidURLs, ...params, origin:
|
|
1166
|
+
let jsonData: any = { urls, webhook, ignoreInvalidURLs, ...params, origin: this.resolveOrigin(params) };
|
|
1152
1167
|
try {
|
|
1153
1168
|
const response: AxiosResponse = await this.postRequest(
|
|
1154
1169
|
this.apiUrl + `/v1/batch/scrape`,
|
|
@@ -1312,7 +1327,7 @@ export default class FirecrawlApp {
|
|
|
1312
1327
|
try {
|
|
1313
1328
|
const response: AxiosResponse = await this.postRequest(
|
|
1314
1329
|
this.apiUrl + `/v1/extract`,
|
|
1315
|
-
{ ...jsonData, schema: jsonSchema, origin:
|
|
1330
|
+
{ ...jsonData, schema: jsonSchema, origin: this.resolveOrigin(params) },
|
|
1316
1331
|
headers
|
|
1317
1332
|
);
|
|
1318
1333
|
|
|
@@ -1372,7 +1387,7 @@ export default class FirecrawlApp {
|
|
|
1372
1387
|
try {
|
|
1373
1388
|
const response: AxiosResponse = await this.postRequest(
|
|
1374
1389
|
this.apiUrl + `/v1/extract`,
|
|
1375
|
-
{ ...jsonData, schema: jsonSchema, origin:
|
|
1390
|
+
{ ...jsonData, schema: jsonSchema, origin: this.resolveOrigin(params) },
|
|
1376
1391
|
headers
|
|
1377
1392
|
);
|
|
1378
1393
|
|
|
@@ -1740,7 +1755,7 @@ export default class FirecrawlApp {
|
|
|
1740
1755
|
*/
|
|
1741
1756
|
async asyncDeepResearch(query: string, params: DeepResearchParams<zt.ZodSchema>): Promise<DeepResearchResponse | ErrorResponse> {
|
|
1742
1757
|
const headers = this.prepareHeaders();
|
|
1743
|
-
let jsonData: any = { query, ...params, origin:
|
|
1758
|
+
let jsonData: any = { query, ...params, origin: this.resolveOrigin(params) };
|
|
1744
1759
|
|
|
1745
1760
|
if (jsonData?.jsonOptions?.schema) {
|
|
1746
1761
|
jsonData = {
|
|
@@ -1888,7 +1903,7 @@ export default class FirecrawlApp {
|
|
|
1888
1903
|
async __asyncDeepResearch(topic: string, params: DeepResearchParams): Promise<DeepResearchResponse | ErrorResponse> {
|
|
1889
1904
|
const headers = this.prepareHeaders();
|
|
1890
1905
|
try {
|
|
1891
|
-
let jsonData: any = { topic, ...params, origin:
|
|
1906
|
+
let jsonData: any = { topic, ...params, origin: this.resolveOrigin(params) };
|
|
1892
1907
|
const response: AxiosResponse = await this.postRequest(
|
|
1893
1908
|
`${this.apiUrl}/v1/deep-research`,
|
|
1894
1909
|
jsonData,
|
|
@@ -2003,7 +2018,7 @@ export default class FirecrawlApp {
|
|
|
2003
2018
|
*/
|
|
2004
2019
|
async asyncGenerateLLMsText(url: string, params?: GenerateLLMsTextParams): Promise<GenerateLLMsTextResponse | ErrorResponse> {
|
|
2005
2020
|
const headers = this.prepareHeaders();
|
|
2006
|
-
let jsonData: any = { url, ...params, origin:
|
|
2021
|
+
let jsonData: any = { url, ...params, origin: this.resolveOrigin(params) };
|
|
2007
2022
|
try {
|
|
2008
2023
|
const response: AxiosResponse = await this.postRequest(
|
|
2009
2024
|
`${this.apiUrl}/v1/llmstxt`,
|
package/src/v2/client.ts
CHANGED
|
@@ -101,6 +101,8 @@ import type {
|
|
|
101
101
|
GetMonitorCheckOptions,
|
|
102
102
|
UpdateMonitorRequest,
|
|
103
103
|
} from "./types";
|
|
104
|
+
import { defaultOrigin } from "../utils/callerOrigin";
|
|
105
|
+
import { getVersion } from "./utils/getVersion";
|
|
104
106
|
import { Watcher } from "./watcher";
|
|
105
107
|
import type { WatcherOptions } from "./watcher";
|
|
106
108
|
import * as zt from "zod";
|
|
@@ -130,6 +132,12 @@ export interface FirecrawlClientOptions {
|
|
|
130
132
|
maxRetries?: number;
|
|
131
133
|
/** Exponential backoff factor for retries (optional). */
|
|
132
134
|
backoffFactor?: number;
|
|
135
|
+
/**
|
|
136
|
+
* Attribution tag stamped into request bodies. Defaults to `js-sdk@<version>`,
|
|
137
|
+
* or `js-sdk.<package>@<version>` when an installed package creates the client
|
|
138
|
+
* (set FIRECRAWL_DISABLE_CALLER_ORIGIN=1 to keep the plain default).
|
|
139
|
+
*/
|
|
140
|
+
origin?: string;
|
|
133
141
|
}
|
|
134
142
|
|
|
135
143
|
/** Accepts a plain API key string or a full options object. */
|
|
@@ -140,7 +148,7 @@ export type FirecrawlClientInput = FirecrawlClientOptions | string;
|
|
|
140
148
|
*/
|
|
141
149
|
|
|
142
150
|
export class FirecrawlClient {
|
|
143
|
-
|
|
151
|
+
protected readonly http: HttpClient;
|
|
144
152
|
private _research?: ResearchClient;
|
|
145
153
|
|
|
146
154
|
private isCloudService(url: string): boolean {
|
|
@@ -168,6 +176,7 @@ export class FirecrawlClient {
|
|
|
168
176
|
timeoutMs: opts.timeoutMs,
|
|
169
177
|
maxRetries: opts.maxRetries,
|
|
170
178
|
backoffFactor: opts.backoffFactor,
|
|
179
|
+
origin: opts.origin || defaultOrigin(getVersion()),
|
|
171
180
|
});
|
|
172
181
|
}
|
|
173
182
|
|
package/src/v2/methods/parse.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
throwForBadResponse,
|
|
7
7
|
normalizeAxiosError,
|
|
8
8
|
} from "../utils/errorHandler";
|
|
9
|
-
import { getVersion } from "../utils/getVersion";
|
|
10
9
|
|
|
11
10
|
function toUploadBlob(input: ParseFile["data"], contentType?: string): Blob {
|
|
12
11
|
if (typeof Blob !== "undefined" && input instanceof Blob) {
|
|
@@ -57,13 +56,9 @@ export async function parse(
|
|
|
57
56
|
|
|
58
57
|
if (options) ensureValidParseOptions(options);
|
|
59
58
|
|
|
60
|
-
const version = getVersion();
|
|
61
59
|
const normalizedOptions: ParseOptions = {
|
|
62
60
|
...(options ?? {}),
|
|
63
|
-
origin:
|
|
64
|
-
typeof options?.origin === "string" && options.origin.includes("mcp")
|
|
65
|
-
? options.origin
|
|
66
|
-
: (options?.origin ?? `js-sdk@${version}`),
|
|
61
|
+
origin: options?.origin || http.getOrigin(),
|
|
67
62
|
};
|
|
68
63
|
|
|
69
64
|
const formData = new FormData();
|
|
@@ -12,7 +12,6 @@ import type {
|
|
|
12
12
|
import { SdkError } from "../types";
|
|
13
13
|
import { HttpClient } from "../utils/httpClient";
|
|
14
14
|
import { throwForBadResponse } from "../utils/errorHandler";
|
|
15
|
-
import { getVersion } from "../utils/getVersion";
|
|
16
15
|
|
|
17
16
|
const BASE = "/v2/search/research";
|
|
18
17
|
|
|
@@ -32,10 +31,14 @@ function appendParam(
|
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
function withQuery(
|
|
34
|
+
function withQuery(
|
|
35
|
+
origin: string,
|
|
36
|
+
path: string,
|
|
37
|
+
params: URLSearchParams,
|
|
38
|
+
): string {
|
|
36
39
|
// Research endpoints are GETs, so the POST-body origin injection in
|
|
37
40
|
// HttpClient never applies — attach it as a query param instead.
|
|
38
|
-
params.append("origin",
|
|
41
|
+
params.append("origin", origin);
|
|
39
42
|
const qs = params.toString();
|
|
40
43
|
return qs ? `${path}?${qs}` : path;
|
|
41
44
|
}
|
|
@@ -121,7 +124,7 @@ export class ResearchClient {
|
|
|
121
124
|
appendParam(params, "to", options.to);
|
|
122
125
|
try {
|
|
123
126
|
const res = await this.http.get<SearchPapersResponse>(
|
|
124
|
-
withQuery(`${BASE}/papers`, params),
|
|
127
|
+
withQuery(this.http.getOrigin(), `${BASE}/papers`, params),
|
|
125
128
|
);
|
|
126
129
|
if (res.status !== 200) throwForBadResponse(res, "search papers");
|
|
127
130
|
return res.data;
|
|
@@ -161,7 +164,13 @@ export class ResearchClient {
|
|
|
161
164
|
try {
|
|
162
165
|
const res = await this.http.get<
|
|
163
166
|
PaperMetadataResponse | ReadPaperResponse
|
|
164
|
-
>(
|
|
167
|
+
>(
|
|
168
|
+
withQuery(
|
|
169
|
+
this.http.getOrigin(),
|
|
170
|
+
`${BASE}/papers/${encodeURIComponent(id)}`,
|
|
171
|
+
params,
|
|
172
|
+
),
|
|
173
|
+
);
|
|
165
174
|
if (res.status !== 200) throwForBadResponse(res, "get paper");
|
|
166
175
|
return res.data;
|
|
167
176
|
} catch (err) {
|
|
@@ -191,7 +200,11 @@ export class ResearchClient {
|
|
|
191
200
|
appendParam(params, "anchor", options.anchor);
|
|
192
201
|
try {
|
|
193
202
|
const res = await this.http.get<SimilarPapersResponse>(
|
|
194
|
-
withQuery(
|
|
203
|
+
withQuery(
|
|
204
|
+
this.http.getOrigin(),
|
|
205
|
+
`${BASE}/papers/${encodeURIComponent(id)}/similar`,
|
|
206
|
+
params,
|
|
207
|
+
),
|
|
195
208
|
);
|
|
196
209
|
if (res.status !== 200) throwForBadResponse(res, "find similar papers");
|
|
197
210
|
return res.data;
|
|
@@ -226,7 +239,7 @@ export class ResearchClient {
|
|
|
226
239
|
appendParam(params, "k", options.k);
|
|
227
240
|
try {
|
|
228
241
|
const res = await this.http.get<GitHubSearchResponse>(
|
|
229
|
-
withQuery(`${BASE}/github`, params),
|
|
242
|
+
withQuery(this.http.getOrigin(), `${BASE}/github`, params),
|
|
230
243
|
);
|
|
231
244
|
if (res.status !== 200) throwForBadResponse(res, "search github");
|
|
232
245
|
return res.data;
|
|
@@ -12,6 +12,7 @@ export interface HttpClientOptions {
|
|
|
12
12
|
timeoutMs?: number;
|
|
13
13
|
maxRetries?: number;
|
|
14
14
|
backoffFactor?: number; // seconds factor for 0.5, 1, 2...
|
|
15
|
+
origin?: string;
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export interface RequestOptions {
|
|
@@ -25,12 +26,14 @@ export class HttpClient {
|
|
|
25
26
|
private readonly apiUrl: string;
|
|
26
27
|
private readonly maxRetries: number;
|
|
27
28
|
private readonly backoffFactor: number;
|
|
29
|
+
private readonly origin: string;
|
|
28
30
|
|
|
29
31
|
constructor(options: HttpClientOptions) {
|
|
30
32
|
this.apiKey = options.apiKey;
|
|
31
33
|
this.apiUrl = options.apiUrl.replace(/\/$/, "");
|
|
32
34
|
this.maxRetries = options.maxRetries ?? 3;
|
|
33
35
|
this.backoffFactor = options.backoffFactor ?? 0.5;
|
|
36
|
+
this.origin = options.origin || `js-sdk@${getVersion()}`;
|
|
34
37
|
this.instance = axios.create({
|
|
35
38
|
baseURL: this.apiUrl,
|
|
36
39
|
timeout: options.timeoutMs ?? 300000,
|
|
@@ -52,6 +55,11 @@ export class HttpClient {
|
|
|
52
55
|
return this.apiKey;
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
/** The attribution origin stamped into requests that do not set their own. */
|
|
59
|
+
getOrigin(): string {
|
|
60
|
+
return this.origin;
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
/** The client-wide default request timeout, for callers that need to
|
|
56
64
|
* extend a specific request beyond it (e.g. scrape auto-resume). */
|
|
57
65
|
getTimeoutMs(): number {
|
|
@@ -61,7 +69,6 @@ export class HttpClient {
|
|
|
61
69
|
private async request<T = any>(
|
|
62
70
|
config: AxiosRequestConfig,
|
|
63
71
|
): Promise<AxiosResponse<T>> {
|
|
64
|
-
const version = getVersion();
|
|
65
72
|
config.headers = {
|
|
66
73
|
...(config.headers || {}),
|
|
67
74
|
};
|
|
@@ -89,9 +96,9 @@ export class HttpClient {
|
|
|
89
96
|
cfg.data = {
|
|
90
97
|
...data,
|
|
91
98
|
origin:
|
|
92
|
-
typeof data.origin === "string" && data.origin
|
|
99
|
+
typeof data.origin === "string" && data.origin
|
|
93
100
|
? data.origin
|
|
94
|
-
:
|
|
101
|
+
: this.origin,
|
|
95
102
|
};
|
|
96
103
|
}
|
|
97
104
|
|