@parcha/pi-browser 0.1.0-beta.56 → 0.1.0-beta.58

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/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.1.0-beta.57 (2026-11-24)
6
+
7
+ - `@parcha/agentrun-web` is new: the machinery behind `web_search` and `web_fetch`, moved out of `@parcha/agentrun-serve` with no change to what a model is sent or told. It holds the providers (Parallel, keyless Firecrawl, keyless Exa, a hosted search given as a function, and the direct fetch), a breaker per provider, the per-run page cache read in parts, and Parallel's prices. It imports no server, browser or vendor SDK code. The provider order, keys, public-host guard, run cap and refusal words come in through `WebConfig`. `createWeb(config)` answers a search or a fetch together with a receipt of the providers tried and the fees sent. `@parcha/agentrun-web/text-urls` exports the link finder alone. `@parcha/agentrun-serve` now depends on it and answers both tools through one `createWeb` per run, with pi-browser's `publicFetch` and `publicCheck` as the guard. `@parcha/pi-browser` exports `publicCheck(url, { lookup, signal })`, the check `publicFetch` makes on every hop, without dialling. Both refuse a loopback, `.local` or `.internal` name written with one or more trailing dots before any lookup, as they refuse it without them. <!-- changes/web-extract.md -->
8
+
9
+ Two things a server's users can see change:
10
+
11
+ - A workflow's call node that runs `web_search` now gets its answer held to 100,000 characters, as an agent's `web_search` already was. Past that, the least relevant results are left out and `omitted` counts them. Before, a call node got the whole answer.
12
+ - The MCP client keyless Firecrawl and keyless Exa are asked through now names itself `agentrun-web` in its `initialize` request, in place of `agentrun-serve`.
13
+ - A run with a spend cap can send fal's talking heads, `veed/fabric-1.0` at `"resolution": "480p"` or `"720p"` and `fal-ai/bytedance/omnihuman/v1.5`: each job is held at its voice's length, read before the call from the audio at its `audio_url` alone (on fal's own media, `fal.media` or a subdomain: a voice fal made, or one uploaded to fal; the URL written exactly as it parses, so `V3.fal.media`, a space, a `..` segment or `:443` is not priced), in whole seconds as fal bills them, at get_pricing's rate. The length is what the voice plays: every audio frame of an MP3 (a first frame holding a Xing, Info or VBRI header is skipped, as a decoder skips it), or a PCM WAV's samples at its sample rate, every byte after its data header counted. It is never read from the job's image, from a length its input states, or from a length the file's own header states (an MP3's Xing, Info or VBRI frame count, a WAV's byte rate or data size), which whoever made the file could write short. Only a voice on fal's own media is priced because fal fetches the `audio_url` again after this read, and another host could serve fal a longer voice than the one measured. The voice is read https only and following no redirect (fal.media serves its files directly), so a fal.media URL can't send the read to another host, through the same public-host guard as web_fetch and web_save, and at most 32 MiB. A job is still refused unsent under a cap, as before, when its voice can't be read (an `audio_url` that is not https or not on `fal.media`, a private host, over 32 MiB, a timeout, a WAV that is not integer PCM or float with one format chunk whose fields agree, an MP3 with bytes that are not frames, or any other format: an mp4 or m4a voice states its length only in its header), and for Fabric with no `resolution`: its resolution has no default, so send `"480p"` or `"720p"` (720p is held at $0.15 a second against 480p's $0.08, as fal bills it; see the fal setting tiers note). With no cap such a job runs, booked as an unknown charge, never $0. Fabric's reply states no length, so it is booked at its hold: the ledger books the voice's length, read before the call, not a length fal reports. OmniHuman settles at the length its reply states, in whole seconds. LatentSync, infinitalk and `ffmpeg-api/merge-audio-video` stay unpriceable under a cap. <!-- changes/fal-talking-head-price.md -->
14
+ `publicFetch` and `publicDownload` take `httpsOnly`, which refuses http on the first hop and at every redirect, and `maxRedirects` (a whole number from 0 to 5, default 5; with 0 any redirect is refused before its target is dialled; any other value is a `RangeError` before a lookup).
15
+ A job billed by length is priced from a length its input names only on the endpoints whose input sets the length fal bills, and only from that field: `duration` on Kling v2.5 turbo pro (text and image to video), Kling v3 pro image to video, Hailuo-02 standard text to video, Veo 3 fast, Veo 3.1 (fast, image to video) and ACE-Step; `seconds_total` on Stable Audio 2.5; `music_length_ms` or `composition_plan` on ElevenLabs Music. Before, any per-second or per-minute endpoint trusted a named `duration`, `duration_seconds`, `seconds_total` or `music_length_ms`, so a capped run could send `fal-ai/sync-lipsync/v2` with a 10 minute video and `duration: 0.001` and be held at about $0. Now dubbing, voice isolation, speech-to-text and sync-lipsync v2 are always priced from the media they are given, and any other endpoint billed by length (LatentSync, infinitalk, a merge, Fabric fast, OmniHuman v1, an endpoint this server doesn't know) is refused unsent under a cap, whatever length its input names. A listed endpoint that names no length, or another of the length fields, is refused unsent too.
16
+ An ElevenLabs Music job with a `composition_plan` is priced from its sections' `duration_ms`, never from a `music_length_ms` beside it: before, `music_length_ms` was read first, so a job naming 10 s beside a 10 minute plan was held at 10 s and billed for 10 minutes. A job naming both is refused unsent under a cap (send one: a plan sets the length, and `music_length_ms` goes only with a prompt), and so is a plan with `respect_sections_durations` other than `true` or left out (its default), since the model may then change the sections' lengths.
17
+
5
18
  ## 0.1.0-beta.50 (2026-11-20)
6
19
 
7
20
  - `web_save {url, path}`, a new host tool, saves one public file (at most 200 MiB) into the run's `work/`, a bare name under `media/`. It downloads through `web_fetch`'s guard, never overwrites, and saves media only when the bytes, the declared type and the extension agree. An agent gets it by naming it. pi-browser adds `publicDownload`, the bytes version of `publicFetch`. A template eval's `web:` fixture takes an optional `save` section. <!-- changes/web-save-tool.md -->
@@ -13,6 +13,11 @@ export type PublicFetchOptions = {
13
13
  signal?: AbortSignal;
14
14
  /** Default 5 MiB. */
15
15
  maxBytes?: number;
16
+ /** Refuse http as well, on the first hop and at every redirect: https only. Default false. */
17
+ httpsOnly?: boolean;
18
+ /** The most redirects followed, a whole number from 0 to 5; with 0 any redirect is refused before its target is
19
+ * dialled. Default 5. */
20
+ maxRedirects?: number;
16
21
  };
17
22
  /** The answer that ended the redirects: its URL, status and type, and its body when it is a 2xx text answer. */
18
23
  export type PublicAnswer = {
@@ -29,13 +34,20 @@ export type PublicFile = {
29
34
  contentType: string;
30
35
  bytes: Uint8Array | null;
31
36
  };
37
+ type Lookup = (host: string) => Promise<string[]>;
38
+ /** Whether publicFetch's first hop would be dialled for `url`: http(s), and hopAddresses' checks, with nothing sent.
39
+ * Resolves when it passes; throws publicFetch's own refusal when it does not. */
40
+ export declare function publicCheck(url: string, options?: {
41
+ lookup?: Lookup;
42
+ signal?: AbortSignal;
43
+ }): Promise<void>;
32
44
  /**
33
- * Fetches `url` from a public host, following at most 5 redirects, each hop resolved, checked and dialled at the
45
+ * Fetches `url` from a public host, following at most 5 redirects (or `maxRedirects`), each hop resolved, checked and dialled at the
34
46
  * address checked. A 2xx answer of a text type is read whole, up to `maxBytes`; another status comes back without its
35
- * body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s); a host
36
- * that is local by name or resolves to any private address; a port other than 80 or 443; too many redirects; a 2xx body
37
- * that is not text or is over the cap. `signal` ends the fetch at any point, a hop's name lookup included (it rejects
38
- * with the signal's reason), and an aborted hop is never dialled.
47
+ * body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s) (other
48
+ * than https, with `httpsOnly`); a host that is local by name or resolves to any private address; a port other than 80
49
+ * or 443; too many redirects (any, with `maxRedirects` 0); a 2xx body that is not text or is over the cap. `signal` ends the fetch at any point, a
50
+ * hop's name lookup included (it rejects with the signal's reason), and an aborted hop is never dialled.
39
51
  */
40
52
  export declare function publicFetch(url: string, options?: PublicFetchOptions): Promise<PublicAnswer>;
41
53
  /**
@@ -48,3 +60,4 @@ export declare function publicFetch(url: string, options?: PublicFetchOptions):
48
60
  * end, about twice the file's size at the peak. `signal` ends the body's read too, with its reason.
49
61
  */
50
62
  export declare function publicDownload(url: string, options?: PublicFetchOptions): Promise<PublicFile>;
63
+ export {};
@@ -74,13 +74,42 @@ function untilAborted(work, signal) {
74
74
  * a zip, octet-stream, an image/svg+xml) is refused. */
75
75
  const TEXT_TYPE = /^(text\/|application\/(json|xml|[\w.!#$&^-]+\+(xml|json)\b))/i;
76
76
  const MIB = 1024 * 1024;
77
- /** The options checked before any lookup: `maxBytes` (default 5 MiB) a whole number of bytes above 0. */
77
+ /** The options checked before any lookup: `maxBytes` (default 5 MiB) a whole number of bytes above 0, and
78
+ * `maxRedirects` a whole number from 0 to 5. */
78
79
  function capOf(options) {
79
80
  const maxBytes = options.maxBytes ?? PUBLIC_MAX_BYTES;
80
81
  if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
81
82
  throw new RangeError(`maxBytes must be a whole number of bytes above 0, not ${maxBytes}`);
83
+ const redirects = options.maxRedirects ?? MAX_REDIRECTS;
84
+ if (!Number.isSafeInteger(redirects) || redirects < 0 || redirects > MAX_REDIRECTS)
85
+ throw new RangeError(`maxRedirects must be a whole number from 0 to ${MAX_REDIRECTS}, not ${redirects}`);
82
86
  return maxBytes;
83
87
  }
88
+ const systemLookup = async (host) => (await dns.lookup(host, { all: true })).map((a) => a.address);
89
+ /** One hop's checks before it is dialled: its name is not a local one, every address it resolves to is public, and its
90
+ * port is 80 or 443. Answers the addresses, the first of which the hop dials; throws the refusal otherwise. */
91
+ async function hopAddresses(target, lookup, signal) {
92
+ const host = target.hostname.replace(/^\[|\]$/g, "");
93
+ // Trailing dots name the same host (WHATWG keeps them): the name checks read the host without any.
94
+ const name = host.replace(/\.+$/, "");
95
+ if (name === "localhost" || name.endsWith(".localhost") || name.endsWith(".local") || name.endsWith(".internal"))
96
+ throw refusedError(`refused: ${host} is not a public host`);
97
+ const addresses = net.isIP(host) ? [host] : await untilAborted(() => lookup(host), signal);
98
+ if (!addresses.length || addresses.some(isPrivateAddress))
99
+ throw refusedError(`refused: ${host} is not a public host`);
100
+ if (!PORTS.has(target.port))
101
+ throw refusedError(`refused: port ${target.port} is not 80 or 443`);
102
+ signal?.throwIfAborted();
103
+ return addresses;
104
+ }
105
+ /** Whether publicFetch's first hop would be dialled for `url`: http(s), and hopAddresses' checks, with nothing sent.
106
+ * Resolves when it passes; throws publicFetch's own refusal when it does not. */
107
+ export async function publicCheck(url, options = {}) {
108
+ const target = new URL(url);
109
+ if (!/^https?:$/.test(target.protocol))
110
+ throw refusedError(`refused: ${target.protocol} is not http(s)`);
111
+ await hopAddresses(target, options.lookup ?? systemLookup, options.signal);
112
+ }
84
113
  /**
85
114
  * The hop loop both answers share: `url` fetched from a public host, following at most 5 redirects, each hop resolved,
86
115
  * checked and dialled at the address checked, asking for `accept`. The answer that ends the redirects goes to `answer`,
@@ -88,31 +117,25 @@ function capOf(options) {
88
117
  * returns or throws.
89
118
  */
90
119
  async function publicHops(url, options, accept, answer) {
91
- const lookup = options.lookup ?? (async (host) => (await dns.lookup(host, { all: true })).map((a) => a.address));
120
+ const lookup = options.lookup ?? systemLookup;
92
121
  const request = options.fetchImpl ?? ((target, init) => undiciFetch(target, init));
122
+ const [scheme, schemeName] = options.httpsOnly ? [/^https:$/, "https"] : [/^https?:$/, "http(s)"];
123
+ const most = options.maxRedirects ?? MAX_REDIRECTS;
93
124
  let target = new URL(url);
94
- if (!/^https?:$/.test(target.protocol))
95
- throw refusedError(`refused: ${target.protocol} is not http(s)`);
125
+ if (!scheme.test(target.protocol))
126
+ throw refusedError(`refused: ${target.protocol} is not ${schemeName}`);
96
127
  for (let hop = 0;; hop += 1) {
97
- const host = target.hostname.replace(/^\[|\]$/g, "");
98
- if (host === "localhost" || host.endsWith(".localhost") || host.endsWith(".local") || host.endsWith(".internal"))
99
- throw refusedError(`refused: ${host} is not a public host`);
100
- const addresses = net.isIP(host) ? [host] : await untilAborted(() => lookup(host), options.signal);
101
- if (!addresses.length || addresses.some(isPrivateAddress))
102
- throw refusedError(`refused: ${host} is not a public host`);
103
- if (!PORTS.has(target.port))
104
- throw refusedError(`refused: port ${target.port} is not 80 or 443`);
105
- options.signal?.throwIfAborted();
128
+ const addresses = await hopAddresses(target, lookup, options.signal);
106
129
  const dispatcher = new Agent({ connect: { lookup: pinnedLookup(addresses[0]) } });
107
130
  let res;
108
131
  try {
109
132
  res = await request(target, { redirect: "manual", signal: options.signal, dispatcher, headers: { accept, "user-agent": "pi-browser" } });
110
133
  if (res.status >= 300 && res.status < 400 && res.headers.get("location")) {
111
- if (hop >= MAX_REDIRECTS)
112
- throw refusedError("refused: too many redirects");
134
+ if (hop >= most)
135
+ throw refusedError(most === 0 ? "refused: a redirect, and this download follows none" : "refused: too many redirects");
113
136
  target = new URL(res.headers.get("location"), target);
114
- if (!/^https?:$/.test(target.protocol))
115
- throw refusedError("refused: a redirect left http(s)");
137
+ if (!scheme.test(target.protocol))
138
+ throw refusedError(`refused: a redirect left ${schemeName}`);
116
139
  continue;
117
140
  }
118
141
  return await answer(res, target);
@@ -180,12 +203,12 @@ function statedLength(headers) {
180
203
  return Number.isSafeInteger(length) ? length : undefined;
181
204
  }
182
205
  /**
183
- * Fetches `url` from a public host, following at most 5 redirects, each hop resolved, checked and dialled at the
206
+ * Fetches `url` from a public host, following at most 5 redirects (or `maxRedirects`), each hop resolved, checked and dialled at the
184
207
  * address checked. A 2xx answer of a text type is read whole, up to `maxBytes`; another status comes back without its
185
- * body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s); a host
186
- * that is local by name or resolves to any private address; a port other than 80 or 443; too many redirects; a 2xx body
187
- * that is not text or is over the cap. `signal` ends the fetch at any point, a hop's name lookup included (it rejects
188
- * with the signal's reason), and an aborted hop is never dialled.
208
+ * body. Refused (`BrowserFailureError` `refused`), on the first hop or a redirect: a scheme other than http(s) (other
209
+ * than https, with `httpsOnly`); a host that is local by name or resolves to any private address; a port other than 80
210
+ * or 443; too many redirects (any, with `maxRedirects` 0); a 2xx body that is not text or is over the cap. `signal` ends the fetch at any point, a
211
+ * hop's name lookup included (it rejects with the signal's reason), and an aborted hop is never dialled.
189
212
  */
190
213
  export async function publicFetch(url, options = {}) {
191
214
  const maxBytes = capOf(options);
package/dist/index.d.ts CHANGED
@@ -13,7 +13,7 @@ export * from "./core/host.js";
13
13
  export * from "./core/images.js";
14
14
  export * from "./core/lease.js";
15
15
  export * from "./core/page-classifier.js";
16
- export { isPrivateAddress, pinnedLookup, PUBLIC_MAX_BYTES, publicDownload, publicFetch, type PublicAnswer, type PublicFetchOptions, type PublicFile } from "./core/public-fetch.js";
16
+ export { isPrivateAddress, pinnedLookup, PUBLIC_MAX_BYTES, publicCheck, publicDownload, publicFetch, type PublicAnswer, type PublicFetchOptions, type PublicFile } from "./core/public-fetch.js";
17
17
  export { READ_DEADLINE_MS, READ_MAX_CHARS, readPage, type PageRead, type ReadPageOptions } from "./core/read-page.js";
18
18
  export * from "./core/receipts.js";
19
19
  export * from "./core/redact.js";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export * from "./core/host.js";
14
14
  export * from "./core/images.js";
15
15
  export * from "./core/lease.js";
16
16
  export * from "./core/page-classifier.js";
17
- export { isPrivateAddress, pinnedLookup, PUBLIC_MAX_BYTES, publicDownload, publicFetch } from "./core/public-fetch.js";
17
+ export { isPrivateAddress, pinnedLookup, PUBLIC_MAX_BYTES, publicCheck, publicDownload, publicFetch } from "./core/public-fetch.js";
18
18
  export { READ_DEADLINE_MS, READ_MAX_CHARS, readPage } from "./core/read-page.js";
19
19
  export * from "./core/receipts.js";
20
20
  export * from "./core/redact.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/pi-browser",
3
- "version": "0.1.0-beta.56",
3
+ "version": "0.1.0-beta.58",
4
4
  "description": "Your agent gets its own browser, and you can take over and hand it back.",
5
5
  "keywords": [
6
6
  "pi-durable",