@parcha/agentrun-web 0.1.0-beta.70 → 0.1.0-beta.73
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/providers/direct.js
CHANGED
|
@@ -51,7 +51,7 @@ async function readTyped(url, guard, options) {
|
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
catch (error) {
|
|
54
|
-
// Never a URL's user name or password:
|
|
54
|
+
// Never a URL's user name or password: an error may quote a URL whole (undici's refusal of one does).
|
|
55
55
|
const message = withoutUserinfo(error?.message ?? String(error));
|
|
56
56
|
if (isRefused(error))
|
|
57
57
|
return failed("refused", "GUARD", { refused: message });
|
|
@@ -3,8 +3,18 @@ import { type Read } from "../page.js";
|
|
|
3
3
|
import { type Failed, type Hit, type SearchAsk, type Searched } from "../search.js";
|
|
4
4
|
import { type Keyed, type KeyedFailed } from "./keyed.js";
|
|
5
5
|
export declare const FIRECRAWL_API_URL = "https://api.firecrawl.dev";
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/** This client's bound on one request: past it, it hangs up. A scrape tells Firecrawl to stop well before it
|
|
7
|
+
* (FIRECRAWL_SCRAPE_TIMEOUT_MS), so Firecrawl answers first. */
|
|
8
|
+
export declare const FIRECRAWL_KEYED_MS = 120000;
|
|
9
|
+
/** The time a scrape gives Firecrawl (its body's `timeout`): below this client's bound by the time its answer, up to
|
|
10
|
+
* KEYED_MAX_BYTES, takes to come back. A scrape sent with no timeout has no limit at Firecrawl: a PDF is parsed to its
|
|
11
|
+
* last page asked, and billed, after this client has hung up. With one, a PDF Firecrawl reckons it cannot parse in
|
|
12
|
+
* time (150 ms a page, out of the time left once it has the file) is refused at once, and a scrape that runs out
|
|
13
|
+
* answers 408; Firecrawl bills neither (fees.ts firecrawlChargeOf charges them 0 credits). */
|
|
14
|
+
export declare const FIRECRAWL_SCRAPE_TIMEOUT_MS = 100000;
|
|
15
|
+
/** The most PDF pages a scrape asks unless pdfMaxPages says otherwise: what Firecrawl reads within its timeout once it
|
|
16
|
+
* has the file, 200. Past it a PDF comes back cut, and its text says which pages it holds (firecrawlPageOf). */
|
|
17
|
+
export declare const FIRECRAWL_PDF_PAGES_IN_TIME: number;
|
|
8
18
|
/** How Firecrawl searches and reads, each setting optional (FIRECRAWL_DEFAULTS):
|
|
9
19
|
* - `onlyMainContent`: a scrape leaves out a page's headers, navigation and footers, default true;
|
|
10
20
|
* - `maxAgeMs`: the oldest cached page a scrape may answer from, 0 a fresh scrape; unset, Firecrawl's own (2 days);
|
|
@@ -13,8 +23,9 @@ export declare const FIRECRAWL_KEYED_MS = 60000;
|
|
|
13
23
|
* - `country`: the country a search is made from, ISO 3166-1 alpha-2; unset, Firecrawl's own (US);
|
|
14
24
|
* - `highlights`: each result's description is its query-relevant highlight; unset, Firecrawl's own (true);
|
|
15
25
|
* - `pdfMaxPages`: the most pages of a PDF a web_fetch parses, and is held for (1 credit a page), 1 to 10,000; unset,
|
|
16
|
-
*
|
|
17
|
-
*
|
|
26
|
+
* the pages Firecrawl reads within its timeout, FIRECRAWL_PDF_PAGES_IN_TIME (200). Set past that, a long PDF may be
|
|
27
|
+
* one Firecrawl refuses or runs out of time on, at no charge. A run whose cap has less than the hold left holds what
|
|
28
|
+
* it has left and asks only the pages that buys (firecrawlFitOf). */
|
|
18
29
|
export type FirecrawlSettings = {
|
|
19
30
|
onlyMainContent?: boolean;
|
|
20
31
|
maxAgeMs?: number;
|
|
@@ -60,7 +71,8 @@ export declare function firecrawlSearchBody(query: string, n: number, settings?:
|
|
|
60
71
|
* up to FIRECRAWL_QUERIES_MAX of its queries, one paid request each, all at once, merged (firecrawlMerged), and the
|
|
61
72
|
* limit Firecrawl answered for the run's key, if any. */
|
|
62
73
|
export declare function firecrawlSearched(args: Record<string, unknown>, client: Keyed | null, settings?: FirecrawlSettings, signal?: AbortSignal): Promise<Searched>;
|
|
63
|
-
/** The /v2/scrape request for `url` under `settings`: markdown alone, on the basic proxy,
|
|
74
|
+
/** The /v2/scrape request for `url` under `settings`: markdown alone, on the basic proxy, within Firecrawl's timeout, a
|
|
75
|
+
* PDF to pdfMaxPages, else to the pages that timeout reads. */
|
|
64
76
|
export declare function firecrawlScrapeBody(url: string, settings?: FirecrawlSettings): Record<string, unknown>;
|
|
65
77
|
/** A page Firecrawl scraped for `url` (`page`, its scrape's `{markdown, metadata}`, keyed or keyless alike) as a Read:
|
|
66
78
|
* the url it ended at (metadata's url, else its sourceURL, else `url`), its title (a list's first string), its status.
|
|
@@ -8,8 +8,22 @@ import { defineProvider, settingsOf } from "../provider.js";
|
|
|
8
8
|
import { failed, failure, retryAfterMs, searchArgs, snippetOf, waitOf } from "../search.js";
|
|
9
9
|
import { domains, keyedCall, keyedClient, matching, settingsProblems, wholeIn, yesNo } from "./keyed.js";
|
|
10
10
|
export const FIRECRAWL_API_URL = "https://api.firecrawl.dev";
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/** This client's bound on one request: past it, it hangs up. A scrape tells Firecrawl to stop well before it
|
|
12
|
+
* (FIRECRAWL_SCRAPE_TIMEOUT_MS), so Firecrawl answers first. */
|
|
13
|
+
export const FIRECRAWL_KEYED_MS = 120_000;
|
|
14
|
+
/** The time a scrape gives Firecrawl (its body's `timeout`): below this client's bound by the time its answer, up to
|
|
15
|
+
* KEYED_MAX_BYTES, takes to come back. A scrape sent with no timeout has no limit at Firecrawl: a PDF is parsed to its
|
|
16
|
+
* last page asked, and billed, after this client has hung up. With one, a PDF Firecrawl reckons it cannot parse in
|
|
17
|
+
* time (150 ms a page, out of the time left once it has the file) is refused at once, and a scrape that runs out
|
|
18
|
+
* answers 408; Firecrawl bills neither (fees.ts firecrawlChargeOf charges them 0 credits). */
|
|
19
|
+
export const FIRECRAWL_SCRAPE_TIMEOUT_MS = 100_000;
|
|
20
|
+
/** How long Firecrawl may take to fetch a PDF before it parses a page: an 841-page federal PDF took 46 s. */
|
|
21
|
+
const PDF_FETCH_ALLOWANCE_MS = 50_000;
|
|
22
|
+
/** How long Firecrawl takes to parse a PDF page: that PDF's pages took 0.22 s each. */
|
|
23
|
+
const PDF_PAGE_MS = 250;
|
|
24
|
+
/** The most PDF pages a scrape asks unless pdfMaxPages says otherwise: what Firecrawl reads within its timeout once it
|
|
25
|
+
* has the file, 200. Past it a PDF comes back cut, and its text says which pages it holds (firecrawlPageOf). */
|
|
26
|
+
export const FIRECRAWL_PDF_PAGES_IN_TIME = Math.floor((FIRECRAWL_SCRAPE_TIMEOUT_MS - PDF_FETCH_ALLOWANCE_MS) / PDF_PAGE_MS);
|
|
13
27
|
export const FIRECRAWL_DEFAULTS = Object.freeze({ onlyMainContent: true });
|
|
14
28
|
const FIRECRAWL_CHECKS = {
|
|
15
29
|
onlyMainContent: yesNo,
|
|
@@ -35,9 +49,9 @@ export const FIRECRAWL_QUERIES_MAX = 3;
|
|
|
35
49
|
/** The scrape keyless Firecrawl's search asks of each result, as Firecrawl's guidance for agents asks: its page as
|
|
36
50
|
* markdown, its main content alone unless `settings` say otherwise. A keyed search asks none (firecrawlSearchBody). */
|
|
37
51
|
export const firecrawlScrapeOptions = (settings = {}) => ({ formats: ["markdown"], onlyMainContent: settings.onlyMainContent ?? FIRECRAWL_DEFAULTS.onlyMainContent });
|
|
38
|
-
/** How a keyed web_fetch has Firecrawl read a page: on its basic proxy (the one priced here),
|
|
39
|
-
*
|
|
40
|
-
const keyedRead = (pages) => ({ proxy: "basic",
|
|
52
|
+
/** How a keyed web_fetch has Firecrawl read a page: on its basic proxy (the one priced here), within its timeout
|
|
53
|
+
* (FIRECRAWL_SCRAPE_TIMEOUT_MS), a PDF to `pages` at most (pdfMaxPages), else to what that timeout reads. */
|
|
54
|
+
const keyedRead = (pages) => ({ proxy: "basic", timeout: FIRECRAWL_SCRAPE_TIMEOUT_MS, parsers: [{ type: "pdf", maxPages: pages ?? FIRECRAWL_PDF_PAGES_IN_TIME }] });
|
|
41
55
|
/** Firecrawl's search rows, an answer's `data` or its `data.web`, as hits: each row whose url parses, its snippet its
|
|
42
56
|
* page's markdown, else its description; undefined where the answer holds no rows this server reads. */
|
|
43
57
|
export function firecrawlHits(data) {
|
|
@@ -117,7 +131,8 @@ export async function firecrawlSearched(args, client, settings = {}, signal) {
|
|
|
117
131
|
}));
|
|
118
132
|
return firecrawlMerged("firecrawl", ask, each);
|
|
119
133
|
}
|
|
120
|
-
/** The /v2/scrape request for `url` under `settings`: markdown alone, on the basic proxy,
|
|
134
|
+
/** The /v2/scrape request for `url` under `settings`: markdown alone, on the basic proxy, within Firecrawl's timeout, a
|
|
135
|
+
* PDF to pdfMaxPages, else to the pages that timeout reads. */
|
|
121
136
|
export function firecrawlScrapeBody(url, settings = {}) {
|
|
122
137
|
return { url, formats: ["markdown"], onlyMainContent: settings.onlyMainContent ?? FIRECRAWL_DEFAULTS.onlyMainContent, ...(settings.maxAgeMs === undefined ? {} : { maxAge: settings.maxAgeMs }), ...keyedRead(settings.pdfMaxPages) };
|
|
123
138
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-web",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.73",
|
|
4
4
|
"description": "Web search and web fetch for agents: providers asked in an order given as data, a breaker per provider, a per-run page cache read in parts, and a direct fetch through an injected public-host guard.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"undici": "^8.14.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@parcha/pi-browser": "0.1.0-beta.
|
|
49
|
+
"@parcha/pi-browser": "0.1.0-beta.73"
|
|
50
50
|
},
|
|
51
51
|
"repository": {
|
|
52
52
|
"type": "git",
|