@parcha/agentrun-web 0.1.0-beta.73 → 0.1.0-beta.74
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 +2 -1
- package/dist/fees.d.ts +12 -0
- package/dist/fees.js +33 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/providers/parallel.d.ts +1 -1
- package/dist/providers/parallel.js +5 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -188,7 +188,8 @@ The pieces `createWeb` is built from are exported too: `searchInTurn` and `break
|
|
|
188
188
|
providers (`exaSearch`, `firecrawlFetch`, `firecrawlScrape`, `firecrawlSearch`, `parallelExtract`, `parallelSearched`)
|
|
189
189
|
and Parallel's prices and fees (`PARALLEL_EXTRACT_USD`, `PARALLEL_SEARCH_USD`, `PARALLEL_SEARCH_INCLUDED`,
|
|
190
190
|
`PARALLEL_SEARCH_MODE_USD`, `PARALLEL_SEARCH_RESULT_USD`, `parallelExtractFee`, `parallelSearchFee`, `parallelFeeOf`,
|
|
191
|
-
`
|
|
191
|
+
`parallelChargeOf` (an extract charged the URLs Parallel's `usage` says it billed: none for a URL it lists in `errors`,
|
|
192
|
+
the hold when its answer says nothing certain), `PaidRefused` and `unmetered`). The package's entry names each export; nothing else in it is API.
|
|
192
193
|
`@parcha/agentrun-web/text-urls` holds the link finder alone, for code that only finds the URLs in a text (the
|
|
193
194
|
console's timeline compiles it from source).
|
|
194
195
|
|
package/dist/fees.d.ts
CHANGED
|
@@ -32,6 +32,18 @@ export declare const parallelExtractFee: (urls?: number) => Fee;
|
|
|
32
32
|
* default), or its extract's, by the URLs; undefined for an endpoint the web tools do not ask, and for a search whose
|
|
33
33
|
* mode has no price here (one naming none, or one Parallel added since): never $0, never another mode's price. */
|
|
34
34
|
export declare function parallelFeeOf(url: string, body: unknown): Fee | undefined;
|
|
35
|
+
/** The URLs a 2xx extract's `usage` says Parallel billed: the sum of its extract SKUs' counts (`sku_extract_*`, one a
|
|
36
|
+
* URL it read), so an empty `usage` is none. Undefined when it says nothing this server can be sure of: no `usage`
|
|
37
|
+
* array, an item that is not a SKU with a whole count, or a SKU other than an extract's. */
|
|
38
|
+
export declare function parallelExtractBilled(json: unknown): number | undefined;
|
|
39
|
+
/** What an answer of `status` to Parallel's `path` held at `fee` is charged, and the receipt's line for it. A 2xx extract
|
|
40
|
+
* is charged the URLs Parallel's `usage` says it billed (parallelExtractBilled), at its list price: Parallel bills no URL
|
|
41
|
+
* it lists in `errors` (its usage is empty for one), so a page it could not read costs nothing. An extract whose usage
|
|
42
|
+
* says nothing certain, or none at all, is charged its fee, as is every other answer: an unknown is never free. */
|
|
43
|
+
export declare function parallelChargeOf(fee: Fee, path: string, json: unknown, status: number): {
|
|
44
|
+
usd: number;
|
|
45
|
+
basis: string;
|
|
46
|
+
};
|
|
35
47
|
/** Exa's search types priced here (https://exa.ai/pricing, read 2026-11-24): per request, 10 results included. A search
|
|
36
48
|
* in a type with no price here is never sent. */
|
|
37
49
|
export type ExaSearchType = "lite" | "instant" | "auto" | "fast" | "deep-lite" | "deep" | "deep-reasoning";
|
package/dist/fees.js
CHANGED
|
@@ -32,6 +32,39 @@ export function parallelFeeOf(url, body) {
|
|
|
32
32
|
return parallelExtractFee(Array.isArray(asked.urls) ? Math.max(1, asked.urls.length) : 1);
|
|
33
33
|
return undefined;
|
|
34
34
|
}
|
|
35
|
+
/** The URLs a 2xx extract's `usage` says Parallel billed: the sum of its extract SKUs' counts (`sku_extract_*`, one a
|
|
36
|
+
* URL it read), so an empty `usage` is none. Undefined when it says nothing this server can be sure of: no `usage`
|
|
37
|
+
* array, an item that is not a SKU with a whole count, or a SKU other than an extract's. */
|
|
38
|
+
export function parallelExtractBilled(json) {
|
|
39
|
+
const usage = json?.usage;
|
|
40
|
+
if (!Array.isArray(usage))
|
|
41
|
+
return undefined;
|
|
42
|
+
let urls = 0;
|
|
43
|
+
for (const item of usage) {
|
|
44
|
+
const { name, count } = (item ?? {});
|
|
45
|
+
if (typeof name !== "string" || !name.startsWith("sku_extract_") || typeof count !== "number" || !Number.isInteger(count) || count < 0)
|
|
46
|
+
return undefined;
|
|
47
|
+
urls += count;
|
|
48
|
+
}
|
|
49
|
+
return urls;
|
|
50
|
+
}
|
|
51
|
+
/** What an answer of `status` to Parallel's `path` held at `fee` is charged, and the receipt's line for it. A 2xx extract
|
|
52
|
+
* is charged the URLs Parallel's `usage` says it billed (parallelExtractBilled), at its list price: Parallel bills no URL
|
|
53
|
+
* it lists in `errors` (its usage is empty for one), so a page it could not read costs nothing. An extract whose usage
|
|
54
|
+
* says nothing certain, or none at all, is charged its fee, as is every other answer: an unknown is never free. */
|
|
55
|
+
export function parallelChargeOf(fee, path, json, status) {
|
|
56
|
+
const billed = path === "/v1/extract" && status >= 200 && status < 300 ? parallelExtractBilled(json) : undefined;
|
|
57
|
+
if (billed === undefined)
|
|
58
|
+
return { usd: fee.usd, basis: fee.basis };
|
|
59
|
+
const urls = (n) => `${n} URL${n === 1 ? "" : "s"}`;
|
|
60
|
+
const charged = usd(PARALLEL_EXTRACT_USD * billed);
|
|
61
|
+
// Usage that bills what was held (one URL read, as asked) leaves the receipt's line as it was.
|
|
62
|
+
if (charged === fee.usd)
|
|
63
|
+
return { usd: fee.usd, basis: fee.basis };
|
|
64
|
+
if (charged > fee.usd)
|
|
65
|
+
return { usd: fee.usd, basis: `the hold, ${fee.basis}; Parallel's usage said ${urls(billed)}` };
|
|
66
|
+
return { usd: charged, basis: billed === 0 ? "Parallel's usage billed no URL: it listed each in errors" : `Parallel's usage billed ${urls(billed)}, at its list price` };
|
|
67
|
+
}
|
|
35
68
|
export const EXA_SEARCH_TYPE_USD = Object.freeze({ lite: 0.004, instant: 0.004, auto: 0.007, fast: 0.007, "deep-lite": 0.012, deep: 0.012, "deep-reasoning": 0.015 });
|
|
36
69
|
/** Each search result past the 10 a type includes: $1 per 1,000. */
|
|
37
70
|
export const EXA_SEARCH_RESULT_USD = 0.001;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { type Destination, type Destinations, type FetchOptions, type Hold, type
|
|
|
2
2
|
export { type Guard, type GuardOptions, type HtmlRead, type HtmlReader, type PublicAnswer, type PublicCheck, type PublicFetch } from "./guard.js";
|
|
3
3
|
export { type FetchShape, type NativeSearch, type ProviderParts, type ProviderRun, type ReadFailed, type Reader, type SearchAsk, type SettingsSpec, type WebClient, type WebProvider, defineProvider, holdingWords, readerOf, } from "./provider.js";
|
|
4
4
|
export { type AheadProvider, type FetchProvider, type KeyedProvider, type ProviderId, type ProviderSettings, type SaidProvider, type SearchProvider, AHEAD, isProviderId, PROVIDERS, providerName, providerOf, SAID, serves, settingsProblemsOf, } from "./providers/registry.js";
|
|
5
|
-
export { type ExaSearchType, type Fee, type ParallelSearchMode, type Pay, EXA_CONTENT_USD, EXA_SEARCH_INCLUDED, EXA_SEARCH_RESULT_USD, EXA_SEARCH_TYPE_USD, EXA_SUMMARY_USD, exaFeeOf, FIRECRAWL_CREDIT_USD, FIRECRAWL_JSON_CREDITS, FIRECRAWL_SCRAPE_CREDITS, FIRECRAWL_SEARCH_CREDITS, firecrawlFeeOf, PARALLEL_EXTRACT_USD, PARALLEL_SEARCH_INCLUDED, PARALLEL_SEARCH_MODE_USD, PARALLEL_SEARCH_RESULT_USD, PARALLEL_SEARCH_USD, PaidRefused, parallelExtractFee, parallelFeeOf, parallelSearchFee, unmetered, } from "./fees.js";
|
|
5
|
+
export { type ExaSearchType, type Fee, type ParallelSearchMode, type Pay, EXA_CONTENT_USD, EXA_SEARCH_INCLUDED, EXA_SEARCH_RESULT_USD, EXA_SEARCH_TYPE_USD, EXA_SUMMARY_USD, exaFeeOf, FIRECRAWL_CREDIT_USD, FIRECRAWL_JSON_CREDITS, FIRECRAWL_SCRAPE_CREDITS, FIRECRAWL_SEARCH_CREDITS, firecrawlFeeOf, PARALLEL_EXTRACT_USD, PARALLEL_SEARCH_INCLUDED, PARALLEL_SEARCH_MODE_USD, PARALLEL_SEARCH_RESULT_USD, PARALLEL_SEARCH_USD, PaidRefused, parallelChargeOf, parallelExtractFee, parallelFeeOf, parallelSearchFee, unmetered, } from "./fees.js";
|
|
6
6
|
export { type Backend, type Breaker, type Failure, type FailureClass, type Hit, type Holding, type Limit, type Search, type SearchBounds, type Searched, type Try, ANSWER_MAX, breakers, CITE, fitSearch, OBJECTIVE_MAX, QUERIES_MAX, QUERY_MAX, RESULTS_DEFAULT, RESULTS_MAX, SEARCH_MAX_CHARS, SNIPPET_MAX, searchArgs, searchBreaker, searchInTurn, searchText, snippetOf, } from "./search.js";
|
|
7
7
|
export { type FetchTry, type Pages, type Readers, type Via, type WebFetchOptions, type WebLog, type WebPage, type WebRead, type WebUnread, FETCH_ORDER, PAGES_HELD, webFetch, webFetchText, } from "./fetch.js";
|
|
8
8
|
export { type Page, type Part, type Read, type Unread, askedUrl, clip, HTML_READ_CHARS, LINKS_CAP, LINKS_CHARS, MAX_CHARS_MIN, PAGE_CHARS, PAGE_MAX_BYTES, PAGE_READ_MAX_CHARS, partEnd, partProblem, TEXT_CAP, TITLE_CAP, URL_MAX, } from "./page.js";
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export { createWeb, destinationsLine, destinationsWords, } from "./web.js";
|
|
9
9
|
export { defineProvider, holdingWords, readerOf, } from "./provider.js";
|
|
10
10
|
export { AHEAD, isProviderId, PROVIDERS, providerName, providerOf, SAID, serves, settingsProblemsOf, } from "./providers/registry.js";
|
|
11
|
-
export { EXA_CONTENT_USD, EXA_SEARCH_INCLUDED, EXA_SEARCH_RESULT_USD, EXA_SEARCH_TYPE_USD, EXA_SUMMARY_USD, exaFeeOf, FIRECRAWL_CREDIT_USD, FIRECRAWL_JSON_CREDITS, FIRECRAWL_SCRAPE_CREDITS, FIRECRAWL_SEARCH_CREDITS, firecrawlFeeOf, PARALLEL_EXTRACT_USD, PARALLEL_SEARCH_INCLUDED, PARALLEL_SEARCH_MODE_USD, PARALLEL_SEARCH_RESULT_USD, PARALLEL_SEARCH_USD, PaidRefused, parallelExtractFee, parallelFeeOf, parallelSearchFee, unmetered, } from "./fees.js";
|
|
11
|
+
export { EXA_CONTENT_USD, EXA_SEARCH_INCLUDED, EXA_SEARCH_RESULT_USD, EXA_SEARCH_TYPE_USD, EXA_SUMMARY_USD, exaFeeOf, FIRECRAWL_CREDIT_USD, FIRECRAWL_JSON_CREDITS, FIRECRAWL_SCRAPE_CREDITS, FIRECRAWL_SEARCH_CREDITS, firecrawlFeeOf, PARALLEL_EXTRACT_USD, PARALLEL_SEARCH_INCLUDED, PARALLEL_SEARCH_MODE_USD, PARALLEL_SEARCH_RESULT_USD, PARALLEL_SEARCH_USD, PaidRefused, parallelChargeOf, parallelExtractFee, parallelFeeOf, parallelSearchFee, unmetered, } from "./fees.js";
|
|
12
12
|
export { ANSWER_MAX, breakers, CITE, fitSearch, OBJECTIVE_MAX, QUERIES_MAX, QUERY_MAX, RESULTS_DEFAULT, RESULTS_MAX, SEARCH_MAX_CHARS, SNIPPET_MAX, searchArgs, searchBreaker, searchInTurn, searchText, snippetOf, } from "./search.js";
|
|
13
13
|
export { FETCH_ORDER, PAGES_HELD, webFetch, webFetchText, } from "./fetch.js";
|
|
14
14
|
export { askedUrl, clip, HTML_READ_CHARS, LINKS_CAP, LINKS_CHARS, MAX_CHARS_MIN, PAGE_CHARS, PAGE_MAX_BYTES, PAGE_READ_MAX_CHARS, partEnd, partProblem, TEXT_CAP, TITLE_CAP, URL_MAX, } from "./page.js";
|
|
@@ -34,7 +34,7 @@ export type Extract = {
|
|
|
34
34
|
read(url: string, signal?: AbortSignal, client?: WebClient): Promise<Read | string>;
|
|
35
35
|
post(url: string, body: unknown, signal?: AbortSignal): Promise<Response>;
|
|
36
36
|
};
|
|
37
|
-
/** Parallel's extract on `apiKey`: one URL a request, each
|
|
37
|
+
/** Parallel's extract on `apiKey`: one URL a request, each billed as its usage says, its full content to the most of a page
|
|
38
38
|
* web_fetch reads as the page's text (markdown), its links read from it, status 200 (Parallel answers a page it could
|
|
39
39
|
* not read in `errors`, with no content), told the read's client (clientFields). */
|
|
40
40
|
export declare function parallelExtract(apiKey: string, send?: typeof fetch, pay?: Pay, settings?: ParallelSettings): Extract;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Parallel on the run's key: Extract for web_fetch, Search for web_search. Every request is paid through the injected
|
|
2
2
|
// Pay at its endpoint's price, and a 401 or 403 stops both for the client's life. Nothing is retried; each ends at 60 s.
|
|
3
|
-
import { PARALLEL_SEARCH_MODE_USD, PaidRefused, parallelFeeOf, unmetered } from "../fees.js";
|
|
3
|
+
import { PARALLEL_SEARCH_MODE_USD, PaidRefused, parallelChargeOf, parallelFeeOf, unmetered } from "../fees.js";
|
|
4
4
|
import { clip, cutAt, markdownRead, PAGE_READ_MAX_CHARS, TITLE_CAP } from "../page.js";
|
|
5
5
|
import { failed, failure, keyWide, searchArgs, searchFailed, snippetOf } from "../search.js";
|
|
6
6
|
import { defineProvider, settingsOf } from "../provider.js";
|
|
@@ -37,14 +37,15 @@ const clientFields = (client) => ({
|
|
|
37
37
|
...(client.model ? { client_model: client.model } : {}),
|
|
38
38
|
...(client.session ? { session_id: client.session.slice(0, SESSION_MAX) } : {}),
|
|
39
39
|
});
|
|
40
|
-
/** Parallel's extract on `apiKey`: one URL a request, each
|
|
40
|
+
/** Parallel's extract on `apiKey`: one URL a request, each billed as its usage says, its full content to the most of a page
|
|
41
41
|
* web_fetch reads as the page's text (markdown), its links read from it, status 200 (Parallel answers a page it could
|
|
42
42
|
* not read in `errors`, with no content), told the read's client (clientFields). */
|
|
43
43
|
export function parallelExtract(apiKey, send = fetch, pay = unmetered, settings = {}) {
|
|
44
44
|
// One keyed client for both tools (keyed.ts keyedClient): each request paid through `pay` at its endpoint's price
|
|
45
45
|
// (fees.ts; serve's paid-calls.ts holds it to the run's cap), one with no price, or one the cap refuses, not sent
|
|
46
|
-
// (PaidRefused), a stopped call sending nothing and one that never left not billed (paidSend).
|
|
47
|
-
|
|
46
|
+
// (PaidRefused), a stopped call sending nothing and one that never left not billed (paidSend). An extract is charged
|
|
47
|
+
// the URLs Parallel's usage says it billed (parallelChargeOf): none for a URL it lists in errors.
|
|
48
|
+
const client = keyedClient({ who: "Parallel", base: PARALLEL_API_URL, headers: { "x-api-key": apiKey }, feeOf: (path, body) => parallelFeeOf(`${PARALLEL_API_URL}${path}`, body), chargeOf: parallelChargeOf, timeoutMs: PARALLEL_TIMEOUT_MS, refuseOn: [401, 403] }, send, pay);
|
|
48
49
|
const post = async (url, body, signal) => {
|
|
49
50
|
// It carries the key: a URL not below Parallel's API is never sent, as a request with no price here.
|
|
50
51
|
if (!url.startsWith(`${PARALLEL_API_URL}/`))
|
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.74",
|
|
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.74"
|
|
50
50
|
},
|
|
51
51
|
"repository": {
|
|
52
52
|
"type": "git",
|