firecrawl 4.25.2 → 4.25.4
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/audit-ci.jsonc +1 -4
- package/dist/{chunk-XCQC2QCZ.js → chunk-BVQPX6RA.js} +9 -4
- package/dist/index.cjs +158 -4
- package/dist/index.d.cts +190 -31
- package/dist/index.d.ts +190 -31
- package/dist/index.js +150 -2
- package/dist/{package-D6422PQU.js → package-4T5PXLTT.js} +1 -1
- package/package.json +2 -2
- package/pnpm-workspace.yaml +3 -0
- package/src/__tests__/e2e/v1/index.test.ts +15 -15
- package/src/__tests__/unit/v2/research.test.ts +168 -0
- package/src/index.ts +2 -0
- package/src/v2/client.ts +12 -0
- package/src/v2/methods/research.ts +195 -0
- package/src/v2/types.ts +159 -42
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { AxiosResponse, AxiosRequestHeaders } from 'axios';
|
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
import { TypedEventTarget } from 'typescript-event-target';
|
|
6
6
|
|
|
7
|
-
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary" | "changeTracking" | "json" | "attributes" | "branding" | "audio" | "video"
|
|
7
|
+
type FormatString = "markdown" | "html" | "rawHtml" | "links" | "images" | "screenshot" | "summary" | "changeTracking" | "json" | "attributes" | "branding" | "audio" | "video";
|
|
8
8
|
interface Viewport {
|
|
9
9
|
width: number;
|
|
10
10
|
height: number;
|
|
@@ -165,34 +165,6 @@ interface RedactPIIOptions {
|
|
|
165
165
|
*/
|
|
166
166
|
replaceStyle?: "tag" | "mask" | "remove";
|
|
167
167
|
}
|
|
168
|
-
type PIISource = "model" | "heuristics" | "unknown";
|
|
169
|
-
interface PIISpan {
|
|
170
|
-
start: number;
|
|
171
|
-
end: number;
|
|
172
|
-
/** Unified entity bucket. Omitted when `kind` doesn't map onto one. */
|
|
173
|
-
entity?: RedactPIIEntity;
|
|
174
|
-
/** Granular recognizer label from fire-privacy. */
|
|
175
|
-
kind: string;
|
|
176
|
-
source: PIISource;
|
|
177
|
-
/** Confidence in [0, 1] when supplied. */
|
|
178
|
-
score?: number;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* - ok: redaction completed; redactedMarkdown is the result.
|
|
182
|
-
* - skipped: redaction was not performed; see `reason`.
|
|
183
|
-
* - failed: redaction was attempted but did not produce a usable result.
|
|
184
|
-
*/
|
|
185
|
-
type PIIStatus = "ok" | "skipped" | "failed";
|
|
186
|
-
/** Always set when status !== "ok". */
|
|
187
|
-
type PIIReason = "empty_input" | "too_large" | "upstream_skipped" | "service_unavailable" | "timeout" | "error";
|
|
188
|
-
interface PIIBlock {
|
|
189
|
-
status: PIIStatus;
|
|
190
|
-
reason?: PIIReason;
|
|
191
|
-
redactedMarkdown: string | null;
|
|
192
|
-
spans: PIISpan[];
|
|
193
|
-
/** Span count per entity bucket. Only non-zero entries are present. */
|
|
194
|
-
counts: Partial<Record<RedactPIIEntity, number>>;
|
|
195
|
-
}
|
|
196
168
|
type ParseFileData = Blob | File | Buffer | Uint8Array | ArrayBuffer | string;
|
|
197
169
|
interface ParseFile {
|
|
198
170
|
data: ParseFileData;
|
|
@@ -410,7 +382,6 @@ interface Document {
|
|
|
410
382
|
warning?: string;
|
|
411
383
|
changeTracking?: Record<string, unknown>;
|
|
412
384
|
branding?: BrandingProfile;
|
|
413
|
-
pii?: PIIBlock;
|
|
414
385
|
}
|
|
415
386
|
interface PaginationConfig {
|
|
416
387
|
/** When true (default), automatically follow `next` links and aggregate all documents. */
|
|
@@ -918,6 +889,146 @@ interface BrowserListResponse {
|
|
|
918
889
|
sessions?: BrowserSession[];
|
|
919
890
|
error?: string;
|
|
920
891
|
}
|
|
892
|
+
/**
|
|
893
|
+
* Source identifiers grouped by namespace. Currently only `arxiv` is
|
|
894
|
+
* populated; each value is an array of ids in that namespace.
|
|
895
|
+
*/
|
|
896
|
+
type IdMap = Record<string, string[]>;
|
|
897
|
+
/** Per-candidate ranking signals (present on similarity results). */
|
|
898
|
+
interface PaperSignals {
|
|
899
|
+
/** Raw structural strength (co-citation / coupling counts, or seed overlap). */
|
|
900
|
+
structural: number;
|
|
901
|
+
/** Semantic score from the intent abstract search (0 if absent). */
|
|
902
|
+
semantic: number;
|
|
903
|
+
/** Citation-graph PageRank of the candidate. */
|
|
904
|
+
pagerank: number;
|
|
905
|
+
/** Number of distinct seeds connected to this candidate. */
|
|
906
|
+
seed_overlap: number;
|
|
907
|
+
}
|
|
908
|
+
/** A ranked paper. `paper_id` is canonical; arXiv lives in `ids`. */
|
|
909
|
+
interface PaperResult {
|
|
910
|
+
/** Canonical paper id — the Milvus INT64 primary key as a decimal string. */
|
|
911
|
+
paper_id: string;
|
|
912
|
+
ids?: IdMap;
|
|
913
|
+
title: string;
|
|
914
|
+
abstract: string;
|
|
915
|
+
/** Final ranking score (post-rerank when enabled). Not normalized. */
|
|
916
|
+
score: number;
|
|
917
|
+
/** Present on similarity results. */
|
|
918
|
+
signals?: PaperSignals;
|
|
919
|
+
}
|
|
920
|
+
interface PaperMetadata {
|
|
921
|
+
paper_id: string;
|
|
922
|
+
ids?: IdMap;
|
|
923
|
+
title: string;
|
|
924
|
+
abstract: string;
|
|
925
|
+
/** Comma-joined author names. Omitted if unknown. */
|
|
926
|
+
authors?: string;
|
|
927
|
+
/** arXiv categories. Omitted if unknown. */
|
|
928
|
+
categories?: string[];
|
|
929
|
+
/** Original creation date string (format varies). Omitted if unknown. */
|
|
930
|
+
created_date?: string;
|
|
931
|
+
/** Last-updated date string. Omitted if unknown. */
|
|
932
|
+
update_date?: string;
|
|
933
|
+
}
|
|
934
|
+
interface Passage {
|
|
935
|
+
/** In-body passage text (may be markdown, including tables). */
|
|
936
|
+
text: string;
|
|
937
|
+
/** Dense similarity score for the passage. */
|
|
938
|
+
score: number;
|
|
939
|
+
}
|
|
940
|
+
interface SearchPapersResponse {
|
|
941
|
+
results: PaperResult[];
|
|
942
|
+
}
|
|
943
|
+
interface PaperMetadataResponse {
|
|
944
|
+
paper: PaperMetadata;
|
|
945
|
+
}
|
|
946
|
+
interface ReadPaperResponse {
|
|
947
|
+
paper: PaperMetadata;
|
|
948
|
+
/** Resolved canonical paper id (empty string if not found via id-key). */
|
|
949
|
+
paper_id: string;
|
|
950
|
+
/** Echo of the read query. */
|
|
951
|
+
query: string;
|
|
952
|
+
/** Top matching in-body passages. */
|
|
953
|
+
passages: Passage[];
|
|
954
|
+
}
|
|
955
|
+
interface SimilarPapersResponse {
|
|
956
|
+
/** Ranked related papers; each carries `signals`. */
|
|
957
|
+
results: PaperResult[];
|
|
958
|
+
/** Number of resolved candidates considered before truncation to `k`. */
|
|
959
|
+
pool_size: number;
|
|
960
|
+
/** True if more resolved candidates existed than were returned. */
|
|
961
|
+
truncated: boolean;
|
|
962
|
+
/** Human-readable note when no results are produced. */
|
|
963
|
+
note?: string | null;
|
|
964
|
+
}
|
|
965
|
+
/** Component scores; each field is present only when that signal contributed. */
|
|
966
|
+
interface GitHubScoreBreakdown {
|
|
967
|
+
rrf?: number;
|
|
968
|
+
semantic?: number;
|
|
969
|
+
lexical?: number;
|
|
970
|
+
fusion?: number;
|
|
971
|
+
}
|
|
972
|
+
interface GitHubSearchItem {
|
|
973
|
+
resultType: "github_history" | "repo_readme";
|
|
974
|
+
/** `owner/name`. */
|
|
975
|
+
repo: string;
|
|
976
|
+
url: string;
|
|
977
|
+
/** History page type (e.g. `issue`, `pull`). Omitted for readmes. */
|
|
978
|
+
pageType?: string;
|
|
979
|
+
/** Issue/PR number. Omitted for readmes. */
|
|
980
|
+
number?: number;
|
|
981
|
+
/** Number of matched segments/chunks. Omitted when not applicable. */
|
|
982
|
+
segmentCount?: number;
|
|
983
|
+
/** Readme URL (readme results). Omitted otherwise. */
|
|
984
|
+
readmeUrl?: string;
|
|
985
|
+
/** Short matched excerpt. */
|
|
986
|
+
snippet: string;
|
|
987
|
+
/** Full matched content in markdown. Omitted unless available. */
|
|
988
|
+
contentMd?: string;
|
|
989
|
+
scores: GitHubScoreBreakdown;
|
|
990
|
+
}
|
|
991
|
+
interface GitHubSearchResponse {
|
|
992
|
+
results: GitHubSearchItem[];
|
|
993
|
+
}
|
|
994
|
+
/** Options for `research.searchPapers`. */
|
|
995
|
+
interface SearchPapersOptions {
|
|
996
|
+
/** Number of results to return (1–500, default 40). */
|
|
997
|
+
k?: number;
|
|
998
|
+
/** Author substring filter(s); ALL must match (case-insensitive). */
|
|
999
|
+
authors?: string[];
|
|
1000
|
+
/** arXiv category filter(s) (e.g. `cs.LG`); ALL must match. */
|
|
1001
|
+
categories?: string[];
|
|
1002
|
+
/** Inclusive lower bound on created/updated date (ISO `YYYY-MM-DD`). */
|
|
1003
|
+
from?: string;
|
|
1004
|
+
/** Inclusive upper bound on created/updated date (lexicographic). */
|
|
1005
|
+
to?: string;
|
|
1006
|
+
}
|
|
1007
|
+
/** Options for `research.getPaper`. */
|
|
1008
|
+
interface GetPaperOptions {
|
|
1009
|
+
/** When present, switches to read mode and returns in-body passages. */
|
|
1010
|
+
query?: string;
|
|
1011
|
+
/** Passage count (read mode only; 1–50, default 4). Requires `query`. */
|
|
1012
|
+
k?: number;
|
|
1013
|
+
}
|
|
1014
|
+
/** Options for `research.similarPapers`. */
|
|
1015
|
+
interface SimilarPapersOptions {
|
|
1016
|
+
/** Natural-language intent used to semantically rerank candidates. Required. */
|
|
1017
|
+
intent: string;
|
|
1018
|
+
/** Traversal mode (default `similar`). */
|
|
1019
|
+
mode?: "similar" | "citers" | "references";
|
|
1020
|
+
/** Number of related papers to return (1–500, default 40). */
|
|
1021
|
+
k?: number;
|
|
1022
|
+
/** Apply an additional ZeroEntropy rerank over the fused candidates. */
|
|
1023
|
+
rerank?: boolean;
|
|
1024
|
+
/** Additional seed paper reference(s), same format as `id`. */
|
|
1025
|
+
anchor?: string[];
|
|
1026
|
+
}
|
|
1027
|
+
/** Options for `research.searchGithub`. */
|
|
1028
|
+
interface SearchGithubOptions {
|
|
1029
|
+
/** Number of results to return (1–100, default 20). */
|
|
1030
|
+
k?: number;
|
|
1031
|
+
}
|
|
921
1032
|
|
|
922
1033
|
interface HttpClientOptions {
|
|
923
1034
|
apiKey: string;
|
|
@@ -1002,6 +1113,48 @@ declare function listBrowsers(http: HttpClient, args?: {
|
|
|
1002
1113
|
status?: "active" | "destroyed";
|
|
1003
1114
|
}): Promise<BrowserListResponse>;
|
|
1004
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Client for the v2 research endpoints (arXiv papers + GitHub history/readmes).
|
|
1118
|
+
* Accessed via `firecrawl.research`.
|
|
1119
|
+
*/
|
|
1120
|
+
declare class ResearchClient {
|
|
1121
|
+
private readonly http;
|
|
1122
|
+
constructor(http: HttpClient);
|
|
1123
|
+
/**
|
|
1124
|
+
* Search papers by abstract relevance.
|
|
1125
|
+
* @param query Natural-language search query.
|
|
1126
|
+
* @param options Optional filters (k, authors, categories, from, to).
|
|
1127
|
+
*/
|
|
1128
|
+
searchPapers(query: string, options?: SearchPapersOptions): Promise<SearchPapersResponse>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Get paper metadata (detail mode), or read in-body passages (when `query` is
|
|
1131
|
+
* supplied). `k` is only valid together with `query`.
|
|
1132
|
+
* @param id Paper reference: a canonical `paper_id`, an `arxiv:<id>` key, or a
|
|
1133
|
+
* bare arXiv id / URL.
|
|
1134
|
+
* @param options Optional `query` (switches to read mode) and `k`.
|
|
1135
|
+
*/
|
|
1136
|
+
getPaper(id: string, options?: {
|
|
1137
|
+
query?: undefined;
|
|
1138
|
+
k?: undefined;
|
|
1139
|
+
}): Promise<PaperMetadataResponse>;
|
|
1140
|
+
getPaper(id: string, options: {
|
|
1141
|
+
query: string;
|
|
1142
|
+
k?: number;
|
|
1143
|
+
}): Promise<ReadPaperResponse>;
|
|
1144
|
+
/**
|
|
1145
|
+
* Find related papers via the citation graph.
|
|
1146
|
+
* @param id Primary seed paper reference.
|
|
1147
|
+
* @param options Required `intent` plus optional mode, k, rerank, anchor.
|
|
1148
|
+
*/
|
|
1149
|
+
similarPapers(id: string, options: SimilarPapersOptions): Promise<SimilarPapersResponse>;
|
|
1150
|
+
/**
|
|
1151
|
+
* Search GitHub issue/PR history and repository readmes.
|
|
1152
|
+
* @param query Search query.
|
|
1153
|
+
* @param options Optional `k`.
|
|
1154
|
+
*/
|
|
1155
|
+
searchGithub(query: string, options?: SearchGithubOptions): Promise<GitHubSearchResponse>;
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1005
1158
|
type JobKind = "crawl" | "batch";
|
|
1006
1159
|
interface WatcherOptions {
|
|
1007
1160
|
kind?: JobKind;
|
|
@@ -1057,6 +1210,7 @@ type FirecrawlClientInput = FirecrawlClientOptions | string;
|
|
|
1057
1210
|
*/
|
|
1058
1211
|
declare class FirecrawlClient {
|
|
1059
1212
|
private readonly http;
|
|
1213
|
+
private _research?;
|
|
1060
1214
|
private isCloudService;
|
|
1061
1215
|
/**
|
|
1062
1216
|
* Create a v2 client.
|
|
@@ -1117,6 +1271,11 @@ declare class FirecrawlClient {
|
|
|
1117
1271
|
* @returns Structured search results.
|
|
1118
1272
|
*/
|
|
1119
1273
|
search(query: string, req?: Omit<SearchRequest, "query">): Promise<SearchData>;
|
|
1274
|
+
/**
|
|
1275
|
+
* Access the v2 research endpoints (arXiv papers + GitHub history/readmes).
|
|
1276
|
+
* Example: `firecrawl.research.searchPapers("diffusion models")`.
|
|
1277
|
+
*/
|
|
1278
|
+
get research(): ResearchClient;
|
|
1120
1279
|
/**
|
|
1121
1280
|
* Map a site to discover URLs (sitemap-aware).
|
|
1122
1281
|
* @param url Root URL to map.
|
|
@@ -2280,4 +2439,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
2280
2439
|
get v1(): FirecrawlApp;
|
|
2281
2440
|
}
|
|
2282
2441
|
|
|
2283
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, 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 Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientInput, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type GetMonitorCheckOptions, type HighlightsFormat, JobTimeoutError, type JsonFormat, type ListMonitorChecksOptions, type ListMonitorsOptions, type LocationConfig$1 as LocationConfig, type MapData, type MapOptions, type Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorEmailRecipientSubscription, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, type
|
|
2442
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AgentOptions$1 as AgentOptions, type AgentResponse, type AgentStatusResponse, type AgentWebhookConfig, type AgentWebhookEvent, type AttributesFormat, 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 Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, 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 Monitor, type MonitorCheck, type MonitorCheckDetail, type MonitorCheckPage, type MonitorCrawlTarget, type MonitorEmailNotification, type MonitorEmailRecipientSubscription, type MonitorJsonFieldDiff, type MonitorNotification, type MonitorPageDiff, type MonitorPageJudgment, type MonitorPageSnapshot, type MonitorSchedule, type MonitorScrapeTarget, type MonitorSummary, type MonitorTarget, type MonitorWebhookConfig, type PDFAction, 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 PressAction, 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 SearchGithubOptions, type SearchPapersOptions, type SearchPapersResponse, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type SimilarPapersOptions, type SimilarPapersResponse, 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-BVQPX6RA.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -1301,6 +1301,143 @@ async function getTokenUsageHistorical(http, byApiKey) {
|
|
|
1301
1301
|
}
|
|
1302
1302
|
}
|
|
1303
1303
|
|
|
1304
|
+
// src/v2/methods/research.ts
|
|
1305
|
+
var BASE = "/v2/research";
|
|
1306
|
+
function appendParam(params, key, value) {
|
|
1307
|
+
if (value == null) return;
|
|
1308
|
+
if (Array.isArray(value)) {
|
|
1309
|
+
for (const v of value) {
|
|
1310
|
+
if (v != null && String(v).length > 0) params.append(key, String(v));
|
|
1311
|
+
}
|
|
1312
|
+
} else {
|
|
1313
|
+
params.append(key, String(value));
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
function withQuery(path, params) {
|
|
1317
|
+
const qs = params.toString();
|
|
1318
|
+
return qs ? `${path}?${qs}` : path;
|
|
1319
|
+
}
|
|
1320
|
+
function normalizeResearchError(err, action) {
|
|
1321
|
+
if (err?.isAxiosError) {
|
|
1322
|
+
const status = err.response?.status;
|
|
1323
|
+
const body = err.response?.data;
|
|
1324
|
+
if (body && (body.detail || body.title)) {
|
|
1325
|
+
const message = body.detail || body.title;
|
|
1326
|
+
throw new SdkError(message, status, body.type, body);
|
|
1327
|
+
}
|
|
1328
|
+
throw new SdkError(
|
|
1329
|
+
err.message || `Request failed while trying to ${action}`,
|
|
1330
|
+
status,
|
|
1331
|
+
err.code,
|
|
1332
|
+
body
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
throw err;
|
|
1336
|
+
}
|
|
1337
|
+
var ResearchClient = class {
|
|
1338
|
+
constructor(http) {
|
|
1339
|
+
this.http = http;
|
|
1340
|
+
}
|
|
1341
|
+
http;
|
|
1342
|
+
/**
|
|
1343
|
+
* Search papers by abstract relevance.
|
|
1344
|
+
* @param query Natural-language search query.
|
|
1345
|
+
* @param options Optional filters (k, authors, categories, from, to).
|
|
1346
|
+
*/
|
|
1347
|
+
async searchPapers(query, options = {}) {
|
|
1348
|
+
if (!query || !query.trim()) throw new Error("query cannot be empty");
|
|
1349
|
+
if (options.k != null && options.k <= 0)
|
|
1350
|
+
throw new Error("k must be positive");
|
|
1351
|
+
const params = new URLSearchParams();
|
|
1352
|
+
appendParam(params, "query", query);
|
|
1353
|
+
appendParam(params, "k", options.k);
|
|
1354
|
+
appendParam(params, "authors", options.authors);
|
|
1355
|
+
appendParam(params, "categories", options.categories);
|
|
1356
|
+
appendParam(params, "from", options.from);
|
|
1357
|
+
appendParam(params, "to", options.to);
|
|
1358
|
+
try {
|
|
1359
|
+
const res = await this.http.get(
|
|
1360
|
+
withQuery(`${BASE}/papers`, params)
|
|
1361
|
+
);
|
|
1362
|
+
if (res.status !== 200) throwForBadResponse(res, "search papers");
|
|
1363
|
+
return res.data;
|
|
1364
|
+
} catch (err) {
|
|
1365
|
+
return normalizeResearchError(err, "search papers");
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
async getPaper(id, options = {}) {
|
|
1369
|
+
if (!id || !id.trim()) throw new Error("id cannot be empty");
|
|
1370
|
+
if (options.k != null && options.query == null)
|
|
1371
|
+
throw new Error("k is only valid together with query");
|
|
1372
|
+
if (options.k != null && options.k <= 0)
|
|
1373
|
+
throw new Error("k must be positive");
|
|
1374
|
+
const params = new URLSearchParams();
|
|
1375
|
+
appendParam(params, "query", options.query);
|
|
1376
|
+
appendParam(params, "k", options.k);
|
|
1377
|
+
try {
|
|
1378
|
+
const res = await this.http.get(
|
|
1379
|
+
withQuery(`${BASE}/papers/${encodeURIComponent(id)}`, params)
|
|
1380
|
+
);
|
|
1381
|
+
if (res.status !== 200) throwForBadResponse(res, "get paper");
|
|
1382
|
+
return res.data;
|
|
1383
|
+
} catch (err) {
|
|
1384
|
+
return normalizeResearchError(err, "get paper");
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
/**
|
|
1388
|
+
* Find related papers via the citation graph.
|
|
1389
|
+
* @param id Primary seed paper reference.
|
|
1390
|
+
* @param options Required `intent` plus optional mode, k, rerank, anchor.
|
|
1391
|
+
*/
|
|
1392
|
+
async similarPapers(id, options) {
|
|
1393
|
+
if (!id || !id.trim()) throw new Error("id cannot be empty");
|
|
1394
|
+
if (!options?.intent || !options.intent.trim())
|
|
1395
|
+
throw new Error("intent cannot be empty");
|
|
1396
|
+
if (options.k != null && options.k <= 0)
|
|
1397
|
+
throw new Error("k must be positive");
|
|
1398
|
+
const params = new URLSearchParams();
|
|
1399
|
+
appendParam(params, "intent", options.intent);
|
|
1400
|
+
appendParam(params, "mode", options.mode);
|
|
1401
|
+
appendParam(params, "k", options.k);
|
|
1402
|
+
if (options.rerank != null) appendParam(params, "rerank", options.rerank);
|
|
1403
|
+
appendParam(params, "anchor", options.anchor);
|
|
1404
|
+
try {
|
|
1405
|
+
const res = await this.http.get(
|
|
1406
|
+
withQuery(
|
|
1407
|
+
`${BASE}/papers/${encodeURIComponent(id)}/similar`,
|
|
1408
|
+
params
|
|
1409
|
+
)
|
|
1410
|
+
);
|
|
1411
|
+
if (res.status !== 200) throwForBadResponse(res, "find similar papers");
|
|
1412
|
+
return res.data;
|
|
1413
|
+
} catch (err) {
|
|
1414
|
+
return normalizeResearchError(err, "find similar papers");
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Search GitHub issue/PR history and repository readmes.
|
|
1419
|
+
* @param query Search query.
|
|
1420
|
+
* @param options Optional `k`.
|
|
1421
|
+
*/
|
|
1422
|
+
async searchGithub(query, options = {}) {
|
|
1423
|
+
if (!query || !query.trim()) throw new Error("query cannot be empty");
|
|
1424
|
+
if (options.k != null && options.k <= 0)
|
|
1425
|
+
throw new Error("k must be positive");
|
|
1426
|
+
const params = new URLSearchParams();
|
|
1427
|
+
appendParam(params, "query", query);
|
|
1428
|
+
appendParam(params, "k", options.k);
|
|
1429
|
+
try {
|
|
1430
|
+
const res = await this.http.get(
|
|
1431
|
+
withQuery(`${BASE}/github`, params)
|
|
1432
|
+
);
|
|
1433
|
+
if (res.status !== 200) throwForBadResponse(res, "search github");
|
|
1434
|
+
return res.data;
|
|
1435
|
+
} catch (err) {
|
|
1436
|
+
return normalizeResearchError(err, "search github");
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1304
1441
|
// src/v2/methods/monitor.ts
|
|
1305
1442
|
function queryString(params) {
|
|
1306
1443
|
if (!params) return "";
|
|
@@ -1666,6 +1803,7 @@ var Watcher = class extends EventEmitter {
|
|
|
1666
1803
|
import "zod";
|
|
1667
1804
|
var FirecrawlClient = class {
|
|
1668
1805
|
http;
|
|
1806
|
+
_research;
|
|
1669
1807
|
isCloudService(url) {
|
|
1670
1808
|
return url.includes("api.firecrawl.dev");
|
|
1671
1809
|
}
|
|
@@ -1738,6 +1876,15 @@ var FirecrawlClient = class {
|
|
|
1738
1876
|
async search(query, req = {}) {
|
|
1739
1877
|
return search(this.http, { query, ...req });
|
|
1740
1878
|
}
|
|
1879
|
+
// Research
|
|
1880
|
+
/**
|
|
1881
|
+
* Access the v2 research endpoints (arXiv papers + GitHub history/readmes).
|
|
1882
|
+
* Example: `firecrawl.research.searchPapers("diffusion models")`.
|
|
1883
|
+
*/
|
|
1884
|
+
get research() {
|
|
1885
|
+
if (!this._research) this._research = new ResearchClient(this.http);
|
|
1886
|
+
return this._research;
|
|
1887
|
+
}
|
|
1741
1888
|
// Map
|
|
1742
1889
|
/**
|
|
1743
1890
|
* Map a site to discover URLs (sitemap-aware).
|
|
@@ -2097,7 +2244,7 @@ var FirecrawlApp = class {
|
|
|
2097
2244
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
2098
2245
|
return process.env.npm_package_version;
|
|
2099
2246
|
}
|
|
2100
|
-
const packageJson = await import("./package-
|
|
2247
|
+
const packageJson = await import("./package-4T5PXLTT.js");
|
|
2101
2248
|
return packageJson.default.version;
|
|
2102
2249
|
} catch (error) {
|
|
2103
2250
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -3494,6 +3641,7 @@ export {
|
|
|
3494
3641
|
FirecrawlApp as FirecrawlAppV1,
|
|
3495
3642
|
FirecrawlClient,
|
|
3496
3643
|
JobTimeoutError,
|
|
3644
|
+
ResearchClient,
|
|
3497
3645
|
SdkError,
|
|
3498
3646
|
Watcher,
|
|
3499
3647
|
index_default as default
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firecrawl",
|
|
3
|
-
"version": "4.25.
|
|
3
|
+
"version": "4.25.4",
|
|
4
4
|
"description": "JavaScript SDK for Firecrawl API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"ts-jest": "^29.4.5",
|
|
41
41
|
"tsup": "^8.5.0",
|
|
42
42
|
"typescript": "^5.4.5",
|
|
43
|
-
"uuid": "^
|
|
43
|
+
"uuid": "^14.0.0"
|
|
44
44
|
},
|
|
45
45
|
"keywords": [
|
|
46
46
|
"firecrawl",
|
|
@@ -26,10 +26,10 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
26
26
|
test.concurrent('should throw error for invalid API key on scrape', async () => {
|
|
27
27
|
if (API_URL.includes('api.firecrawl.dev')) {
|
|
28
28
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
29
|
-
await expect(invalidApp.scrapeUrl('https://
|
|
29
|
+
await expect(invalidApp.scrapeUrl('https://firecrawl-test-site.vercel.app')).rejects.toThrow("Unexpected error occurred while trying to scrape URL. Status code: 401");
|
|
30
30
|
} else {
|
|
31
31
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
32
|
-
await expect(invalidApp.scrapeUrl('https://
|
|
32
|
+
await expect(invalidApp.scrapeUrl('https://firecrawl-test-site.vercel.app')).resolves.not.toThrow();
|
|
33
33
|
}
|
|
34
34
|
});
|
|
35
35
|
|
|
@@ -42,7 +42,7 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
42
42
|
test.concurrent('should return successful response for valid scrape', async () => {
|
|
43
43
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
44
44
|
|
|
45
|
-
const response = await app.scrapeUrl('https://
|
|
45
|
+
const response = await app.scrapeUrl('https://firecrawl-test-site.vercel.app');
|
|
46
46
|
if (!response.success) {
|
|
47
47
|
throw new Error(response.error);
|
|
48
48
|
}
|
|
@@ -51,7 +51,7 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
51
51
|
test.concurrent('should return successful response with valid API key and options', async () => {
|
|
52
52
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
53
53
|
const response = await app.scrapeUrl(
|
|
54
|
-
'https://
|
|
54
|
+
'https://firecrawl-test-site.vercel.app', {
|
|
55
55
|
formats: ['markdown', 'html', 'rawHtml', 'screenshot', 'links'],
|
|
56
56
|
headers: { "x-key": "test" },
|
|
57
57
|
includeTags: ['h1'],
|
|
@@ -69,7 +69,7 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
69
69
|
test.concurrent('should return successful response with valid API key and screenshot fullPage', async () => {
|
|
70
70
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
71
71
|
const response = await app.scrapeUrl(
|
|
72
|
-
'https://
|
|
72
|
+
'https://firecrawl-test-site.vercel.app', {
|
|
73
73
|
formats: ['screenshot@fullPage'],
|
|
74
74
|
});
|
|
75
75
|
if (!response.success) {
|
|
@@ -132,16 +132,16 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
132
132
|
test.concurrent('should throw error for invalid API key on crawl', async () => {
|
|
133
133
|
if (API_URL.includes('api.firecrawl.dev')) {
|
|
134
134
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
135
|
-
await expect(invalidApp.crawlUrl('https://
|
|
135
|
+
await expect(invalidApp.crawlUrl('https://firecrawl-test-site.vercel.app')).rejects.toThrow("Request failed with status code 401");
|
|
136
136
|
} else {
|
|
137
137
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
138
|
-
await expect(invalidApp.crawlUrl('https://
|
|
138
|
+
await expect(invalidApp.crawlUrl('https://firecrawl-test-site.vercel.app')).resolves.not.toThrow();
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
|
|
142
142
|
test.concurrent('should return successful response for crawl and wait for completion', async () => {
|
|
143
143
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
144
|
-
const response = await app.crawlUrl('https://
|
|
144
|
+
const response = await app.crawlUrl('https://firecrawl-test-site.vercel.app', {}, 30) as CrawlStatusResponse;
|
|
145
145
|
expect(response).not.toHaveProperty("next"); // wait until done
|
|
146
146
|
expect(response.data.length).toBeGreaterThan(0);
|
|
147
147
|
if (response.data[0]) {
|
|
@@ -151,7 +151,7 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
151
151
|
|
|
152
152
|
test.concurrent('should return successful response for crawl with options and wait for completion', async () => {
|
|
153
153
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
154
|
-
const response = await app.crawlUrl('https://
|
|
154
|
+
const response = await app.crawlUrl('https://firecrawl-test-site.vercel.app', {
|
|
155
155
|
excludePaths: ['blog/*'],
|
|
156
156
|
includePaths: ['/'],
|
|
157
157
|
maxDepth: 2,
|
|
@@ -183,11 +183,11 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
183
183
|
test.concurrent('should handle idempotency key for crawl', async () => {
|
|
184
184
|
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL });
|
|
185
185
|
const uniqueIdempotencyKey = uuidv4();
|
|
186
|
-
const response = await app.asyncCrawlUrl('https://
|
|
186
|
+
const response = await app.asyncCrawlUrl('https://firecrawl-test-site.vercel.app', {}, uniqueIdempotencyKey) as CrawlResponse;
|
|
187
187
|
expect(response).not.toBeNull();
|
|
188
188
|
expect(response.id).toBeDefined();
|
|
189
189
|
|
|
190
|
-
await expect(app.crawlUrl('https://
|
|
190
|
+
await expect(app.crawlUrl('https://firecrawl-test-site.vercel.app', {}, 2, uniqueIdempotencyKey)).rejects.toThrow("Request failed with status code 409");
|
|
191
191
|
});
|
|
192
192
|
|
|
193
193
|
test.concurrent('should check crawl status', async () => {
|
|
@@ -236,10 +236,10 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
236
236
|
test.concurrent('should throw error for invalid API key on map', async () => {
|
|
237
237
|
if (API_URL.includes('api.firecrawl.dev')) {
|
|
238
238
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
239
|
-
await expect(invalidApp.mapUrl('https://
|
|
239
|
+
await expect(invalidApp.mapUrl('https://firecrawl-test-site.vercel.app')).rejects.toThrow("Request failed with status code 401");
|
|
240
240
|
} else {
|
|
241
241
|
const invalidApp = new FirecrawlApp({ apiKey: "invalid_api_key", apiUrl: API_URL });
|
|
242
|
-
await expect(invalidApp.mapUrl('https://
|
|
242
|
+
await expect(invalidApp.mapUrl('https://firecrawl-test-site.vercel.app')).resolves.not.toThrow();
|
|
243
243
|
}
|
|
244
244
|
});
|
|
245
245
|
|
|
@@ -250,12 +250,12 @@ describe('FirecrawlApp E2E Tests', () => {
|
|
|
250
250
|
});
|
|
251
251
|
|
|
252
252
|
test.concurrent('should return successful response for valid map', async () => {
|
|
253
|
-
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL }); const response = await app.mapUrl('https://
|
|
253
|
+
const app = new FirecrawlApp({ apiKey: TEST_API_KEY, apiUrl: API_URL }); const response = await app.mapUrl('https://firecrawl-test-site.vercel.app') as MapResponse;
|
|
254
254
|
expect(response).not.toBeNull();
|
|
255
255
|
|
|
256
256
|
expect(response.links?.length).toBeGreaterThan(0);
|
|
257
257
|
expect(response.links?.[0]).toContain("https://");
|
|
258
|
-
const filteredLinks = response.links?.filter((link: string) => link.includes("
|
|
258
|
+
const filteredLinks = response.links?.filter((link: string) => link.includes("firecrawl-test-site.vercel.app"));
|
|
259
259
|
expect(filteredLinks?.length).toBeGreaterThan(0);
|
|
260
260
|
}, 30000); // 30 seconds timeout
|
|
261
261
|
|