@fungi.computer/oyster 0.33.0 → 0.35.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.
Files changed (44) hide show
  1. package/README.md +62 -1
  2. package/dist/app-sandbox.d.ts +2 -2
  3. package/dist/app-sandbox.js +2 -2
  4. package/dist/approval-deadline.d.ts +2 -0
  5. package/dist/approval-deadline.js +7 -0
  6. package/dist/approval-home.d.ts +26 -3
  7. package/dist/approval-home.js +148 -18
  8. package/dist/apps/index.d.ts +1 -1
  9. package/dist/apps/index.js +1 -1
  10. package/dist/boot-host-script.js +1 -1
  11. package/dist/embed-metafiles.js +2 -2
  12. package/dist/embed-scripts.js +1 -1
  13. package/dist/hello-app-script.js +1 -1
  14. package/dist/host.d.ts +6 -4
  15. package/dist/host.js +8 -4
  16. package/dist/mcp.js +42 -13
  17. package/dist/page/app-permissions.js +8 -7
  18. package/dist/page/computer-handles.d.ts +0 -1
  19. package/dist/page/mount.js +1 -0
  20. package/dist/page-config.d.ts +1 -0
  21. package/dist/page-config.js +1 -0
  22. package/dist/page-script.js +2 -2
  23. package/dist/platform-skills.generated.d.ts +5 -2
  24. package/dist/platform-skills.generated.js +6 -2
  25. package/dist/standalone/agents.js +43 -7
  26. package/dist/standalone/computer-fleet.js +3 -0
  27. package/dist/standalone/computer.d.ts +6 -2
  28. package/dist/standalone/computer.js +27 -14
  29. package/dist/standalone/media.js +7 -2
  30. package/dist/standalone/preview.d.ts +21 -20
  31. package/dist/standalone/preview.js +147 -151
  32. package/dist/standalone/registry.d.ts +16 -21
  33. package/dist/standalone/registry.js +81 -28
  34. package/dist/standalone/worker.d.ts +1 -1
  35. package/dist/standalone/worker.js +23 -7
  36. package/dist/starter-agent.d.ts +6 -2
  37. package/dist/starter-agent.js +25 -4
  38. package/dist/workers.d.ts +31 -13
  39. package/dist/workers.js +86 -15
  40. package/docs/api/apps.md +21 -0
  41. package/docs/api/host.md +41 -11
  42. package/docs/api/page/mount.md +24 -22
  43. package/docs/api/workers.md +168 -81
  44. package/package.json +25 -24
@@ -1,9 +1,11 @@
1
1
  import * as Schema from "effect/Schema";
2
2
  import * as z from "zod";
3
- import { ComputerPortPreview } from "@fungi.computer/computer/preview";
3
+ import { ComputerPortAccess, PortAccessError, } from "@fungi.computer/computer/port-access";
4
4
  import { selectionSchema } from "../index.js";
5
5
  import { sha256DigestSchema } from "@fungi.computer/puffball/effect";
6
6
  import { computerPortInputSchema } from "@fungi.computer/computer-contract";
7
+ import { owner, publicRoute, routes } from "../authorization.js";
8
+ import { html } from "hono/html";
7
9
  export const previewSelectorSchema = Schema.Struct({
8
10
  ownerId: Schema.NonEmptyString,
9
11
  installationId: Schema.NonEmptyString,
@@ -19,176 +21,170 @@ const originSchema = z.lazy(() => z
19
21
  url.pathname === "/" &&
20
22
  !url.search &&
21
23
  !url.hash));
22
- export function previewOrigins(env) {
23
- if (env.OYSTER_PREVIEW_ORIGIN === undefined)
24
- return null;
25
- const parsed = z
26
- .object({ owner: originSchema, preview: originSchema })
27
- .safeParse({
28
- owner: env.OYSTER_ORIGIN,
29
- preview: env.OYSTER_PREVIEW_ORIGIN,
30
- });
31
- if (!parsed.success)
24
+ function configuredPreview(env) {
25
+ if (env.OYSTER_PREVIEW_DOMAIN !== undefined) {
26
+ const parsed = originSchema.safeParse(`https://${env.OYSTER_PREVIEW_DOMAIN}`);
27
+ return parsed.success &&
28
+ parsed.data.hostname === env.OYSTER_PREVIEW_DOMAIN &&
29
+ !parsed.data.port
30
+ ? { preview: parsed.data, mode: "host" }
31
+ : null;
32
+ }
33
+ const parsed = originSchema.safeParse(env.OYSTER_PREVIEW_ORIGIN);
34
+ return parsed.success
35
+ ? { preview: parsed.data, mode: "path" }
36
+ : null;
37
+ }
38
+ export async function previewOrigins(env) {
39
+ const owner = originSchema.safeParse(env.OYSTER_ORIGIN);
40
+ const configured = configuredPreview(env);
41
+ if (!owner.success || configured?.mode !== "host")
32
42
  return null;
33
- const { owner, preview } = parsed.data;
34
- // The preview tunnel must be a distinct origin from the canonical owner
35
- // origin: it carries no cookies and no owner credential, so it cannot be
36
- // the same origin the owner signs in on. Which two origins those are is a
37
- // deploy-time choice (this Worker's own custom domain plus its workers.dev
38
- // address, or any other pair the operator actually controls) — never a
39
- // literal this module hard-codes.
40
- if (owner.origin === preview.origin)
43
+ const { getDomain } = await import("tldts");
44
+ const site = (url) => getDomain(url.hostname, { allowPrivateDomains: true });
45
+ const ownerSite = site(owner.data);
46
+ const previewSite = site(configured.preview);
47
+ if (ownerSite === null || previewSite === null || ownerSite === previewSite)
41
48
  return null;
42
- return { owner: owner.origin, preview: preview.origin };
43
- }
44
- /**
45
- * The configured preview tunnel origin alone, independent of whether the
46
- * owner origin also validates. Once an operator points OYSTER_PREVIEW_ORIGIN
47
- * at a host, that host is always treated as preview-only and never falls
48
- * through to the normal router — even if the rest of the config (the owner
49
- * origin) is separately broken. Only a host nothing configured as preview
50
- * is left to the caller's own routing.
51
- */
52
- function configuredPreviewOrigin(env) {
53
- const parsed = originSchema.safeParse(env.OYSTER_PREVIEW_ORIGIN);
54
- return parsed.success ? parsed.data.origin : null;
49
+ return {
50
+ owner: owner.data.origin,
51
+ preview: configured.preview.origin,
52
+ };
55
53
  }
56
54
  export class PreviewRefused extends Error {
57
55
  }
58
- export function createStandalonePreview(storage, computerId, origin, native) {
59
- const tickets = new ComputerPortPreview(storage, {
60
- selector: previewSelectorSchema,
61
- previewUrl: (signature, base) => `${base}/${signature}/`,
62
- accept: native.accept,
63
- listPorts: native.list,
64
- forward: native.forward,
65
- portDenied: () => {
66
- throw new PreviewRefused();
67
- },
68
- dispatchFailure: (cause) => {
69
- if (cause instanceof PreviewRefused)
70
- return new Response(null, { status: 403 });
71
- console.error("Standalone preview native dispatch failed", cause);
72
- return new Response(null, { status: 502 });
73
- },
74
- invalidClaims: () => {
75
- console.error("Standalone preview ticket claims refused");
76
- },
77
- });
56
+ // The retained flat hostname uses the Computer's non-secret identity. Fleet
57
+ // IDs have a computer_ prefix; configured standalone IDs can be simple labels.
58
+ const hostnameComputer = z.string().regex(/^(?:computer_)?[a-z0-9]+$/u);
59
+ function previewUrl(origins, computerId, port) {
60
+ if (!hostnameComputer.safeParse(computerId).success)
61
+ throw new PreviewRefused();
62
+ const label = `${computerId.replace("computer_", "computer-")}-${String(port)}`;
63
+ if (label.length > 63)
64
+ throw new PreviewRefused();
65
+ const result = new URL(origins.preview);
66
+ result.hostname = `${label}.${result.hostname}`;
67
+ return result;
68
+ }
69
+ function entryUrl(origins, computerId, port) {
70
+ return new URL(`/computers/${encodeURIComponent(computerId)}/ports/${String(port)}`, origins.owner).href;
71
+ }
72
+ export function createStandalonePreview(storage, computerId, origins, native) {
73
+ const access = new ComputerPortAccess(storage);
74
+ const issueOwner = async (ownerId, port) => {
75
+ const target = previewUrl(origins, computerId, port);
76
+ const token = await access.issue(port, { ownerId }, () => {
77
+ native.accept(ownerId);
78
+ });
79
+ target.searchParams.set("token", token);
80
+ return { previewUrl: target.href };
81
+ };
78
82
  return {
79
- async issue(selector, port) {
80
- await native.current(selector);
81
- return tickets.issueAfterAcceptance(selector, port, `${origin}/preview/${encodeURIComponent(computerId)}/${String(port)}`);
83
+ issueOwner,
84
+ entry(port) {
85
+ return entryUrl(origins, computerId, port);
82
86
  },
83
- async fetch(signature, port, request) {
84
- return tickets.dispatchSigned(signature, request, async (selector, selectedPort, incoming) => {
85
- if (selectedPort !== port)
86
- return new Response(null, { status: 403 });
87
- try {
88
- await native.current(selector);
89
- return await passivePreviewResponse(await tickets.dispatch(selector, port, incoming));
90
- }
91
- catch (cause) {
92
- if (cause instanceof PreviewRefused)
93
- return new Response(null, { status: 403 });
94
- console.error("Standalone preview current authority check failed", cause);
95
- return new Response(null, { status: 503 });
96
- }
97
- });
87
+ async fetch(port, request) {
88
+ const target = previewUrl(origins, computerId, port);
89
+ const incoming = new URL(request.url);
90
+ if (incoming.origin !== target.origin ||
91
+ !incoming.pathname.startsWith(target.pathname))
92
+ return new Response(null, { status: 404 });
93
+ return access
94
+ .gate(port, entryUrl(origins, computerId, port), async (admitted) => {
95
+ const service = new URL("http://localhost");
96
+ service.pathname = incoming.pathname;
97
+ service.search = incoming.search;
98
+ const headers = new Headers(admitted.headers);
99
+ headers.delete("host");
100
+ return native.forward(port, new Request(service, new Request(admitted, { headers })), () => undefined);
101
+ })
102
+ .fetch(request);
98
103
  },
99
104
  };
100
105
  }
101
- export async function passivePreviewResponse(response) {
102
- if (response.status < 200 ||
103
- response.status >= 300 ||
104
- response.headers.has("Refresh")) {
105
- await response.body?.cancel();
106
- return new Response(null, {
107
- status: response.headers.has("Refresh") ||
108
- (response.status >= 300 && response.status < 400)
109
- ? 502
110
- : response.status,
111
- });
112
- }
113
- const contentType = response.headers
114
- .get("Content-Type")
115
- ?.split(";")[0]
116
- ?.trim()
117
- .toLowerCase();
118
- if (contentType !== "text/html" && contentType !== "text/plain") {
119
- await response.body?.cancel();
120
- return new Response(null, { status: 415 });
121
- }
122
- const headers = new Headers({
123
- "Content-Type": `${contentType}; charset=utf-8`,
124
- "Content-Security-Policy": "sandbox; default-src 'none'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
125
- "Cache-Control": "no-store",
126
- "X-Robots-Tag": "noindex, nofollow",
127
- "Referrer-Policy": "no-referrer",
128
- "X-Content-Type-Options": "nosniff",
129
- });
130
- return new Response(response.body, { status: response.status, headers });
131
- }
132
106
  export async function standalonePreviewRequest(request, env, ownsComputer, forward) {
133
107
  const incoming = new URL(request.url);
134
- const previewHost = configuredPreviewOrigin(env);
135
- // A host nothing configured as the preview tunnel is left to the caller's
136
- // own routing, like any other Host this module doesn't recognize.
137
- if (previewHost === null || incoming.origin !== previewHost)
108
+ const configured = configuredPreview(env);
109
+ if (configured === null)
138
110
  return null;
139
- // Past this point the Host is the configured preview tunnel: it never
140
- // falls through to the normal router, even if the rest of the pair (the
141
- // owner origin) turns out to be broken — the checks below just decide
142
- // 403/404/503 vs. forwarding.
143
- if (!["GET", "HEAD"].includes(request.method) ||
144
- request.headers.has("Upgrade"))
145
- return new Response(null, { status: 404 });
146
- const path = new URLPattern({
147
- pathname: "/preview/:computerId/:port/:signature/*",
148
- }).exec(incoming)?.pathname.groups;
149
- if (path === undefined)
111
+ const matches = configured.mode === "path"
112
+ ? incoming.origin === configured.preview.origin
113
+ : incoming.hostname === configured.preview.hostname ||
114
+ incoming.hostname.endsWith(`.${configured.preview.hostname}`);
115
+ if (!matches)
116
+ return null;
117
+ const origins = await previewOrigins(env);
118
+ if (origins === null ||
119
+ incoming.protocol !== "https:" ||
120
+ incoming.port !== configured.preview.port)
150
121
  return new Response(null, { status: 404 });
151
- if (previewOrigins(env) === null)
122
+ const pattern = new URLPattern({
123
+ hostname: `:computerId-:port([0-9]{1,5}).${configured.preview.hostname}`,
124
+ }).exec(incoming)?.hostname.groups;
125
+ if (pattern === undefined)
152
126
  return new Response(null, { status: 404 });
153
- const ticket = z
127
+ const parsed = z
154
128
  .object({
155
- computerId: z.string().min(1),
156
- port: z.string().regex(/^[0-9]{1,5}$/u),
157
- signature: z.string().regex(/^[a-z2-7]{20}$/u),
158
- "0": z.string(),
129
+ computerId: z.string().min(1).max(768),
130
+ port: z.string().regex(/^[1-9][0-9]{0,4}$/u),
159
131
  })
160
- .safeParse(path);
161
- if (!ticket.success)
162
- return new Response(null, { status: 404 });
163
- let computerId;
164
- try {
165
- computerId = decodeURIComponent(ticket.data.computerId);
166
- }
167
- catch (cause) {
168
- if (cause instanceof URIError)
169
- return new Response(null, { status: 404 });
170
- throw cause;
171
- }
172
- if (computerId.length === 0 ||
173
- computerId.length > 256 ||
174
- encodeURIComponent(computerId) !== ticket.data.computerId)
132
+ .safeParse(pattern);
133
+ if (!parsed.success)
175
134
  return new Response(null, { status: 404 });
176
- const input = computerPortInputSchema.safeParse({
177
- port: Number(ticket.data.port),
135
+ const computerId = parsed.data.computerId.replace(/^computer-/u, "computer_");
136
+ const port = computerPortInputSchema.safeParse({
137
+ port: Number(parsed.data.port),
178
138
  });
179
- if (!input.success || String(input.data.port) !== ticket.data.port)
139
+ if (!port.success || computerId.length > 256)
180
140
  return new Response(null, { status: 404 });
181
141
  if (!(await ownsComputer(computerId)))
182
142
  return new Response(null, { status: 404 });
183
- const service = new URL("http://localhost");
184
- service.pathname = `/${ticket.data["0"]}`;
185
- service.search = incoming.search;
186
- const headers = new Headers(request.headers);
187
- for (const name of ["cookie", "authorization", "proxy-authorization", "host"])
188
- headers.delete(name);
189
- return forward(computerId, ticket.data.signature, input.data.port, new Request(service, {
190
- method: request.method,
191
- headers,
192
- signal: request.signal,
193
- }));
143
+ return forward(computerId, port.data.port, request);
144
+ }
145
+ /** Establish a top-level same-site document before the owner's Strict-cookie POST. */
146
+ export function standalonePortEntryRoutes(ports) {
147
+ const path = "/computers/:computerId/ports/:port";
148
+ return routes()
149
+ .get(path, publicRoute("a preview entry document; only the owner-admitted POST issues a token"), (context) => {
150
+ context.header("Cache-Control", "no-store");
151
+ context.header("Referrer-Policy", "no-referrer");
152
+ context.header("Cross-Origin-Opener-Policy", "same-origin");
153
+ // Chromium applies form-action to the POST redirect as well. The fixed
154
+ // same-origin form must be able to finish on the HTTPS preview site.
155
+ context.header("Content-Security-Policy", "default-src 'none'; script-src 'unsafe-inline'; form-action https:; frame-ancestors 'none'; base-uri 'none'");
156
+ return context.html(html `<!doctype html><title>Open preview</title>
157
+ <main>
158
+ <form method="post" action="${context.req.path}">
159
+ <button>Open preview</button>
160
+ </form>
161
+ <script>
162
+ document.forms[0].requestSubmit();
163
+ </script>
164
+ </main>`);
165
+ })
166
+ .post(path, owner("direct"), async (context, { principal }) => {
167
+ const computerId = context.req.param("computerId");
168
+ const portParam = context.req.param("port");
169
+ const port = computerPortInputSchema.safeParse({
170
+ port: Number(portParam),
171
+ });
172
+ if (!/^[1-9][0-9]{0,4}$/u.test(portParam) ||
173
+ !port.success ||
174
+ !(await ports.ownsComputer(computerId)))
175
+ return context.body(null, 404);
176
+ try {
177
+ const issued = await ports.issue(computerId, principal.actor.memberId, port.data.port);
178
+ if (issued === null)
179
+ return context.body(null, 404);
180
+ context.header("Cache-Control", "no-store");
181
+ context.header("Referrer-Policy", "no-referrer");
182
+ return context.redirect(issued.previewUrl, 302);
183
+ }
184
+ catch (cause) {
185
+ if (cause instanceof PreviewRefused || cause instanceof PortAccessError)
186
+ return context.body(null, 404);
187
+ throw cause;
188
+ }
189
+ });
194
190
  }
@@ -81,6 +81,20 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
81
81
  updatedAt: number;
82
82
  }>[];
83
83
  readonly nextOffset: number | null;
84
+ } | {
85
+ computers: (Readonly<{
86
+ computerId: string;
87
+ name: string;
88
+ size: import("@fungi.computer/computer").ComputerSize;
89
+ createdAt: number;
90
+ updatedAt: number;
91
+ }> | {
92
+ computerId: string;
93
+ name: string;
94
+ })[];
95
+ nextOffset: number | null;
96
+ } | {
97
+ readonly error: "unavailable";
84
98
  } | ({
85
99
  backendId: string;
86
100
  error?: undefined;
@@ -123,40 +137,21 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
123
137
  state: "running";
124
138
  } & Disposable) | {
125
139
  error: string;
126
- computers?: undefined;
127
- nextOffset?: undefined;
128
- computerId?: undefined;
129
- enabled?: undefined;
130
- } | {
131
- computers: ({
132
- computerId: string;
133
- name: string;
134
- } | Readonly<{
135
- computerId: string;
136
- name: string;
137
- size: import("@fungi.computer/computer").ComputerSize;
138
- createdAt: number;
139
- updatedAt: number;
140
- }>)[];
141
- nextOffset: number | null;
142
- error?: undefined;
143
140
  computerId?: undefined;
144
141
  enabled?: undefined;
145
142
  } | {
146
143
  computerId: string;
147
144
  error?: undefined;
148
- computers?: undefined;
149
- nextOffset?: undefined;
150
145
  enabled?: undefined;
151
146
  } | {
152
147
  enabled: boolean;
153
148
  error?: undefined;
154
- computers?: undefined;
155
- nextOffset?: undefined;
156
149
  computerId?: undefined;
157
150
  } | null>;
158
151
  /** A durable selection snapshot; the configured default remains the App build Computer. */
159
152
  selectedComputer(): Promise<string>;
153
+ /** Name for the host's captured selection, from the same owner as the picker. */
154
+ computerName(computerId: string): string | null;
160
155
  /** Frame dispatch checks inventory ownership, not a mutable UI selection. */
161
156
  ownsComputer(computerId: string): boolean;
162
157
  /** One atomic registry admission proves the stored creator is still the owner. */
@@ -17,6 +17,7 @@ import { buildJobsFromOlderOyster } from "../older-oyster-store.js";
17
17
  import { readBuildManifest, appBuildRecipe } from "../build/workspace-build.js";
18
18
  import { standaloneTenancy } from "./tenancy.js";
19
19
  import { createFleetComputers, ComputerInventoryError, } from "@fungi.computer/computer/fleet";
20
+ import { defaultComputerSize } from "@fungi.computer/computer/backing";
20
21
  import { standaloneFleetRequestSchema, } from "./computer-fleet.js";
21
22
  const standaloneAppForkIds = defineIdFamily({
22
23
  family: "oyster-app-fork",
@@ -110,33 +111,23 @@ export class StandaloneRegistry extends OysterRegistry {
110
111
  await this.#env.COMPUTER.getByName(created.computerId).initializeFleetBackings(backings, created.size);
111
112
  return created;
112
113
  }
113
- case "list":
114
- return this.#computers.list(input.page);
114
+ case "list": {
115
+ // A trial's Computer is configured, not created: report it ahead of
116
+ // the fleet without a row, as the picker does.
117
+ const configured = this.#localConfigured();
118
+ return configured === null
119
+ ? this.#computers.list(input.page)
120
+ : this.#withConfigured(input.page, configured);
121
+ }
115
122
  case "choices": {
116
123
  // The configured build Computer is an existing supported workspace,
117
124
  // not a fabricated fleet creation receipt. Keep its UI row outside inventory.
118
- const { limit, offset } = input.page;
119
- const first = offset === 0;
120
- const configured = {
121
- computerId: this.#env.OYSTER_COMPUTER_ID,
122
- name: this.#env.OYSTER_COMPUTER_ID,
123
- };
124
- if (first && limit === 1)
125
- return {
126
- computers: [configured],
127
- nextOffset: this.#computers.count() > 0 ? 1 : null,
128
- };
129
- const page = this.#computers.list({
130
- limit: limit - (first ? 1 : 0),
131
- offset: Math.max(0, offset - 1),
132
- });
133
- return {
134
- computers: first ? [configured, ...page.computers] : page.computers,
135
- nextOffset: page.nextOffset === null ? null : page.nextOffset + 1,
136
- };
125
+ const { computerId, name } = this.#configured();
126
+ return this.#withConfigured(input.page, { computerId, name });
137
127
  }
138
128
  case "read":
139
- return this.#computers.read(input.computerId);
129
+ return (this.#computers.read(input.computerId) ??
130
+ this.#trialComputer(input.computerId));
140
131
  case "resolve":
141
132
  // Context may name the configured build Computer, which has no fleet
142
133
  // creation receipt. Keep canonical-owner admission above this lookup.
@@ -146,7 +137,7 @@ export class StandaloneRegistry extends OysterRegistry {
146
137
  case "read-internet-access":
147
138
  case "set-internet-access": {
148
139
  if (this.#computers.read(input.computerId) === null)
149
- return null;
140
+ return this.#withoutSwitches(input.computerId);
150
141
  const computer = this.#env.COMPUTER.getByName(input.computerId);
151
142
  return {
152
143
  enabled: await computer.internetAccess(input.operation === "set-internet-access"
@@ -157,7 +148,7 @@ export class StandaloneRegistry extends OysterRegistry {
157
148
  case "read-keep-awake":
158
149
  case "set-keep-awake": {
159
150
  if (this.#computers.read(input.computerId) === null)
160
- return null;
151
+ return this.#withoutSwitches(input.computerId);
161
152
  const computer = this.#env.COMPUTER.getByName(input.computerId);
162
153
  return {
163
154
  enabled: await computer.keepAwake(input.operation === "set-keep-awake" ? input.enabled : undefined),
@@ -168,7 +159,8 @@ export class StandaloneRegistry extends OysterRegistry {
168
159
  case "detach-local":
169
160
  return this.#machines(memberId, input);
170
161
  case "select": {
171
- const computer = this.#computers.read(input.computerId);
162
+ const computer = this.#computers.read(input.computerId) ??
163
+ this.#trialComputer(input.computerId);
172
164
  if (computer === null)
173
165
  return null;
174
166
  await this.#fleetStorage.put("selected-computer", input.computerId);
@@ -203,6 +195,59 @@ export class StandaloneRegistry extends OysterRegistry {
203
195
  });
204
196
  }
205
197
  }
198
+ /**
199
+ * The one definition of the configured Computer, however a caller meets it
200
+ * (picker row, inventory row, ownership, default). It was never created
201
+ * through the fleet, so it has no inventory row and no recorded creation
202
+ * time.
203
+ */
204
+ #configured() {
205
+ const computerId = this.#env.OYSTER_COMPUTER_ID;
206
+ return {
207
+ computerId,
208
+ name: computerId,
209
+ size: defaultComputerSize,
210
+ createdAt: 0,
211
+ updatedAt: 0,
212
+ };
213
+ }
214
+ /** The configured Computer as a local trial's inventory entry; hosted fleets list only what they created. */
215
+ #localConfigured() {
216
+ return this.#env.OYSTER_COMPUTER_BACKEND === "local"
217
+ ? this.#configured()
218
+ : null;
219
+ }
220
+ #trialComputer(computerId) {
221
+ const configured = this.#localConfigured();
222
+ return configured?.computerId === computerId ? configured : null;
223
+ }
224
+ /**
225
+ * A trial's Computer is the owner's own machine: it has no sleep to keep
226
+ * off and no egress policy to switch, so its Settings switches are
227
+ * unavailable rather than missing.
228
+ */
229
+ #withoutSwitches(computerId) {
230
+ return this.#trialComputer(computerId) === null
231
+ ? null
232
+ : { error: "unavailable" };
233
+ }
234
+ /** One page of the configured Computer ahead of the fleet's own. */
235
+ #withConfigured({ limit, offset }, configured) {
236
+ const first = offset === 0;
237
+ if (first && limit === 1)
238
+ return {
239
+ computers: [configured],
240
+ nextOffset: this.#computers.count() > 0 ? 1 : null,
241
+ };
242
+ const page = this.#computers.list({
243
+ limit: limit - (first ? 1 : 0),
244
+ offset: Math.max(0, offset - 1),
245
+ });
246
+ return {
247
+ computers: first ? [configured, ...page.computers] : page.computers,
248
+ nextOffset: page.nextOffset === null ? null : page.nextOffset + 1,
249
+ };
250
+ }
206
251
  /** Attached machines of one owned Computer; the Computer holds the rows. */
207
252
  async #machines(memberId, input) {
208
253
  const computerId = input.operation === "backends"
@@ -233,15 +278,23 @@ export class StandaloneRegistry extends OysterRegistry {
233
278
  async selectedComputer() {
234
279
  const selected = await this.#fleetStorage.get("selected-computer");
235
280
  if (selected === undefined)
236
- return this.#env.OYSTER_COMPUTER_ID;
281
+ return this.#configured().computerId;
237
282
  const computerId = Schema.decodeUnknownSync(Schema.NonEmptyString)(selected);
238
- if (this.#computers.read(computerId) === null)
283
+ if (this.#computers.read(computerId) === null &&
284
+ this.#trialComputer(computerId) === null)
239
285
  throw new Error("Selected Computer is missing");
240
286
  return computerId;
241
287
  }
288
+ /** Name for the host's captured selection, from the same owner as the picker. */
289
+ computerName(computerId) {
290
+ const configured = this.#configured();
291
+ const computer = this.#computers.read(computerId) ??
292
+ (configured.computerId === computerId ? configured : null);
293
+ return computer?.name ?? null;
294
+ }
242
295
  /** Frame dispatch checks inventory ownership, not a mutable UI selection. */
243
296
  ownsComputer(computerId) {
244
- return (computerId === this.#env.OYSTER_COMPUTER_ID ||
297
+ return (computerId === this.#configured().computerId ||
245
298
  this.#computers.read(computerId) !== null);
246
299
  }
247
300
  /** One atomic registry admission proves the stored creator is still the owner. */
@@ -30,7 +30,7 @@ export type StandaloneEnv = OysterGitWorkerEnv & StandaloneTenancyEnv & Standalo
30
30
  export { ComputerDO } from "./computer.js";
31
31
  export { WorkspaceProxy, WorkspaceServiceProxy, } from "@fungi.computer/computer";
32
32
  import { StandaloneRegistry as BaseRegistry, type StandaloneRegistryGit } from "./registry.js";
33
- /** The registry uses the same root, with its own in-process Computer selection. */
33
+ /** The registry reads both Computer identity fields in process, never by self RPC. */
34
34
  export declare class OysterRegistry extends BaseRegistry {
35
35
  #private;
36
36
  constructor(state: DurableObjectState, env: StandaloneEnv, git?: StandaloneRegistryGit);
@@ -22,7 +22,7 @@ export { OysterBinding } from "./instance.js";
22
22
  import { StandaloneWorkflowRunsBase, } from "./workflows.js";
23
23
  import { standaloneTenancyForRequest, StandaloneSeedConfigurationChanged, } from "./tenancy.js";
24
24
  export { StandaloneTenants } from "./tenancy.js";
25
- import { standalonePreviewRequest } from "./preview.js";
25
+ import { standalonePreviewRequest, standalonePortEntryRoutes, } from "./preview.js";
26
26
  import { standaloneMachineLinkRoutes, } from "./machine-link.js";
27
27
  export { MachineLinkDO } from "./machine-link.js";
28
28
  import { standaloneWorkflowControl } from "./workflow-control.js";
@@ -45,10 +45,13 @@ const computerRegistry = (env) => tenantRegistry(env, tenantScope(defaultTenant,
45
45
  export { ComputerDO } from "./computer.js";
46
46
  export { WorkspaceProxy, WorkspaceServiceProxy, } from "@fungi.computer/computer";
47
47
  import { StandaloneRegistry as BaseRegistry, } from "./registry.js";
48
- /** The registry uses the same root, with its own in-process Computer selection. */
48
+ /** The registry reads both Computer identity fields in process, never by self RPC. */
49
49
  export class OysterRegistry extends BaseRegistry {
50
50
  #rootEnv;
51
- #root = standaloneRoot(() => this.selectedComputer());
51
+ #root = standaloneRoot(async () => {
52
+ const computerId = await this.selectedComputer();
53
+ return { computerId, computerName: this.computerName(computerId) };
54
+ });
52
55
  constructor(state, env, git = {}) {
53
56
  super(state, env, git);
54
57
  this.#rootEnv = env;
@@ -81,7 +84,14 @@ const standaloneRoot = (selectComputer) => {
81
84
  computerControl: (env, scope) => (principal) => oysterPrincipalIsOwner(principal)
82
85
  ? standaloneComputerControl(tenantRegistry(env, scope), principal.actor.memberId)
83
86
  : null,
84
- workspace: async (env, keysLive, scope, request) => standaloneWorkspace(env, keysLive, await selectComputer(tenantRegistry(env, scope), request)),
87
+ workspace: async (env, keysLive, scope, request) => {
88
+ const registry = tenantRegistry(env, scope);
89
+ const { computerId, computerName } = await selectComputer(registry, request);
90
+ return {
91
+ ...standaloneWorkspace(env, keysLive, computerId),
92
+ computerName,
93
+ };
94
+ },
85
95
  capabilities: (env, workspace) => [
86
96
  ...standaloneComputerCapabilities(env, workspace),
87
97
  ...workersMedia(env, workspace),
@@ -110,11 +120,17 @@ const standaloneRoot = (selectComputer) => {
110
120
  };
111
121
  },
112
122
  // Operator source seeding and owner builds share the one owner guard.
113
- ownerRoutes: (env, scope) => standaloneOwnerRoutes(env, scope, () => root.hostFor(env, scope)),
123
+ ownerRoutes: (env, scope) => standaloneOwnerRoutes(env, scope, () => root.hostFor(env, scope)).include(standalonePortEntryRoutes({
124
+ ownsComputer: (id) => tenantRegistry(env, scope).ownsComputer(id),
125
+ issue: (id, ownerId, port) => env.COMPUTER.getByName(id).issuePortConnect(ownerId, port),
126
+ })),
114
127
  });
115
128
  return root;
116
129
  };
117
- const oysterRoot = standaloneRoot(standaloneComputerSelection);
130
+ const oysterRoot = standaloneRoot(async (registry, incoming) => {
131
+ const computerId = await standaloneComputerSelection(registry, incoming);
132
+ return { computerId, computerName: await registry.computerName(computerId) };
133
+ });
118
134
  export class OysterMcp extends createOysterGitMcpOwner(oysterRoot) {
119
135
  }
120
136
  /** Background wakes readmit members through this root's tenancy, as HTTP and MCP do. */
@@ -186,7 +202,7 @@ const standaloneWorkerErrorHandler = (error, context) => {
186
202
  };
187
203
  export default {
188
204
  async fetch(request, env, context) {
189
- const preview = await standalonePreviewRequest(request, env, (computerId) => computerRegistry(env).ownsComputer(computerId), (computerId, signature, port, service) => env.COMPUTER.getByName(computerId).portPreview(signature, port, service));
205
+ const preview = await standalonePreviewRequest(request, env, (computerId) => computerRegistry(env).ownsComputer(computerId), (computerId, port, incoming) => env.COMPUTER.getByName(computerId).portPreview(port, incoming));
190
206
  if (preview !== null)
191
207
  return preview;
192
208
  const ingress = onBoxVmIngress(request, env, env.COMPUTER);