@fungi.computer/oyster 0.32.0 → 0.34.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.
- package/README.md +59 -0
- package/dist/app-sandbox.d.ts +2 -2
- package/dist/app-sandbox.js +2 -2
- package/dist/app-test-copies.d.ts +87 -0
- package/dist/app-test-copies.js +170 -0
- package/dist/app-test-copy-page.d.ts +4 -0
- package/dist/app-test-copy-page.js +89 -0
- package/dist/approval-deadline.d.ts +2 -0
- package/dist/approval-deadline.js +7 -0
- package/dist/approval-home.d.ts +26 -3
- package/dist/approval-home.js +148 -18
- package/dist/apps/index.d.ts +1 -1
- package/dist/apps/index.js +1 -1
- package/dist/browser/operations.d.ts +1 -1
- package/dist/cloudflare.d.ts +68 -3
- package/dist/cloudflare.js +214 -3
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +1 -1
- package/dist/host.d.ts +20 -4
- package/dist/host.js +314 -3
- package/dist/installation-operations.d.ts +247 -8
- package/dist/installation-operations.js +145 -7
- package/dist/installation-recovery-page.d.ts +24 -0
- package/dist/installation-recovery-page.js +168 -0
- package/dist/mcp.js +42 -13
- package/dist/older-oyster-store.d.ts +1 -1
- package/dist/older-oyster-store.js +2 -4
- package/dist/page/app-permissions.js +8 -7
- package/dist/page/computer-handles.d.ts +0 -1
- package/dist/page/mount.d.ts +2 -101
- package/dist/page/mount.js +1 -22
- package/dist/page-config.d.ts +102 -0
- package/dist/page-config.js +24 -0
- package/dist/page-script.js +2 -2
- package/dist/platform-skills.generated.d.ts +5 -2
- package/dist/platform-skills.generated.js +6 -2
- package/dist/recovery-style.d.ts +5 -0
- package/dist/recovery-style.js +32 -0
- package/dist/standalone/agents.d.ts +1 -1
- package/dist/standalone/agents.js +43 -7
- package/dist/standalone/computer-fleet.js +3 -0
- package/dist/standalone/computer.d.ts +6 -2
- package/dist/standalone/computer.js +27 -14
- package/dist/standalone/media.js +7 -2
- package/dist/standalone/preview.d.ts +21 -20
- package/dist/standalone/preview.js +147 -151
- package/dist/standalone/registry.d.ts +14 -21
- package/dist/standalone/registry.js +74 -28
- package/dist/standalone/worker.js +6 -3
- package/dist/starter-agent.d.ts +6 -2
- package/dist/starter-agent.js +25 -4
- package/dist/upgrade/old-worker-http.d.ts +2 -0
- package/dist/upgrade/old-worker-http.js +22 -0
- package/dist/upgrade/old-worker-readonly.d.ts +14 -0
- package/dist/upgrade/old-worker-readonly.js +22 -0
- package/dist/upgrade/old-worker-sql.d.ts +10 -0
- package/dist/upgrade/old-worker-sql.js +68 -0
- package/dist/upgrade/old-worker-stream.d.ts +12 -0
- package/dist/upgrade/old-worker-stream.js +54 -0
- package/dist/upgrade/private-stage.d.ts +23 -0
- package/dist/upgrade/private-stage.js +109 -0
- package/dist/upgrade/standalone-001.d.ts +16 -0
- package/dist/upgrade/standalone-001.js +31 -0
- package/dist/upgrade/standalone-01.d.ts +37 -0
- package/dist/upgrade/standalone-01.js +55 -0
- package/dist/upgrade/standalone-02.d.ts +37 -0
- package/dist/upgrade/standalone-02.js +55 -0
- package/dist/workers.d.ts +45 -14
- package/dist/workers.js +198 -21
- package/docs/api/README.md +8 -3
- package/docs/api/apps.md +21 -0
- package/docs/api/cloudflare.md +57 -0
- package/docs/api/host.md +263 -25
- package/docs/api/page/mount.md +13 -81
- package/docs/api/workers-git.md +246 -1
- package/docs/api/workers.md +518 -95
- package/package.json +38 -24
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as Schema from "effect/Schema";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
-
import {
|
|
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
|
-
|
|
23
|
-
if (env.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
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 {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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 {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
return
|
|
83
|
+
issueOwner,
|
|
84
|
+
entry(port) {
|
|
85
|
+
return entryUrl(origins, computerId, port);
|
|
82
86
|
},
|
|
83
|
-
async fetch(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
|
135
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
-
|
|
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
|
|
127
|
+
const parsed = z
|
|
154
128
|
.object({
|
|
155
|
-
computerId: z.string().min(1),
|
|
156
|
-
port: z.string().regex(/^[0-9]{
|
|
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(
|
|
161
|
-
if (!
|
|
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
|
|
177
|
-
|
|
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 (!
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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,36 +137,15 @@ 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. */
|
|
@@ -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
|
-
|
|
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 {
|
|
119
|
-
|
|
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
|
|
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
|
|
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,16 @@ 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.#
|
|
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
|
}
|
|
242
288
|
/** Frame dispatch checks inventory ownership, not a mutable UI selection. */
|
|
243
289
|
ownsComputer(computerId) {
|
|
244
|
-
return (computerId === this.#
|
|
290
|
+
return (computerId === this.#configured().computerId ||
|
|
245
291
|
this.#computers.read(computerId) !== null);
|
|
246
292
|
}
|
|
247
293
|
/** One atomic registry admission proves the stored creator is still the owner. */
|
|
@@ -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";
|
|
@@ -110,7 +110,10 @@ const standaloneRoot = (selectComputer) => {
|
|
|
110
110
|
};
|
|
111
111
|
},
|
|
112
112
|
// Operator source seeding and owner builds share the one owner guard.
|
|
113
|
-
ownerRoutes: (env, scope) => standaloneOwnerRoutes(env, scope, () => root.hostFor(env, scope))
|
|
113
|
+
ownerRoutes: (env, scope) => standaloneOwnerRoutes(env, scope, () => root.hostFor(env, scope)).include(standalonePortEntryRoutes({
|
|
114
|
+
ownsComputer: (id) => tenantRegistry(env, scope).ownsComputer(id),
|
|
115
|
+
issue: (id, ownerId, port) => env.COMPUTER.getByName(id).issuePortConnect(ownerId, port),
|
|
116
|
+
})),
|
|
114
117
|
});
|
|
115
118
|
return root;
|
|
116
119
|
};
|
|
@@ -186,7 +189,7 @@ const standaloneWorkerErrorHandler = (error, context) => {
|
|
|
186
189
|
};
|
|
187
190
|
export default {
|
|
188
191
|
async fetch(request, env, context) {
|
|
189
|
-
const preview = await standalonePreviewRequest(request, env, (computerId) => computerRegistry(env).ownsComputer(computerId), (computerId,
|
|
192
|
+
const preview = await standalonePreviewRequest(request, env, (computerId) => computerRegistry(env).ownsComputer(computerId), (computerId, port, incoming) => env.COMPUTER.getByName(computerId).portPreview(port, incoming));
|
|
190
193
|
if (preview !== null)
|
|
191
194
|
return preview;
|
|
192
195
|
const ingress = onBoxVmIngress(request, env, env.COMPUTER);
|
package/dist/starter-agent.d.ts
CHANGED
|
@@ -13,17 +13,19 @@ export declare const starterAgent: {
|
|
|
13
13
|
readonly name: "Shiitake";
|
|
14
14
|
readonly requestId: "starter-agent:v1";
|
|
15
15
|
};
|
|
16
|
+
/** Seed only a missing Home file; the host supplies an atomic create-if-absent. */
|
|
17
|
+
export declare function seedStarterHome(writeIfMissing: (path: string, content: string) => Promise<void>): Promise<void>;
|
|
16
18
|
/** What the ledger remembers: that the starter was settled, never to be offered again. */
|
|
17
19
|
export type StarterLedgerRow = Readonly<{
|
|
18
20
|
version: number;
|
|
19
|
-
outcome: "created" | "team-not-empty";
|
|
21
|
+
outcome: "seed-pending" | "created" | "team-not-empty";
|
|
20
22
|
agentId: string | null;
|
|
21
23
|
at: number;
|
|
22
24
|
}>;
|
|
23
25
|
/** One row per Team in the host's own SQLite. */
|
|
24
26
|
export type StarterLedgerStore = Readonly<{
|
|
25
27
|
read(): StarterLedgerRow | undefined;
|
|
26
|
-
/** First write wins
|
|
28
|
+
/** First write wins, except completing the same pending starter's seed. */
|
|
27
29
|
record(row: StarterLedgerRow): void;
|
|
28
30
|
}>;
|
|
29
31
|
/** The ledger as the policy reads it; a host across an RPC awaits its store. */
|
|
@@ -49,6 +51,8 @@ export type StarterAgentHost = Readonly<{
|
|
|
49
51
|
name: string;
|
|
50
52
|
requestId: string;
|
|
51
53
|
}): Promise<StarterCreateResult>;
|
|
54
|
+
/** Hosts with a Home seed it atomically; failure leaves a retryable ledger row. */
|
|
55
|
+
seedHome?(agentId: string): Promise<void>;
|
|
52
56
|
/** Where a failed attempt is reported; the caller's read never fails. */
|
|
53
57
|
report?(cause: unknown): void;
|
|
54
58
|
now?(): number;
|