@parcha/pi-browser 0.1.0-beta.62 → 0.1.0-beta.64
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 +4 -0
- package/README.md +8 -3
- package/dist/core/host.d.ts +4 -1
- package/dist/core/usage.d.ts +4 -1
- package/dist/core/usage.js +5 -2
- package/dist/durable.d.ts +6 -0
- package/dist/durable.js +20 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.1.0-beta.63 (2026-11-26)
|
|
6
|
+
|
|
7
|
+
- `BrowserExtensionHandle.charge(conversation, context)` bills each open session of a conversation through now, not final. A session counts as open when it is live, held, or releasing (its release asked and not yet confirmed). The charge and the session's `chargedThrough` move in one commit, and it resolves to the number of sessions charged. A host that stops waiting on a session's release uses it to book the time known so far. The release's own charge, when it lands, bills only the time after that, so a cut charge followed by the final charge books what one uninterrupted session books, the provider's minimum included. A charge through a time before the session's `chargedThrough` bills nothing, never a negative amount, and reports the difference in seconds as `SessionCharge.overbookedS`. That happens when the release was confirmed before an earlier charge that billed past it. A session billed final is never billed again. <!-- changes/pi-browser-cut-charge.md -->
|
|
8
|
+
|
|
5
9
|
## 0.1.0-beta.57 (2026-11-24)
|
|
6
10
|
|
|
7
11
|
- `@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 -->
|
package/README.md
CHANGED
|
@@ -359,8 +359,10 @@ await browser.reconcile(harness, () => true, context); // settles what a dead
|
|
|
359
359
|
final, state }`, called in the commit that writes it on the session's record, so a host that books it in `tx` books
|
|
360
360
|
exactly what the record bills: at a browser call (`call.callId`), what the session ran since its last charge; at its
|
|
361
361
|
release, or when custody gives up releasing it (`lost`) (`final`), the rest, topped up to `prices.sessionMinimumS`. A session already billed in full is never charged
|
|
362
|
-
again. `state` is `priced`, or `unpriced`/`invalid` with `usd` 0 (no price, not $0).
|
|
363
|
-
|
|
362
|
+
again. `state` is `priced`, or `unpriced`/`invalid` with `usd` 0 (no price, not $0). `overbookedS`, when present: an
|
|
363
|
+
earlier charge billed the session past this one's `at` (a `handle.charge` taken while its release was under way, the
|
|
364
|
+
release confirmed before it), by that many seconds; this charge bills none of it again and never a negative. It must
|
|
365
|
+
not throw: a throw fails the commit, and a call's charge is then carried by the session's next one.
|
|
364
366
|
|
|
365
367
|
Per conversation, the host writes a `BrowserConfig` (`label`, `run`, and the policy: proxies, verified, captcha, geolocation,
|
|
366
368
|
region, a raw context id, the session timeout, the idle release and the batch timeout; `DEFAULT_BROWSER_POLICY` holds the
|
|
@@ -368,7 +370,10 @@ package's defaults to spread and override) in the conversation's creating commit
|
|
|
368
370
|
selects the extensions for it, and calls `handle.release(conversation, "close", ctx)` when the conversation ends. Releases run
|
|
369
371
|
as background tasks, which `waitForIdle` skips and closing the harness aborts: before it closes, a host calls
|
|
370
372
|
`handle.drain(harness, ctx, signal?)`, which resolves once none is live. A host that closes with no drain after its `close`
|
|
371
|
-
releases gets them at the provider all the same: `handle.close()` waits, 30 s at most, for every one no drain since covered.
|
|
373
|
+
releases gets them at the provider all the same: `handle.close()` waits, 30 s at most, for every one no drain since covered.
|
|
374
|
+
A host that stops waiting on a release calls `handle.charge(conversation, ctx)` to book the time known so far: each session
|
|
375
|
+
still open (live, held, or releasing) is billed through now, not final, its `chargedThrough` moved in the same commit, and
|
|
376
|
+
the release's own charge, when it lands, bills only the time after it. A release the store cannot record (a storage error)
|
|
372
377
|
is still made at the provider, and the record is left for the next run's reconcile; once the store has failed,
|
|
373
378
|
`handle.close()` releases every session the process still holds, and over a healthy store it releases nothing. At run open,
|
|
374
379
|
after the extensions are installed and
|
package/dist/core/host.d.ts
CHANGED
|
@@ -342,7 +342,9 @@ export type PriceTable = {
|
|
|
342
342
|
};
|
|
343
343
|
/** One charge of a session's time, as its record bills it: `seconds` and `usd` since the session's last charge, through `at`,
|
|
344
344
|
* or, `final`, at its release, topped up to the provider's minimum. `state` says whether `usd` is a price (`priced`) or
|
|
345
|
-
* the time went unpriced (`unpriced`, `invalid`: `usd` is 0 and is no charge).
|
|
345
|
+
* the time went unpriced (`unpriced`, `invalid`: `usd` is 0 and is no charge). `overbookedS`: an earlier charge billed
|
|
346
|
+
* the session through a later time than this one's `at` (a charge taken while its release was under way, the release
|
|
347
|
+
* confirmed before it), by that many seconds; this one bills none of it again. Absent: none. */
|
|
346
348
|
export type SessionCharge = {
|
|
347
349
|
conversationId: number;
|
|
348
350
|
tag: string;
|
|
@@ -352,6 +354,7 @@ export type SessionCharge = {
|
|
|
352
354
|
usd: number;
|
|
353
355
|
final: boolean;
|
|
354
356
|
state: PriceState;
|
|
357
|
+
overbookedS?: number;
|
|
355
358
|
};
|
|
356
359
|
/** Browserbase list prices as of 2026-10-06: the Developer overage rate, one-minute minimum. */
|
|
357
360
|
export declare const LIST_PRICES: PriceTable;
|
package/dist/core/usage.d.ts
CHANGED
|
@@ -11,9 +11,12 @@ type Spent = SessionRecord["spent"];
|
|
|
11
11
|
export declare const startSpent: (createdAt: string) => Spent;
|
|
12
12
|
/** The record after a charge, with its list-priced dollars: the ones it already held plus this charge's when the price was the list's. `after` is what `sessionCharge` returned. */
|
|
13
13
|
export declare function withEstimate(before: Spent, after: Spent, listPriced: boolean): Spent;
|
|
14
|
-
/** `final` (the release) tops up to the provider's minimum and marks the record, so a retried release adds nothing.
|
|
14
|
+
/** `final` (the release) tops up to the provider's minimum and marks the record, so a retried release adds nothing. A
|
|
15
|
+
* charge through an `at` before the record's `chargedThrough` bills no time (an earlier charge billed past it), and says
|
|
16
|
+
* by how much in `overbookedS`. */
|
|
15
17
|
export declare function sessionCharge(spent: Spent, at: string, prices: PriceTable, state?: PriceState, final?: boolean): {
|
|
16
18
|
spent: Spent;
|
|
17
19
|
usage: ToolUsage;
|
|
20
|
+
overbookedS?: number;
|
|
18
21
|
};
|
|
19
22
|
export {};
|
package/dist/core/usage.js
CHANGED
|
@@ -27,7 +27,9 @@ export function withEstimate(before, after, listPriced) {
|
|
|
27
27
|
const estimated = Math.round(((before.estimatedUsd ?? 0) + (listPriced ? added : 0)) * PICO) / PICO;
|
|
28
28
|
return estimated > 0 ? { ...after, estimatedUsd: estimated } : after;
|
|
29
29
|
}
|
|
30
|
-
/** `final` (the release) tops up to the provider's minimum and marks the record, so a retried release adds nothing.
|
|
30
|
+
/** `final` (the release) tops up to the provider's minimum and marks the record, so a retried release adds nothing. A
|
|
31
|
+
* charge through an `at` before the record's `chargedThrough` bills no time (an earlier charge billed past it), and says
|
|
32
|
+
* by how much in `overbookedS`. */
|
|
31
33
|
export function sessionCharge(spent, at, prices, state = "priced", final = false) {
|
|
32
34
|
if (spent.final)
|
|
33
35
|
return { spent, usage: toolUsage(0, state === "invalid" ? "invalid" : prices.sessionUsdPerHour === null || state !== "priced" ? "unpriced" : "priced") };
|
|
@@ -35,6 +37,7 @@ export function sessionCharge(spent, at, prices, state = "priced", final = false
|
|
|
35
37
|
// 59.99999999999999 s.
|
|
36
38
|
const before = Math.round(spent.seconds * 1000);
|
|
37
39
|
const elapsed = Math.max(0, Date.parse(at) - Date.parse(spent.chargedThrough));
|
|
40
|
+
const overbooked = Math.max(0, Date.parse(spent.chargedThrough) - Date.parse(at));
|
|
38
41
|
const charged = elapsed + (final ? Math.max(0, Math.round(prices.sessionMinimumS * 1000) - (before + elapsed)) : 0);
|
|
39
42
|
const price = prices.sessionUsdPerHour;
|
|
40
43
|
const priced = price !== null && state === "priced";
|
|
@@ -44,5 +47,5 @@ export function sessionCharge(spent, at, prices, state = "priced", final = false
|
|
|
44
47
|
const picos = Number(owed / HOUR_MS);
|
|
45
48
|
const carry = Number(owed % HOUR_MS);
|
|
46
49
|
const gap = priced ? "priced" : state === "invalid" ? "invalid" : "unpriced";
|
|
47
|
-
return { spent: { seconds: (before + charged) / 1000, usd: (Math.round(spent.usd * PICO) + picos) / PICO, chargedThrough: elapsed > 0 ? at : spent.chargedThrough, ...(final ? { final: true } : {}), ...(carry ? { carry } : {}) }, usage: toolUsage(picos / PICO, gap) };
|
|
50
|
+
return { spent: { seconds: (before + charged) / 1000, usd: (Math.round(spent.usd * PICO) + picos) / PICO, chargedThrough: elapsed > 0 ? at : spent.chargedThrough, ...(final ? { final: true } : {}), ...(carry ? { carry } : {}) }, usage: toolUsage(picos / PICO, gap), ...(overbooked > 0 ? { overbookedS: overbooked / 1000 } : {}) };
|
|
48
51
|
}
|
package/dist/durable.d.ts
CHANGED
|
@@ -112,6 +112,12 @@ export type BrowserExtensionHandle = {
|
|
|
112
112
|
* the tag goes, its idle window starts again from then. Releases for any other reason (the tool, a close, its end)
|
|
113
113
|
* are not held. */
|
|
114
114
|
keepForPerson(tag: string): () => void;
|
|
115
|
+
/** Bills each session of the conversation still open (live, held, or releasing: its release asked, not yet confirmed)
|
|
116
|
+
* through now, not final, in one commit that moves each one's `chargedThrough` with its charge (onCharge): what a host
|
|
117
|
+
* that stops waiting on a release books of the time known so far. The release's own charge, when it lands, bills only
|
|
118
|
+
* the time after it, and an `at` before it bills nothing and says so (SessionCharge.overbookedS). Resolves to the
|
|
119
|
+
* sessions charged. */
|
|
120
|
+
charge(conversation: Pick<Conversation, "id" | "commit">, context: Context): Promise<number>;
|
|
115
121
|
};
|
|
116
122
|
export { CONFIRM_POLLS, RELEASE_ATTEMPTS } from "./durable/store.js";
|
|
117
123
|
export { HANDOFF_POLL_MS } from "./core/custody.js";
|
package/dist/durable.js
CHANGED
|
@@ -705,6 +705,22 @@ async function releasePlane(c, conversation, reason, context, still = () => true
|
|
|
705
705
|
c.leaving.set(tag, rearmWhenLeft(kept.gate, () => c.idle.keys().includes(conversation.id), () => { c.leaving.delete(tag); c.idle.activity(conversation.id, 0); }, idleS * 1000));
|
|
706
706
|
}
|
|
707
707
|
}
|
|
708
|
+
/** The open sessions' time through now, not final, in one commit (BrowserExtensionHandle.charge): no lock is taken, so a
|
|
709
|
+
* release under way (its record `releasing`) never holds it back. */
|
|
710
|
+
async function chargeOpen(c, conversation, context) {
|
|
711
|
+
return conversation.commit(async (tx) => {
|
|
712
|
+
const state = await tx.doc(c.Sessions, conversation.id);
|
|
713
|
+
const at = now();
|
|
714
|
+
let charged = 0;
|
|
715
|
+
for (const record of state.sessions) {
|
|
716
|
+
if ((record.state !== "live" && record.state !== "held" && record.state !== "releasing") || record.resourceId === null || record.spent.final)
|
|
717
|
+
continue;
|
|
718
|
+
if (await c.bill(tx, conversation.id, record, at, false))
|
|
719
|
+
charged += 1;
|
|
720
|
+
}
|
|
721
|
+
return charged;
|
|
722
|
+
}, context);
|
|
723
|
+
}
|
|
708
724
|
async function chargeCall(c, api, context) {
|
|
709
725
|
if (currentRecord(await api.snapshot(c.Sessions, api.conversationId, context), PLANE)?.state !== "live")
|
|
710
726
|
return null;
|
|
@@ -802,16 +818,16 @@ export function createBrowserExtension(options) {
|
|
|
802
818
|
const listPriced = options.prices?.sessionUsdPerHour === undefined && prices.sessionUsdPerHour !== null;
|
|
803
819
|
const meter = (spent, at, final = false) => {
|
|
804
820
|
const charged = sessionCharge(spent, at, prices, priceState, final);
|
|
805
|
-
return { spent: { ...withEstimate(spent, charged.spent, listPriced), state: charged.usage.state }, usage: charged.usage };
|
|
821
|
+
return { spent: { ...withEstimate(spent, charged.spent, listPriced), state: charged.usage.state }, usage: charged.usage, ...(charged.overbookedS === undefined ? {} : { overbookedS: charged.overbookedS }) };
|
|
806
822
|
};
|
|
807
823
|
const bill = async (tx, conversationId, record, at, final, call) => {
|
|
808
824
|
const before = record.spent;
|
|
809
825
|
if (before.final)
|
|
810
826
|
return null;
|
|
811
|
-
const { spent, usage } = meter(before, at, final);
|
|
827
|
+
const { spent, usage, overbookedS } = meter(before, at, final);
|
|
812
828
|
record.spent = spent;
|
|
813
829
|
const seconds = Math.round((spent.seconds - before.seconds) * 1000) / 1000;
|
|
814
|
-
await options.onCharge?.({ conversationId, tag: record.tag, provider: record.provider, at, seconds, usd: usage.usage.cost.total, final, state: usage.state }, tx, call);
|
|
830
|
+
await options.onCharge?.({ conversationId, tag: record.tag, provider: record.provider, at, seconds, usd: usage.usage.cost.total, final, state: usage.state, ...(overbookedS === undefined ? {} : { overbookedS }) }, tx, call);
|
|
815
831
|
return usage;
|
|
816
832
|
};
|
|
817
833
|
const leaving = new Map();
|
|
@@ -848,6 +864,7 @@ export function createBrowserExtension(options) {
|
|
|
848
864
|
docs: { Config, Sessions, Inventory: store.Inventory },
|
|
849
865
|
tools,
|
|
850
866
|
release: (conversation, reason, context) => releasePlane(c, conversation, reason, context),
|
|
867
|
+
charge: (conversation, context) => chargeOpen(c, conversation, context),
|
|
851
868
|
async reconcile(harness, isActive, context) {
|
|
852
869
|
c.opened = { harness, context };
|
|
853
870
|
c.ending = endingOf(harness);
|