@fungi.computer/computer 0.5.0 → 0.6.1

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,7 @@
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
6
  export { computerKeepAwake } from "./keep-awake.js";
7
7
  export { computerUsageIntervalSchema, type ComputerUsageInterval, } from "./wire.js";
@@ -1,7 +1,7 @@
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
6
  export { computerKeepAwake } from "./keep-awake.js";
7
7
  export { computerUsageIntervalSchema, } from "./wire.js";
@@ -133,6 +133,27 @@ export declare const localBackendDetachRequestSchema: z.ZodObject<{
133
133
  requestId: z.ZodString;
134
134
  }, z.core.$strict>;
135
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>;
136
157
  /** One runtime observation; the host owns delivery and settlement. */
137
158
  export declare const computerUsageIntervalSchema: z.ZodObject<{
138
159
  runtimeId: z.ZodString;
@@ -77,6 +77,18 @@ export const localBackendDetachRequestSchema = z.strictObject({
77
77
  computerId: localBackendAttachSchema.shape.computerId,
78
78
  requestId: localBackendAttachSchema.shape.requestId,
79
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
+ });
80
92
  const factIdentity = {
81
93
  computerId: computerGrantSchema.shape.computerId,
82
94
  provenance: computerProvenanceSchema,
package/dist/index.d.ts CHANGED
@@ -302,7 +302,7 @@ export { WorkspaceProxy, WorkspaceServiceProxy };
302
302
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, type OnBoxVmEnv, type OnBoxVmOperation, type OnBoxVmState, } from "./on-box-vm.js";
303
303
  export { computerContainerSleepAfterMs } from "./container-policy.js";
304
304
  export * from "./computer-backends.js";
305
- export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
305
+ export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
306
306
  /** Keep each native Workspace lease inside the operation that uses it. */
307
307
  export declare function createComputerFilesPort(computer: ComputerFilesRpc | Rpc.Provider<ComputerFilesRpc>): FilesPort;
308
308
  export { createWorkspaceFilesPort, type WorkspaceFilesOwner } from "./files.js";
package/dist/index.js CHANGED
@@ -79,7 +79,7 @@ import { OnBoxVmContainerHost, onBoxVmPlacement, } from "./on-box-vm.js";
79
79
  import { computerKeepAwake } from "./fleet/keep-awake.js";
80
80
  import { attachedBackendId, describeAttachedBackend, routeComputerBackend, } from "./computer-backends.js";
81
81
  import { MeteredContainerHost } from "./metered-container-host.js";
82
- import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
82
+ import { LocalBackendConnections, LocalWorkspaceBackend, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
83
83
  const computerBinding = "COMPUTER";
84
84
  const utf8 = new TextEncoder();
85
85
  const terminalDefaultCols = 80;
@@ -470,6 +470,9 @@ class ContainerComputer extends ContainerComputerBase {
470
470
  const dial = localBackendDialPath.exec(url.pathname);
471
471
  if (dial !== null)
472
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] ?? "");
473
476
  const vm = vmUpgradePath.exec(url.pathname);
474
477
  const id = vm === null ? "container" : `vm-${vm[1] ?? ""}`;
475
478
  if (vm !== null)
@@ -1535,7 +1538,7 @@ export { WorkspaceProxy, WorkspaceServiceProxy };
1535
1538
  export { OnBoxVmContainerHost, OnBoxVmTimeoutError, onBoxVmPlacement, onBoxVmIngress, } from "./on-box-vm.js";
1536
1539
  export { computerContainerSleepAfterMs } from "./container-policy.js";
1537
1540
  export * from "./computer-backends.js";
1538
- export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
1541
+ export { LocalBackendOfflineError, localBackendAudience, localBackendDialPath, ownerLocalBackendDialPath, verifyLocalBackendDial, } from "./local-backend.js";
1539
1542
  /** Keep each native Workspace lease inside the operation that uses it. */
1540
1543
  export function createComputerFilesPort(computer) {
1541
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$/;
package/dist/on-box-vm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import * as Data from "effect/Data";
3
- import { SeamReplayGuard, importSeamSigner, importSeamVerifiers, seamBodyDigest, seamHeader, signSeamRequest, unsignedPayload, verifySeamRequest, } from "@fungi.computer/seam";
3
+ import { SeamReplayPartitions, importSeamSigner, importSeamVerifiers, seamBodyDigest, seamHeader, signSeamRequest, unsignedPayload, verifySeamRequest, } from "@fungi.computer/seam";
4
4
  function accessHeaders(env) {
5
5
  const id = env.COMPUTER_VM_ACCESS_CLIENT_ID;
6
6
  const secret = env.COMPUTER_VM_ACCESS_CLIENT_SECRET;
@@ -241,7 +241,24 @@ export class OnBoxVmContainerHost {
241
241
  }
242
242
  const ingressPath = /^\/__computer-vm\/([0-9a-f]{64})(\/.*)$/;
243
243
  const egressUrlSchema = z.url({ protocol: /^https?$/ });
244
- const ingressReplay = new SeamReplayGuard();
244
+ /** Slots one host's vmd can place (`maxSlots` in the celld VM instances). */
245
+ const vmSlotsPerHost = 16_000;
246
+ const ingressReplays = new Map();
247
+ /**
248
+ * Ingress replay history, one bounded partition per VM id. The id is part of
249
+ * the signed path, so one guest's request rate fills only its own VM's
250
+ * history and never refuses another VM on the same or another host. The
251
+ * partition ceiling is every VM the registered hosts can place.
252
+ */
253
+ function ingressReplay(env, vmId) {
254
+ const raw = env.COMPUTER_VM_HOSTS ?? "{}";
255
+ let replays = ingressReplays.get(raw);
256
+ if (replays === undefined) {
257
+ replays = new SeamReplayPartitions(Math.max(1, Object.keys(hostRegistry(env)).length) * vmSlotsPerHost);
258
+ ingressReplays.set(raw, replays);
259
+ }
260
+ return replays.partition(vmId);
261
+ }
245
262
  /**
246
263
  * The host service's door into this Worker: a VM's intercepted request
247
264
  * reaches its Computer exactly as the platform container's interception
@@ -258,9 +275,9 @@ export function onBoxVmIngress(request, env, computers) {
258
275
  return verifiedVmIngress(request, env, computers, id, rest, url.search);
259
276
  }
260
277
  /** The verified host id of a signed ingress request, or undefined. */
261
- async function ingressHost(request, env) {
278
+ async function ingressHost(request, env, vmId) {
262
279
  try {
263
- return await verifySeamRequest(await hostVerifiers(env), vmIngressAudience, request.method, request.url, request.headers.get(seamHeader), null, ingressReplay);
280
+ return await verifySeamRequest(await hostVerifiers(env), vmIngressAudience, request.method, request.url, request.headers.get(seamHeader), null, ingressReplay(env, vmId));
264
281
  }
265
282
  catch (cause) {
266
283
  console.error("VM seam verification refused", cause);
@@ -296,7 +313,7 @@ function vmEgressTarget(target, headers, token, url) {
296
313
  target.search = "";
297
314
  }
298
315
  async function verifiedVmIngress(request, env, computers, id, rest, search) {
299
- const hostId = await ingressHost(request, env);
316
+ const hostId = await ingressHost(request, env, id);
300
317
  if (hostId === undefined)
301
318
  return new Response(null, { status: 404 });
302
319
  const headers = new Headers(request.headers);
@@ -22548,15 +22548,15 @@ function encodeTeamAppCandidateManifest(manifest) {
22548
22548
  function candidateManifestObjects(output) {
22549
22549
  const objects = [];
22550
22550
  const add2 = (object3, mediaType) => {
22551
- const seen = objects.find(({ digest }) => digest === object3.digest);
22552
- if (seen === void 0)
22551
+ const named = objects.filter(({ digest }) => digest === object3.digest);
22552
+ if (named.some(({ byteLength }) => byteLength !== object3.byteLength))
22553
+ throw new Error("One object digest names two sizes");
22554
+ if (!named.some((seen) => seen.mediaType === mediaType))
22553
22555
  objects.push({
22554
22556
  digest: object3.digest,
22555
22557
  byteLength: object3.byteLength,
22556
22558
  mediaType
22557
22559
  });
22558
- else if (seen.byteLength !== object3.byteLength)
22559
- throw new Error("One object digest names two sizes");
22560
22560
  };
22561
22561
  if (output.kind !== "backend") {
22562
22562
  const { content } = output.ui;
@@ -24034,26 +24034,24 @@ function sha256(bytes) {
24034
24034
  `sha256:${createHash2("sha256").update(bytes).digest("hex")}`
24035
24035
  );
24036
24036
  }
24037
- function contentArtifactRef(digest) {
24038
- return parseArtifactRef(`artifact:sha256-${digest.slice("sha256:".length)}`);
24039
- }
24040
24037
  var fallbackRootBytes = 1024 * 1024;
24041
24038
  function stageBuildOutput(output) {
24042
24039
  const objects = [];
24043
- const stage = (bytes) => {
24040
+ const stage = (bytes, mediaType) => {
24044
24041
  const digest = sha256(bytes);
24045
- if (!objects.some((object3) => object3.digest === digest))
24046
- objects.push({
24047
- artifactRef: contentArtifactRef(digest),
24048
- bytes: bytes.slice(),
24049
- digest
24050
- });
24042
+ if (!objects.some(
24043
+ (object3) => object3.digest === digest && object3.mediaType === mediaType
24044
+ ))
24045
+ objects.push({ bytes: bytes.slice(), digest, mediaType });
24051
24046
  return { digest, byteLength: bytes.byteLength };
24052
24047
  };
24053
24048
  const declared = output.declaration === void 0 ? {} : { declaration: output.declaration };
24054
24049
  const ui = (prepared) => prepared.content.kind === "html" ? {
24055
24050
  mediaType: "text/html; charset=utf-8",
24056
- content: { kind: "html", ...stage(prepared.content.bytes) }
24051
+ content: {
24052
+ kind: "html",
24053
+ ...stage(prepared.content.bytes, "text/html; charset=utf-8")
24054
+ }
24057
24055
  } : {
24058
24056
  mediaType: "application/vnd.fungi.app-assets+json",
24059
24057
  content: {
@@ -24061,14 +24059,24 @@ function stageBuildOutput(output) {
24061
24059
  base: prepared.content.base,
24062
24060
  assets: prepared.content.assets.map((asset) => ({
24063
24061
  path: asset.path,
24064
- ...stage(asset.bytes)
24062
+ ...stage(asset.bytes, "application/octet-stream")
24065
24063
  }))
24066
24064
  }
24067
24065
  };
24068
- const manifest = output.kind === "ui" ? { kind: "ui", ui: ui(output.ui), ...declared } : output.kind === "backend" ? { kind: "backend", backend: stage(output.backend), ...declared } : {
24066
+ const manifest = output.kind === "ui" ? { kind: "ui", ui: ui(output.ui), ...declared } : output.kind === "backend" ? {
24067
+ kind: "backend",
24068
+ backend: stage(
24069
+ output.backend,
24070
+ "application/vnd.fungi.app-backend+json"
24071
+ ),
24072
+ ...declared
24073
+ } : {
24069
24074
  kind: "app",
24070
24075
  ui: ui(output.ui),
24071
- backend: stage(output.backend),
24076
+ backend: stage(
24077
+ output.backend,
24078
+ "application/vnd.fungi.app-backend+json"
24079
+ ),
24072
24080
  ...declared
24073
24081
  };
24074
24082
  return { manifest, objects };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fungi.computer/computer",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
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.4",
64
- "@fungi.computer/seam": "0.2.0",
63
+ "@fungi.computer/knapsack": "0.4.5",
64
+ "@fungi.computer/seam": "0.2.2",
65
65
  "@fungi.computer/watchdog": "0.1.0",
66
- "@fungi.computer/computer-contract": "0.0.9",
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,7 +118,7 @@
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/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",
121
+ "test:unit": "bash ../../tooling/proof-runner/hermetic-host.sh -- sh -c \"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
123
  "assemble:image": "node scripts/assemble-image.mjs"
124
124
  }