@fungi.computer/oyster 0.14.1 → 0.15.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 +178 -1552
- package/dist/app-builds.d.ts +5 -6
- package/dist/app-builds.js +3 -10
- package/dist/boot-host-script.js +1 -1
- package/dist/catalog-frame.d.ts +0 -1
- package/dist/embed-metafiles.js +2 -2
- package/dist/embed-scripts.js +3 -3
- package/dist/hello-app-script.js +1 -1
- package/dist/page/app-permissions.js +165 -50
- package/dist/page-script.js +3 -3
- package/dist/standalone/app-set.d.ts +9 -0
- package/dist/standalone/app-set.js +43 -0
- package/dist/standalone/app-source.js +16 -1
- package/dist/standalone/builds.d.ts +2 -2
- package/dist/standalone/builds.js +4 -0
- package/dist/standalone/computer.d.ts +6 -1
- package/dist/standalone/computer.js +10 -2
- package/dist/standalone/install-apps-cli.js +1 -1
- package/dist/standalone/local-desktop.d.ts +19 -2
- package/dist/standalone/local-desktop.js +38 -15
- package/dist/standalone/registry.d.ts +4 -1
- package/dist/standalone/registry.js +6 -0
- package/dist/standalone/try-cli.d.ts +7 -0
- package/dist/standalone/try-cli.js +88 -8
- package/docs/api/README.md +744 -88
- package/docs/site/agent-quickstart.mdx +1 -1
- package/package.json +29 -49
|
@@ -10,8 +10,17 @@ export type StarterApp = Readonly<{
|
|
|
10
10
|
directory: string;
|
|
11
11
|
/** Its own public source repository's name, the App at that repository's root. */
|
|
12
12
|
repository: string;
|
|
13
|
+
/**
|
|
14
|
+
* What `oyster try` can do with it: `local` runs on a laptop; `needs-runtime`
|
|
15
|
+
* installs but needs a Computer runtime that a trial does not have.
|
|
16
|
+
*/
|
|
17
|
+
trial: "local" | "needs-runtime";
|
|
13
18
|
}>;
|
|
14
19
|
export declare const standaloneAppSet: readonly StarterApp[];
|
|
20
|
+
/** The Apps `oyster try` installs after the desktop, in the order it reports them. */
|
|
21
|
+
export declare const trialStarterOrder: readonly ["grove", "prints", "inkcap", "trellis", "bonsai", "shed"];
|
|
22
|
+
/** The plain refusal for an Oyster without a Computer to build on. */
|
|
23
|
+
export declare const noStarterBuildBackendMessage = "This Oyster has no Computer to build the starter Apps on, so none were installed. A local `oyster try` Oyster has none; it runs the Tourtois desktop and Apps you install yourself. Deploy Oyster to Cloudflare to install the seven starter Apps: https://docs.fungi.computer/guides/run-your-own-oyster/#deploy-it";
|
|
15
24
|
/** Where the starter Apps' sources come from. */
|
|
16
25
|
export type StarterAppSource = Readonly<{
|
|
17
26
|
/** A Botanical checkout at one exact commit; each App is its directory. */
|
|
@@ -19,44 +19,60 @@ export const standaloneAppSet = [
|
|
|
19
19
|
directory: "apps/tourtois",
|
|
20
20
|
repository: "tourtois",
|
|
21
21
|
appId: "app_tourtois",
|
|
22
|
+
trial: "local",
|
|
22
23
|
},
|
|
23
24
|
{
|
|
24
25
|
installationId: "bonsai",
|
|
25
26
|
directory: "apps/bonsai",
|
|
26
27
|
repository: "bonsai",
|
|
27
28
|
appId: "app_bonsai",
|
|
29
|
+
trial: "local",
|
|
28
30
|
},
|
|
29
31
|
{
|
|
30
32
|
installationId: "shed",
|
|
31
33
|
directory: "apps/shed",
|
|
32
34
|
repository: "shed",
|
|
33
35
|
appId: "app_shed",
|
|
36
|
+
trial: "needs-runtime",
|
|
34
37
|
},
|
|
35
38
|
{
|
|
36
39
|
installationId: "inkcap",
|
|
37
40
|
directory: "apps/inkcap",
|
|
38
41
|
repository: "inkcap",
|
|
39
42
|
appId: "app_inkcap",
|
|
43
|
+
trial: "local",
|
|
40
44
|
},
|
|
41
45
|
{
|
|
42
46
|
installationId: "trellis",
|
|
43
47
|
directory: "apps/trellis",
|
|
44
48
|
repository: "trellis",
|
|
45
49
|
appId: "app_trellis",
|
|
50
|
+
trial: "local",
|
|
46
51
|
},
|
|
47
52
|
{
|
|
48
53
|
installationId: "prints",
|
|
49
54
|
directory: "apps/prints",
|
|
50
55
|
repository: "prints",
|
|
51
56
|
appId: "app_prints",
|
|
57
|
+
trial: "local",
|
|
52
58
|
},
|
|
53
59
|
{
|
|
54
60
|
installationId: "grove",
|
|
55
61
|
directory: "apps/grove",
|
|
56
62
|
repository: "grove",
|
|
57
63
|
appId: "app_grove",
|
|
64
|
+
trial: "local",
|
|
58
65
|
},
|
|
59
66
|
];
|
|
67
|
+
/** The Apps `oyster try` installs after the desktop, in the order it reports them. */
|
|
68
|
+
export const trialStarterOrder = [
|
|
69
|
+
"grove",
|
|
70
|
+
"prints",
|
|
71
|
+
"inkcap",
|
|
72
|
+
"trellis",
|
|
73
|
+
"bonsai",
|
|
74
|
+
"shed",
|
|
75
|
+
];
|
|
60
76
|
/** The host's refusal of a store written by Oyster 0.2 or earlier. */
|
|
61
77
|
const olderOysterStoreRefusal = Schema.Struct({
|
|
62
78
|
error: Schema.Literal(olderOysterStoreCode),
|
|
@@ -83,6 +99,32 @@ const buildSchema = Schema.Struct({
|
|
|
83
99
|
/** Installed exactly as the host encoded it. */
|
|
84
100
|
release: Schema.NullOr(Schema.Json),
|
|
85
101
|
});
|
|
102
|
+
/** The host's read of whether its Computer can build (`GET /api/build-backend`). */
|
|
103
|
+
const buildBackendSchema = Schema.Struct({
|
|
104
|
+
kind: Schema.Literals(["hosted", "no_backend"]),
|
|
105
|
+
});
|
|
106
|
+
/** Where a stranger deploys an Oyster that can build the starter Apps. */
|
|
107
|
+
const deployGuideUrl = "https://docs.fungi.computer/guides/run-your-own-oyster/#deploy-it";
|
|
108
|
+
/** The plain refusal for an Oyster without a Computer to build on. */
|
|
109
|
+
export const noStarterBuildBackendMessage = `This Oyster has no Computer to build the starter Apps on, so none were installed. A local \`oyster try\` Oyster has none; it runs the Tourtois desktop and Apps you install yourself. Deploy Oyster to Cloudflare to install the seven starter Apps: ${deployGuideUrl}`;
|
|
110
|
+
/** Ask the host whether its Computer can build before seeding anything, so
|
|
111
|
+
* an Oyster that cannot build fails once, plainly, instead of once per App. */
|
|
112
|
+
async function requireStarterBuildBackend(url, read) {
|
|
113
|
+
let response;
|
|
114
|
+
try {
|
|
115
|
+
response = await read();
|
|
116
|
+
}
|
|
117
|
+
catch (cause) {
|
|
118
|
+
throw new Error(`Could not reach the Oyster at ${url}. Check OYSTER_URL and that the Oyster is running.`, { cause });
|
|
119
|
+
}
|
|
120
|
+
if (response.status === 401 || response.status === 403)
|
|
121
|
+
throw new Error(`The Oyster at ${url} refused the owner key (HTTP ${String(response.status)}). Check OYSTER_OWNER_KEY.`);
|
|
122
|
+
if (!response.ok)
|
|
123
|
+
throw new Error(`The Oyster at ${url} did not report whether it can build Apps (HTTP ${String(response.status)}). Check that OYSTER_URL is an Oyster of this version.`);
|
|
124
|
+
const { kind } = Schema.decodeUnknownSync(buildBackendSchema)(await response.json());
|
|
125
|
+
if (kind === "no_backend")
|
|
126
|
+
throw new Error(noStarterBuildBackendMessage);
|
|
127
|
+
}
|
|
86
128
|
/** The phases a Computer build reports in its success detail. */
|
|
87
129
|
const computerPhasesSchema = Schema.fromJsonString(Schema.Struct({
|
|
88
130
|
phasesMs: Schema.Struct({
|
|
@@ -141,6 +183,7 @@ export async function installStandaloneAppSet(options) {
|
|
|
141
183
|
init.signal = signal;
|
|
142
184
|
return fetch(new URL(path, options.url), init);
|
|
143
185
|
};
|
|
186
|
+
await requireStarterBuildBackend(options.url, () => owner("GET", "/api/build-backend"));
|
|
144
187
|
const idle = options.idle ??
|
|
145
188
|
((ms, signal) => sleep(ms, undefined, { signal }));
|
|
146
189
|
/** Start one build and wait for its terminal outcome within the build
|
|
@@ -31,6 +31,12 @@ export async function dispatchAppSourceBinding(env, scope, frame, method, args)
|
|
|
31
31
|
});
|
|
32
32
|
return Schema.decodeUnknownSync(appForkResultSchema)(result);
|
|
33
33
|
}
|
|
34
|
+
/** The refusal a template-source Git exchange returns when this Oyster's
|
|
35
|
+
* git storage cannot serve it. */
|
|
36
|
+
const templateSourceUnavailable = {
|
|
37
|
+
code: "source_unavailable",
|
|
38
|
+
error: "This Oyster's git storage is unavailable, so it cannot hold App sources. Starter Apps need a deployed Oyster.",
|
|
39
|
+
};
|
|
34
40
|
/** Operator-only: seed one App's editable source template (`install-apps.mjs`).
|
|
35
41
|
* Each route declares the owner requirement (`authorization.ts`).
|
|
36
42
|
* The operator `git push`es the projected source to
|
|
@@ -38,7 +44,16 @@ export async function dispatchAppSourceBinding(env, scope, frame, method, args)
|
|
|
38
44
|
export function appSourceOwnerRoutes(env, scope) {
|
|
39
45
|
const routes = routeTable();
|
|
40
46
|
const registry = () => env.REGISTRY.getByName(scope.durableName("registry"));
|
|
41
|
-
routes.on(["GET", "POST"], "/api/apps/:appId/source.git/:suffix{info/refs|git-upload-pack|git-receive-pack}", owner("direct-or-app"), (context) =>
|
|
47
|
+
routes.on(["GET", "POST"], "/api/apps/:appId/source.git/:suffix{info/refs|git-upload-pack|git-receive-pack}", owner("direct-or-app"), async (context) => {
|
|
48
|
+
try {
|
|
49
|
+
return await registry().exchangeTemplateSource(context.req.param("appId"), context.req.param("suffix"), context.req.raw);
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Git storage this Oyster cannot reach (a local `oyster try` has no
|
|
53
|
+
// Cloudflare Artifacts): a typed refusal Git prints, not a bare 500.
|
|
54
|
+
return Response.json(templateSourceUnavailable, { status: 503 });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
42
57
|
routes.put("/api/apps/:appId/source", owner("direct-or-app"), async (context) => {
|
|
43
58
|
const claim = parseTemplateSeedClaim(await context.req.text());
|
|
44
59
|
if (claim === null)
|
|
@@ -6,10 +6,10 @@ import type { StandaloneRegistry } from "./registry.js";
|
|
|
6
6
|
export declare function buildStartFailureReply(reason: OysterBuildStartReason | "unavailable"): {
|
|
7
7
|
status: number;
|
|
8
8
|
body: {
|
|
9
|
-
code: "unavailable" |
|
|
9
|
+
code: "unavailable" | OysterBuildStartReason;
|
|
10
10
|
error: string;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
/** The build routes over the tenant registry that owns builds, resolved per
|
|
14
14
|
* request so mounting the routes reaches no registry. */
|
|
15
|
-
export declare function standaloneBuildRoutes(registryFor: () => Pick<StandaloneRegistry, "startBuild" | "readBuild" | "readBuildLog">): Routes<OysterEnv>;
|
|
15
|
+
export declare function standaloneBuildRoutes(registryFor: () => Pick<StandaloneRegistry, "buildBackend" | "startBuild" | "readBuild" | "readBuildLog">): Routes<OysterEnv>;
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* metadata. Publishing an App's source (PUT /api/apps/:appId/source) instead
|
|
7
7
|
* makes its template the build source at the returned seed revision.
|
|
8
8
|
*
|
|
9
|
+
* - `GET /api/build-backend` reads whether this Oyster's Computer can build
|
|
10
|
+
* at all, without starting a machine; installers ask before seeding.
|
|
9
11
|
* - `POST /api/builds` starts a build of that source at one exact commit.
|
|
10
12
|
* - `GET /api/builds/:jobId` reads it; `?log` reads its combined raw output.
|
|
11
13
|
* Both require the same owner admission. A finished build carries its
|
|
@@ -41,6 +43,8 @@ export function buildStartFailureReply(reason) {
|
|
|
41
43
|
export function standaloneBuildRoutes(registryFor) {
|
|
42
44
|
const routes = routeTable();
|
|
43
45
|
const owner = ownerRoute("direct-or-app");
|
|
46
|
+
// Only the owner's own installer asks; no App needs this read.
|
|
47
|
+
routes.get("/api/build-backend", ownerRoute("direct"), async () => Response.json(await registryFor().buildBackend()));
|
|
44
48
|
routes.post("/api/builds", owner, async (context, { principal }) => {
|
|
45
49
|
let input;
|
|
46
50
|
try {
|
|
@@ -113,7 +113,12 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
|
|
|
113
113
|
state: "running" | "sleeping";
|
|
114
114
|
position?: never;
|
|
115
115
|
}>;
|
|
116
|
-
/**
|
|
116
|
+
/**
|
|
117
|
+
* A read-only preflight over the maintained hosted-route selector. A
|
|
118
|
+
* platform container needs a container-enabled Durable Object: a Worker run
|
|
119
|
+
* without containers (`oyster try` runs Wrangler with
|
|
120
|
+
* `--enable-containers=false`) has no machine to build on.
|
|
121
|
+
*/
|
|
117
122
|
buildBackend(): OysterBuildBackend;
|
|
118
123
|
/**
|
|
119
124
|
* Run one App build job's fixed command, under the build budget. The
|
|
@@ -285,9 +285,17 @@ export class ComputerDO extends NativeComputerDO {
|
|
|
285
285
|
});
|
|
286
286
|
return this.#preview;
|
|
287
287
|
}
|
|
288
|
-
/**
|
|
288
|
+
/**
|
|
289
|
+
* A read-only preflight over the maintained hosted-route selector. A
|
|
290
|
+
* platform container needs a container-enabled Durable Object: a Worker run
|
|
291
|
+
* without containers (`oyster try` runs Wrangler with
|
|
292
|
+
* `--enable-containers=false`) has no machine to build on.
|
|
293
|
+
*/
|
|
289
294
|
buildBackend() {
|
|
290
|
-
|
|
295
|
+
const route = this.hostedRoute();
|
|
296
|
+
return route === undefined ||
|
|
297
|
+
(route.backing.kind === "platform-container" &&
|
|
298
|
+
this.state.container === undefined)
|
|
291
299
|
? { kind: "no_backend" }
|
|
292
300
|
: { kind: "hosted" };
|
|
293
301
|
}
|
|
@@ -20,7 +20,7 @@ import { defaultStarterBuildConcurrency, installStandaloneAppSet, } from "./app-
|
|
|
20
20
|
/** The starter Apps' public source repositories. */
|
|
21
21
|
const defaultRepositories = "https://github.com/fungi-computer";
|
|
22
22
|
const usage = "Usage: oyster install-apps [--repositories <base URL>] [--ref <ref>] [--from <checkout>] [--concurrency 1-3] [--timings <file>]";
|
|
23
|
-
const urlSource = "OYSTER_URL is the address of your deployed Oyster Worker, such as https://oyster.<your-subdomain>.workers.dev
|
|
23
|
+
const urlSource = "OYSTER_URL is the address of your deployed Oyster Worker, such as https://oyster.<your-subdomain>.workers.dev. You set it when you deploy. A local `oyster try` Oyster has no Computer, so it cannot build the starter Apps.";
|
|
24
24
|
const keySource = "OYSTER_OWNER_KEY is the owner key you chose for that Oyster: export OYSTER_OWNER_KEY=$(openssl rand -hex 24), then store it with `wrangler secret put OYSTER_OWNER_KEY`.";
|
|
25
25
|
const helpText = `${usage}
|
|
26
26
|
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
+
import { type StarterApp } from "./app-set.js";
|
|
2
|
+
/** The Tourtois desktop, which `oyster try` installs before anything else. */
|
|
3
|
+
export declare const desktopApp: Readonly<{
|
|
4
|
+
dashboard?: true;
|
|
5
|
+
installationId: string;
|
|
6
|
+
appId: string;
|
|
7
|
+
directory: string;
|
|
8
|
+
repository: string;
|
|
9
|
+
trial: "local" | "needs-runtime";
|
|
10
|
+
}>;
|
|
1
11
|
export type DesktopReadiness = "ready" | "approval-required" | "disabled" | "deleted" | "unavailable";
|
|
12
|
+
/** Whether an installation of this id is saved on the Oyster. Read-only. */
|
|
13
|
+
export declare function localStarterInstalled(input: Readonly<{
|
|
14
|
+
url: string;
|
|
15
|
+
key: string;
|
|
16
|
+
installationId: string;
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}>): Promise<boolean>;
|
|
2
19
|
/** The host-owned entry decides whether the saved desktop may run. Read-only. */
|
|
3
20
|
export declare function localDesktopState(input: Readonly<{
|
|
4
21
|
url: string;
|
|
5
22
|
key: string;
|
|
6
23
|
signal?: AbortSignal;
|
|
7
24
|
}>): Promise<DesktopReadiness | "missing">;
|
|
8
|
-
/** Build
|
|
9
|
-
export declare function
|
|
25
|
+
/** Build one starter App from source on this machine and install it. */
|
|
26
|
+
export declare function installLocalStarter(app: StarterApp, input: Readonly<{
|
|
10
27
|
url: string;
|
|
11
28
|
key: string;
|
|
12
29
|
signal?: AbortSignal;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CleanupError } from "../build/process-group.js";
|
|
2
|
-
// The
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// same way `install-apps` does.
|
|
2
|
+
// The starter Apps for a local Oyster. The standalone Oyster builds its starter
|
|
3
|
+
// Apps on its own Computer, which a laptop does not have, so `oyster try`
|
|
4
|
+
// builds each App here from its public source with the ordinary local packer
|
|
5
|
+
// and installs it; the Tourtois desktop is the home installation, and its shell
|
|
6
|
+
// is approved the same way `install-apps` does.
|
|
7
7
|
import { runGit } from "../build/local-build.js";
|
|
8
8
|
import { mkdtemp, realpath, rm } from "node:fs/promises";
|
|
9
9
|
import { tmpdir } from "node:os";
|
|
@@ -14,9 +14,32 @@ import { installRelease, packRelease } from "../pack.js";
|
|
|
14
14
|
import { appBuildRecipe, readBuildManifest } from "../build/workspace-build.js";
|
|
15
15
|
import { installationSchema } from "../apps/installation.js";
|
|
16
16
|
import { approveChosenDashboard } from "./dashboard-approval.js";
|
|
17
|
-
|
|
17
|
+
import { standaloneAppSet } from "./app-set.js";
|
|
18
|
+
const repositoryUrl = (app) => `https://github.com/fungi-computer/${app.repository}.git`;
|
|
19
|
+
/** The Tourtois desktop, which `oyster try` installs before anything else. */
|
|
20
|
+
export const desktopApp = requireStarter("tourtois");
|
|
21
|
+
function requireStarter(installationId) {
|
|
22
|
+
const found = standaloneAppSet.find((app) => app.installationId === installationId);
|
|
23
|
+
if (found === undefined)
|
|
24
|
+
throw new Error(`${installationId} is not a starter App`);
|
|
25
|
+
return found;
|
|
26
|
+
}
|
|
18
27
|
const installationRowsSchema = z.array(installationSchema);
|
|
19
28
|
const git = async (cwd, args, signal) => new TextDecoder().decode(await runGit(args, cwd, signal, process.env)).trim();
|
|
29
|
+
/** Whether an installation of this id is saved on the Oyster. Read-only. */
|
|
30
|
+
export async function localStarterInstalled(input) {
|
|
31
|
+
const request = {
|
|
32
|
+
headers: { Authorization: `Bearer ${input.key}` },
|
|
33
|
+
};
|
|
34
|
+
if (input.signal !== undefined)
|
|
35
|
+
request.signal = input.signal;
|
|
36
|
+
const response = await fetch(new URL("/api/installations", input.url), request);
|
|
37
|
+
if (!response.ok)
|
|
38
|
+
throw new Error(`Installation read failed (HTTP ${String(response.status)}).`);
|
|
39
|
+
return installationRowsSchema
|
|
40
|
+
.parse(await response.json())
|
|
41
|
+
.some((row) => row.installationId === input.installationId);
|
|
42
|
+
}
|
|
20
43
|
/** The host-owned entry decides whether the saved desktop may run. Read-only. */
|
|
21
44
|
export async function localDesktopState(input) {
|
|
22
45
|
const request = {
|
|
@@ -40,20 +63,20 @@ export async function localDesktopState(input) {
|
|
|
40
63
|
return "ready";
|
|
41
64
|
return entry.status === 403 ? "approval-required" : "unavailable";
|
|
42
65
|
}
|
|
43
|
-
/** Build
|
|
44
|
-
export async function
|
|
66
|
+
/** Build one starter App from source on this machine and install it. */
|
|
67
|
+
export async function installLocalStarter(app, input) {
|
|
45
68
|
const signal = input.signal ?? new AbortController().signal;
|
|
46
69
|
signal.throwIfAborted();
|
|
47
|
-
const scratch = await mkdtemp(join(tmpdir(),
|
|
70
|
+
const scratch = await mkdtemp(join(tmpdir(), `oyster-${app.repository}-`));
|
|
48
71
|
try {
|
|
49
72
|
const canonical = await realpath(scratch);
|
|
50
73
|
signal.throwIfAborted();
|
|
51
|
-
const source = join(canonical,
|
|
52
|
-
await git(canonical, ["clone", "--quiet", "--depth=1",
|
|
74
|
+
const source = join(canonical, app.repository);
|
|
75
|
+
await git(canonical, ["clone", "--quiet", "--depth=1", repositoryUrl(app), source], signal);
|
|
53
76
|
const commit = await git(source, ["rev-parse", "HEAD"], signal);
|
|
54
77
|
const release = join(scratch, "release");
|
|
55
78
|
await packRelease({
|
|
56
|
-
appId:
|
|
79
|
+
appId: app.appId,
|
|
57
80
|
sourceDirectory: source,
|
|
58
81
|
sourceRevision: `git:${commit}`,
|
|
59
82
|
recipe: appBuildRecipe(readBuildManifest(await git(source, ["show", `${commit}:package.json`], signal)), ""),
|
|
@@ -76,15 +99,15 @@ export async function installLocalDesktop(input) {
|
|
|
76
99
|
directory: release,
|
|
77
100
|
url: input.url,
|
|
78
101
|
key: input.key,
|
|
79
|
-
installationId:
|
|
102
|
+
installationId: app.installationId,
|
|
80
103
|
signal,
|
|
81
104
|
onCompleted: async (operation) => {
|
|
82
|
-
if (operation.state === "succeeded")
|
|
105
|
+
if (operation.state === "succeeded" && app.dashboard === true)
|
|
83
106
|
await approveChosenDashboard(operation, owner);
|
|
84
107
|
},
|
|
85
108
|
});
|
|
86
109
|
if (!response.ok)
|
|
87
|
-
throw new Error(
|
|
110
|
+
throw new Error(`${app.installationId} install failed (${String(response.status)})`);
|
|
88
111
|
}
|
|
89
112
|
finally {
|
|
90
113
|
await rm(scratch, { recursive: true, force: true }).catch((cause) => {
|
|
@@ -5,7 +5,7 @@ import { type TenantScope, type TenantId } from "../tenant.js";
|
|
|
5
5
|
import { type OysterGitEnv } from "../workers-git.js";
|
|
6
6
|
import { type AppSourceForkResult, type TemplateSeedClaim } from "../source/index.js";
|
|
7
7
|
import { type CloudflareArtifactsOptions } from "@fungi.computer/burrow/cloudflare";
|
|
8
|
-
import { type OysterBuildStartResult, type OysterBuildView } from "../app-builds.js";
|
|
8
|
+
import { type OysterBuildStartResult, type OysterBuildView, type OysterBuildBackend } from "../app-builds.js";
|
|
9
9
|
import type { TeamAppCandidateManifest } from "../build-contract.js";
|
|
10
10
|
import type { BuildGitEvent } from "../build-egress.js";
|
|
11
11
|
import type { ContentObjectOwner } from "../build/content-objects.js";
|
|
@@ -202,6 +202,9 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
|
|
|
202
202
|
repositoryBuildSource(installationId: string, repository: string): Promise<{
|
|
203
203
|
appId: import("@fungi.computer/puffball").AppId;
|
|
204
204
|
} | null>;
|
|
205
|
+
/** Owner: whether this Oyster's Computer can run App builds, read
|
|
206
|
+
* without starting a machine. */
|
|
207
|
+
buildBackend(): Promise<OysterBuildBackend>;
|
|
205
208
|
readBuild(jobId: string): Promise<OysterBuildView | null>;
|
|
206
209
|
readBuildLog(jobId: string): Promise<{
|
|
207
210
|
readonly encoding: "base64url";
|
|
@@ -408,6 +408,12 @@ export class StandaloneRegistry extends OysterRegistry {
|
|
|
408
408
|
const source = (await this.#appBuilds()).readRepositorySource(installationId, repository);
|
|
409
409
|
return source === null ? null : { appId: source.appId };
|
|
410
410
|
}
|
|
411
|
+
/** Owner: whether this Oyster's Computer can run App builds, read
|
|
412
|
+
* without starting a machine. */
|
|
413
|
+
async buildBackend() {
|
|
414
|
+
const env = this.#env;
|
|
415
|
+
return env.COMPUTER.getByName(env.OYSTER_COMPUTER_ID).buildBackend();
|
|
416
|
+
}
|
|
411
417
|
async readBuild(jobId) {
|
|
412
418
|
return (await this.#appBuilds()).read(jobId);
|
|
413
419
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Cli } from "@fungi.computer/lantern";
|
|
2
2
|
import { type DesktopReadiness } from "./local-desktop.js";
|
|
3
|
+
import { type StarterApp } from "./app-set.js";
|
|
3
4
|
import { type SignInLink } from "./sign-in-link.js";
|
|
4
5
|
export declare const tryUsage = "Usage: oyster try [directory] [--port 8787] [--no-open] [--verbose] [--package <npm spec>]";
|
|
5
6
|
/**
|
|
@@ -38,6 +39,12 @@ export type TryEffects = Readonly<{
|
|
|
38
39
|
key: string;
|
|
39
40
|
signal: AbortSignal;
|
|
40
41
|
}) => Promise<DesktopReadiness>;
|
|
42
|
+
/** Build and install one more starter App; resolves once it is installed. */
|
|
43
|
+
installStarter: (app: StarterApp, input: {
|
|
44
|
+
url: string;
|
|
45
|
+
key: string;
|
|
46
|
+
signal: AbortSignal;
|
|
47
|
+
}) => Promise<"installed" | "already-installed">;
|
|
41
48
|
/** A one-time page that signs the owner in without the key in a URL. */
|
|
42
49
|
signInLink: (input: {
|
|
43
50
|
oysterUrl: string;
|
|
@@ -23,11 +23,12 @@ import { copyFile, mkdir, mkdtemp, rename, readdir, rm, readFile, stat, writeFil
|
|
|
23
23
|
import { createServer } from "node:net";
|
|
24
24
|
import { basename, dirname, delimiter, join, resolve } from "node:path";
|
|
25
25
|
import process from "node:process";
|
|
26
|
-
import { parseArgs } from "node:util";
|
|
26
|
+
import { parseArgs, stripVTControlCharacters } from "node:util";
|
|
27
27
|
import { Cli } from "@fungi.computer/lantern";
|
|
28
28
|
import * as z from "zod";
|
|
29
29
|
import { installHelloApp } from "./hello-app.js";
|
|
30
|
-
import {
|
|
30
|
+
import { desktopApp, installLocalStarter, localDesktopState, localStarterInstalled, } from "./local-desktop.js";
|
|
31
|
+
import { standaloneAppSet, trialStarterOrder, } from "./app-set.js";
|
|
31
32
|
import { startSignInLink } from "./sign-in-link.js";
|
|
32
33
|
export const tryUsage = "Usage: oyster try [directory] [--port 8787] [--no-open] [--verbose] [--package <npm spec>]";
|
|
33
34
|
const tryHelp = `${tryUsage}
|
|
@@ -225,6 +226,30 @@ function captureOutput(child, log, verbose) {
|
|
|
225
226
|
stream?.pipe(process.stderr, { end: false });
|
|
226
227
|
}
|
|
227
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Wrangler keeps running after a failed build, so a startup that will never
|
|
231
|
+
* answer is only visible in its output. Resolves with its first error line.
|
|
232
|
+
*/
|
|
233
|
+
class StartupFailure {
|
|
234
|
+
line;
|
|
235
|
+
constructor(line) {
|
|
236
|
+
this.line = line;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function firstWranglerError(child) {
|
|
240
|
+
return new Promise((found) => {
|
|
241
|
+
let seen = "";
|
|
242
|
+
for (const stream of [child.stdout, child.stderr])
|
|
243
|
+
stream?.setEncoding("utf8").on("data", (chunk) => {
|
|
244
|
+
seen = (seen + chunk).slice(-4096);
|
|
245
|
+
const line = stripVTControlCharacters(seen)
|
|
246
|
+
.split("\n")
|
|
247
|
+
.find((candidate) => candidate.includes("[ERROR]"));
|
|
248
|
+
if (line !== undefined)
|
|
249
|
+
found(line.slice(line.indexOf("[ERROR]") + "[ERROR]".length).trim());
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
228
253
|
const npmFailureSchema = z.object({ error: z.object({ code: z.string() }) });
|
|
229
254
|
function npmFailureCode(output) {
|
|
230
255
|
try {
|
|
@@ -372,6 +397,7 @@ function startWrangler(input) {
|
|
|
372
397
|
env: { ...process.env, WRANGLER_SEND_METRICS: "false" },
|
|
373
398
|
});
|
|
374
399
|
captureOutput(child, logStream, input.verbose);
|
|
400
|
+
const startupError = firstWranglerError(child);
|
|
375
401
|
const lifetime = new AbortController();
|
|
376
402
|
const spawnError = new Promise((done) => {
|
|
377
403
|
child.once("error", () => {
|
|
@@ -405,16 +431,19 @@ function startWrangler(input) {
|
|
|
405
431
|
});
|
|
406
432
|
try {
|
|
407
433
|
const readiness = await Promise.race([
|
|
434
|
+
startupError.then((line) => new StartupFailure(line)),
|
|
408
435
|
waitUntilReady(url, child, 120_000, AbortSignal.any([lifetime.signal, input.signal])),
|
|
409
436
|
spawnError,
|
|
410
437
|
]);
|
|
411
438
|
input.signal.throwIfAborted();
|
|
412
439
|
if (readiness !== "ready") {
|
|
413
|
-
const diagnostic = readiness
|
|
414
|
-
?
|
|
415
|
-
: readiness === "
|
|
416
|
-
?
|
|
417
|
-
:
|
|
440
|
+
const diagnostic = readiness instanceof StartupFailure
|
|
441
|
+
? `Oyster could not start: ${readiness.line}`
|
|
442
|
+
: readiness === "spawn-error"
|
|
443
|
+
? "Oyster could not launch its server process."
|
|
444
|
+
: readiness === "exited"
|
|
445
|
+
? `Oyster stopped before readiness (${child.signalCode === null ? `exit ${String(child.exitCode)}` : `signal ${child.signalCode}`}).`
|
|
446
|
+
: "Oyster did not answer within 120 seconds.";
|
|
418
447
|
await stop();
|
|
419
448
|
throw new TryError(diagnostic, `Read ${log} for the server output.`);
|
|
420
449
|
}
|
|
@@ -462,10 +491,19 @@ const realEffects = {
|
|
|
462
491
|
const saved = await localDesktopState(input);
|
|
463
492
|
if (saved !== "missing")
|
|
464
493
|
return saved;
|
|
465
|
-
await
|
|
494
|
+
await installLocalStarter(desktopApp, input);
|
|
466
495
|
const installed = await localDesktopState(input);
|
|
467
496
|
return installed === "missing" ? "unavailable" : installed;
|
|
468
497
|
},
|
|
498
|
+
installStarter: async (app, input) => {
|
|
499
|
+
if (await localStarterInstalled({
|
|
500
|
+
...input,
|
|
501
|
+
installationId: app.installationId,
|
|
502
|
+
}))
|
|
503
|
+
return "already-installed";
|
|
504
|
+
await installLocalStarter(app, input);
|
|
505
|
+
return "installed";
|
|
506
|
+
},
|
|
469
507
|
signInLink: startSignInLink,
|
|
470
508
|
open: openBrowser,
|
|
471
509
|
portFree,
|
|
@@ -718,6 +756,46 @@ export async function tryOyster(args, effects = realEffects, ui = createTryCli(a
|
|
|
718
756
|
`Sign in later by pasting that key at ${url}/login.`,
|
|
719
757
|
"Press Ctrl-C to stop.",
|
|
720
758
|
]);
|
|
759
|
+
// The rest of the starter Apps build here, one at a time, while the desktop
|
|
760
|
+
// is already usable. Each reports one line; a failure never stops the rest.
|
|
761
|
+
const starters = trialStarterOrder.map((id) => {
|
|
762
|
+
const app = standaloneAppSet.find((item) => item.installationId === id);
|
|
763
|
+
if (app === undefined)
|
|
764
|
+
throw new Error(`${id} is not a starter App`);
|
|
765
|
+
return app;
|
|
766
|
+
});
|
|
767
|
+
const trialAbort = new AbortController();
|
|
768
|
+
const trialSignal = AbortSignal.any([signal, trialAbort.signal]);
|
|
769
|
+
void watchedExit.then(() => {
|
|
770
|
+
trialAbort.abort();
|
|
771
|
+
});
|
|
772
|
+
const stopped = () => trialSignal.aborted;
|
|
773
|
+
// A stop interrupts the build in flight; that is not a failure to report.
|
|
774
|
+
const reportStarterFailure = (name, cause) => {
|
|
775
|
+
if (!stopped())
|
|
776
|
+
ui.warn(`${name} couldn't be installed: ${innermostError(cause).message}`, `Run \`${retry}\` again to retry it.`);
|
|
777
|
+
};
|
|
778
|
+
const background = desktopReady
|
|
779
|
+
? (async () => {
|
|
780
|
+
ui.info(`Getting ${String(starters.length)} more Apps ready in the background.`);
|
|
781
|
+
for (const app of starters) {
|
|
782
|
+
if (stopped())
|
|
783
|
+
return;
|
|
784
|
+
const name = app.installationId;
|
|
785
|
+
const settled = await effects
|
|
786
|
+
.installStarter(app, { url, key, signal: trialSignal })
|
|
787
|
+
.then((result) => ({ kind: "done", result }), (cause) => ({ kind: "failed", cause }));
|
|
788
|
+
if (settled.kind === "failed")
|
|
789
|
+
reportStarterFailure(name, settled.cause);
|
|
790
|
+
else
|
|
791
|
+
ui.info(app.trial === "needs-runtime"
|
|
792
|
+
? `${name} installed: needs a Computer runtime (see ${name})`
|
|
793
|
+
: settled.result === "already-installed"
|
|
794
|
+
? `${name} already installed`
|
|
795
|
+
: `${name} ready`);
|
|
796
|
+
}
|
|
797
|
+
})()
|
|
798
|
+
: Promise.resolve();
|
|
721
799
|
let stopListener;
|
|
722
800
|
try {
|
|
723
801
|
const requested = new Promise((done) => {
|
|
@@ -734,6 +812,8 @@ export async function tryOyster(args, effects = realEffects, ui = createTryCli(a
|
|
|
734
812
|
}
|
|
735
813
|
finally {
|
|
736
814
|
stopListener?.[Symbol.dispose]();
|
|
815
|
+
trialAbort.abort();
|
|
816
|
+
await background;
|
|
737
817
|
}
|
|
738
818
|
}
|
|
739
819
|
catch (cause) {
|