@parcha/agentrun-computer 0.1.0-beta.60 → 0.1.0-beta.61
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 +21 -8
- package/dist/browser.d.ts +13 -3
- package/dist/browser.js +22 -3
- package/dist/browserbase.d.ts +4 -1
- package/dist/browserbase.js +39 -16
- package/dist/computerd-linux-amd64 +0 -0
- package/dist/computerd-linux-arm64 +0 -0
- package/dist/computerd.json +1 -1
- package/dist/host.d.ts +4 -1
- package/dist/hosted/provider.d.ts +3 -1
- package/dist/hosted/provider.js +26 -6
- package/dist/kernel.js +18 -12
- package/dist/modal.js +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1322,12 +1322,18 @@ runs on the VM runtime, or on gVisor for a GPU computer (below). Its unit tests
|
|
|
1322
1322
|
- **Sizes are limits**, as in Docker: `cpus` (at least 0.25) becomes `cpuLimit` in physical cores (2 CPUs each) and
|
|
1323
1323
|
`memoryMb` becomes `memoryLimitMiB`, each with Modal's default request (0.125 cores, 128 MiB) or less. `pids` and
|
|
1324
1324
|
`workdir` are refused: Modal has no pids limit, and a computer works in `/work`, its home.
|
|
1325
|
-
- **Tags.** A sandbox's
|
|
1326
|
-
computer's GPUs; no max-deadline, which only `extend` reads) and the caller's. Modal takes 10 tags, 512 bytes of them,
|
|
1327
|
-
values together
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1325
|
+
- **Tags.** A sandbox's labels are the adapter's (`agentrun.computer`, its name, deadline and image, and a GPU
|
|
1326
|
+
computer's GPUs; no max-deadline, which only `extend` reads) and the caller's. Modal takes 10 tags, 512 bytes of them,
|
|
1327
|
+
names and values together, and a computer with a mount, a network list and a run's labels passes 512 bytes as they
|
|
1328
|
+
are, so the adapter keeps them packed (the host's `labels.packed`): two tags, `agentrun` with the computer's name and
|
|
1329
|
+
`agentrun-0` with the labels deflated, and get and list answer them unpacked. `check()` packs them as create gives
|
|
1330
|
+
them, its own at their longest, and refuses in words with no call where the packed tags pass either bound; create
|
|
1331
|
+
refuses the same words first. A sandbox made before the tags were packed carries its labels as tags, and reads as
|
|
1332
|
+
them (`labels.packed.unpacked`): a listing by name asks for the labels as given beside the packed name, within the
|
|
1333
|
+
one bound, so a request that made one sandbox of each form across an upgrade has both seen and one kept. An Archil
|
|
1334
|
+
computer's mount label records the folder's agent alone, as on every host: the folder's run is the `agentrun.run`
|
|
1335
|
+
label's. `list` is `sandboxes.list({ appId, tags })` over the provider's app: running sandboxes only, and one Modal
|
|
1336
|
+
still lists after its terminate is polled and left out once `poll()` reads it finished.
|
|
1331
1337
|
- **release** `delete` is `terminate()`, and the adapter waits until get answers none (`poll()` reads it finished).
|
|
1332
1338
|
`stop` is refused as `unsupported`: terminate is a sandbox's only end.
|
|
1333
1339
|
- **GPU.** `capabilities().gpu` declares Modal's GPU types by its own names (guide/gpu): `T4`, `L4`, `A10`, `L40S`,
|
|
@@ -2641,11 +2647,18 @@ has ended on its own (its timeout), leaves its request refused `exists`: the pro
|
|
|
2641
2647
|
aborted it) never sends a second create: each POST also writes `agentrun.attempt` (`ATTEMPT_LABEL`), a random value of
|
|
2642
2648
|
its own, and a lost create finds the browsers carrying its attempt label as list does, in every state not ended, under
|
|
2643
2649
|
a signal of its own, releases each under it, and its failure says so; that request is then refused `exists`. Every
|
|
2644
|
-
release a create runs for itself (this one, the newer browser's,
|
|
2650
|
+
release a create runs for itself (this one, the newer browser's, the one after an abort, and that of a browser the
|
|
2651
|
+
vendor made with no usable CDP URL) is bounded by the
|
|
2645
2652
|
provider's `cleanupMs` option (default `RECOVER_MS`, 30 s), never by the caller's signal: one that does not finish in
|
|
2646
2653
|
time fails the create in words that say the browser may still be running, and a retry is answered as above, never
|
|
2647
2654
|
stuck behind it. Another create's browser of the same request, even one another process answered, carries another attempt
|
|
2648
|
-
label and is left running. A
|
|
2655
|
+
label and is left running. A lost create's own browser is left running too, for another create's converge and to its
|
|
2656
|
+
lifetime, when it is the oldest of the request's that runs and the request's browsers, ended ones included, hold a
|
|
2657
|
+
newer one: only another create made that one, and its converge answers the older. Browserbase is asked status by
|
|
2658
|
+
status in a session's own order (pending, then running, then the ended ones), so a session that moves on while a
|
|
2659
|
+
list runs is found in a later answer, never missed; Kernel answers every state in one list. Where the lost create's browser is
|
|
2660
|
+
the request's only one it is released, even when another process's create answered it by its lookup: nothing on the
|
|
2661
|
+
vendor says so. A 4xx refusal made nothing, so nothing is looked for. Both labels are the provider's own:
|
|
2649
2662
|
`check()` refuses them in a spec, and no list or attach shows them.
|
|
2650
2663
|
|
|
2651
2664
|
The conformance CLI runs the browser case set for a provider of kind browser: the health cases, then `browser.*`
|
package/dist/browser.d.ts
CHANGED
|
@@ -96,6 +96,15 @@ export declare function heldBrowser(asked: Record<string, string>, found: Readon
|
|
|
96
96
|
* answers in place of its own once it has released its own. Every process picks the same one from the same listing.
|
|
97
97
|
*/
|
|
98
98
|
export declare function convergedBrowser(listed: ReadonlyArray<HeldBrowser>, mine: HeldBrowser): "mine" | HeldBrowser;
|
|
99
|
+
/**
|
|
100
|
+
* Whether a lost create's browser (`mine`) is left to another create of its request rather than released: it still runs,
|
|
101
|
+
* no older browser of the request runs (so every converge keeps it), and the request's browsers, ended ones included,
|
|
102
|
+
* hold a newer one, which only another create made: that create's converge answers mine. A lost create whose browser is
|
|
103
|
+
* the request's only one releases it.
|
|
104
|
+
*/
|
|
105
|
+
export declare function leftToConverge(mine: string, made: ReadonlyArray<HeldBrowser & {
|
|
106
|
+
live: boolean;
|
|
107
|
+
}>): boolean;
|
|
99
108
|
/**
|
|
100
109
|
* Whether a create that threw may still have made a browser: anything but the vendor's own 4xx answer (a refusal, which
|
|
101
110
|
* makes nothing). A request not answered, aborted, cut short, or answered 5xx or with a body that is no browser may
|
|
@@ -109,10 +118,11 @@ export declare function createUncertain(error: unknown): boolean;
|
|
|
109
118
|
export declare const RECOVER_MS = 30000;
|
|
110
119
|
/**
|
|
111
120
|
* After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
|
|
112
|
-
* of the recovery's own, `ms` in all (the caller's may be what ended the create)
|
|
113
|
-
* the create's failure; they never
|
|
121
|
+
* of the recovery's own, `ms` in all (the caller's may be what ended the create), save one `leave` says another create
|
|
122
|
+
* of the request answers (leftToConverge). The words say what became of them, for the create's failure; they never
|
|
123
|
+
* carry a URL.
|
|
114
124
|
*/
|
|
115
|
-
export declare function recoverCreate(what: string, find: (signal: AbortSignal) => Promise<Result<string[]>>, release: (id: string, signal: AbortSignal) => Promise<Result<void>>, sleep: (ms: number) => Promise<void>, ms?: number): Promise<string>;
|
|
125
|
+
export declare function recoverCreate(what: string, find: (signal: AbortSignal) => Promise<Result<string[]>>, release: (id: string, signal: AbortSignal) => Promise<Result<void>>, sleep: (ms: number) => Promise<void>, ms?: number, leave?: (id: string, signal: AbortSignal) => Promise<boolean>): Promise<string>;
|
|
116
126
|
/**
|
|
117
127
|
* The checks every browser provider makes before a vendor call: the image is chromium, the lifetime is within the
|
|
118
128
|
* vendor's cap (and at least min), the network is open, the labels are ones the vendor's metadata holds, the session's
|
package/dist/browser.js
CHANGED
|
@@ -105,6 +105,20 @@ export function convergedBrowser(listed, mine) {
|
|
|
105
105
|
const kept = holders.sort(oldestBrowserFirst)[0];
|
|
106
106
|
return kept.id === mine.id ? "mine" : kept;
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Whether a lost create's browser (`mine`) is left to another create of its request rather than released: it still runs,
|
|
110
|
+
* no older browser of the request runs (so every converge keeps it), and the request's browsers, ended ones included,
|
|
111
|
+
* hold a newer one, which only another create made: that create's converge answers mine. A lost create whose browser is
|
|
112
|
+
* the request's only one releases it.
|
|
113
|
+
*/
|
|
114
|
+
export function leftToConverge(mine, made) {
|
|
115
|
+
const own = made.find((one) => one.id === mine);
|
|
116
|
+
if (own === undefined || !own.live)
|
|
117
|
+
return false;
|
|
118
|
+
if (made.some((one) => one.id !== mine && one.live && oldestBrowserFirst(one, own) < 0))
|
|
119
|
+
return false;
|
|
120
|
+
return made.some((one) => one.id !== mine && oldestBrowserFirst(own, one) < 0);
|
|
121
|
+
}
|
|
108
122
|
/**
|
|
109
123
|
* Whether a create that threw may still have made a browser: anything but the vendor's own 4xx answer (a refusal, which
|
|
110
124
|
* makes nothing). A request not answered, aborted, cut short, or answered 5xx or with a body that is no browser may
|
|
@@ -123,10 +137,11 @@ const RECOVER_TRIES = 3;
|
|
|
123
137
|
const RECOVER_GAP_MS = 2_000;
|
|
124
138
|
/**
|
|
125
139
|
* After a create whose outcome is unknown: the browsers carrying its create label, found and released under a signal
|
|
126
|
-
* of the recovery's own, `ms` in all (the caller's may be what ended the create)
|
|
127
|
-
* the create's failure; they never
|
|
140
|
+
* of the recovery's own, `ms` in all (the caller's may be what ended the create), save one `leave` says another create
|
|
141
|
+
* of the request answers (leftToConverge). The words say what became of them, for the create's failure; they never
|
|
142
|
+
* carry a URL.
|
|
128
143
|
*/
|
|
129
|
-
export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS) {
|
|
144
|
+
export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS, leave) {
|
|
130
145
|
const signal = AbortSignal.timeout(ms);
|
|
131
146
|
let found = ok([]);
|
|
132
147
|
for (let tries = 0; tries < RECOVER_TRIES; tries++) {
|
|
@@ -142,6 +157,10 @@ export async function recoverCreate(what, find, release, sleep, ms = RECOVER_MS)
|
|
|
142
157
|
return `no ${what} carries its create label, so none was made or the vendor does not list it yet; its labels let a sweep find it`;
|
|
143
158
|
const words = [];
|
|
144
159
|
for (const id of found.value) {
|
|
160
|
+
if (leave !== undefined && (await leave(id, signal))) {
|
|
161
|
+
words.push(`the ${what} it made (${id}) is its request's oldest, which another create of the request answers: it is left running for that create, to its lifetime`);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
145
164
|
const released = await release(id, signal);
|
|
146
165
|
if (released.ok)
|
|
147
166
|
words.push(`the ${what} it made (${id}) was released`);
|
package/dist/browserbase.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare const BROWSERBASE_CDP_DOMAIN = "browserbase.com";
|
|
|
8
8
|
export declare const BROWSERBASE_MAX_LIFETIME_MS: number;
|
|
9
9
|
/** Browserbase's shortest session timeout: 60 s. */
|
|
10
10
|
export declare const BROWSERBASE_MIN_LIFETIME_MS = 60000;
|
|
11
|
+
/** The statuses of a session that runs (PENDING bills once it starts); any other has ended. */
|
|
12
|
+
type SessionStatus = "RUNNING" | "PENDING" | "COMPLETED" | "ERROR" | "TIMED_OUT";
|
|
11
13
|
/** The userMetadata key a label key is written under: each "." as "_", since Browserbase refuses a dot there. */
|
|
12
14
|
export declare const metadataKey: (labelKey: string) => string;
|
|
13
15
|
/** The label key a userMetadata key reads back as: each "_" as ".". */
|
|
@@ -59,7 +61,7 @@ export interface BrowserbaseApi {
|
|
|
59
61
|
/** undefined when Browserbase does not know the session (404). */
|
|
60
62
|
retrieve(id: string, signal?: AbortSignal): Promise<BrowserbaseSession | undefined>;
|
|
61
63
|
list(query: {
|
|
62
|
-
status:
|
|
64
|
+
status: SessionStatus;
|
|
63
65
|
q?: string;
|
|
64
66
|
}, signal?: AbortSignal): Promise<BrowserbaseSession[]>;
|
|
65
67
|
/** "gone" when Browserbase does not know the session (404). */
|
|
@@ -179,3 +181,4 @@ export declare class BrowserbaseProvider implements ComputerProvider, BrowserCom
|
|
|
179
181
|
export declare function create(options: BrowserbaseProviderOptions): BrowserbaseProvider;
|
|
180
182
|
/** The conformance CLI's module for Browserbase: its live switch, its image and its notes. */
|
|
181
183
|
export declare const conformance: () => Promise<typeof import("./conformance/browserbase.js")>;
|
|
184
|
+
export {};
|
package/dist/browserbase.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { readFileSync } from "node:fs";
|
|
22
22
|
import { BROWSERBASE } from "./descriptors/browserbase.js";
|
|
23
23
|
import { BROWSER_IMAGE } from "./descriptors/shared.js";
|
|
24
|
-
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, limitedBytes, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restBytes, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
24
|
+
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, limitedBytes, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, leftToConverge, releaseConfirmed, boundedRelease, restBytes, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
25
25
|
import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
|
|
26
26
|
import { httpsBase } from "./hosted/rest.js";
|
|
27
27
|
import { runLifetimeMs, } from "./provider.js";
|
|
@@ -39,8 +39,16 @@ const CDP_DOMAIN = BROWSERBASE_CDP_DOMAIN;
|
|
|
39
39
|
export const BROWSERBASE_MAX_LIFETIME_MS = 6 * 60 * 60_000;
|
|
40
40
|
/** Browserbase's shortest session timeout: 60 s. */
|
|
41
41
|
export const BROWSERBASE_MIN_LIFETIME_MS = 60_000;
|
|
42
|
-
/** The statuses of a session that runs (PENDING bills once it starts); any other has ended. */
|
|
43
42
|
const LIVE = new Set(["RUNNING", "PENDING"]);
|
|
43
|
+
/** Every status a session reads as, ended ones included: a request's whole record (#leftToConverge). */
|
|
44
|
+
const EVER = new Set([...LIVE, "COMPLETED", "ERROR", "TIMED_OUT"]);
|
|
45
|
+
/**
|
|
46
|
+
* The order #sessions asks for the statuses, a session's own: it is PENDING, then RUNNING, then ended, and never goes
|
|
47
|
+
* back. Each group is asked once the one before has answered, so a session that moves on while the read runs is found
|
|
48
|
+
* by a later group, never missed between two (asked side by side, a session could leave RUNNING after the COMPLETED
|
|
49
|
+
* answer and before the RUNNING one, and be in neither). The ended statuses are asked together: none moves to another.
|
|
50
|
+
*/
|
|
51
|
+
const LIFECYCLE = [["PENDING"], ["RUNNING"], ["COMPLETED", "ERROR", "TIMED_OUT"]];
|
|
44
52
|
/** A label key Browserbase's metadata can carry once its dots are underscores: letters, digits and dots, so the mapping is one to one. */
|
|
45
53
|
const LABEL_KEY = /^[A-Za-z0-9.]+$/;
|
|
46
54
|
/** The userMetadata key a label key is written under: each "." as "_", since Browserbase refuses a dot there. */
|
|
@@ -345,11 +353,11 @@ export class BrowserbaseProvider {
|
|
|
345
353
|
// The session may have been made though its answer never came: found by this POST's attempt label and
|
|
346
354
|
// released, and the request is ended, so it is never made again.
|
|
347
355
|
this.#requests.end(request);
|
|
348
|
-
return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt)}`, causeOf(failed), "browserbase");
|
|
356
|
+
return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt, request)}`, causeOf(failed), "browserbase");
|
|
349
357
|
}
|
|
350
358
|
if (idProblem(made?.id, NAME) !== undefined) {
|
|
351
359
|
this.#requests.end(request);
|
|
352
|
-
return vendorFail("browserbase", `Browserbase POST /v1/sessions answered with no session id, so there is no session to connect to; ${await this.#recover(attempt)}`);
|
|
360
|
+
return vendorFail("browserbase", `Browserbase POST /v1/sessions answered with no session id, so there is no session to connect to; ${await this.#recover(attempt, request)}`);
|
|
353
361
|
}
|
|
354
362
|
this.#requests.made(request);
|
|
355
363
|
// Another process's create of this request may have made one too (#converge): the older is answered.
|
|
@@ -359,9 +367,9 @@ export class BrowserbaseProvider {
|
|
|
359
367
|
this.#requestOf.set(made.id, request);
|
|
360
368
|
const unusable = cdpUrlProblem(made.connectUrl, NAME, CDP_DOMAIN);
|
|
361
369
|
if (unusable !== undefined) {
|
|
362
|
-
// The session is made and billed (keepAlive, up to its timeout): released here,
|
|
363
|
-
const released = await this.release(refOf(made), "delete");
|
|
364
|
-
return vendorFail("browserbase", `Browserbase POST /v1/sessions made a session with no CDP URL to hand over: ${unusable}; ${released.ok ? "the session was released" : `the session was not released (${released.error.
|
|
370
|
+
// The session is made and billed (keepAlive, up to its timeout): released here, under the cleanup's own bound.
|
|
371
|
+
const released = await boundedRelease("session", made.id, this.#cleanupMs, (bound) => this.release(refOf(made), "delete", { signal: bound }));
|
|
372
|
+
return vendorFail("browserbase", `Browserbase POST /v1/sessions made a session with no CDP URL to hand over: ${unusable}; ${released.ok ? "the session was released" : `the session was not released (${released.error.message}), and its labels let a sweep find it`}`);
|
|
365
373
|
}
|
|
366
374
|
this.#urls.set(made.id, made.connectUrl);
|
|
367
375
|
return ok(refOf(made));
|
|
@@ -527,12 +535,18 @@ export class BrowserbaseProvider {
|
|
|
527
535
|
* session, of this request or another, carries an attempt label of its own and is left alone, even one another
|
|
528
536
|
* instance has answered.
|
|
529
537
|
*/
|
|
530
|
-
#recover(labels) {
|
|
538
|
+
#recover(labels, request) {
|
|
531
539
|
const find = async (signal) => {
|
|
532
540
|
const found = await this.#sessions(labels, signal);
|
|
533
541
|
return found.ok ? ok(found.value.map((s) => s.id)) : found;
|
|
534
542
|
};
|
|
535
|
-
|
|
543
|
+
const leave = (id, signal) => this.#leftToConverge(request, id, signal);
|
|
544
|
+
return recoverCreate("session", find, (id, signal) => this.release({ id, name: id }, "delete", { signal }), this.#sleep, this.#cleanupMs, leave);
|
|
545
|
+
}
|
|
546
|
+
/** Whether a lost create's session is left to another create of its request (leftToConverge); a listing that fails releases it. */
|
|
547
|
+
async #leftToConverge(request, id, signal) {
|
|
548
|
+
const made = await this.#sessions({ [CREATE_LABEL]: request }, signal, EVER);
|
|
549
|
+
return made.ok && leftToConverge(id, made.value.map((s) => ({ ...heldOf(s), live: LIVE.has(s.status) })));
|
|
536
550
|
}
|
|
537
551
|
/**
|
|
538
552
|
* Settings' test: one read of the project's running sessions (GET /v1/sessions?status=RUNNING), which makes nothing.
|
|
@@ -567,7 +581,7 @@ export class BrowserbaseProvider {
|
|
|
567
581
|
}
|
|
568
582
|
if (found === undefined)
|
|
569
583
|
return fail("not_found", `no Browserbase session has the id ${id}`);
|
|
570
|
-
if (!LIVE.has(found.status
|
|
584
|
+
if (!LIVE.has(found.status))
|
|
571
585
|
return fail("gone", `the Browserbase session ${id} has ended (${found.status ?? "no status"}): only a running session is attached or connected to`);
|
|
572
586
|
return ok(found);
|
|
573
587
|
}
|
|
@@ -603,9 +617,10 @@ export class BrowserbaseProvider {
|
|
|
603
617
|
/**
|
|
604
618
|
* The running and pending sessions with all of these labels. Browserbase is asked by status and by the first label a
|
|
605
619
|
* query carries as it is; the match is the provider's own, so a lane that drops the query never hands back another's.
|
|
606
|
-
* Both statuses must answer: a release trusts this list.
|
|
620
|
+
* Both statuses must answer: a release trusts this list. `statuses` widens it, to the ended ones too (EVER). The
|
|
621
|
+
* statuses are asked in a session's own order (LIFECYCLE), so every session there when the read starts is found.
|
|
607
622
|
*/
|
|
608
|
-
async #sessions(labels, signal) {
|
|
623
|
+
async #sessions(labels, signal, statuses = LIVE) {
|
|
609
624
|
const problem = browserbaseLabelsProblem(labels);
|
|
610
625
|
if (problem)
|
|
611
626
|
return fail("invalid", problem);
|
|
@@ -613,15 +628,23 @@ export class BrowserbaseProvider {
|
|
|
613
628
|
return fail("invalid", "list and attach take at least one label: a Browserbase project holds sessions this provider did not make");
|
|
614
629
|
const first = Object.entries(labels).find(queryable);
|
|
615
630
|
const q = first === undefined ? undefined : `user_metadata['${metadataKey(first[0])}']:'${first[1]}'`;
|
|
616
|
-
|
|
631
|
+
const found = new Map();
|
|
617
632
|
try {
|
|
618
|
-
|
|
633
|
+
for (const group of LIFECYCLE) {
|
|
634
|
+
const asked = group.filter((status) => statuses.has(status));
|
|
635
|
+
if (asked.length === 0)
|
|
636
|
+
continue;
|
|
637
|
+
const pages = await Promise.all(asked.map((status) => this.#api.list({ status, ...(q === undefined ? {} : { q }) }, signal)));
|
|
638
|
+
for (const s of pages.flat()) {
|
|
639
|
+
if (typeof s?.id === "string" && statuses.has(s.status) && carries(metadataLabels(s.userMetadata), labels) && !found.has(s.id))
|
|
640
|
+
found.set(s.id, s);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
619
643
|
}
|
|
620
644
|
catch (error) {
|
|
621
645
|
return vendorFailure("browserbase", NAME, "GET /v1/sessions", error);
|
|
622
646
|
}
|
|
623
|
-
|
|
624
|
-
return ok(pages.flat().filter((s) => typeof s?.id === "string" && LIVE.has(s.status ?? "") && carries(metadataLabels(s.userMetadata), labels) && !seen.has(s.id) && seen.add(s.id)));
|
|
647
|
+
return ok([...found.values()]);
|
|
625
648
|
}
|
|
626
649
|
async list(labels, { signal } = {}) {
|
|
627
650
|
const found = await this.#sessions(labels, signal);
|
|
Binary file
|
|
Binary file
|
package/dist/computerd.json
CHANGED
package/dist/host.d.ts
CHANGED
|
@@ -266,13 +266,16 @@ export interface HostFacts {
|
|
|
266
266
|
* value together, the adapter's at their longest. Past either, check() refuses, and so create, before any host call.
|
|
267
267
|
* Absent: no bound. packed: the adapter packs the labels it gives create (packLabels, ./hosted/values.ts: one name to
|
|
268
268
|
* list by, the map in parts of at most valueBytes each), unpacks those get and list answer, and asks list for that
|
|
269
|
-
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'.
|
|
269
|
+
* name alone; the host stores and answers them as they are. count and bytes are then the packed labels'. unpacked:
|
|
270
|
+
* the host's machines may also carry their labels as given (made before it packed): one with no packed map reads as
|
|
271
|
+
* its stored labels, and a listing by name asks for the labels as given beside the packed name.
|
|
270
272
|
*/
|
|
271
273
|
labels?: {
|
|
272
274
|
count?: number;
|
|
273
275
|
bytes?: number;
|
|
274
276
|
packed?: {
|
|
275
277
|
valueBytes?: number;
|
|
278
|
+
unpacked?: true;
|
|
276
279
|
};
|
|
277
280
|
};
|
|
278
281
|
/**
|
|
@@ -184,7 +184,9 @@ export declare class HostedProvider implements ComputerProvider {
|
|
|
184
184
|
/**
|
|
185
185
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
186
186
|
* may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
|
|
187
|
-
* its machines' labels unpacked.
|
|
187
|
+
* its machines' labels unpacked. A listing by name on a host whose machines may also carry their labels as given
|
|
188
|
+
* (facts.labels.packed.unpacked) asks both ways, one after the other within ms together, and answers every machine
|
|
189
|
+
* either finds: across an upgrade one request can make one machine of each form, and convergence must see both.
|
|
188
190
|
*/
|
|
189
191
|
export declare function listedBy(host: MachineHost, what: string, labels: Record<string, string>, ms: number, signal?: AbortSignal): Promise<Result<Machine[]>>;
|
|
190
192
|
/**
|
package/dist/hosted/provider.js
CHANGED
|
@@ -1772,18 +1772,38 @@ function packedRoom(host) {
|
|
|
1772
1772
|
const room = host.facts.labels;
|
|
1773
1773
|
return room?.packed ? room : undefined;
|
|
1774
1774
|
}
|
|
1775
|
-
/**
|
|
1776
|
-
|
|
1775
|
+
/**
|
|
1776
|
+
* A machine as the host read it, with a packed host's labels unpacked. One that holds no packed map has none (not the
|
|
1777
|
+
* adapter's), or its stored labels on a host whose machines may carry them as given (facts.labels.packed.unpacked).
|
|
1778
|
+
*/
|
|
1779
|
+
function unpacked(host, machine) {
|
|
1780
|
+
const room = packedRoom(host);
|
|
1781
|
+
if (room === undefined)
|
|
1782
|
+
return machine;
|
|
1783
|
+
return { ...machine, labels: unpackLabels(machine.labels) ?? (room.packed?.unpacked ? machine.labels : {}) };
|
|
1784
|
+
}
|
|
1777
1785
|
/**
|
|
1778
1786
|
* The host's listing by labels, bounded by ms: only the machines that carry every one of them, since a vendor's listing
|
|
1779
1787
|
* may answer more (MachineHost.list). A packed host is asked for PACKED_NAME alone, the name's where one is asked, and
|
|
1780
|
-
* its machines' labels unpacked.
|
|
1788
|
+
* its machines' labels unpacked. A listing by name on a host whose machines may also carry their labels as given
|
|
1789
|
+
* (facts.labels.packed.unpacked) asks both ways, one after the other within ms together, and answers every machine
|
|
1790
|
+
* either finds: across an upgrade one request can make one machine of each form, and convergence must see both.
|
|
1781
1791
|
*/
|
|
1782
1792
|
export async function listedBy(host, what, labels, ms, signal) {
|
|
1783
1793
|
const name = labels[NAME_LABEL];
|
|
1784
|
-
const
|
|
1785
|
-
const
|
|
1786
|
-
|
|
1794
|
+
const room = packedRoom(host);
|
|
1795
|
+
const asks = room === undefined ? [labels] : name === undefined ? [{}] : room.packed?.unpacked ? [{ [PACKED_NAME]: name }, labels] : [{ [PACKED_NAME]: name }];
|
|
1796
|
+
const until = Date.now() + ms;
|
|
1797
|
+
const found = new Map();
|
|
1798
|
+
for (const asked of asks) {
|
|
1799
|
+
const listed = await hostCall(host, what, (ctx) => host.list(asked, ctx), Math.max(1, until - Date.now()), signal);
|
|
1800
|
+
if (!listed.ok)
|
|
1801
|
+
return listed;
|
|
1802
|
+
for (const machine of listed.value)
|
|
1803
|
+
if (!found.has(machine.id))
|
|
1804
|
+
found.set(machine.id, unpacked(host, machine));
|
|
1805
|
+
}
|
|
1806
|
+
return ok([...found.values()].filter((machine) => carries(machine, labels)));
|
|
1787
1807
|
}
|
|
1788
1808
|
/** Whether a machine carries every one of these labels. */
|
|
1789
1809
|
const carries = (machine, labels) => Object.entries(labels).every(([key, value]) => machine.labels?.[key] === value);
|
package/dist/kernel.js
CHANGED
|
@@ -20,7 +20,7 @@ import { randomBytes } from "node:crypto";
|
|
|
20
20
|
import { readFileSync } from "node:fs";
|
|
21
21
|
import { KERNEL } from "./descriptors/kernel.js";
|
|
22
22
|
import { BROWSER_IMAGE } from "./descriptors/shared.js";
|
|
23
|
-
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
23
|
+
import { cdpUrlProblem, browserClient, browserHello, BrowserVendorError, CREATE_LABEL, carries, causeOf, checkBrowser, createUncertain, DEFAULT_CONFIRM, ATTEMPT_LABEL, convergedBrowser, heldBrowser, newAttempt, defaultSleep, idProblem, labelsOf, labelsProblem, memoryUrls, pointerOk, queryable, RECOVER_MS, recoverCreate, leftToConverge, releaseConfirmed, boundedRelease, restCall, causedFail, vendorFailure, withoutCreateLabel, } from "./browser.js";
|
|
24
24
|
import { CreateRequests, endedWords, labelsDiffer, otherSpecWords } from "./create-requests.js";
|
|
25
25
|
import { httpsBase } from "./hosted/rest.js";
|
|
26
26
|
import { runLifetimeMs, } from "./provider.js";
|
|
@@ -173,7 +173,7 @@ export class KernelProvider {
|
|
|
173
173
|
// The browser may have been made though its answer never came: found by this POST's attempt label and deleted,
|
|
174
174
|
// and the request is ended, so it is never made again.
|
|
175
175
|
this.#requests.end(request);
|
|
176
|
-
return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt)}`, causeOf(failed), "kernel");
|
|
176
|
+
return causedFail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt, request)}`, causeOf(failed), "kernel");
|
|
177
177
|
}
|
|
178
178
|
const browser = (made.json ?? {});
|
|
179
179
|
const id = text(browser.session_id);
|
|
@@ -185,7 +185,7 @@ export class KernelProvider {
|
|
|
185
185
|
if (failed.ok)
|
|
186
186
|
return failed;
|
|
187
187
|
this.#requests.end(request);
|
|
188
|
-
return fail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt)}`);
|
|
188
|
+
return fail(failed.error.code, `${failed.error.message}; ${await this.#recover(attempt, request)}`);
|
|
189
189
|
}
|
|
190
190
|
this.#requests.made(request);
|
|
191
191
|
// Another process's create of this request may have made one too (#converge): the older is answered.
|
|
@@ -195,9 +195,9 @@ export class KernelProvider {
|
|
|
195
195
|
this.#requestOf.set(id, request);
|
|
196
196
|
const unusable = cdpUrlProblem(url, NAME, CDP_DOMAIN);
|
|
197
197
|
if (unusable !== undefined) {
|
|
198
|
-
// The browser is made and billed until its idle timeout: deleted here,
|
|
199
|
-
const released = await this.release(refOf(id), "delete");
|
|
200
|
-
return vendorFail("kernel", `Kernel POST /browsers made a browser with no CDP URL to hand over: ${unusable}; ${released.ok ? "the browser was released" : `the browser was not released (${released.error.
|
|
198
|
+
// The browser is made and billed until its idle timeout: deleted here, under the cleanup's own bound.
|
|
199
|
+
const released = await boundedRelease("browser", id, this.#cleanupMs, (bound) => this.release(refOf(id), "delete", { signal: bound }));
|
|
200
|
+
return vendorFail("kernel", `Kernel POST /browsers made a browser with no CDP URL to hand over: ${unusable}; ${released.ok ? "the browser was released" : `the browser was not released (${released.error.message}), and its tags let a sweep find it`}`);
|
|
201
201
|
}
|
|
202
202
|
this.#urls.set(id, url);
|
|
203
203
|
const live = text(browser.browser_live_view_url);
|
|
@@ -318,12 +318,18 @@ export class KernelProvider {
|
|
|
318
318
|
* another, carries an attempt label of its own and is left alone, even one another instance has answered. #browsers
|
|
319
319
|
* reads every state not deleted, so a browser still starting is found and released too.
|
|
320
320
|
*/
|
|
321
|
-
#recover(labels) {
|
|
321
|
+
#recover(labels, request) {
|
|
322
322
|
const find = async (signal) => {
|
|
323
323
|
const found = await this.#browsers(labels, signal);
|
|
324
324
|
return found.ok ? ok(found.value.map((b) => b.id)) : found;
|
|
325
325
|
};
|
|
326
|
-
|
|
326
|
+
const leave = (id, signal) => this.#leftToConverge(request, id, signal);
|
|
327
|
+
return recoverCreate("browser", find, (id, signal) => this.release(refOf(id), "delete", { signal }), this.#sleep, this.#cleanupMs, leave);
|
|
328
|
+
}
|
|
329
|
+
/** Whether a lost create's browser is left to another create of its request (leftToConverge); a listing that fails releases it. */
|
|
330
|
+
async #leftToConverge(request, id, signal) {
|
|
331
|
+
const made = await this.#browsers({ [CREATE_LABEL]: request }, signal, true);
|
|
332
|
+
return made.ok && leftToConverge(id, made.value.map((row) => ({ ...heldOf(row), live: row.deleted === undefined })));
|
|
327
333
|
}
|
|
328
334
|
/**
|
|
329
335
|
* Settings' test: one page of the organization's active browsers (GET /browsers?status=active), which makes nothing.
|
|
@@ -403,9 +409,9 @@ export class KernelProvider {
|
|
|
403
409
|
* browser still starting, which bills), and a row with deleted_at is dropped here; so list and attach show a starting
|
|
404
410
|
* browser, as Browserbase lists a PENDING session, and a lost create's recovery misses none. The match is the
|
|
405
411
|
* provider's own, so a lane that drops the filter never hands back another's. A page that cannot be read fails the
|
|
406
|
-
* whole list: a release trusts it.
|
|
412
|
+
* whole list: a release trusts it. `withDeleted` keeps the deleted rows too, marked deleted (#leftToConverge).
|
|
407
413
|
*/
|
|
408
|
-
async #browsers(labels, signal) {
|
|
414
|
+
async #browsers(labels, signal, withDeleted = false) {
|
|
409
415
|
const problem = labelsProblem(labels);
|
|
410
416
|
if (problem)
|
|
411
417
|
return fail("invalid", problem);
|
|
@@ -431,10 +437,10 @@ export class KernelProvider {
|
|
|
431
437
|
return vendorFailure("kernel", NAME, call, new BrowserVendorError(NAME, call, page.status, "not_a_list"));
|
|
432
438
|
for (const row of page.json) {
|
|
433
439
|
const id = text(row?.session_id);
|
|
434
|
-
if (id !== "" && !row.deleted_at && carries(row.tags, labels) && !seen.has(id)) {
|
|
440
|
+
if (id !== "" && (withDeleted || !row.deleted_at) && carries(row.tags, labels) && !seen.has(id)) {
|
|
435
441
|
seen.add(id);
|
|
436
442
|
const createdAt = text(row.created_at);
|
|
437
|
-
found.push({ id, tags: withoutCreateLabel(labelsOf(row.tags)), ...(createdAt === "" ? {} : { createdAt }) });
|
|
443
|
+
found.push({ id, tags: withoutCreateLabel(labelsOf(row.tags)), ...(createdAt === "" ? {} : { createdAt }), ...(row.deleted_at ? { deleted: true } : {}) });
|
|
438
444
|
}
|
|
439
445
|
}
|
|
440
446
|
if (page.headers.get("x-has-more") !== "true")
|
package/dist/modal.js
CHANGED
|
@@ -143,7 +143,9 @@ class ModalHost {
|
|
|
143
143
|
windowManager: true,
|
|
144
144
|
// Never root: each connection is Modal's exec of the stdio bridge, as Modal's root, outside the daemon.
|
|
145
145
|
user: ["uid"],
|
|
146
|
-
|
|
146
|
+
// Packed: the server's labels (a mount, a network list, an owner, a run and its deadlines) pass 512 bytes as they
|
|
147
|
+
// are. A value holds 64 KiB, so the map is one tag. Sandboxes made before packing carry their tags as given.
|
|
148
|
+
labels: { count: MAX_TAGS, bytes: MAX_TAG_BYTES, packed: { unpacked: true } },
|
|
147
149
|
};
|
|
148
150
|
if (connect === "exec")
|
|
149
151
|
this.exec = (id, argv, ctx) => this.#exec(id, argv, ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcha/agentrun-computer",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.61",
|
|
4
4
|
"description": "The open platform's computer protocol: a daemon in every computer, and one provisioner per vendor, starting with Docker.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentrun",
|