@fungi.computer/computer 0.8.4 → 0.8.5
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/dist/computer-name.d.ts +9 -0
- package/dist/computer-name.js +38 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +14 -2
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WatchdogSqliteOwner } from "@fungi.computer/watchdog";
|
|
2
|
+
/** Record the name a name-addressed wake carries. */
|
|
3
|
+
export declare function recordComputerName(sql: WatchdogSqliteOwner["sql"], name: string): void;
|
|
4
|
+
/**
|
|
5
|
+
* The wake's own name, else the recorded one. Read-only: it never recreates
|
|
6
|
+
* the record after an erasure. Undefined only when no name-addressed wake has
|
|
7
|
+
* reached this Computer.
|
|
8
|
+
*/
|
|
9
|
+
export declare function computerName(sql: WatchdogSqliteOwner["sql"], wokenAs: string | undefined): string | undefined;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/*
|
|
3
|
+
* A Computer's durable name, recorded by each name-addressed wake.
|
|
4
|
+
*
|
|
5
|
+
* `ctx.id.name` belongs to the wake that constructed the live instance, not to
|
|
6
|
+
* the object. The doors that address a Computer by object id (the container's
|
|
7
|
+
* WorkspaceProxy reconnect and egress, the service proxy, VM ingress) and
|
|
8
|
+
* alarms wake it with no name, and every later name-addressed call reaches
|
|
9
|
+
* that same nameless instance. A redeploy restarts the object while its
|
|
10
|
+
* container reconnects, so a nameless instance reads the name from storage.
|
|
11
|
+
*/
|
|
12
|
+
/** Record the name a name-addressed wake carries. */
|
|
13
|
+
export function recordComputerName(sql, name) {
|
|
14
|
+
sql.exec("CREATE TABLE IF NOT EXISTS computer_name (singleton INTEGER PRIMARY KEY CHECK (singleton=1), name TEXT NOT NULL) STRICT");
|
|
15
|
+
sql.exec("INSERT INTO computer_name (singleton,name) VALUES (1,?) ON CONFLICT (singleton) DO NOTHING", name);
|
|
16
|
+
// An object id is derived from its name, so a second name is corruption.
|
|
17
|
+
if (storedComputerName(sql) !== name)
|
|
18
|
+
throw new Error("Computer storage records a different name");
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The wake's own name, else the recorded one. Read-only: it never recreates
|
|
22
|
+
* the record after an erasure. Undefined only when no name-addressed wake has
|
|
23
|
+
* reached this Computer.
|
|
24
|
+
*/
|
|
25
|
+
export function computerName(sql, wokenAs) {
|
|
26
|
+
return wokenAs ?? storedComputerName(sql);
|
|
27
|
+
}
|
|
28
|
+
function storedComputerName(sql) {
|
|
29
|
+
const recorded = sql
|
|
30
|
+
.exec("SELECT 1 FROM sqlite_master WHERE type='table' AND name='computer_name'")
|
|
31
|
+
.toArray().length > 0;
|
|
32
|
+
if (!recorded)
|
|
33
|
+
return undefined;
|
|
34
|
+
const row = sql
|
|
35
|
+
.exec("SELECT name FROM computer_name WHERE singleton=1")
|
|
36
|
+
.toArray()[0];
|
|
37
|
+
return row === undefined ? undefined : z.string().parse(row.name);
|
|
38
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -78,6 +78,12 @@ declare class ContainerComputer extends ContainerComputerBase {
|
|
|
78
78
|
/** Parked dial-ins from attached machines; survives Workspace rebuilds. */
|
|
79
79
|
readonly localConnections: LocalBackendConnections;
|
|
80
80
|
constructor(ctx: DurableObjectState, env: ComputerEnv);
|
|
81
|
+
/**
|
|
82
|
+
* This Computer's name, from storage: an instance first woken by object id
|
|
83
|
+
* has no `ctx.id.name` for its whole life. Undefined only when no
|
|
84
|
+
* name-addressed wake has reached this Computer yet.
|
|
85
|
+
*/
|
|
86
|
+
protected computerName(): string | undefined;
|
|
81
87
|
getWorkspaceContainer(): import("@fungi.computer/cloudflare-computer/backends/container").WorkspaceContainerAPI;
|
|
82
88
|
/**
|
|
83
89
|
* This Computer's attached backends, in attach order. The standalone
|
|
@@ -302,6 +308,7 @@ export declare class ComputerDO extends ContainerComputer implements ComputerFil
|
|
|
302
308
|
protected replaceFileIfUnchangedAfterAcceptance(input: ComputerFileReplacement, accept: () => void): Promise<ComputerFileReplacementResult>;
|
|
303
309
|
}
|
|
304
310
|
export { WorkspaceProxy, WorkspaceServiceProxy };
|
|
311
|
+
export { computerName } from "./computer-name.js";
|
|
305
312
|
export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, type OnBoxVmEnv, type OnBoxVmOperation, type OnBoxVmState, } from "./on-box-vm.js";
|
|
306
313
|
export { computerContainerSleepAfterMs } from "./container-policy.js";
|
|
307
314
|
export * from "./computer-backends.js";
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
53
53
|
import { boundExecStream } from "./exec-output.js";
|
|
54
54
|
export { createLocalBackendReplayStore } from "./local-backend-replay.js";
|
|
55
55
|
import { computerInternetAccess } from "./internet-access.js";
|
|
56
|
+
import { computerName, recordComputerName } from "./computer-name.js";
|
|
56
57
|
import { getWorkspace, SQLiteWorkspaceProvider, Workspace, WorkspaceProxy, WorkspaceServiceProxy, } from "@fungi.computer/cloudflare-computer";
|
|
57
58
|
import { WorkerShellBackend, } from "@fungi.computer/cloudflare-computer/backends/worker-shell";
|
|
58
59
|
import jqCommands from "@fungi.computer/cloudflare-computer/shell/jq";
|
|
@@ -235,11 +236,21 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
235
236
|
#pullPending = new PullPendingTracker();
|
|
236
237
|
constructor(ctx, env) {
|
|
237
238
|
super(ctx, env);
|
|
239
|
+
if (ctx.id.name !== undefined)
|
|
240
|
+
recordComputerName(ctx.storage.sql, ctx.id.name);
|
|
238
241
|
if (ctx.container === undefined ||
|
|
239
242
|
hostedComputerContainersPaused(env.HOSTED_COMPUTERS))
|
|
240
243
|
return;
|
|
241
244
|
ctx.waitUntil(configureComputerContainer(ctx.container, computerKeepAwake(ctx.storage.sql)));
|
|
242
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* This Computer's name, from storage: an instance first woken by object id
|
|
248
|
+
* has no `ctx.id.name` for its whole life. Undefined only when no
|
|
249
|
+
* name-addressed wake has reached this Computer yet.
|
|
250
|
+
*/
|
|
251
|
+
computerName() {
|
|
252
|
+
return computerName(this.state.storage.sql, this.state.id.name);
|
|
253
|
+
}
|
|
243
254
|
getWorkspaceContainer() {
|
|
244
255
|
assertComputerContainersEnabled(this.bindings.HOSTED_COMPUTERS);
|
|
245
256
|
return super.getWorkspaceContainer();
|
|
@@ -280,7 +291,7 @@ class ContainerComputer extends ContainerComputerBase {
|
|
|
280
291
|
const backend = this.attachedBackends().find((candidate) => candidate.kind === "local" &&
|
|
281
292
|
attachedBackendId(candidate) === backendId);
|
|
282
293
|
if (backend === undefined ||
|
|
283
|
-
computerName !== this.
|
|
294
|
+
computerName !== this.computerName() ||
|
|
284
295
|
!(await verifyLocalBackendDial(request, computerName, backend, this.state.storage)))
|
|
285
296
|
return new Response(null, { status: 404 });
|
|
286
297
|
// A verified plain request lets the machine tell attached from detached.
|
|
@@ -1535,7 +1546,7 @@ export class ComputerDO extends ContainerComputer {
|
|
|
1535
1546
|
/** Host-owned display labels only; never credentials or provider URLs. */
|
|
1536
1547
|
terminalDisplayEnvironment() {
|
|
1537
1548
|
return Promise.resolve({
|
|
1538
|
-
FUNGI_COMPUTER_NAME: this.
|
|
1549
|
+
FUNGI_COMPUTER_NAME: this.computerName() ?? "Computer",
|
|
1539
1550
|
});
|
|
1540
1551
|
}
|
|
1541
1552
|
/** Atomically replace one bounded file only when its raw contents still match. */
|
|
@@ -1567,6 +1578,7 @@ export class ComputerDO extends ContainerComputer {
|
|
|
1567
1578
|
// Runtime backends reach the authoritative Workspace through these loopback
|
|
1568
1579
|
// entrypoints. The consuming Worker must re-export both from its main module.
|
|
1569
1580
|
export { WorkspaceProxy, WorkspaceServiceProxy };
|
|
1581
|
+
export { computerName } from "./computer-name.js";
|
|
1570
1582
|
export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, } from "./on-box-vm.js";
|
|
1571
1583
|
export { computerContainerSleepAfterMs } from "./container-policy.js";
|
|
1572
1584
|
export * from "./computer-backends.js";
|