@fungi.computer/computer 0.4.2 → 0.6.0

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.
@@ -1,7 +1,11 @@
1
+ /** The one idle window: a Computer sleeps this long after its last activity. */
1
2
  export declare const computerContainerSleepAfterMs: number;
3
+ /** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
4
+ export declare const computerKeepAwakeTimeoutMs: number;
2
5
  export declare function hostedComputerContainersPaused(hostedComputers: string | undefined): boolean;
3
6
  export declare class ComputerContainersPausedError extends Error {
4
7
  constructor();
5
8
  }
6
9
  export declare function assertComputerContainersEnabled(hostedComputers: string | undefined): void;
7
- export declare function configureComputerContainer(container: Pick<Container, "setInactivityTimeout"> | undefined): Promise<void>;
10
+ /** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
11
+ export declare function configureComputerContainer(container: Pick<Container, "setInactivityTimeout"> | undefined, keepAwake: boolean): Promise<void>;
@@ -1,5 +1,8 @@
1
1
  import { z } from "zod";
2
+ /** The one idle window: a Computer sleeps this long after its last activity. */
2
3
  export const computerContainerSleepAfterMs = 15 * 60 * 1_000;
4
+ /** A kept-awake container's platform backstop: the 24 hour runtime ceiling. */
5
+ export const computerKeepAwakeTimeoutMs = 24 * 60 * 60 * 1_000;
3
6
  const hostedComputersSchema = z
4
7
  .enum(["enabled", "paused"])
5
8
  .default("enabled")
@@ -17,8 +20,9 @@ export function assertComputerContainersEnabled(hostedComputers) {
17
20
  if (hostedComputerContainersPaused(hostedComputers))
18
21
  throw new ComputerContainersPausedError();
19
22
  }
20
- export async function configureComputerContainer(container) {
23
+ /** The platform inactivity timeout is a backstop; ComputerDO owns idle sleep. */
24
+ export async function configureComputerContainer(container, keepAwake) {
21
25
  if (container === undefined)
22
26
  throw new Error("Computer Durable Object is not container-enabled");
23
- await container.setInactivityTimeout(computerContainerSleepAfterMs);
27
+ await container.setInactivityTimeout(keepAwake ? computerKeepAwakeTimeoutMs : computerContainerSleepAfterMs);
24
28
  }
@@ -1,8 +1,9 @@
1
1
  /** Host-neutral fleet contracts. Host policy is supplied as grants, never imported. */
2
2
  export { checkComputerGrant, type ComputerAdmission } from "./admission.js";
3
3
  export { createFleetBacking } from "./backing.js";
4
- export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, type ComputerAction, type ComputerProvenance, type ComputerGrant, type ComputerRuntimeState, type ComputerFact, type ComputerBackendsProjection, type ComputerBackingChange, type LocalBackendAttachInput, type LocalBackendDetachInput, } from "./wire.js";
4
+ export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, computerBackendViewSchema, localBackendAttachSchema, localBackendDetachSchema, localBackendDetachRequestSchema, ComputerBackingError, type ComputerAction, type ComputerProvenance, type ComputerGrant, type ComputerRuntimeState, type ComputerFact, type ComputerBackendView, type ComputerBackendsProjection, type ComputerBackingChange, type LocalBackendAttachInput, type LocalBackendDetachInput, } from "./wire.js";
5
5
  export { ComputerRuntimeUsage } from "./runtime-usage.js";
6
+ export { computerKeepAwake } from "./keep-awake.js";
6
7
  export { computerUsageIntervalSchema, type ComputerUsageInterval, } from "./wire.js";
7
8
  export { createFleetInventory } from "./inventory.js";
8
9
  export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, type ComputerCreateRequest, type ComputerPage, type FleetActor, type FleetComputer, } from "./inventory-wire.js";
@@ -1,8 +1,9 @@
1
1
  /** Host-neutral fleet contracts. Host policy is supplied as grants, never imported. */
2
2
  export { checkComputerGrant } from "./admission.js";
3
3
  export { createFleetBacking } from "./backing.js";
4
- export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, ComputerBackingError, } from "./wire.js";
4
+ export { computerActionSchema, computerProvenanceSchema, computerGrantSchema, computerStateSchema, computerFactSchema, computerBackendViewSchema, localBackendAttachSchema, localBackendDetachSchema, localBackendDetachRequestSchema, ComputerBackingError, } from "./wire.js";
5
5
  export { ComputerRuntimeUsage } from "./runtime-usage.js";
6
+ export { computerKeepAwake } from "./keep-awake.js";
6
7
  export { computerUsageIntervalSchema, } from "./wire.js";
7
8
  export { createFleetInventory } from "./inventory.js";
8
9
  export { ComputerInventoryError, computerCreateRequestSchema, computerPageSchema, } from "./inventory-wire.js";
@@ -0,0 +1,4 @@
1
+ import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
2
+ /** This Computer's durable Keep awake opt-in. Absence means off: an idle
3
+ * Computer sleeps, and only an intentional opt-in keeps it up and metered. */
4
+ export declare function computerKeepAwake(sql: WatchdogSqliteOwner["sql"], enabled?: boolean): boolean;
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ /** This Computer's durable Keep awake opt-in. Absence means off: an idle
3
+ * Computer sleeps, and only an intentional opt-in keeps it up and metered. */
4
+ export function computerKeepAwake(sql, enabled) {
5
+ sql.exec("CREATE TABLE IF NOT EXISTS computer_keep_awake (singleton INTEGER PRIMARY KEY CHECK (singleton=1), enabled INTEGER NOT NULL CHECK (enabled IN (0,1))) STRICT");
6
+ if (enabled !== undefined)
7
+ sql.exec("INSERT INTO computer_keep_awake (singleton,enabled) VALUES (1,?) ON CONFLICT (singleton) DO UPDATE SET enabled=excluded.enabled", enabled ? 1 : 0);
8
+ const row = sql
9
+ .exec("SELECT enabled FROM computer_keep_awake WHERE singleton=1")
10
+ .toArray()[0];
11
+ return row === undefined
12
+ ? false
13
+ : z.union([z.literal(0), z.literal(1)]).parse(row.enabled) === 1;
14
+ }
@@ -88,7 +88,16 @@ export declare class FleetLifecycle {
88
88
  syncRecycledWorkspace(backing: HostedBacking): Promise<void>;
89
89
  private finishVmRecycle;
90
90
  private recycleQuietVms;
91
+ /** Whether this Computer is metered without fresh activity: a dispatch is
92
+ * in flight, or its owner opted into Keep awake. */
93
+ private get awake();
94
+ /** Metering never runs past the last activity of a Computer that is not awake. */
95
+ private billedThrough;
96
+ /** Whether an idle runtime has passed its sleep window. */
97
+ private sleepDue;
91
98
  private observeRuntime;
99
+ /** Whether the runtime still runs, and when it stopped if it does not. */
100
+ private readRuntime;
92
101
  awaitRecycle(): Promise<void>;
93
102
  /** Reconcile durable observations before the host delivers usage facts. */
94
103
  observe(): Promise<HostedBacking[]>;
@@ -4,6 +4,7 @@ import { attachedBackendId, } from "../computer-backends.js";
4
4
  import { z } from "zod";
5
5
  import { ComputerRuntimeUsage } from "./runtime-usage.js";
6
6
  import { checkComputerGrant } from "./admission.js";
7
+ import { computerKeepAwake } from "./keep-awake.js";
7
8
  const vmRecycleAfterMs = 23 * 60 * 60 * 1_000;
8
9
  const vmRecycleQuietMs = 30_000;
9
10
  const runtimeWatchSchema = z.lazy(() => z.coerce.number().int().min(1_000).max(3_600_000).catch(60_000));
@@ -132,15 +133,13 @@ export class FleetLifecycle {
132
133
  throw new FleetGrantRefused();
133
134
  this.#hostedOperations++;
134
135
  try {
135
- if (backing.kind === "platform-container")
136
- this.usage.touchActivity(backing, Date.now());
136
+ this.usage.touchActivity(backing, Date.now());
137
137
  return await run();
138
138
  }
139
139
  finally {
140
140
  this.#hostedOperations--;
141
141
  this.#lastHostedActivity = Date.now();
142
- if (backing.kind === "platform-container")
143
- this.usage.touchActivity(backing, this.#lastHostedActivity);
142
+ this.usage.touchActivity(backing, this.#lastHostedActivity);
144
143
  if (backing.kind === "on-box-vm") {
145
144
  if (!this.usage.hasOpen(backing))
146
145
  this.#facts.push({ kind: "reservation.release" });
@@ -166,8 +165,7 @@ export class FleetLifecycle {
166
165
  return;
167
166
  lastRecordedAt = now;
168
167
  this.#lastHostedActivity = now;
169
- if (backing.kind === "platform-container")
170
- this.usage.touchActivity(backing, now);
168
+ this.usage.touchActivity(backing, now);
171
169
  };
172
170
  if (socket !== null) {
173
171
  const pair = new WebSocketPair();
@@ -267,7 +265,7 @@ export class FleetLifecycle {
267
265
  if (!(current.running && current.runtimeId === row.runtimeId)) {
268
266
  this.usage.observe(row.runtimeId, {
269
267
  running: false,
270
- endedAt: row.requestedAt,
268
+ at: this.billedThrough(row.runtimeId, row.requestedAt),
271
269
  });
272
270
  if (current.running && current.runtimeId !== null)
273
271
  this.containerRuntimeStarted({
@@ -330,32 +328,50 @@ export class FleetLifecycle {
330
328
  }
331
329
  }
332
330
  }
331
+ /** Whether this Computer is metered without fresh activity: a dispatch is
332
+ * in flight, or its owner opted into Keep awake. */
333
+ get awake() {
334
+ return (this.#hostedOperations > 0 || computerKeepAwake(this.ports.storage.sql));
335
+ }
336
+ /** Metering never runs past the last activity of a Computer that is not awake. */
337
+ billedThrough(runtimeId, at) {
338
+ if (this.awake)
339
+ return at;
340
+ return Math.min(at, this.usage.lastActivity(runtimeId, at) ?? at);
341
+ }
342
+ /** Whether an idle runtime has passed its sleep window. */
343
+ sleepDue(runtimeId, now) {
344
+ if (this.awake)
345
+ return false;
346
+ const last = this.usage.lastActivity(runtimeId, now);
347
+ return last !== null && now >= last + computerContainerSleepAfterMs;
348
+ }
333
349
  async observeRuntime(runtimeId, backing, newest) {
334
350
  const now = Date.now();
335
- if (backing.kind === "platform-container") {
336
- const container = this.ports.backend.state.container;
337
- if (newest && container?.running === true) {
338
- const deadline = this.usage.idleDeadline(runtimeId, computerContainerSleepAfterMs, now);
339
- if (deadline !== null &&
340
- this.#hostedOperations === 0 &&
341
- now >= deadline) {
342
- try {
343
- await container.destroy(new Error("Computer idle timeout"));
344
- }
345
- catch (cause) {
346
- this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
347
- return { running: true, endedAt: now };
348
- }
349
- return { running: false, endedAt: deadline };
350
- }
351
- return { running: true, endedAt: now };
351
+ const { running, exitedAt } = await this.readRuntime(runtimeId, backing, newest, now);
352
+ if (running && this.sleepDue(runtimeId, now)) {
353
+ try {
354
+ await this.destroyRuntime(backing, "Computer idle timeout");
355
+ }
356
+ catch (cause) {
357
+ this.diagnostic("computer_idle_stop_failed", "idle_stop", cause);
358
+ return { running: true, at: this.billedThrough(runtimeId, now) };
352
359
  }
353
- return { running: false, endedAt: now };
360
+ return { running: false, at: this.billedThrough(runtimeId, now) };
354
361
  }
362
+ return { running, at: this.billedThrough(runtimeId, exitedAt) };
363
+ }
364
+ /** Whether the runtime still runs, and when it stopped if it does not. */
365
+ async readRuntime(runtimeId, backing, newest, now) {
366
+ if (backing.kind === "platform-container")
367
+ return {
368
+ running: newest && this.ports.backend.state.container?.running === true,
369
+ exitedAt: now,
370
+ };
355
371
  const state = await this.ports.backend.onBoxVmHost(backing.hostId).state();
356
372
  return {
357
373
  running: state.running && state.runtimeId === runtimeId,
358
- endedAt: state.exit?.exitedAt ?? now,
374
+ exitedAt: Math.min(now, state.exit?.exitedAt ?? now),
359
375
  };
360
376
  }
361
377
  async awaitRecycle() {
@@ -429,12 +445,12 @@ export class FleetLifecycle {
429
445
  await this.ports.backend.state.container.destroy(new Error(reason));
430
446
  return this.observeOpenRuntimes();
431
447
  }
432
- async destroyRuntime(backing) {
448
+ async destroyRuntime(backing, reason = "Computer usage delivery unavailable") {
433
449
  if (backing.kind === "on-box-vm") {
434
450
  await this.ports.backend.onBoxVmHost(backing.hostId).destroy();
435
451
  return;
436
452
  }
437
453
  if (this.ports.backend.state.container !== undefined)
438
- await this.ports.backend.state.container.destroy(new Error("Computer usage delivery unavailable"));
454
+ await this.ports.backend.state.container.destroy(new Error(reason));
439
455
  }
440
456
  }
@@ -4,9 +4,9 @@ import type { ComputerFact, ComputerProvenance, ComputerUsageInterval } from "./
4
4
  /**
5
5
  * Computer-local interval ledger; the host owns usage settlement.
6
6
  *
7
- * A running runtime's checkpoint advances at most once per `checkpointMs`.
8
- * Repeated reads inside one checkpoint expose the same interval so the host
9
- * can deliver it idempotently.
7
+ * A running runtime's checkpoint advances at most once per `checkpointMs`, and
8
+ * only as far as its owner says it is billed through. Repeated reads inside one
9
+ * checkpoint expose the same interval so the host can deliver it idempotently.
10
10
  */
11
11
  export declare class ComputerRuntimeUsage {
12
12
  private readonly sql;
@@ -15,7 +15,8 @@ export declare class ComputerRuntimeUsage {
15
15
  ensure(): void;
16
16
  started(start: ContainerRuntimeStart): void;
17
17
  touchActivity(backing: HostedBacking, at: number): void;
18
- idleDeadline(runtimeId: string, idleMs: number, now: number): number | null;
18
+ /** The last recorded activity of an open runtime; a missing record starts now. */
19
+ lastActivity(runtimeId: string, now: number): number | null;
19
20
  hasOpen(backing: HostedBacking): boolean;
20
21
  hasAnyOpen(): boolean;
21
22
  open(): {
@@ -37,9 +38,13 @@ export declare class ComputerRuntimeUsage {
37
38
  requestRecycle(runtimeId: string, backing: HostedBacking, requestedAt: number): void;
38
39
  finishRecycle(runtimeId: string): void;
39
40
  oldestVmStart(): number | null;
41
+ /**
42
+ * Record a runtime observation. `at` is the end of an ended runtime, or the
43
+ * billed-through time of a running one; checkpoints never move backward.
44
+ */
40
45
  observe(runtimeId: string, observed: {
41
46
  running: boolean;
42
- endedAt: number;
47
+ at: number;
43
48
  }): void;
44
49
  pending(): ComputerUsageInterval[];
45
50
  /** Read delivery facts without changing the retained checkpoint or acknowledgment. */
@@ -3,9 +3,9 @@ import { hostedBackingSchema, } from "../computer-backends.js";
3
3
  /**
4
4
  * Computer-local interval ledger; the host owns usage settlement.
5
5
  *
6
- * A running runtime's checkpoint advances at most once per `checkpointMs`.
7
- * Repeated reads inside one checkpoint expose the same interval so the host
8
- * can deliver it idempotently.
6
+ * A running runtime's checkpoint advances at most once per `checkpointMs`, and
7
+ * only as far as its owner says it is billed through. Repeated reads inside one
8
+ * checkpoint expose the same interval so the host can deliver it idempotently.
9
9
  */
10
10
  export class ComputerRuntimeUsage {
11
11
  sql;
@@ -29,7 +29,8 @@ export class ComputerRuntimeUsage {
29
29
  this.sql.exec("UPDATE hub_computer_runtime_activity SET last_activity_at=MAX(last_activity_at, ?) WHERE runtime_id IN (SELECT runtime_id FROM hub_computer_runtime_usage WHERE backing=? AND ended=0)", at, encodedBacking);
30
30
  this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE backing=? AND ended=0", at, encodedBacking);
31
31
  }
32
- idleDeadline(runtimeId, idleMs, now) {
32
+ /** The last recorded activity of an open runtime; a missing record starts now. */
33
+ lastActivity(runtimeId, now) {
33
34
  this.ensure();
34
35
  this.sql.exec("INSERT OR IGNORE INTO hub_computer_runtime_activity (runtime_id, last_activity_at) SELECT runtime_id, ? FROM hub_computer_runtime_usage WHERE runtime_id=? AND ended=0", now, runtimeId);
35
36
  const row = this.sql
@@ -37,7 +38,7 @@ export class ComputerRuntimeUsage {
37
38
  .toArray()[0];
38
39
  return row === undefined
39
40
  ? null
40
- : z.number().int().nonnegative().parse(row.last_activity_at) + idleMs;
41
+ : z.number().int().nonnegative().parse(row.last_activity_at);
41
42
  }
42
43
  hasOpen(backing) {
43
44
  this.ensure();
@@ -102,13 +103,16 @@ export class ComputerRuntimeUsage {
102
103
  .exec("SELECT MIN(started_at) AS started_at FROM hub_computer_runtime_usage WHERE ended=0 AND json_extract(backing,'$.kind')='on-box-vm'")
103
104
  .toArray()[0]?.started_at ?? null);
104
105
  }
106
+ /**
107
+ * Record a runtime observation. `at` is the end of an ended runtime, or the
108
+ * billed-through time of a running one; checkpoints never move backward.
109
+ */
105
110
  observe(runtimeId, observed) {
106
111
  if (!observed.running) {
107
- this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.endedAt, runtimeId);
112
+ this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = MAX(observed_at, ?), ended = 1 WHERE runtime_id = ?", observed.at, runtimeId);
108
113
  return;
109
114
  }
110
- const now = Date.now();
111
- this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at <= ?", now, runtimeId, now - this.checkpointMs);
115
+ this.sql.exec("UPDATE hub_computer_runtime_usage SET observed_at = ? WHERE runtime_id = ? AND ended = 0 AND observed_at < ? AND observed_at <= ?", observed.at, runtimeId, observed.at, Date.now() - this.checkpointMs);
112
116
  }
113
117
  pending() {
114
118
  return this.sql
@@ -75,6 +75,7 @@ export declare const computerStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
75
75
  running: "running";
76
76
  sleeping: "sleeping";
77
77
  starting: "starting";
78
+ start_failed: "start_failed";
78
79
  }>;
79
80
  }, z.core.$strict>, z.ZodObject<{
80
81
  state: z.ZodLiteral<"queued">;
@@ -132,6 +133,27 @@ export declare const localBackendDetachRequestSchema: z.ZodObject<{
132
133
  requestId: z.ZodString;
133
134
  }, z.core.$strict>;
134
135
  export type LocalBackendDetachInput = z.output<typeof localBackendDetachSchema> | z.output<typeof localBackendDetachRequestSchema>;
136
+ /** One attached backend as its owner sees it on the Computer page. */
137
+ export declare const computerBackendViewSchema: z.ZodObject<{
138
+ id: z.ZodString;
139
+ kind: z.ZodEnum<{
140
+ "platform-container": "platform-container";
141
+ "on-box-vm": "on-box-vm";
142
+ local: "local";
143
+ }>;
144
+ status: z.ZodEnum<{
145
+ ready: "ready";
146
+ online: "online";
147
+ offline: "offline";
148
+ queued: "queued";
149
+ }>;
150
+ queuePosition: z.ZodNullable<z.ZodNumber>;
151
+ hostId: z.ZodNullable<z.ZodString>;
152
+ hostLabel: z.ZodNullable<z.ZodString>;
153
+ folderLabel: z.ZodNullable<z.ZodString>;
154
+ detachable: z.ZodBoolean;
155
+ }, z.core.$strict>;
156
+ export type ComputerBackendView = z.output<typeof computerBackendViewSchema>;
135
157
  /** One runtime observation; the host owns delivery and settlement. */
136
158
  export declare const computerUsageIntervalSchema: z.ZodObject<{
137
159
  runtimeId: z.ZodString;
@@ -197,6 +219,7 @@ export declare const computerFactSchema: z.ZodLazy<z.ZodDiscriminatedUnion<[z.Zo
197
219
  running: "running";
198
220
  sleeping: "sleeping";
199
221
  starting: "starting";
222
+ start_failed: "start_failed";
200
223
  }>;
201
224
  }, z.core.$strict>, z.ZodObject<{
202
225
  state: z.ZodLiteral<"queued">;
@@ -32,7 +32,10 @@ export const computerGrantSchema = z.strictObject({
32
32
  });
33
33
  /** State visible without knowing which application hosts the Computer. */
34
34
  export const computerStateSchema = z.discriminatedUnion("state", [
35
- z.strictObject({ state: z.enum(["running", "sleeping", "starting"]) }),
35
+ // start_failed: a queued start ended without running; start again.
36
+ z.strictObject({
37
+ state: z.enum(["running", "sleeping", "starting", "start_failed"]),
38
+ }),
36
39
  z.strictObject({
37
40
  state: z.literal("queued"),
38
41
  position: z.number().int().positive(),
@@ -74,6 +77,18 @@ export const localBackendDetachRequestSchema = z.strictObject({
74
77
  computerId: localBackendAttachSchema.shape.computerId,
75
78
  requestId: localBackendAttachSchema.shape.requestId,
76
79
  });
80
+ /** One attached backend as its owner sees it on the Computer page. */
81
+ export const computerBackendViewSchema = z.strictObject({
82
+ id: z.string(),
83
+ kind: z.enum(["platform-container", "on-box-vm", "local"]),
84
+ status: z.enum(["ready", "queued", "online", "offline"]),
85
+ queuePosition: z.number().int().positive().nullable(),
86
+ hostId: z.string().nullable(),
87
+ hostLabel: z.string().nullable(),
88
+ folderLabel: z.string().nullable(),
89
+ /** Only the actor who attached a machine may detach it. */
90
+ detachable: z.boolean(),
91
+ });
77
92
  const factIdentity = {
78
93
  computerId: computerGrantSchema.shape.computerId,
79
94
  provenance: computerProvenanceSchema,
package/dist/index.d.ts CHANGED
@@ -140,6 +140,11 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
140
140
  constructor(ctx: DurableObjectState, env: ComputerEnv);
141
141
  /** Host-admitted settings write; egress reads the current durable value. */
142
142
  internetAccess(enabled?: boolean): boolean;
143
+ /**
144
+ * Host-admitted Keep awake write. The fleet's idle policy and metering read
145
+ * the durable value; a container's platform backstop follows it.
146
+ */
147
+ keepAwake(enabled?: boolean): Promise<boolean>;
143
148
  /** Ordinary Computers have no credential host; resource hosts override it. */
144
149
  protected executionHooks(): ComputerExecutionHostHooks | undefined;
145
150
  /**
@@ -297,7 +302,7 @@ export { WorkspaceProxy, WorkspaceServiceProxy };
297
302
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, type OnBoxVmEnv, type OnBoxVmOperation, type OnBoxVmState, } from "./on-box-vm.js";
298
303
  export { computerContainerSleepAfterMs } from "./container-policy.js";
299
304
  export * from "./computer-backends.js";
300
- export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
305
+ export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
301
306
  /** Keep each native Workspace lease inside the operation that uses it. */
302
307
  export declare function createComputerFilesPort(computer: ComputerFilesRpc | Rpc.Provider<ComputerFilesRpc>): FilesPort;
303
308
  export { createWorkspaceFilesPort, type WorkspaceFilesOwner } from "./files.js";
package/dist/index.js CHANGED
@@ -74,11 +74,12 @@ import { ComputerOperationRecord } from "./operation-record.js";
74
74
  import { createComputerExecutionLifecycle } from "./execution-lifecycle.js";
75
75
  import { applyWorkspacePatch } from "./files-patch.js";
76
76
  import { ComputerProcessInventory, drainProcessExit, failedObservation, observeProcess, } from "./process-inventory.js";
77
- import { assertComputerContainersEnabled, computerContainerSleepAfterMs, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
77
+ import { assertComputerContainersEnabled, ComputerContainersPausedError, configureComputerContainer, hostedComputerContainersPaused, } from "./container-policy.js";
78
78
  import { OnBoxVmContainerHost, onBoxVmPlacement, } from "./on-box-vm.js";
79
+ import { computerKeepAwake } from "./fleet/keep-awake.js";
79
80
  import { attachedBackendId, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
80
81
  import { MeteredContainerHost } from "./metered-container-host.js";
81
- import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
82
+ import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
82
83
  const computerBinding = "COMPUTER";
83
84
  const utf8 = new TextEncoder();
84
85
  const terminalDefaultCols = 80;
@@ -237,7 +238,7 @@ class ContainerComputer extends ContainerComputerBase {
237
238
  if (ctx.container === undefined ||
238
239
  hostedComputerContainersPaused(env.HOSTED_COMPUTERS))
239
240
  return;
240
- ctx.waitUntil(configureComputerContainer(ctx.container));
241
+ ctx.waitUntil(configureComputerContainer(ctx.container, computerKeepAwake(ctx.storage.sql)));
241
242
  }
242
243
  getWorkspaceContainer() {
243
244
  assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
@@ -352,7 +353,7 @@ class ContainerComputer extends ContainerComputerBase {
352
353
  }
353
354
  /** Let the consuming owner admit boots while preserving the runtime host seam. */
354
355
  createOnBoxVmHost(placement) {
355
- return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString(), computerContainerSleepAfterMs);
356
+ return new OnBoxVmContainerHost(placement, this.bindings, this.state.id.toString());
356
357
  }
357
358
  /** Whether a hosted backend's runtime is running now. */
358
359
  async containerRunning(backing) {
@@ -469,6 +470,9 @@ class ContainerComputer extends ContainerComputerBase {
469
470
  const dial = localBackendDialPath.exec(url.pathname);
470
471
  if (dial !== null)
471
472
  return this.#acceptLocalDial(request, dial[2] ?? "", dial[3] ?? "");
473
+ const ownerDial = ownerLocalBackendDialPath.exec(url.pathname);
474
+ if (ownerDial !== null)
475
+ return this.#acceptLocalDial(request, ownerDial[1] ?? "", ownerDial[2] ?? "");
472
476
  const vm = vmUpgradePath.exec(url.pathname);
473
477
  const id = vm === null ? "container" : `vm-${vm[1] ?? ""}`;
474
478
  if (vm !== null)
@@ -490,6 +494,18 @@ export class ComputerDO extends ContainerComputer {
490
494
  internetAccess(enabled) {
491
495
  return computerInternetAccess(this.state.storage.sql, enabled);
492
496
  }
497
+ /**
498
+ * Host-admitted Keep awake write. The fleet's idle policy and metering read
499
+ * the durable value; a container's platform backstop follows it.
500
+ */
501
+ async keepAwake(enabled) {
502
+ const kept = computerKeepAwake(this.state.storage.sql, enabled);
503
+ if (enabled !== undefined &&
504
+ this.state.container !== undefined &&
505
+ !hostedComputerContainersPaused(this.bindings.HOSTED_COMPUTERS))
506
+ await configureComputerContainer(this.state.container, kept);
507
+ return kept;
508
+ }
493
509
  #binaryFileTail = Promise.resolve(undefined);
494
510
  #operationRecord;
495
511
  #processRecord;
@@ -1522,7 +1538,7 @@ export { WorkspaceProxy, WorkspaceServiceProxy };
1522
1538
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, } from "./on-box-vm.js";
1523
1539
  export { computerContainerSleepAfterMs } from "./container-policy.js";
1524
1540
  export * from "./computer-backends.js";
1525
- export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
1541
+ export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
1526
1542
  /** Keep each native Workspace lease inside the operation that uses it. */
1527
1543
  export function createComputerFilesPort(computer) {
1528
1544
  async function withFiles(operation) {
@@ -51,3 +51,9 @@ export declare function verifyLocalBackendDial(request: Request, computerName: s
51
51
  * The Hub forwards it unchanged so the signature covers what the machine sent.
52
52
  */
53
53
  export declare const localBackendDialPath: RegExp;
54
+ /**
55
+ * A standalone Oyster has one owner and no Teams. Its machines dial the owner's
56
+ * Computer directly: `/api/computers/:computer/backends/:id/connect`, signed
57
+ * for the same audience.
58
+ */
59
+ export declare const ownerLocalBackendDialPath: RegExp;
@@ -141,3 +141,9 @@ export async function verifyLocalBackendDial(request, computerName, backend, own
141
141
  * The Hub forwards it unchanged so the signature covers what the machine sent.
142
142
  */
143
143
  export const localBackendDialPath = /^\/api\/teams\/([^/]+)\/computers\/([^/]+)\/backends\/(local-[a-z2-7]{16})\/connect$/;
144
+ /**
145
+ * A standalone Oyster has one owner and no Teams. Its machines dial the owner's
146
+ * Computer directly: `/api/computers/:computer/backends/:id/connect`, signed
147
+ * for the same audience.
148
+ */
149
+ export const ownerLocalBackendDialPath = /^\/api\/computers\/([^/]+)\/backends\/(local-[a-z2-7]{16})\/connect$/;
@@ -74,7 +74,7 @@ export declare class OnBoxVmTimeoutError extends OnBoxVmTimeoutError_base<{
74
74
  /** One Durable Object's view of its microVM through the host service. */
75
75
  export declare class OnBoxVmContainerHost implements IWorkspaceContainerAPI {
76
76
  #private;
77
- constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string, sleepAfterMs: number);
77
+ constructor(placement: OnBoxVmPlacement, env: OnBoxVmEnv, vmId: string);
78
78
  /** Signed host-wide inventory; includes VMs outside this Hub's directory. */
79
79
  inventory(): Promise<OnBoxVmInventory>;
80
80
  start(env: Record<string, string>, enableInternet: boolean): Promise<{
package/dist/on-box-vm.js CHANGED
@@ -90,6 +90,11 @@ const vmInventorySchema = z.array(vmStateSchema.extend({
90
90
  const vmStartSchema = z.lazy(() => z.strictObject({
91
91
  runtimeId: z.string().min(1).max(128),
92
92
  }));
93
+ /**
94
+ * vmd's own traffic timer is only a backstop at its maximum: ComputerDO owns
95
+ * idle sleep, so a kept-awake VM is not stopped by the host while it is quiet.
96
+ */
97
+ const vmHostSleepBackstopMs = 24 * 60 * 60 * 1_000;
93
98
  /** A bounded control-plane wait, not the VM's execution or allocation lifetime. */
94
99
  const vmControlTimeoutMs = 60_000;
95
100
  /** The host's outcome is unknown after a timeout; this is not evidence of offline. */
@@ -119,15 +124,13 @@ export class OnBoxVmContainerHost {
119
124
  #placement;
120
125
  #env;
121
126
  #vmId;
122
- #sleepAfterMs;
123
- constructor(placement, env, vmId, sleepAfterMs) {
127
+ constructor(placement, env, vmId) {
124
128
  this.#placement = placement;
125
129
  this.#env = env;
126
130
  this.#vmId = z
127
131
  .string()
128
132
  .regex(/^[0-9a-f]{64}$/)
129
133
  .parse(vmId);
130
- this.#sleepAfterMs = sleepAfterMs;
131
134
  }
132
135
  async #call(operation, schema, body) {
133
136
  let path = `/vms/${this.#vmId}`;
@@ -161,7 +164,7 @@ export class OnBoxVmContainerHost {
161
164
  const started = await this.#call(operation, vmStartSchema, {
162
165
  env,
163
166
  enableInternet,
164
- sleepAfterMs: this.#sleepAfterMs,
167
+ sleepAfterMs: vmHostSleepBackstopMs,
165
168
  });
166
169
  return { runtimeId: started.runtimeId };
167
170
  }
@@ -19718,6 +19718,7 @@ var appCapabilityIds = [
19718
19718
  "computer.execute",
19719
19719
  "llm.generation",
19720
19720
  "media.generation",
19721
+ "media.share",
19721
19722
  "games:servers",
19722
19723
  "git.repository",
19723
19724
  "apps.open",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "author": "Levi <levi@technomancy.dev>",
5
5
  "description": "Cloudflare Computer host for one durable Fungi Computer",
6
6
  "type": "module",
@@ -60,10 +60,10 @@
60
60
  "@fungi.computer/capnweb": "0.12.0",
61
61
  "@fungi.computer/cloudflare-computer": "0.2.1-fungi.2",
62
62
  "@fungi.computer/cordyceps": "0.4.0",
63
- "@fungi.computer/knapsack": "0.4.3",
64
- "@fungi.computer/seam": "0.2.0",
63
+ "@fungi.computer/knapsack": "0.4.5",
64
+ "@fungi.computer/seam": "0.2.1",
65
65
  "@fungi.computer/watchdog": "0.1.0",
66
- "@fungi.computer/computer-contract": "0.0.8",
66
+ "@fungi.computer/computer-contract": "0.0.10",
67
67
  "effect": "4.0.2",
68
68
  "just-bash": "3.4.2",
69
69
  "zod": "4.4.3"
@@ -118,9 +118,8 @@
118
118
  "test:nightly": "bash ../../tooling/proof-runner/run-proof.sh node test/egress-proof.mjs",
119
119
  "test:app-method-execution": "node test/app-method-execution-proof.mjs",
120
120
  "test:execution-lifecycle": "node test/execution-lifecycle-proof.mjs",
121
- "test:unit": "node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs",
121
+ "test:unit": "node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/egress-policy.test.mjs test/preview.test.mjs test/fleet.test.mjs test/proof-worker.test.mjs test/proof-client.test.mjs test/native-readiness.test.mjs test/workspace-sync.test.mjs test/runtime-observer.test.mjs test/files-patch.test.mjs test/exec-output.test.mjs && node --test --test-concurrency=${BOTANICAL_TEST_WORKERS:-4} test/seam-signature.test.mjs test/local-backend-replay.test.mjs test/machine-link-reopen-replay.test.mjs test/computer-backends.test.mjs test/terminal-welcome.test.mjs test/on-box-vm.test.mjs && node test/terminal-protocol.test.mjs && node test/container-policy.test.mjs && node test/files-adapter-proof.mjs && node test/operation-record-proof.mjs && node test/process-inventory-proof.mjs",
122
122
  "test:fleet-native": "node test/fleet.native.mjs",
123
- "test:light-shell:native": "node --import tsx test/light-shell.native.mjs --state",
124
123
  "assemble:image": "node scripts/assemble-image.mjs"
125
124
  }
126
125
  }