@parcha/agentrun-computer 0.1.0-beta.48 → 0.1.0-beta.50

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 CHANGED
@@ -452,7 +452,7 @@ in the kernel's tool registry, keyed by these groups.
452
452
  | id | label | kinds | keys (required unless marked) | mounts | metered |
453
453
  | --- | --- | --- | --- | --- | --- |
454
454
  | docker | Docker | sandbox, desktop | none | bind | no |
455
- | daytona | Daytona | sandbox | `DAYTONA_API_KEY`; `DAYTONA_API_URL`, `DAYTONA_TARGET`, `DAYTONA_ARCHIL_EGRESS` (optional) | none (`unmounted`: archil); archil with `DAYTONA_ARCHIL_EGRESS` (`mountsWith`) | yes |
455
+ | daytona | Daytona | sandbox | `DAYTONA_API_KEY`; `DAYTONA_API_URL`, `DAYTONA_TARGET`, `DAYTONA_ARCHIL_EGRESS`, `DAYTONA_ATTACH_EGRESS` (optional) | none (`unmounted`: archil); archil with `DAYTONA_ARCHIL_EGRESS` (`mountsWith`) | yes |
456
456
  | modal | Modal | sandbox | `MODAL_TOKEN_ID`, `MODAL_TOKEN_SECRET` | archil | yes |
457
457
  | e2b | E2B | sandbox, desktop | `E2B_API_KEY` | archil | yes |
458
458
  | orgo | Orgo | desktop (Linux; Windows and macOS with `os`) | `ORGO_API_KEY` | none | yes |
@@ -1582,6 +1582,11 @@ the TTL.
1582
1582
  own namespace (`agentrun.computer`), `cpus`, `memoryMb` or `pids` (a snapshot's size is its own), `user`, `workdir`
1583
1583
  (the daemon works in `/work`), a GPU computer's snapshot other than the GPU snapshot or `"default"`, and any other
1584
1584
  field.
1585
+ - What the computer was given is the sandbox's own: `create` answers `resources` (`CreatedComputer.resources`) with
1586
+ the `cpu`, `memory` (GiB, as `memoryMb`), `disk` (GiB, as `diskGb`) and GPUs (`gpu` and `gpuType`) Daytona's read of
1587
+ the running sandbox says, each only where it says it. These are the figures Daytona bills by, and a host prices
1588
+ computer time by them (serve's `AGENTRUN_COMPUTE_USD_PER_*` settings). E2B's create answers its `getInfo`'s `cpuCount`
1589
+ and `memoryMB` the same way, and Fly's its machine guest's `cpus` and `memory_mb`; any other provider answers none.
1585
1590
  - `create(spec, { requestId })` names the computer `computer-<12 hex digits of sha256(requestId)>` and lists that name
1586
1591
  first: a retry of the same request finds the computer the first one made (the adapter's idempotent create,
1587
1592
  [PROVIDERS.md](PROVIDERS.md)). It sends `POST /sandbox` with that name, the snapshot (none for `"default"`), the
@@ -1708,14 +1713,19 @@ What each part of a dial sandbox rests on:
1708
1713
  ([api snapshot.service.ts:883-901](https://github.com/daytonaio/daytona/blob/b5a5d9e7/apps/api/src/sandbox/services/snapshot.service.ts#L883-L901)),
1709
1714
  so `box/build-daytona.py` names the Dockerfile's CMD as the snapshot's `entrypoint`. The box snapshots it built
1710
1715
  before, `agentrun-archil-<recipe hash>`, have none and never dial, so the snapshot it builds now has a name of its
1711
- own, `agentrun-box-<recipe hash>`, which no snapshot without the entrypoint holds. (The Dockerfile's comment that Daytona runs its
1712
- CMD is wrong; it stays until the recipe next changes, since editing it changes the hash.)
1716
+ own, `agentrun-box-<recipe hash>`, which no snapshot without the entrypoint holds.
1713
1717
  - **Outbound https, by tier.** Tier 1 and 2 organizations reach "essential services" alone, and those leave out shared
1714
1718
  hosting domains; Tier 3 and 4 have full access
1715
1719
  ([docs: tier-based network restrictions](https://www.daytona.io/docs/en/network-limits.md#tier-based-network-restrictions)).
1716
1720
  A server on such a domain (`*.onrender.com`) is out of a Tier 1 or 2 sandbox's reach unless Daytona adds that exact
1717
1721
  host to the list ([docs: essential services](https://www.daytona.io/docs/en/network-limits.md#essential-services)).
1718
1722
  **Unverified**: our organization's tier, and a dial from it.
1723
+ - **A target that reaches listed addresses alone: `attachEgress`.** A self-hosted target whose runners drop every
1724
+ sandbox connection outside an allow list never reaches a public server. Give the operator's relay on that list as
1725
+ `attachEgress` (`DAYTONA_ATTACH_EGRESS` in Settings), `<IPv4 relay>:<port>`, checked at construction: create puts it
1726
+ in the boot env as `AGENTRUN_ATTACH_EGRESS`, and `agentrun-dial`'s daemon fetch (curl `--connect-to`) and
1727
+ `computerd attach` both open TCP to it and speak TLS and HTTP to the public host through it, so the SNI, the
1728
+ certificate checked and `Host` stay the public host's and TLS is end to end. Unset, nothing changes.
1719
1729
  - **No GPU on dial**, refused in words: `daytona-gpu` holds no `agentrun-dial`, and Daytona runs a GPU sandbox
1720
1730
  unprivileged (`Privileged: gpuIndex == nil`,
1721
1731
  [runner container_configs.go:205](https://github.com/daytonaio/daytona/blob/b5a5d9e7/apps/runner/pkg/docker/container_configs.go#L205)),
@@ -1897,16 +1907,11 @@ E2B's envd is the sandbox's first process, a systemd service with `Restart=alway
1897
1907
  whose start answers after the call gave up on it (its bound passed, or the caller aborted) is killed as it lands.
1898
1908
  6. A desktop's X server, `Xvfb :0 -screen 0 1280x800x24 -nolisten tcp`, starts through the daemon with
1899
1909
  `process.start`, as the computer's user, and create waits until hello declares the display (`src/desktop.ts`,
1900
- shared with Docker). Then xfwm4, which the template has, starts on it (`xfwm4 --compositor=off
1901
- --sm-client-disable`), so the apps an agent opens are framed and focused: computerd starts it itself, asked by
1902
- init's `--window-manager` (the host's facts say `windowManager`), once the display answers, and hello's
1903
- `windowManager` says it runs, which create waits on. xfwm4 reads its settings over a session bus and exits without
1904
- one. So it runs under `dbus-run-session`, as the computer's user, in a network namespace of its own that init makes
1905
- as root before it drops to that user (no user namespace is needed), and its bus listens on an abstract name there,
1906
- which a program of the computer's user cannot connect to. One that joins that namespace (nsenter) can, as the same
1907
- uid can ptrace xfwm4. xfwm4 reaches the display by its path. An older computerd, whose hello has no
1908
- `windowManager`, gets the manager through `process.start`, as before (`WINDOW_MANAGER`, under `unshare --user
1909
- --map-current-user --net`). It and every app `apps.launch` opens get `NO_AT_BRIDGE=1`: the template has at-spi2-core, so GTK's
1910
+ shared with Docker). Then computerd starts xfwm4 itself (init `--window-manager`, where the host's facts say
1911
+ `windowManager`; see `daemon/internal/windowmanager`) on a session bus of its own, in a network namespace root
1912
+ made, so the apps an agent opens are framed and focused; hello's `windowManager` says it runs, which create waits
1913
+ on. A program of the user can't join it: root made it, and the user holds no capability there; the same uid may
1914
+ still ptrace xfwm4. It and every app `apps.launch` opens get `NO_AT_BRIDGE=1`: the template has at-spi2-core, so GTK's
1910
1915
  accessibility bridge would start an at-spi bus, a socket of the user's at `/work/.cache/at-spi/bus_0` that nothing
1911
1916
  of ours uses. An app also gets no session bus (`DBUS_SESSION_BUS_ADDRESS=disabled:`). Given none, it would start
1912
1917
  one with the template's dbus-launch, and that bus starts gnome-keyring-daemon, a socket of the user's at
@@ -2475,6 +2480,12 @@ kind browser that declares them.
2475
2480
  | `profile` | a context: `browserSettings.context { id, persist }` | a profile by name: `profile { name, save_changes }`, made first if Kernel does not know it | not declared |
2476
2481
  | `profiles { create, remove }` | `POST /v1/contexts`, `DELETE /v1/contexts/{id}` | `POST /profiles` under a random name (the pointer), `DELETE /profiles/{name}` | none |
2477
2482
  | `downloads { list, read }` | `GET /v1/downloads?sessionId=` (paged), `GET /v1/downloads/{id}`, cut at `maxBytes` | none | none |
2483
+ | `sessionUsage(ref)` | `GET /v1/sessions/{id}`: its `startedAt`, `endedAt` and `proxyBytes` | none | none |
2484
+
2485
+ `sessionUsage(ref)` is the vendor's own record of a session, for a host that reconciles its own measure of a session's
2486
+ time with the vendor's bill: `{ startedAt, endedAt, proxyBytes }`, each null where the vendor's answer does not hold a
2487
+ well-formed one (a session still running has no end), never a zero in its place; undefined for a session the vendor
2488
+ does not know. A host reads it once, when it lets the session go.
2478
2489
 
2479
2490
  A pointer is a capability: whoever holds it opens the profile, so no error's words carry one.
2480
2491
 
package/box/Dockerfile CHANGED
@@ -36,7 +36,7 @@ COPY agentrun-archil /tmp/agentrun-box/agentrun-archil
36
36
  RUN sh /tmp/agentrun-box/install.sh && rm -rf /tmp/agentrun-box
37
37
 
38
38
  USER root
39
- # A computer's first process is its provider's own (Daytona's runs this when a snapshot names no entrypoint; Modal's and
40
- # E2B's are their own): never the base image's python. A machine whose create set AGENTRUN_ATTACH_URL dials the server
41
- # instead (install.sh's agentrun-dial).
39
+ # A computer's first process is its provider's own (Daytona's toolbox, Modal's and E2B's own), never the base image's
40
+ # python. Daytona never runs an image's CMD, only a snapshot's entrypoint, so box/build-daytona.py names this CMD as
41
+ # the snapshot's. A machine whose create set AGENTRUN_ATTACH_URL dials the server instead (install.sh's agentrun-dial).
42
42
  CMD ["sh", "-c", "[ -z \"${AGENTRUN_ATTACH_URL-}\" ] || exec agentrun-dial; exec sleep infinity"]
package/box/install.sh CHANGED
@@ -75,8 +75,10 @@ dial() {
75
75
  # where the provider's exec install puts it, starts `computerd init` as that start does, in a clean environment without
76
76
  # the token (with DISPLAY, for a desktop), and becomes `computerd attach` with the attach URL and the token alone in its environment. Before init, it
77
77
  # gives /workspace to init's user (its --user), 0700, where a synced folder's runner pushes the run's folder. A daemon
78
- # whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. Exits 2 for env missing, 3 when the fetch
79
- # failed, 4 for a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
78
+ # whose sha256 is not AGENTRUN_DAEMON_SHA256 is removed, and nothing runs. With AGENTRUN_ATTACH_EGRESS, the operator's
79
+ # relay (<IPv4>:<port>), the fetch and attach's dial both connect to the relay and speak TLS and HTTP to the URL's host
80
+ # through it, and attach is given it too. Exits 2 for env missing or a malformed relay, 3 when the fetch failed, 4 for
81
+ # a sha256 mismatch, 5 when init never listened, 6 when /workspace was not made init's user's; else it is
80
82
  # `computerd attach` and exits as it does.
81
83
  set -euf
82
84
  DAEMON=/opt/agentrun/computerd
@@ -89,6 +91,16 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
89
91
  for v in AGENTRUN_ATTACH_URL AGENTRUN_ATTACH_TOKEN AGENTRUN_DAEMON_URL AGENTRUN_DAEMON_SHA256 AGENTRUN_INIT_ARGS; do
90
92
  eval "[ -n \"\${$v-}\" ]" || { echo "agentrun-dial: $v is not set; the provider's create sets it" >&2; exit 2; }
91
93
  done
94
+ # The operator's relay, where the machine reaches the server only through it (a provider's attach egress): curl connects
95
+ # there and speaks TLS and HTTP to the URL's host as it would directly (--connect-to keeps the SNI, the certificate check
96
+ # and the Host header the URL's). Digits, dots and colons alone, so it splits into exactly curl's two words; attach
97
+ # checks its shape whole.
98
+ relay=
99
+ case "${AGENTRUN_ATTACH_EGRESS-}" in
100
+ "") ;;
101
+ *[!0-9.:]*) echo "agentrun-dial: AGENTRUN_ATTACH_EGRESS is the relay's <IPv4>:<port>; the provider's create sets it" >&2; exit 2 ;;
102
+ *) relay="--connect-to ::$AGENTRUN_ATTACH_EGRESS" ;;
103
+ esac
92
104
  # init's user, uid:gid, from its --user: /workspace is that user's alone, never a link.
93
105
  user=
94
106
  set -- $AGENTRUN_INIT_ARGS
@@ -107,8 +119,8 @@ chmod 0700 "$SOCKET_DIR"
107
119
  rm -f "$DAEMON.part"
108
120
  # The token goes to curl on its stdin, never on a command line, which every user may read in /proc.
109
121
  printf 'Authorization: Bearer %s\n' "$AGENTRUN_ATTACH_TOKEN" |
110
- curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
111
- { echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL failed" >&2; rm -f "$DAEMON.part"; exit 3; }
122
+ curl -fsS --connect-timeout 10 --retry 10 --retry-connrefused --retry-max-time 300 $relay -H @- -o "$DAEMON.part" "$AGENTRUN_DAEMON_URL" ||
123
+ { echo "agentrun-dial: fetching the daemon from $AGENTRUN_DAEMON_URL${relay:+ through $AGENTRUN_ATTACH_EGRESS} failed" >&2; rm -f "$DAEMON.part"; exit 3; }
112
124
  sum=$(sha256sum "$DAEMON.part" | cut -c1-64)
113
125
  if [ "$sum" != "$AGENTRUN_DAEMON_SHA256" ]; then
114
126
  rm -f "$DAEMON.part"
@@ -128,9 +140,10 @@ until [ -S "$SOCKET_DIR/computerd.sock" ]; do
128
140
  [ "$i" -le 300 ] || { echo "agentrun-dial: init did not listen at $SOCKET_DIR/computerd.sock within 30 s; its log:" >&2; cat "$INIT_LOG" >&2; exit 5; }
129
141
  sleep 0.1
130
142
  done
131
- # attach's environment: the URL and token alone (it dials init at its default socket, SOCKET_DIR's).
143
+ # attach's environment: the URL and token alone, and the relay when given (it dials init at its default socket,
144
+ # SOCKET_DIR's).
132
145
  for v in $(env | sed -n 's/^\([A-Za-z_][A-Za-z0-9_]*\)=.*/\1/p'); do
133
- case "$v" in AGENTRUN_ATTACH_URL | AGENTRUN_ATTACH_TOKEN | DAEMON) ;; *) unset "$v" 2>/dev/null || : ;; esac
146
+ case "$v" in AGENTRUN_ATTACH_URL | AGENTRUN_ATTACH_TOKEN | AGENTRUN_ATTACH_EGRESS | DAEMON) ;; *) unset "$v" 2>/dev/null || : ;; esac
134
147
  done
135
148
  exec "$DAEMON" attach
136
149
  EOF
package/dist/attach.d.ts CHANGED
@@ -5,6 +5,15 @@ import { type Result } from "./result.js";
5
5
  export declare const ATTACH_PATH = "/v2/computers/attach";
6
6
  /** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
7
7
  export declare const DAEMON_PATH = "/v2/computers/daemon";
8
+ /** The boot env name of a dial machine's attach egress (HostedOptions.attachEgress), which agentrun-dial and computerd attach read. */
9
+ export declare const ATTACH_EGRESS_ENV = "AGENTRUN_ATTACH_EGRESS";
10
+ /**
11
+ * Reads an attach egress, `<IPv4 relay>:<port>` such as 192.0.2.40:18443: the operator's relay a dial machine opens TCP
12
+ * to in place of the public host, for its daemon fetch and its attach socket alike, speaking TLS and HTTP to the public
13
+ * host through it (the SNI, the certificate checked and the Host header stay the public host's). computerd attach holds
14
+ * it to the same shape. Anything else throws, in words.
15
+ */
16
+ export declare function attachEgressOf(text: string): string;
8
17
  /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
9
18
  export declare const ATTACH_SUBPROTOCOL = "agentrun.computer.0.2";
10
19
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
package/dist/attach.js CHANGED
@@ -15,6 +15,20 @@ import { fail, ok } from "./result.js";
15
15
  export const ATTACH_PATH = "/v2/computers/attach";
16
16
  /** Where a hosted machine that dials fetches the server's computerd for its arch (?arch=amd64|arm64), with its token. */
17
17
  export const DAEMON_PATH = "/v2/computers/daemon";
18
+ /** The boot env name of a dial machine's attach egress (HostedOptions.attachEgress), which agentrun-dial and computerd attach read. */
19
+ export const ATTACH_EGRESS_ENV = "AGENTRUN_ATTACH_EGRESS";
20
+ const ATTACH_EGRESS = /^(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d):(?:[1-9]\d{0,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/;
21
+ /**
22
+ * Reads an attach egress, `<IPv4 relay>:<port>` such as 192.0.2.40:18443: the operator's relay a dial machine opens TCP
23
+ * to in place of the public host, for its daemon fetch and its attach socket alike, speaking TLS and HTTP to the public
24
+ * host through it (the SNI, the certificate checked and the Host header stay the public host's). computerd attach holds
25
+ * it to the same shape. Anything else throws, in words.
26
+ */
27
+ export function attachEgressOf(text) {
28
+ if (!ATTACH_EGRESS.test(text))
29
+ throw new Error(`the attach egress is <IPv4 relay>:<port>, such as 192.0.2.40:18443, a port from 1 to 65535; not ${JSON.stringify(text)}`);
30
+ return text;
31
+ }
18
32
  /** The WebSocket subprotocol a driver asks for: the protocol version it speaks. Serve answers with it or refuses. */
19
33
  export const ATTACH_SUBPROTOCOL = `agentrun.computer.${PROTOCOL_VERSION}`;
20
34
  /** Each side pings this often (WebSocket ping frames, not JSON-RPC), so a NAT keeps the path open. */
package/dist/browser.d.ts CHANGED
@@ -181,13 +181,26 @@ export interface BrowserDownloads {
181
181
  /** The file's bytes, streamed; the stream fails in words once it passes maxBytes. */
182
182
  read(ref: ComputerRef, name: string, maxBytes: number, context?: CallContext): Promise<Result<AsyncIterable<Uint8Array>>>;
183
183
  }
184
+ /**
185
+ * A session as its vendor itself records it, for a host that reconciles its own measure of a session with the vendor's
186
+ * bill: when the vendor says the session started and ended, and the bytes it moved through the vendor's proxy. Each
187
+ * field is null where the vendor's record does not say it (a session still running has no end; a vendor that reports no
188
+ * proxy traffic has no bytes), never a zero standing in for one.
189
+ */
190
+ export interface BrowserSessionUsage {
191
+ startedAt: string | null;
192
+ endedAt: string | null;
193
+ proxyBytes: number | null;
194
+ }
184
195
  /**
185
196
  * A provider of browsers, with the members its features may bring: profiles where capabilities().browser declares
186
- * profiles, downloads where it declares downloads.
197
+ * profiles, downloads where it declares downloads. sessionUsage, where the vendor keeps a record of each session it ran:
198
+ * that record, read once (a host reads it when the session is let go); undefined for a session the vendor does not know.
187
199
  */
188
200
  export interface BrowserComputerProvider extends ComputerProvider {
189
201
  readonly profiles?: BrowserProfiles;
190
202
  readonly downloads?: BrowserDownloads;
203
+ sessionUsage?(ref: ComputerRef, context?: CallContext): Promise<Result<BrowserSessionUsage | undefined>>;
191
204
  }
192
205
  /** Whether a provider is a browser provider: its capabilities are of kind browser and declare its sessions' features. */
193
206
  export declare function isBrowserProvider(provider: ComputerProvider): provider is BrowserComputerProvider;
@@ -1,4 +1,4 @@
1
- import { type BrowserComputerProvider, type BrowserDownloads, type BrowserProfiles, type BrowserStream, type ReleaseConfirm } from "./browser.js";
1
+ import { type BrowserComputerProvider, type BrowserDownloads, type BrowserProfiles, type BrowserSessionUsage, type BrowserStream, type ReleaseConfirm } from "./browser.js";
2
2
  import { type AttachedComputer, type CallContext, type ComputerCapabilities, type ComputerConnection, type ComputerInfo, type ComputerProvider, type ComputerRef, type ComputerSpec, type CreateContext, type CreatedComputer, type NetworkPolicy, type NetworkSpec, type Refusal, type ReleaseHow } from "./provider.js";
3
3
  import { type Result } from "./result.js";
4
4
  export declare const BROWSERBASE_API_URL = "https://api.browserbase.com";
@@ -22,6 +22,11 @@ export interface BrowserbaseSession {
22
22
  connectUrl?: string;
23
23
  userMetadata?: Record<string, unknown>;
24
24
  expiresAt?: string;
25
+ /** When the session started and ended, as Browserbase records them (no end while it runs). */
26
+ startedAt?: string;
27
+ endedAt?: string;
28
+ /** The bytes the session moved through Browserbase's proxy. */
29
+ proxyBytes?: number;
25
30
  }
26
31
  /** A session's live view as GET /v1/sessions/{id}/debug answers it: every URL in it is a secret. */
27
32
  export interface BrowserbaseDebug {
@@ -120,6 +125,11 @@ export declare class BrowserbaseProvider implements ComputerProvider, BrowserCom
120
125
  * unless declared.
121
126
  */
122
127
  create(spec: ComputerSpec, context: CreateContext): Promise<Result<CreatedComputer>>;
128
+ /**
129
+ * The session as Browserbase records it (GET /v1/sessions/{id}): its start, its end and its proxy bytes, each null where
130
+ * the answer does not hold a well-formed one. undefined for a session Browserbase does not know (404).
131
+ */
132
+ sessionUsage(ref: ComputerRef, { signal }?: CallContext): Promise<Result<BrowserSessionUsage | undefined>>;
123
133
  /**
124
134
  * Settings' test: one read of the project's running sessions (GET /v1/sessions?status=RUNNING), which makes nothing.
125
135
  * A refused key is unauthorized and a Browserbase not reached unreachable; the words name the call, never the key.
@@ -316,6 +316,27 @@ export class BrowserbaseProvider {
316
316
  }
317
317
  return vendorFail("browserbase", `Browserbase kept answering more pages of downloads past ${MAX_PAGES}`);
318
318
  }
319
+ /**
320
+ * The session as Browserbase records it (GET /v1/sessions/{id}): its start, its end and its proxy bytes, each null where
321
+ * the answer does not hold a well-formed one. undefined for a session Browserbase does not know (404).
322
+ */
323
+ async sessionUsage(ref, { signal } = {}) {
324
+ const problem = idProblem(ref?.id, NAME);
325
+ if (problem)
326
+ return fail("invalid", problem);
327
+ let found;
328
+ try {
329
+ found = await this.#api.retrieve(ref.id, signal);
330
+ }
331
+ catch (error) {
332
+ return vendorFailure("browserbase", NAME, "GET /v1/sessions/{id}", error);
333
+ }
334
+ if (!found)
335
+ return ok(undefined);
336
+ const at = (value) => (typeof value === "string" && Number.isFinite(Date.parse(value)) ? new Date(Date.parse(value)).toISOString() : null);
337
+ const bytes = found.proxyBytes;
338
+ return ok({ startedAt: at(found.startedAt), endedAt: at(found.endedAt), proxyBytes: typeof bytes === "number" && Number.isSafeInteger(bytes) && bytes >= 0 ? bytes : null });
339
+ }
319
340
  async #listDownloads(ref, { signal } = {}) {
320
341
  const rows = await this.#downloadRows(ref?.id, signal);
321
342
  if (!rows.ok)
Binary file
Binary file
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "0.1.0-beta.48",
3
- "source": "sha256:31803ee5ab55da1b0cdb9ebcdcdda5c9373d4ae4b81eb9459a2504e1111d1966"
2
+ "version": "0.1.0-beta.50",
3
+ "source": "sha256:e4c673ff5826d1db1bf27c6c237a80753cae1b5e218ab4d17d123af0075ccb4b"
4
4
  }
@@ -5,6 +5,7 @@ import type { Case, CaseContext } from "../types.js";
5
5
  export declare function shoot(t: CaseContext, region?: Rect): Promise<{
6
6
  shot: ScreenShotResult;
7
7
  image: Png;
8
+ png: Buffer;
8
9
  }>;
9
10
  /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
10
11
  * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
@@ -36,7 +36,7 @@ export async function shoot(t, region) {
36
36
  catch (error) {
37
37
  throw new Error(`${what}: ${error instanceof Error ? error.message : String(error)}`);
38
38
  }
39
- return { shot, image };
39
+ return { shot, image, png };
40
40
  }
41
41
  /** Why this computer's screen is not captured, as hello's screen.capture says it off (an attached Mac whose owner has
42
42
  * not granted the screen); undefined when it is on, or not declared, which a computer of the screen group means as on. */
@@ -61,23 +61,32 @@ export const screenCases = [
61
61
  const off = captureOff(t);
62
62
  if (off !== undefined)
63
63
  return refusedOff(t, off, "screen.shot");
64
- const { shot, image } = await shoot(t);
65
- t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
66
- t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
67
- t.assert(typeof shot.scale === "number" && shot.scale > 0, `scale is a number above 0, not ${JSON.stringify(shot.scale)}`);
68
- const region = [Math.floor(shot.width / 4), Math.floor(shot.height / 4), Math.max(1, Math.floor(shot.width / 2)), Math.max(1, Math.floor(shot.height / 2))];
69
- const part = await shoot(t, region);
70
- t.deepEqual([part.image.width, part.image.height], [region[2], region[3]], `the PNG of region ${JSON.stringify(region)}: its size (IHDR)`);
71
- t.deepEqual([part.shot.width, part.shot.height], [region[2], region[3]], `the shot of region ${JSON.stringify(region)}: its width and height`);
72
- if (t.provider.capabilities().kind !== "desktop")
73
- return;
74
- const fixture = await t.fixture();
75
- const [x, y, w, h] = fixture.bounds;
76
- const painted = (await shoot(t)).image;
77
- for (const [i, [fx, fy]] of [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]].entries()) {
78
- const px = Math.floor(x + fx * w);
79
- const py = Math.floor(y + fy * h);
80
- t.deepEqual(painted.rgb(px, py), FIXTURE_COLORS[i], `the fixture's ${QUADRANTS[i]} quadrant, at (${px}, ${py})`);
64
+ const { shot, image, png } = await shoot(t);
65
+ // The run's frame, handed over once however the case ends: its last whole shot (on a desktop that reached it, the
66
+ // one with the fixture painted).
67
+ let frame = png;
68
+ try {
69
+ t.assert(shot.width > 0 && shot.height > 0, `the shot is ${shot.width}x${shot.height}`);
70
+ t.deepEqual([image.width, image.height], [shot.width, shot.height], "the PNG's size (IHDR), against the shot's width and height");
71
+ t.assert(typeof shot.scale === "number" && shot.scale > 0, `scale is a number above 0, not ${JSON.stringify(shot.scale)}`);
72
+ const region = [Math.floor(shot.width / 4), Math.floor(shot.height / 4), Math.max(1, Math.floor(shot.width / 2)), Math.max(1, Math.floor(shot.height / 2))];
73
+ const part = await shoot(t, region);
74
+ t.deepEqual([part.image.width, part.image.height], [region[2], region[3]], `the PNG of region ${JSON.stringify(region)}: its size (IHDR)`);
75
+ t.deepEqual([part.shot.width, part.shot.height], [region[2], region[3]], `the shot of region ${JSON.stringify(region)}: its width and height`);
76
+ if (t.provider.capabilities().kind !== "desktop")
77
+ return;
78
+ const fixture = await t.fixture();
79
+ const [x, y, w, h] = fixture.bounds;
80
+ const last = await shoot(t);
81
+ frame = last.png;
82
+ for (const [i, [fx, fy]] of [[0.25, 0.25], [0.75, 0.25], [0.25, 0.75], [0.75, 0.75]].entries()) {
83
+ const px = Math.floor(x + fx * w);
84
+ const py = Math.floor(y + fy * h);
85
+ t.deepEqual(last.image.rgb(px, py), FIXTURE_COLORS[i], `the fixture's ${QUADRANTS[i]} quadrant, at (${px}, ${py})`);
86
+ }
87
+ }
88
+ finally {
89
+ t.onScreenshot(frame);
81
90
  }
82
91
  },
83
92
  },
@@ -30,6 +30,8 @@ export declare const DAYTONA_ENV: {
30
30
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
31
31
  */
32
32
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
33
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
34
+ readonly attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS";
33
35
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
34
36
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
35
37
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -60,6 +62,8 @@ export declare const ENV: {
60
62
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
61
63
  */
62
64
  readonly archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS";
65
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
66
+ readonly attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS";
63
67
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
64
68
  readonly connect: "COMPUTER_DAYTONA_CONNECT";
65
69
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -40,6 +40,8 @@ export const DAYTONA_ENV = {
40
40
  * provider takes an Archil mount; unset, it refuses one (Archil's client hangs on Daytona's hosted cloud).
41
41
  */
42
42
  archilEgress: "COMPUTER_DAYTONA_ARCHIL_EGRESS",
43
+ /** attachEgress: a self-hosted Daytona target's attach relay, <IPv4 relay>:<port>, which its machines that dial go through. */
44
+ attachEgress: "COMPUTER_DAYTONA_ATTACH_EGRESS",
43
45
  /** connect: exec (default) or dial, which needs the public server's process (dialKit). */
44
46
  connect: "COMPUTER_DAYTONA_CONNECT",
45
47
  /** kind: linux (default) or desktop, which create() takes on dial alone. */
@@ -64,6 +66,7 @@ export function settingsFromEnv(env = process.env) {
64
66
  const user = named(DAYTONA_ENV.user);
65
67
  const gpuSnapshot = named(DAYTONA_ENV.gpuSnapshot);
66
68
  const archilEgress = named(DAYTONA_ENV.archilEgress);
69
+ const attachEgress = named(DAYTONA_ENV.attachEgress);
67
70
  const connect = named(DAYTONA_ENV.connect);
68
71
  return {
69
72
  apiKey,
@@ -79,6 +82,8 @@ export function settingsFromEnv(env = process.env) {
79
82
  ...(gpuSnapshot ? { gpuSnapshot: gpuSnapshot.value } : {}),
80
83
  // create() refuses one of another shape in words.
81
84
  ...(archilEgress ? { archilEgress: archilEgress.value } : {}),
85
+ // create() refuses one of another shape in words.
86
+ ...(attachEgress ? { attachEgress: attachEgress.value } : {}),
82
87
  // create() refuses any other value in words.
83
88
  ...(connect ? { connect: connect.value } : {}),
84
89
  };
@@ -660,6 +660,9 @@ export async function runConformance(provider, options) {
660
660
  observe(words) {
661
661
  observed.push(words);
662
662
  },
663
+ onScreenshot(png) {
664
+ options.onScreenshot?.(png);
665
+ },
663
666
  };
664
667
  await c.run(t);
665
668
  };
@@ -137,6 +137,8 @@ export interface CaseContext {
137
137
  skip(reason: string): never;
138
138
  /** Records what the case saw without asserting it (its result's observed), for a fact not yet known either way. */
139
139
  observe(words: string): void;
140
+ /** Hands a whole screenshot, its PNG's bytes, to the run's onScreenshot (ConformanceOptions), when it has one. */
141
+ onScreenshot(png: Uint8Array): void;
140
142
  }
141
143
  export interface Case {
142
144
  /** `<group>.<name>`. */
@@ -329,6 +331,9 @@ export interface ConformanceOptions {
329
331
  mountFor?: (kind: MountKind) => Promise<RunFolder | undefined> | RunFolder | undefined;
330
332
  /** Called as each case ends. */
331
333
  onResult?: (result: CaseResult) => void;
334
+ /** Called once with the last whole screenshot screen.screenshot-size read, its PNG's bytes, whether the case passes or
335
+ * fails after it: a frame of what the screen showed. */
336
+ onScreenshot?: (png: Uint8Array) => void;
332
337
  /** Notes the provider module gives for the report, printed before the verdict. */
333
338
  notes?: string[];
334
339
  /** The longest one case may run; default 180 s. */
@@ -1,12 +1,14 @@
1
1
  import type { Rect, UiFlag, UiRole, UiRoute } from "../protocol.js";
2
2
  /**
3
3
  * What pressing an element does, `after` ms later: go opens a screen in its window (through a transition of
4
- * animateMs), open opens a new window of the app on that screen, in front, and close closes the window it is in.
4
+ * animateMs), open opens a new window of the app on that screen, in front, close closes the window it is in, and launch
5
+ * brings another installed app in front, as a phone's press that opens another package's page does.
5
6
  */
6
7
  export interface FakeEffect {
7
8
  go?: string;
8
9
  open?: string;
9
10
  close?: true;
11
+ launch?: string;
10
12
  after?: number;
11
13
  animateMs?: number;
12
14
  }
package/dist/daytona.d.ts CHANGED
@@ -19,7 +19,7 @@ export type DaytonaTimeouts = HostedTimeouts & {
19
19
  };
20
20
  /**
21
21
  * The Daytona provider's options: the key and Daytona's own settings, then the shared adapter's (HostedOptions), kind
22
- * among them: a desktop on connect dial alone (kindRefusal, with DAYTONA_DIAL_DESKTOP's why).
22
+ * among them: a desktop on connect dial alone (kindRefusal; the why is PROVIDERS.md's Daytona bullet).
23
23
  */
24
24
  export interface DaytonaProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs" | "timeouts"> {
25
25
  /** The Daytona API key. The caller passes it; this provider never reads the environment and never puts it in a computer. */
@@ -39,6 +39,13 @@ export interface DaytonaProviderOptions extends Omit<HostedOptions, "desktop" |
39
39
  * words, since Archil's client hangs on Daytona's hosted cloud. Set it only for such a target.
40
40
  */
41
41
  archilEgress?: string;
42
+ /**
43
+ * The operator's attach relay, `<IPv4 relay>:<port>` (HostedOptions.attachEgress, attachEgressOf): for a self-hosted
44
+ * Daytona target whose runners drop every sandbox connection outside an allow list that the public address is not on.
45
+ * A machine that dials (connect dial, and every desktop) fetches the daemon and opens its attach socket through it,
46
+ * with TLS end to end to the public host. Unset, it dials the public host; a machine on exec never reads it.
47
+ */
48
+ attachEgress?: string;
42
49
  /**
43
50
  * The snapshot GPU computers are made from: one of ours, box/Dockerfile built with a GPU (box/build-daytona.py --gpu
44
51
  * H100 prints its name, agentrun-archil-gpu-h100-<hash>), whose user is root; its GPU is the one its name says.
package/dist/daytona.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // README's Daytona section.
9
9
  import { randomBytes } from "node:crypto";
10
10
  import { connectOf, kindRefusal, mountsOf } from "./descriptor.js";
11
- import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_DIAL_DESKTOP, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, daytonaGpuSnapshot } from "./descriptors/daytona.js";
11
+ import { DAYTONA, DAYTONA_DEFAULT_SNAPSHOT, DAYTONA_GPU, DAYTONA_GPU_REGION, DAYTONA_GPU_SNAPSHOT, daytonaGpuSnapshot } from "./descriptors/daytona.js";
12
12
  import { COMPUTER_LABEL } from "./drift.js";
13
13
  import { HostError } from "./host.js";
14
14
  import { framedExec } from "./hosted/framed-exec.js";
@@ -20,6 +20,20 @@ import { dateOf, isWhole, sizeRefusals } from "./hosted/values.js";
20
20
  import { MAX_LINE_BYTES } from "./protocol.js";
21
21
  import { checkGpu } from "./provider.js";
22
22
  import { ok, vendorFail } from "./result.js";
23
+ /** A positive finite figure of Daytona's answer, else undefined (absent, zero or not a number: never guessed). */
24
+ const given = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
25
+ /** What Daytona says a sandbox was given (Machine.resources): its CPUs, its memory (GiB, as MB), its disk (GiB) and its
26
+ * GPUs (count and type), each where its answer says it; none where it says nothing. */
27
+ function resourcesOf(sb) {
28
+ const [cpus, memory, disk, gpus] = [given(sb.cpu), given(sb.memory), given(sb.disk), given(sb.gpu)];
29
+ const resources = {
30
+ ...(cpus === undefined ? {} : { cpus }),
31
+ ...(memory === undefined ? {} : { memoryMb: memory * 1024 }),
32
+ ...(disk === undefined ? {} : { diskGb: disk }),
33
+ ...(gpus !== undefined && typeof sb.gpuType === "string" && sb.gpuType !== "" ? { gpu: { type: sb.gpuType, count: gpus } } : {}),
34
+ };
35
+ return Object.keys(resources).length > 0 ? { resources } : {};
36
+ }
23
37
  /**
24
38
  * A DaytonaProvider from its options alone; it reads no environment, so the key, the API URL (default Daytona's own) and
25
39
  * the target are the caller's: serve passes its DAYTONA_API_KEY, DAYTONA_API_URL and DAYTONA_TARGET, the conformance
@@ -188,6 +202,7 @@ class DaytonaHost {
188
202
  state: stateOf(sb),
189
203
  ...(made ? { createdAt: made } : {}),
190
204
  ...(endsAt ? { endsAt } : {}),
205
+ ...resourcesOf(sb),
191
206
  // A failed sandbox always carries a why, Daytona's or ours, so create stops on it as vendor, never as gone.
192
207
  ...(typeof sb.errorReason === "string" && sb.errorReason !== "" ? { why: sb.errorReason } : FAILED.has(sb.state ?? "") ? { why: `Daytona reads the sandbox ${sb.state}, with no reason given` } : {}),
193
208
  };
@@ -519,7 +534,7 @@ export class DaytonaProvider extends HostedProvider {
519
534
  const via = connectOf(DAYTONA, { connect });
520
535
  const refused = kindRefusal(DAYTONA, { kind: hosted.kind, connect: via });
521
536
  if (refused !== undefined)
522
- throw new Error(hosted.kind === "desktop" ? `${refused}: ${DAYTONA_DIAL_DESKTOP}` : refused);
537
+ throw new Error(refused);
523
538
  if (typeof apiKey !== "string" || apiKey === "")
524
539
  throw new Error("options.apiKey, the Daytona API key, is required: the provider reads no environment, so the caller passes it");
525
540
  const base = new URL(apiUrl);
@@ -1,13 +1,11 @@
1
1
  import type { GpuCapability } from "../provider.js";
2
- /**
3
- * Why a Daytona desktop is made on connect dial alone: its X server and window manager come from a snapshot of
4
- * box/Dockerfile, whose sandbox boots agentrun-dial and dials the server, the path a live run proves; no desktop has run
5
- * on exec, where init is a command started through the toolbox's session. The provider's constructor refuses kind
6
- * desktop on exec in these words, after kindRefusal's.
7
- */
8
- export declare const DAYTONA_DIAL_DESKTOP = "a desktop's sandbox boots from a snapshot of box/Dockerfile and dials this server, and none has run through the toolbox's session commands, so connect \"exec\" makes kind linux";
9
2
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
10
3
  export declare const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
4
+ /**
5
+ * The key that sends a Daytona machine that dials through the operator's relay, `<IPv4 relay>:<port>` (attachEgress):
6
+ * for a self-hosted target whose sandboxes reach only the addresses its runners allow.
7
+ */
8
+ export declare const DAYTONA_ATTACH_EGRESS = "DAYTONA_ATTACH_EGRESS";
11
9
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
12
10
  export declare const DAYTONA_NO_ARCHIL = "Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets DAYTONA_ARCHIL_EGRESS";
13
11
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
@@ -71,6 +69,10 @@ export declare const DAYTONA: {
71
69
  readonly name: "DAYTONA_ARCHIL_EGRESS";
72
70
  readonly option: "archilEgress";
73
71
  readonly required: false;
72
+ }, {
73
+ readonly name: "DAYTONA_ATTACH_EGRESS";
74
+ readonly option: "attachEgress";
75
+ readonly required: false;
74
76
  }];
75
77
  readonly settings: readonly [{
76
78
  readonly name: "daytonaConnect";
@@ -2,15 +2,13 @@
2
2
  // the operator gives an Archil egress relay (a self-hosted Daytona target), never on Daytona's hosted cloud.
3
3
  import { defineProvider } from "../descriptor.js";
4
4
  import { LINUX_DESKTOP, SANDBOX } from "./shared.js";
5
- /**
6
- * Why a Daytona desktop is made on connect dial alone: its X server and window manager come from a snapshot of
7
- * box/Dockerfile, whose sandbox boots agentrun-dial and dials the server, the path a live run proves; no desktop has run
8
- * on exec, where init is a command started through the toolbox's session. The provider's constructor refuses kind
9
- * desktop on exec in these words, after kindRefusal's.
10
- */
11
- export const DAYTONA_DIAL_DESKTOP = "a desktop's sandbox boots from a snapshot of box/Dockerfile and dials this server, and none has run through the toolbox's session commands, so connect \"exec\" makes kind linux";
12
5
  /** The key that turns on a Daytona computer's Archil mount: the operator's Archil egress relay (archilEgress). */
13
6
  export const DAYTONA_ARCHIL_EGRESS = "DAYTONA_ARCHIL_EGRESS";
7
+ /**
8
+ * The key that sends a Daytona machine that dials through the operator's relay, `<IPv4 relay>:<port>` (attachEgress):
9
+ * for a self-hosted target whose sandboxes reach only the addresses its runners allow.
10
+ */
11
+ export const DAYTONA_ATTACH_EGRESS = "DAYTONA_ATTACH_EGRESS";
14
12
  /** Why a Daytona computer made with no Archil egress takes no Archil mount: check() refuses one in these words. */
15
13
  export const DAYTONA_NO_ARCHIL = `Archil mounts don't work on Daytona's hosted cloud, where Archil's client hangs on its sandboxes; a self-hosted Daytona target takes one once its operator sets ${DAYTONA_ARCHIL_EGRESS}`;
16
14
  /** The image a Daytona computer starts from when its spec names "default": Daytona's own default snapshot. */
@@ -78,6 +76,7 @@ export const DAYTONA = defineProvider({
78
76
  { name: "DAYTONA_API_URL", option: "apiUrl", required: false },
79
77
  { name: "DAYTONA_TARGET", option: "target", required: false },
80
78
  { name: DAYTONA_ARCHIL_EGRESS, option: "archilEgress", required: false },
79
+ { name: DAYTONA_ATTACH_EGRESS, option: "attachEgress", required: false },
81
80
  ],
82
81
  // How the server reaches its machines: exec (the provider's default, when the server's settings name none), a session
83
82
  // command through the toolbox per connection, or dial, the machine dials the server (a snapshot of box/Dockerfile).
@@ -101,7 +100,7 @@ export const DAYTONA = defineProvider({
101
100
  // X server, started through computerd over the socket the sandbox dialed, and xfwm4, which computerd starts itself
102
101
  // (init --window-manager), at the snapshot's 2 CPUs and 4 GiB (box/build-daytona.py). The desktop's configuration
103
102
  // selects dial itself, whatever daytonaConnect says: a provider on connect exec refuses kind desktop when it is made
104
- // (DAYTONA_DIAL_DESKTOP).
103
+ // (kindRefusal; the why is PROVIDERS.md's Daytona bullet).
105
104
  capabilities: [{ ...SANDBOX, gpu: DAYTONA_GPU }, { ...LINUX_DESKTOP, options: { kind: "desktop", connect: "dial" } }],
106
105
  defaultImage: { sandbox: DAYTONA_DEFAULT_SNAPSHOT },
107
106
  // The operator's own snapshot for every Daytona computer, named here; the default snapshot stands while unset. A
@@ -55,6 +55,10 @@ export declare const DESCRIPTORS: readonly [{
55
55
  readonly name: "DAYTONA_ARCHIL_EGRESS";
56
56
  readonly option: "archilEgress";
57
57
  readonly required: false;
58
+ }, {
59
+ readonly name: "DAYTONA_ATTACH_EGRESS";
60
+ readonly option: "attachEgress";
61
+ readonly required: false;
58
62
  }];
59
63
  readonly settings: readonly [{
60
64
  readonly name: "daytonaConnect";
package/dist/desktop.d.ts CHANGED
@@ -10,36 +10,16 @@ export interface DesktopOptions {
10
10
  }
11
11
  /** The groups a desktop declares besides exec, files and processes: apps is computerd's, from the desktop's .desktop files. */
12
12
  export declare const DESKTOP_GROUPS: readonly ["screen", "input.pointer", "input.keys", "apps"];
13
- /**
14
- * The window manager a host's desktops run where its facts say so (HostFacts.windowManager: E2B's, Fly's, Cloudflare's,
15
- * Modal's, Agent37's and Daytona's), once the display answers: it frames, stacks and focuses the windows apps.launch
16
- * opens. xfwm4, which the box image has, with no compositor and no session manager. It reads its settings from xfconfd
17
- * over a session bus, and exits at once without one ("Xfconf could not be initialized"). So it runs in a session bus of
18
- * its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of its own under /tmp), in a network namespace of its
19
- * own: a program of the computer's user reaches no socket of that bus, unless it joins that namespace (nsenter), as the
20
- * same uid may ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the
21
- * screen behind every window one slate colour, so a desktop with no window open is not a black screen a person reads as
22
- * broken; a paint that fails starts xfwm4 all the same.
23
- *
24
- * computerd starts it itself (init --window-manager), as root makes the network namespace and then becomes the
25
- * computer's user, so no user namespace is needed there: the user can make neither on some hosts (Daytona's sandboxes,
26
- * under AppArmor's restrict_unprivileged_userns). This argv is create's own start, through process.start as the
27
- * computer's user, for a computerd whose hello says nothing of one: the user makes the network namespace inside a user
28
- * namespace (the same uid) of its own.
29
- */
30
- export declare const WINDOW_MANAGER: readonly string[];
31
13
  /** The desktop options with their defaults, or a throw in words. */
32
14
  export declare function desktopOf({ display, server, timeoutMs }: DesktopOptions): Required<DesktopOptions>;
33
15
  /**
34
16
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
35
17
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
36
18
  * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
37
- * hello with windowManager (computerd was asked to start it) is waited on until the manager runs; else, with
38
- * windowManager (the host's desktops run one, HostFacts.windowManager), create starts WINDOW_MANAGER itself.
19
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
39
20
  */
40
- export declare function startDisplay(client: ComputerClient, desktop: Required<DesktopOptions>, { version, vendor, signal, windowManager }: {
21
+ export declare function startDisplay(client: ComputerClient, desktop: Required<DesktopOptions>, { version, vendor, signal }: {
41
22
  version: string;
42
23
  vendor: string;
43
24
  signal?: AbortSignal | undefined;
44
- windowManager?: boolean;
45
25
  }): Promise<Result<void>>;
package/dist/desktop.js CHANGED
@@ -2,67 +2,17 @@
2
2
  // the daemon with process.start, as any program, so the server is in init's process table and ends with the computer.
3
3
  // The daemon reaches the display once it answers, and hello declares screen, input.pointer, input.keys and apps from then
4
4
  // on (hello re-checks the display on each call). A window manager, when the desktop has one, comes next: computerd starts
5
- // it itself when init was asked to (init --window-manager; hello's windowManager says how it goes), and create starts
6
- // it the same way as the server, through process.start, for a computerd that says nothing of one.
5
+ // it itself when init was asked to (init --window-manager; see daemon/internal/windowmanager), and create waits on
6
+ // hello's windowManager until it runs.
7
7
  // Docker's desktops, E2B's, Agent37's and Daytona's start the display this way.
8
8
  import { setTimeout as sleep } from "node:timers/promises";
9
9
  import { fail, ok, vendorFail } from "./result.js";
10
10
  /** The groups a desktop declares besides exec, files and processes: apps is computerd's, from the desktop's .desktop files. */
11
11
  export const DESKTOP_GROUPS = ["screen", "input.pointer", "input.keys", "apps"];
12
- /**
13
- * The session bus the window manager reads its settings over: dbus's own session config, but listening on an abstract
14
- * name, which only a program in the bus's own network namespace reaches. dbus's unix:tmpdir is a socket under /tmp
15
- * with dbus 1.16 (Agent37's box), which every program of the user reaches.
16
- */
17
- const WINDOW_MANAGER_BUS = `<busconfig>
18
- <type>session</type>
19
- <keep_umask/>
20
- <listen>unix:abstract=/agentrun/window-manager</listen>
21
- <auth>EXTERNAL</auth>
22
- <standard_session_servicedirs/>
23
- <policy context="default">
24
- <allow send_destination="*" eavesdrop="true"/>
25
- <allow eavesdrop="true"/>
26
- <allow own="*"/>
27
- </policy>
28
- </busconfig>`;
29
- /**
30
- * The window manager a host's desktops run where its facts say so (HostFacts.windowManager: E2B's, Fly's, Cloudflare's,
31
- * Modal's, Agent37's and Daytona's), once the display answers: it frames, stacks and focuses the windows apps.launch
32
- * opens. xfwm4, which the box image has, with no compositor and no session manager. It reads its settings from xfconfd
33
- * over a session bus, and exits at once without one ("Xfconf could not be initialized"). So it runs in a session bus of
34
- * its own (dbus-run-session, WINDOW_MANAGER_BUS, written to a file of its own under /tmp), in a network namespace of its
35
- * own: a program of the computer's user reaches no socket of that bus, unless it joins that namespace (nsenter), as the
36
- * same uid may ptrace xfwm4. xfwm4 reaches the display as any program does, by its path. First, xsetroot paints the
37
- * screen behind every window one slate colour, so a desktop with no window open is not a black screen a person reads as
38
- * broken; a paint that fails starts xfwm4 all the same.
39
- *
40
- * computerd starts it itself (init --window-manager), as root makes the network namespace and then becomes the
41
- * computer's user, so no user namespace is needed there: the user can make neither on some hosts (Daytona's sandboxes,
42
- * under AppArmor's restrict_unprivileged_userns). This argv is create's own start, through process.start as the
43
- * computer's user, for a computerd whose hello says nothing of one: the user makes the network namespace inside a user
44
- * namespace (the same uid) of its own.
45
- */
46
- export const WINDOW_MANAGER = [
47
- "unshare",
48
- "--user",
49
- "--map-current-user",
50
- "--net",
51
- "--",
52
- "sh",
53
- "-c",
54
- 'xsetroot -solid "#3b4b5c"; bus=$(mktemp) && printf "%s" "$1" > "$bus" && exec dbus-run-session --config-file="$bus" -- xfwm4 --compositor=off --sm-client-disable',
55
- "sh",
56
- WINDOW_MANAGER_BUS,
57
- ];
58
- /** WINDOW_MANAGER as create's errors name it: what runs, without the shell line and the bus's config. */
59
- const WINDOW_MANAGER_WORDS = "unshare --user --map-current-user --net -- dbus-run-session -- xfwm4 --compositor=off --sm-client-disable";
60
12
  const DISPLAY = /^:\d{1,5}(\.\d{1,5})?$/;
61
13
  /** How often create asks the daemon whether the display is up yet. */
62
14
  const DISPLAY_POLL_MS = 100;
63
- /** How long create watches a window manager it started: one that ends within it (it could not take the display) fails create. */
64
- const WM_SETTLE_MS = 1_000;
65
- /** The longest create gives a window manager's start and that watch, apart from the display's own timeoutMs. */
15
+ /** The longest create waits on the window manager computerd starts, apart from the display's own timeoutMs. */
66
16
  const WM_BOUND_MS = 15_000;
67
17
  /** The longest a Node timer or AbortSignal.timeout holds. */
68
18
  const MAX_TIMER_MS = 2 ** 31 - 1;
@@ -85,10 +35,9 @@ export function desktopOf({ display = ":0", server, timeoutMs = 30_000 }) {
85
35
  * Starts the desktop's X server through the daemon (process.start) and waits until hello declares the display: the
86
36
  * server ending first, or the bound passing, is a failure in words, with the server's own last words, as the vendor's
87
37
  * (code vendor, vendor the provider's id). version is the client's, sent with each hello. Once the display answers, a
88
- * hello with windowManager (computerd was asked to start it) is waited on until the manager runs; else, with
89
- * windowManager (the host's desktops run one, HostFacts.windowManager), create starts WINDOW_MANAGER itself.
38
+ * hello with windowManager (computerd was asked to start it) is waited on until the manager runs.
90
39
  */
91
- export async function startDisplay(client, desktop, { version, vendor, signal, windowManager = false }) {
40
+ export async function startDisplay(client, desktop, { version, vendor, signal }) {
92
41
  const server = desktop.server.join(" ");
93
42
  // Every call takes a signal that ends at the bound, so a hello the X connection setup holds, or a daemon that stops
94
43
  // answering, cannot outwait it. A call that failed because the bound passed is the timeout; the caller's own abort
@@ -106,9 +55,7 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
106
55
  if (!hello.ok)
107
56
  return timedOut() ? late() : hello;
108
57
  if (Array.isArray(hello.value.groups) && hello.value.groups.includes("screen")) {
109
- if (hello.value.windowManager)
110
- return await awaitWindowManager(client, desktop, { version, vendor, caller: signal });
111
- return windowManager ? await startWindowManager(client, desktop, vendor, signal) : ok(undefined);
58
+ return hello.value.windowManager ? await awaitWindowManager(client, desktop, { version, vendor, caller: signal }) : ok(undefined);
112
59
  }
113
60
  const waited = await client.call("process.wait", { id, timeoutMs: 0 }, { signal: either });
114
61
  if (waited.ok && !waited.value.running) {
@@ -128,8 +75,8 @@ export async function startDisplay(client, desktop, { version, vendor, signal, w
128
75
  }
129
76
  /**
130
77
  * Waits on the window manager computerd starts itself (hello's windowManager, init --window-manager) until hello says it
131
- * runs: one that ended fails create in computerd's words, its last lines among them. The bound is WM_BOUND_MS, as for a
132
- * manager create starts. The caller's abort still ends it.
78
+ * runs: one that ended fails create in computerd's words, its last lines among them. The bound is WM_BOUND_MS; the
79
+ * caller's abort still ends it.
133
80
  */
134
81
  async function awaitWindowManager(client, desktop, { version, vendor, caller }) {
135
82
  const bound = AbortSignal.timeout(WM_BOUND_MS);
@@ -151,36 +98,3 @@ async function awaitWindowManager(client, desktop, { version, vendor, caller })
151
98
  return stopped();
152
99
  }
153
100
  }
154
- /**
155
- * Starts WINDOW_MANAGER on the display that answers, for a computerd that starts none (its hello has no
156
- * windowManager). A manager that cannot start, or ends
157
- * within WM_SETTLE_MS (xfwm4 with no session bus, or no display it may open), fails create with its last words. It has
158
- * its own bound, WM_BOUND_MS, not what is left of the display's: a display that came up late still gets its manager's
159
- * full second. The caller's abort still ends it.
160
- */
161
- async function startWindowManager(client, desktop, vendor, caller) {
162
- const manager = WINDOW_MANAGER_WORDS;
163
- const bound = AbortSignal.timeout(WM_BOUND_MS);
164
- const signal = caller ? AbortSignal.any([caller, bound]) : bound;
165
- const stopped = (code, message) => caller?.aborted
166
- ? fail("aborted", "create was aborted while the window manager started")
167
- : bound.aborted
168
- ? fail("timeout", `the window manager (${manager}) did not start on ${desktop.display} within ${WM_BOUND_MS / 1000} s`)
169
- : fail(code, message);
170
- // NO_AT_BRIDGE: GTK (xfwm4's toolkit) asks its session bus for no accessibility bus. On E2B Desktop, which has
171
- // at-spi2-core, that bus is an at-spi-bus-launcher and a socket of the user's under its home (~/.cache/at-spi/bus_0).
172
- const env = { DISPLAY: desktop.display, NO_AT_BRIDGE: "1" };
173
- const started = await client.call("process.start", { argv: [...WINDOW_MANAGER], env }, { signal });
174
- if (!started.ok)
175
- return stopped(started.error.code, `the window manager (${manager}) did not start on ${desktop.display}: ${started.error.message}`);
176
- const { id } = started.value;
177
- const waited = await client.call("process.wait", { id, timeoutMs: WM_SETTLE_MS }, { signal });
178
- if (!waited.ok)
179
- return stopped(waited.error.code, `the window manager (${manager}) could not be waited on: ${waited.error.message}`);
180
- if (waited.value.running)
181
- return ok(undefined);
182
- const read = await client.call("process.read", { id, stream: "stderr", offset: 0 }, { signal });
183
- const words = read.ok ? Buffer.from(read.value.data, "base64").toString("utf8").trim().split("\n").slice(-5).join("; ") : "";
184
- const how = waited.value.signal ? `signal ${waited.value.signal}` : `exit code ${waited.value.exitCode}`;
185
- return vendorFail(vendor, `the window manager (${manager}) ended with ${how} within ${WM_SETTLE_MS / 1000} s of starting on ${desktop.display}${words ? `: ${words}` : ""}`);
186
- }
package/dist/e2b.js CHANGED
@@ -127,8 +127,13 @@ function machineOf(info) {
127
127
  }
128
128
  const started = dateOf(info.startedAt);
129
129
  const state = info.state === "running" ? "running" : info.state === "paused" ? "stopped" : "gone";
130
- return { id: info.sandboxId, labels, state, ...(started ? { createdAt: started } : {}), ...(end ? { endsAt: end } : {}) };
130
+ // What E2B says the sandbox was given (SandboxInfo's cpuCount and memoryMB), where it says it; E2B's answer has no disk.
131
+ const [cpus, memoryMb] = [positive(info.cpuCount), positive(info.memoryMB)];
132
+ const resources = { ...(cpus === undefined ? {} : { cpus }), ...(memoryMb === undefined ? {} : { memoryMb }) };
133
+ return { id: info.sandboxId, labels, state, ...(started ? { createdAt: started } : {}), ...(end ? { endsAt: end } : {}), ...(Object.keys(resources).length > 0 ? { resources } : {}) };
131
134
  }
135
+ /** A positive finite figure of a vendor's answer, else undefined: never guessed. */
136
+ const positive = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
132
137
  /** One chunk of the SDK's output into a stream, unless the stream has ended. */
133
138
  const push = (stream, data) => void (stream.writableEnded || stream.write(data));
134
139
  /** E2B's sandboxes as a MachineHost (../host.ts). */
@@ -463,13 +463,18 @@ export class FakeUiDriver {
463
463
  this.#apply(state, win, element.press);
464
464
  }
465
465
  /**
466
- * A press's effect, from the window it landed in: go to a screen in that window, open another window, or close that
467
- * one. A delayed effect is that window's pending effect: it never lands once the window closed.
466
+ * A press's effect, from the window it landed in: go to a screen in that window, open another window, close that
467
+ * one, or bring another app in front (on a phone, the app it left is then out of reach). A delayed effect is that
468
+ * window's pending effect: it never lands once the window closed.
468
469
  */
469
470
  #apply(state, win, effect) {
470
471
  const go = () => {
471
472
  if (effect.close === true)
472
473
  return this.#closeWindow(state, win);
474
+ if (effect.launch !== undefined) {
475
+ this.#launch({ id: effect.launch });
476
+ return;
477
+ }
473
478
  if (effect.open !== undefined) {
474
479
  state.opened += 1;
475
480
  const [x, y, w, h] = state.origin;
package/dist/fly.d.ts CHANGED
@@ -7,12 +7,20 @@ export interface FlyMachine {
7
7
  created_at?: string;
8
8
  config?: {
9
9
  metadata?: Record<string, string> | null;
10
+ guest?: FlyGuest | null;
10
11
  } | null;
11
12
  /** fly-go: the config rebuilt in part while host_status isn't "ok". */
12
13
  incomplete_config?: {
13
14
  metadata?: Record<string, string> | null;
15
+ guest?: FlyGuest | null;
14
16
  } | null;
15
17
  }
18
+ /** A machine's guest as Fly answers it (M, MachineGuest): its CPUs and memory, which Fly bills by. */
19
+ export interface FlyGuest {
20
+ cpu_kind?: string;
21
+ cpus?: number;
22
+ memory_mb?: number;
23
+ }
16
24
  /** The Fly provider's options: the token and the app, then the shared adapter's (HostedOptions), kind among them. */
17
25
  export interface FlyProviderOptions extends Omit<HostedOptions, "desktop" | "maxLifetimeMs"> {
18
26
  /** A Fly API token that may make machines in the app. The caller passes it; this provider reads no environment. */
package/dist/fly.js CHANGED
@@ -76,8 +76,17 @@ function machineOf(found) {
76
76
  state: state ?? "gone",
77
77
  ...(created ? { createdAt: created } : {}),
78
78
  ...(why ? { why } : {}),
79
+ ...guestResources(config.guest),
79
80
  };
80
81
  }
82
+ /** What Fly says a machine was given (its guest's cpus and memory_mb), where its answer says it; none else. */
83
+ function guestResources(guest) {
84
+ const figure = (value) => (typeof value === "number" && Number.isFinite(value) && value > 0 ? value : undefined);
85
+ const [cpus, memoryMb] = [figure(guest?.cpus), figure(guest?.memory_mb)];
86
+ if (cpus === undefined && memoryMb === undefined)
87
+ return {};
88
+ return { resources: { ...(cpus === undefined ? {} : { cpus }), ...(memoryMb === undefined ? {} : { memoryMb }) } };
89
+ }
81
90
  /** An id held to Fly's form before it reaches a path: not_found else. */
82
91
  function machineId(id) {
83
92
  if (!MACHINE_ID.test(id))
package/dist/host.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ProviderDescriptor } from "./descriptor.js";
2
- import type { ComputerCapabilities, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
2
+ import type { ComputerCapabilities, ComputerResources, ComputerSpec, GpuSpec, Refusal } from "./provider.js";
3
3
  import type { ComputerErrorCode } from "./result.js";
4
4
  /**
5
5
  * One vendor's machines. Every call answers its value or throws: a failure whose code the host knows throws a
@@ -185,6 +185,9 @@ export interface Machine {
185
185
  createdAt?: Date;
186
186
  /** The vendor's words for a machine that is gone because it failed: a create stops in them. */
187
187
  why?: string;
188
+ /** What the vendor's answer says the machine was given (its CPUs, memory, disk, GPUs), where it says it: a create
189
+ * returns these as its computer's resources. Absent where the answer says none. */
190
+ resources?: ComputerResources;
188
191
  }
189
192
  /** A process exec started: its output as it comes, its stdin, and its end. */
190
193
  export interface MachineProcess {
@@ -224,7 +227,7 @@ export interface HostFacts {
224
227
  arch: "amd64" | "arm64";
225
228
  /** The TCP ports the vendor's own agent listens on inside the machine (E2B's envd 49983). */
226
229
  vendorAgentPorts: number[];
227
- /** Whether its desktops run WINDOW_MANAGER (xfwm4, which its image has) once the display answers. Default none. */
230
+ /** Whether its desktops run a window manager (xfwm4, which its image has), which computerd starts (init --window-manager). Default none. */
228
231
  windowManager?: boolean;
229
232
  /** What spec.user may ask for, beside the daemon user: with it, the spec's user goes in MachineRequest.user. */
230
233
  user?: Array<"root" | "uid">;
@@ -66,6 +66,13 @@ export interface HostedOptions {
66
66
  * Given to the helper's mount and revoke. Unset or empty, the client reaches Archil as the machine's network allows.
67
67
  */
68
68
  archilEgress?: string;
69
+ /**
70
+ * The relay a dial machine reaches this server through, `<IPv4 relay>:<port>` such as 192.0.2.40:18443
71
+ * (attachEgressOf): for a vendor whose machines reach only addresses the operator allows. A dial machine is booted with
72
+ * it as AGENTRUN_ATTACH_EGRESS, and its daemon fetch and attach socket both open TCP to it, speaking TLS and HTTP to
73
+ * the public host through it. Unset or empty, they go to the public host; a host whose machines don't dial ignores it.
74
+ */
75
+ attachEgress?: string;
69
76
  /** What a host whose facts.connect is "dial" needs: create refuses without it, before any call to the vendor, in words
70
77
  * that name serve's one-process start (a runner apart from the server has none). */
71
78
  dial?: HostedDial;
@@ -11,7 +11,7 @@ import { readFileSync } from "node:fs";
11
11
  import { resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
13
13
  import { isDeepStrictEqual } from "node:util";
14
- import { ATTACH_PATH, DAEMON_PATH } from "../attach.js";
14
+ import { ATTACH_EGRESS_ENV, ATTACH_PATH, attachEgressOf, DAEMON_PATH } from "../attach.js";
15
15
  import { CreateRequests, endedWords, otherSpecWords, readBackDiffer } from "../create-requests.js";
16
16
  import { mountsOf, syncs } from "../descriptor.js";
17
17
  import { desktopOf, startDisplay } from "../desktop.js";
@@ -172,17 +172,21 @@ export class HostedProvider {
172
172
  #probeTargets;
173
173
  #onNote;
174
174
  #archilEgress;
175
+ #attachEgress;
175
176
  /** Each create in flight, and the names of the computers this provider ended (create-requests.ts). In memory alone:
176
177
  * past it, and past this process, the vendor's listing is what holds. */
177
178
  #requests = new CreateRequests();
178
179
  /** Each computer's last extend, by machine id, while one runs: the next waits for it. */
179
180
  #extending = new Map();
181
+ /** What the vendor said a machine this create made was given (Machine.resources), by machine id, from its read once it
182
+ * ran (#prepare) until the create answers with it (#createOnce). */
183
+ #given = new Map();
180
184
  /** A dial host's server: what its machines reach, and what holds their tokens and sockets. */
181
185
  #dial;
182
186
  /** The host's descriptor's mounts as its machines reach this server (mountsOf): a dial host's take no Archil mount. */
183
187
  #mounts;
184
188
  constructor(host, options) {
185
- const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, } = options;
189
+ const { kind = "linux", desktop = {}, maxLifetimeMs = host.facts.maxLifetimeMs, daemonPath = hostedDaemonPath(host.facts.arch), daemonUser = TOOL_USER, timeouts = {}, probeTargets = DEFAULT_PROBE_TARGETS, onNote, archilEgress, attachEgress, } = options;
186
190
  const { id, label, capabilities } = host.descriptor;
187
191
  if (kind !== "desktop" && kind !== "linux")
188
192
  throw new Error(`kind is desktop or linux, not ${String(kind)}`);
@@ -196,6 +200,7 @@ export class HostedProvider {
196
200
  this.#fail = failFor(id);
197
201
  this.#onNote = onNote;
198
202
  this.#archilEgress = archilEgress === undefined || archilEgress === "" ? undefined : archilEgressOf(archilEgress);
203
+ this.#attachEgress = attachEgress === undefined || attachEgress === "" ? undefined : attachEgressOf(attachEgress);
199
204
  if (!isWhole(maxLifetimeMs) || maxLifetimeMs <= 0 || maxLifetimeMs > host.facts.maxLifetimeMs) {
200
205
  throw new Error(`maxLifetimeMs must be a whole number of ms above 0 and at most ${host.facts.maxLifetimeMs} ms, the longest ${label} keeps a computer`);
201
206
  }
@@ -543,6 +548,8 @@ export class HostedProvider {
543
548
  if (first.ok && first.value !== undefined && first.value.id !== ref.id)
544
549
  return this.#again(spec, name, first.value, signal);
545
550
  const prepared = await this.#prepare(spec, ref, made, signal);
551
+ const given = this.#given.get(ref.id);
552
+ this.#given.delete(ref.id);
546
553
  if (signal?.aborted)
547
554
  return this.#abandon(ref, { code: "aborted", message: "create was aborted" }, signal);
548
555
  if (!prepared.ok) {
@@ -561,7 +568,7 @@ export class HostedProvider {
561
568
  return this.#abandon(ref, last.error, signal, true);
562
569
  if (last.value !== undefined && last.value.id !== ref.id)
563
570
  return this.#again(spec, name, last.value, signal);
564
- return ok(prepared.value.length > 0 ? { ...ref, notes: prepared.value } : ref);
571
+ return ok({ ...ref, ...(prepared.value.length > 0 ? { notes: prepared.value } : {}), ...(given === undefined ? {} : { resources: given }) });
565
572
  }
566
573
  /**
567
574
  * The one machine a request keeps. Two creates of one request on two provider instances can both find no machine by
@@ -620,8 +627,10 @@ export class HostedProvider {
620
627
  const drift = attached.ok ? readBackDiffer({ ...spec, network: networkOfForm(formOf(spec.network)), user: this.#userOf(spec) }, attached.value.spec, ["user", "network", "gpu"]) : [];
621
628
  if (drift.length > 0)
622
629
  return this.#fail("exists", otherSpecWords(name, "was made", drift));
630
+ // What the vendor gave it, from this read of it running, as a fresh create answers it (#prepare): a retry, or
631
+ // another instance's computer adopted, is priced by the same figures.
623
632
  if (attached.ok)
624
- return ok({ id: attached.value.id, name: attached.value.name, ...(attached.value.notes ? { notes: attached.value.notes } : {}) });
633
+ return ok({ id: attached.value.id, name: attached.value.name, ...(attached.value.notes ? { notes: attached.value.notes } : {}), ...(machine.resources ? { resources: machine.resources } : {}) });
625
634
  if (attached.error.code === "aborted")
626
635
  return attached;
627
636
  // Its daemon is not up yet, or not yet as declared (a desktop whose display the first create is still
@@ -772,6 +781,8 @@ export class HostedProvider {
772
781
  AGENTRUN_INIT_ARGS: initFlags(init).join(" "),
773
782
  // A desktop's init gets its display as the exec path's start gives it: DISPLAY, which agentrun-dial passes on.
774
783
  ...(this.#desktop === undefined ? {} : { DISPLAY: this.#desktop.display }),
784
+ // The relay the machine reaches this server through: agentrun-dial's fetch and computerd attach both dial it.
785
+ ...(this.#attachEgress === undefined ? {} : { [ATTACH_EGRESS_ENV]: this.#attachEgress }),
775
786
  });
776
787
  }
777
788
  /** Deletes a machine create gives up on, then waits, under the caller's signal, until get answers none for it. */
@@ -876,6 +887,8 @@ export class HostedProvider {
876
887
  const running = await this.#running(ref, signal);
877
888
  if (!running.ok)
878
889
  return running;
890
+ if (running.value.resources !== undefined)
891
+ this.#given.set(ref.id, running.value.resources);
879
892
  const drift = this.#machineDrift(running.value, labels);
880
893
  if (drift.length > 0)
881
894
  return this.#fail("refused", `it did not match its spec: ${drift.join("; ")}`);
@@ -1002,7 +1015,7 @@ export class HostedProvider {
1002
1015
  async #checkInside(connection, name, network, starting, want, signal, folder) {
1003
1016
  let current = connection;
1004
1017
  if (starting && this.#desktop) {
1005
- const shown = await startDisplay(connection.client, this.#desktop, { version: VERSION, vendor: this.id, signal, windowManager: this.host.facts.windowManager === true });
1018
+ const shown = await startDisplay(connection.client, this.#desktop, { version: VERSION, vendor: this.id, signal });
1006
1019
  if (!shown.ok)
1007
1020
  return shown;
1008
1021
  const hello = await connection.client.call("hello", { client: `@parcha/agentrun-computer ${VERSION}` }, { signal: bounded(this.#timeouts.helloMs, signal) });
@@ -1107,7 +1120,8 @@ export class HostedProvider {
1107
1120
  if (left <= 0) {
1108
1121
  const dialed = this.#dialed();
1109
1122
  const to = "problem" in dialed ? "this server" : dialed.attach;
1110
- return this.#fail("timeout", `${ref.name} did not dial ${to} within ${seconds(createMs)}: the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set)`);
1123
+ const through = this.#attachEgress === undefined ? "" : ` through ${this.#attachEgress}`;
1124
+ return this.#fail("timeout", `${ref.name} did not dial ${to}${through} within ${seconds(createMs)}: the machine must reach that address, and run agentrun-dial (the box image's entrypoint while AGENTRUN_ATTACH_URL is set)`);
1111
1125
  }
1112
1126
  const polled = pause(Math.min(this.#startPollMs(), left), signal).then(() => false);
1113
1127
  reading ??= this.#dialRefused(ref.name, Math.min(requestMs, left), signal);
package/dist/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { type DockerVolume, VOLUME_SUBPATH_ENGINE } from "./docker/volume.js";
17
17
  export { DEFAULT_DOCKER_IMAGE, DOCKER_BASE, DOCKER_RECIPE, DOCKER_RECIPE_HAS, ensureImage, type EnsureImageOptions, IMAGE_REPOSITORY, IMAGE_TIMEOUT_MS, type ImageSource, imageSourceProblem, type Making, RECIPE_LABEL, recipeHash, recipeTag, } from "./docker/image.js";
18
18
  export { EGRESS_IMAGE, EGRESS_LABEL, EGRESS_MOUNT, EGRESS_SOCKET } from "./docker/egress.js";
19
19
  export { ARCHIL_HELPER, ARCHIL_SYNC_SOCKET, ARCHIL_TOOL_UID, ARCHIL_TOOL_USER, ARCHIL_VERSION, type ArchilMount, type ArchilEgress, type ArchilMountOptions, type ArchilRoot, type ProviderNote, archilEgressOf, archilLabels, archilMount, archilReadBack, archilRefusals, archilRelease, archilSync, claimEpoch, helperSha256, MOUNT_LABEL, mountDrift, mountWords, type RecordedFolder, type RecordedSource, readMount, recordedFolder, recordedMount, SYNC_LABELS, syncingClient, } from "./mount-archil.js";
20
- export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
20
+ export { type BrowserComputerProvider, type BrowserDownloads, type BrowserFile, type BrowserProfiles, type BrowserSessionUsage, browserSpecRefusals, type BrowserStream, isBrowserProvider, BrowserVendorError, CREATE_LABEL, causeOf, memoryUrls, RECOVER_MS, type ReleaseConfirm, type RestReply, type UrlStore, } from "./browser.js";
21
21
  export { CHROME_ENV, CHROME_FLAGS, checkChrome, chromeFence, findChrome, killTree, NO_CHROME } from "./chrome.js";
22
22
  export { DAEMON_IN_COMPUTER, helloDrift, type HelloExpected } from "./drift.js";
23
23
  export { drift, hostOf, inspectDrift, mountOf, networkOf, type DockerHost, type DockerInfo, type DockerInspect, type DriftExpected } from "./docker/inspect.js";
@@ -298,9 +298,24 @@ export interface ReadBackSpec {
298
298
  * back): 1.1.1.1:443, ..."). Recorded, never refused and never hidden. Absent when there is nothing to record.
299
299
  */
300
300
  export type ReadBackNotes = string[];
301
- /** What create returns: the computer's ref, and what its read-back recorded that does not refuse it. */
301
+ /**
302
+ * What a computer was given, as its vendor's own answer for it says (its get or create answer): the figures the vendor
303
+ * bills by. Each field is absent where the vendor's answer does not say it, never guessed from what was asked.
304
+ */
305
+ export interface ComputerResources {
306
+ cpus?: number;
307
+ memoryMb?: number;
308
+ /** Its disk, in GB as the vendor counts it. */
309
+ diskGb?: number;
310
+ gpu?: GpuSpec;
311
+ }
312
+ /**
313
+ * What create returns: the computer's ref, what its read-back recorded that does not refuse it, and what the vendor says
314
+ * it was given (`resources`), where the vendor's answer says it.
315
+ */
302
316
  export interface CreatedComputer extends ComputerRef {
303
317
  notes?: ReadBackNotes;
318
+ resources?: ComputerResources;
304
319
  }
305
320
  /** A computer attach found: its ref, and the spec read back from it, so a caller sees what it attached to (root, open). */
306
321
  export interface AttachedComputer extends ComputerRef {
@@ -309,12 +309,27 @@ export function createSurface(client, hello, { cwd } = {}) {
309
309
  // The default state of a later point step stays the last observation's (stateOf): a state this act returned was never seen.
310
310
  // A script may ask observe as options ({ image: true }); the tool's schema offers only true.
311
311
  const again = args.observe;
312
- // The window the act finished on: its app, else the app of the state it named, never the one in front.
313
- const target = app ?? (args.state ? appOfState.get(args.state) : undefined);
314
312
  if (again)
315
- done.after = await observe({ ...(typeof again === "object" ? again : {}), ...(target ? { app: target } : {}) }, signal);
313
+ done.after = await observeAfter(typeof again === "object" ? again : {}, app ?? (args.state ? appOfState.get(args.state) : undefined), signal);
316
314
  return done;
317
315
  }
316
+ /**
317
+ * The window an act finished on, by the daemons' rule for it (phoned's UiDriver.after): its app's (the act's app, else
318
+ * the app of the state it named), never the one in front while that app shows one; else, once the steps took it away
319
+ * (a press that opened another package's page), the window in front.
320
+ */
321
+ async function observeAfter(options, app, signal) {
322
+ if (!app)
323
+ return observe(options, signal);
324
+ try {
325
+ return await observe({ ...options, app }, signal);
326
+ }
327
+ catch (error) {
328
+ if (!(error instanceof SurfaceError) || error.kind !== "not_found")
329
+ throw error;
330
+ return observe(options, signal);
331
+ }
332
+ }
318
333
  async function readFile(path, encoding, signal) {
319
334
  const parts = [];
320
335
  let offset = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcha/agentrun-computer",
3
- "version": "0.1.0-beta.48",
3
+ "version": "0.1.0-beta.50",
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",