@fungi.computer/oyster 0.14.1 → 0.16.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 (61) hide show
  1. package/README.md +178 -1552
  2. package/dist/agents.d.ts +8 -0
  3. package/dist/agents.js +6 -0
  4. package/dist/app-builds.d.ts +5 -6
  5. package/dist/app-builds.js +3 -10
  6. package/dist/apps/permissions.js +8 -1
  7. package/dist/auth.d.ts +2 -0
  8. package/dist/auth.js +9 -8
  9. package/dist/boot-host-script.js +1 -1
  10. package/dist/build/candidate-cli.mjs +4 -0
  11. package/dist/catalog-frame.d.ts +0 -1
  12. package/dist/computer.d.ts +5 -0
  13. package/dist/computer.js +1 -0
  14. package/dist/embed-metafiles.js +2 -2
  15. package/dist/embed-scripts.js +3 -3
  16. package/dist/hello-app-script.js +1 -1
  17. package/dist/host-page-assets.js +1 -1
  18. package/dist/host-page.d.ts +5 -1
  19. package/dist/host-page.js +23 -23
  20. package/dist/host.js +6 -1
  21. package/dist/page/app-access.js +23 -1
  22. package/dist/page/app-permissions.js +165 -50
  23. package/dist/page/app-rights.d.ts +8 -0
  24. package/dist/page/app-rights.js +13 -0
  25. package/dist/page/computer-handles.d.ts +15 -0
  26. package/dist/page/computer-handles.js +4 -1
  27. package/dist/page/mount.d.ts +5 -0
  28. package/dist/page/mount.js +4 -0
  29. package/dist/page-script.js +3 -3
  30. package/dist/standalone/agents.js +10 -0
  31. package/dist/standalone/app-set.d.ts +9 -0
  32. package/dist/standalone/app-set.js +43 -0
  33. package/dist/standalone/app-source.js +16 -1
  34. package/dist/standalone/builds.d.ts +2 -2
  35. package/dist/standalone/builds.js +4 -0
  36. package/dist/standalone/cloudflare-account.d.ts +10 -0
  37. package/dist/standalone/cloudflare-account.js +17 -0
  38. package/dist/standalone/computer.d.ts +8 -3
  39. package/dist/standalone/computer.js +26 -3
  40. package/dist/standalone/install-apps-cli.js +1 -1
  41. package/dist/standalone/local-desktop.d.ts +19 -2
  42. package/dist/standalone/local-desktop.js +38 -15
  43. package/dist/standalone/media.d.ts +2 -0
  44. package/dist/standalone/media.js +17 -1
  45. package/dist/standalone/registry.d.ts +4 -1
  46. package/dist/standalone/registry.js +6 -0
  47. package/dist/standalone/sign-in-link.d.ts +1 -1
  48. package/dist/standalone/sign-in-link.js +9 -18
  49. package/dist/standalone/try-cli.d.ts +7 -0
  50. package/dist/standalone/try-cli.js +88 -8
  51. package/dist/starter-agent.d.ts +59 -0
  52. package/dist/starter-agent.js +85 -0
  53. package/docs/api/README.md +744 -88
  54. package/docs/api/agents.md +6 -0
  55. package/docs/api/auth.md +10 -0
  56. package/docs/api/computer.md +4 -0
  57. package/docs/api/page/mount.md +2 -0
  58. package/docs/api/workers-git.md +14 -9
  59. package/docs/api/workers.md +8 -3
  60. package/docs/site/agent-quickstart.mdx +1 -1
  61. package/package.json +34 -50
@@ -45,6 +45,7 @@ import { configuredProviderEgress, providerFetch, } from "@fungi.computer/veil/g
45
45
  import { createAssistantMessageEventStream } from "@earendil-works/pi-ai/utils/event-stream";
46
46
  import { agentModelChoice, agentModelChoiceSchema, AgentModelRefused, selectAgentModel, } from "./agent-model-choice.js";
47
47
  import { CLOUDFLARE_GATEWAY_BINDING_AUTH_SENTINEL, createAiBindingFetch, } from "@earendil-works/pi-ai/api/cloudflare-ai-binding";
48
+ import { cloudflareAccountReady } from "./cloudflare-account.js";
48
49
  import { cloudflareWorkersAIProvider } from "@earendil-works/pi-ai/providers/cloudflare-workers-ai";
49
50
  import { getSupportedThinkingLevels } from "@earendil-works/pi-ai/models";
50
51
  import { agentModelListSchema } from "@fungi.computer/shiitake/model-list";
@@ -2023,6 +2024,15 @@ export function standaloneAgents(env, scope) {
2023
2024
  return { error: "not_found" };
2024
2025
  return env.AGENTS.getByName(agentId).setModelChoice(choice);
2025
2026
  },
2027
+ setup: async () => {
2028
+ const account = cloudflareAccountReady(env);
2029
+ const gateway = configuredProviderEgress(env).baseUrl("ai-gateway") !== null;
2030
+ const stored = (await directory().listModelKeys()).length > 0;
2031
+ return {
2032
+ models: account || gateway || stored ? "ready" : "missing",
2033
+ media: account ? "ready" : "missing",
2034
+ };
2035
+ },
2026
2036
  modelKeys: () => directory().listModelKeys(),
2027
2037
  sealModelKey: (input) => directory().sealModelKey(input),
2028
2038
  removeModelKey: (keyId) => directory().removeModelKey(keyId),
@@ -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) => registry().exchangeTemplateSource(context.req.param("appId"), context.req.param("suffix"), context.req.raw));
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" | "invalid_revision" | "no_source" | "not_template_seed" | "no_backend";
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 {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Whether this Worker can reach Workers AI. The AI binding is declared in
3
+ * every Oyster's wrangler config, but a local trial (`oyster try`, served from
4
+ * a loopback origin) has no Cloudflare account behind it: calls through it
5
+ * fail. A deployed Oyster, served from its own origin, does.
6
+ */
7
+ export declare function cloudflareAccountReady(env: Readonly<{
8
+ AI?: unknown;
9
+ OYSTER_ORIGIN?: string | undefined;
10
+ }>): boolean;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Whether this Worker can reach Workers AI. The AI binding is declared in
3
+ * every Oyster's wrangler config, but a local trial (`oyster try`, served from
4
+ * a loopback origin) has no Cloudflare account behind it: calls through it
5
+ * fail. A deployed Oyster, served from its own origin, does.
6
+ */
7
+ export function cloudflareAccountReady(env) {
8
+ if (env.AI === undefined)
9
+ return false;
10
+ // A host that names no origin has no loopback trial to tell apart.
11
+ if (env.OYSTER_ORIGIN === undefined)
12
+ return true;
13
+ if (!URL.canParse(env.OYSTER_ORIGIN))
14
+ return false;
15
+ const { hostname } = new URL(env.OYSTER_ORIGIN);
16
+ return !["localhost", "127.0.0.1", "[::1]"].includes(hostname);
17
+ }
@@ -6,7 +6,7 @@ import * as z from "zod";
6
6
  import { computerProcessSchema, computerToolResultSchema, readOutputSchema } from "@fungi.computer/computer-contract";
7
7
  import { ComputerDO as NativeComputerDO, type AttachedBackend, type ComputerEnv, type ComputerFilesRpc } from "@fungi.computer/computer";
8
8
  import { patchInputSchema, patchOutputSchema } from "@fungi.computer/knapsack/files-patch";
9
- import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
9
+ import { listOutputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsOutputSchema, computerOperationResultSchema, type ComputerExecutionHostHooks, type ComputerValue } from "@fungi.computer/computer-contract";
10
10
  import { type WorkflowGitCredential, type WorkflowGitPassGrant } from "@fungi.computer/braid/runtime";
11
11
  import { type ComputerAction, type ComputerBackendView, type ComputerGrant, type LocalBackendAttachInput, type LocalBackendDetachInput } from "@fungi.computer/computer/fleet";
12
12
  import type { InvocationFrame } from "../invocation.js";
@@ -38,7 +38,7 @@ export type StandaloneComputerResult = z.output<typeof listOutputSchema> | Reado
38
38
  truncated: boolean;
39
39
  }> | Readonly<{
40
40
  error: "conflict";
41
- }> | z.output<typeof writeOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
41
+ }> | z.output<typeof writeOutputSchema> | z.output<typeof mkdirOutputSchema> | z.output<typeof computerPortsOutputSchema> | z.output<typeof computerPortOutputSchema> | z.output<typeof computerPortRemovalOutputSchema> | z.output<typeof processListOutputSchema> | z.output<typeof processKillOutputSchema> | z.output<typeof processLogsOutputSchema> | z.output<typeof computerProcessSchema> | ComputerPorts["ports"][number] | z.output<typeof computerOperationResultSchema> | z.output<typeof readOutputSchema> | z.output<typeof computerToolResultSchema>;
42
42
  /**
43
43
  * A port-preview listing, or the typed refusal the owner route presents with
44
44
  * {@link appMethodRefusalStatus}. A refusal never escapes as a 500.
@@ -113,7 +113,12 @@ export declare class ComputerDO extends NativeComputerDO implements ComputerFetc
113
113
  state: "running" | "sleeping";
114
114
  position?: never;
115
115
  }>;
116
- /** A read-only preflight over the maintained hosted-route selector. */
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
@@ -12,7 +12,7 @@ import * as z from "zod";
12
12
  import { ComputerPortConflictError, computerByteReadReplySchema, computerProcessSchema, installationProcessScope, processStartInputSchema, processStartToolInputSchema, computerCapabilities, computerToolResultSchema, readOutputSchema, } from "@fungi.computer/computer-contract";
13
13
  import { ComputerDO as NativeComputerDO, ComputerOperationConflictError, } from "@fungi.computer/computer";
14
14
  import { patchInputSchema, patchOutputSchema, } from "@fungi.computer/knapsack/files-patch";
15
- import { ComputerFileConflict, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
15
+ import { ComputerFileConflict, computerExecutionRequestSchema, computerValueSchema, computerPortInputSchema, listInputSchema, listOutputSchema, readBytesInputSchema, writeInputSchema, replaceInputSchema, writeOutputSchema, mkdirOutputSchema, computerPortsOutputSchema, computerPortOutputSchema, computerPortRemovalOutputSchema, processListOutputSchema, processKillOutputSchema, processLogsInputSchema, processLogsOutputSchema, computerOperationResultSchema, mintComputerRequestId, processIdInputSchema, } from "@fungi.computer/computer-contract";
16
16
  import { workflowGitExecutionEnvironment, workflowGitPassGrantSchema, } from "@fungi.computer/braid/runtime";
17
17
  import { checkComputerGrant, computerActionSchema, computerGrantSchema, ComputerBackingError, createFleetBacking, FleetGrantRefused, FleetLifecycle, } from "@fungi.computer/computer/fleet";
18
18
  import { AppInstanceError, selectionOf } from "../index.js";
@@ -285,9 +285,17 @@ export class ComputerDO extends NativeComputerDO {
285
285
  });
286
286
  return this.#preview;
287
287
  }
288
- /** A read-only preflight over the maintained hosted-route selector. */
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
- return this.hostedRoute() === undefined
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
  }
@@ -453,6 +461,8 @@ export class ComputerDO extends NativeComputerDO {
453
461
  return { error: "conflict" };
454
462
  throw cause;
455
463
  }
464
+ case "processLogs":
465
+ return this.processLogsAfterAcceptance(processLogsInputSchema.parse(input), accept);
456
466
  case "processKill":
457
467
  return this.killProcessAfterAcceptance(processIdInputSchema.parse(input), accept);
458
468
  case "exec":
@@ -665,6 +675,19 @@ export function standaloneComputerCapabilities(env, workspace) {
665
675
  return context.json({ error: "invalid_input" }, 400);
666
676
  return Response.json(await computer().value(authority(principal), "processKill", input.data));
667
677
  });
678
+ routes.get("/processes/logs", reach, async (context, { principal }) => {
679
+ const query = {
680
+ id: context.req.query("id"),
681
+ lines: context.req.query("lines"),
682
+ };
683
+ const input = processLogsInputSchema.safeParse({
684
+ id: query.id,
685
+ lines: query.lines === undefined ? undefined : Number(query.lines),
686
+ });
687
+ if (!input.success)
688
+ return context.json({ error: "invalid_input" }, 400);
689
+ return Response.json(await computer().value(authority(principal), "processLogs", input.data));
690
+ });
668
691
  routes.get("/terminal", reach, async (context, { principal }) => {
669
692
  const terminal = authority(principal);
670
693
  const url = new URL(context.req.url);
@@ -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 (http://127.0.0.1:8787 for a local one). You set it when you deploy.";
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 Tourtois from source on this machine and install it as `tourtois`. */
9
- export declare function installLocalDesktop(input: Readonly<{
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 Tourtois desktop for a local Oyster. The standalone Oyster builds its
3
- // starter Apps on its own Computer, which a laptop does not have, so `oyster
4
- // try` builds Tourtois here from its public source with the ordinary local
5
- // packer and installs it as the home installation, approving its shell the
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
- const tourtoisRepository = "https://github.com/fungi-computer/tourtois.git";
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 Tourtois from source on this machine and install it as `tourtois`. */
44
- export async function installLocalDesktop(input) {
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(), "oyster-tourtois-"));
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, "tourtois");
52
- await git(canonical, ["clone", "--quiet", "--depth=1", tourtoisRepository, source], signal);
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: "app_tourtois",
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: "tourtois",
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(`Tourtois install failed (${String(response.status)})`);
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) => {
@@ -10,6 +10,8 @@ import type { FileSource } from "../files.js";
10
10
  export type OysterMediaEnv = Readonly<{
11
11
  /** Workers AI provider, admitted by this Worker. */
12
12
  AI: MediaAiPort;
13
+ /** This Worker's own origin; a loopback origin has no Cloudflare account. */
14
+ OYSTER_ORIGIN?: string | undefined;
13
15
  /** Darkroom's durable operation namespace. */
14
16
  MEDIA_OPERATION: MediaServiceHost["operations"];
15
17
  /** Native image decoding and bounded reference fitting. */
@@ -12,6 +12,7 @@ import { createMediaService, estimateMediaModel, mediaPendingSchema, mediaResult
12
12
  import { createWorkersAiMediaProvider, createImagesReferenceFitter, } from "@fungi.computer/darkroom/cloudflare";
13
13
  import { oysterPrincipalId, } from "../host.js";
14
14
  import { normalizeFilePath } from "../files.js";
15
+ import { cloudflareAccountReady } from "./cloudflare-account.js";
15
16
  /** Media capability using Darkroom execution and the existing workspace FileSource. */
16
17
  export function workersMedia(env, workspace) {
17
18
  const { computerId } = workspace;
@@ -22,7 +23,7 @@ export function workersMedia(env, workspace) {
22
23
  const response = await service(principal).request("http://media/models");
23
24
  return context.json(Schema.decodeUnknownSync(mediaGenerationDescriptionSchema)({
24
25
  computerId,
25
- canGenerate: true,
26
+ canGenerate: cloudflareAccountReady(env),
26
27
  models: await response.json(),
27
28
  }));
28
29
  });
@@ -40,6 +41,8 @@ export function workersMedia(env, workspace) {
40
41
  }));
41
42
  if (references?.some((reference) => reference.path === null || reference.path === "/"))
42
43
  return context.json(invalidRequest());
44
+ if (!cloudflareAccountReady(env))
45
+ return context.json(setupRequired());
43
46
  const response = await service(principal).request("http://media/generate", {
44
47
  method: "POST",
45
48
  signal: context.req.raw.signal,
@@ -104,6 +107,19 @@ export function workersMedia(env, workspace) {
104
107
  },
105
108
  ];
106
109
  }
110
+ /** A missing provider or account is setup, not a failed generation. */
111
+ function setupRequired() {
112
+ return {
113
+ kind: "failed",
114
+ failure: {
115
+ message: "Media generation needs an image provider",
116
+ stage: "admission",
117
+ code: "SETUP_REQUIRED",
118
+ need: "an image provider",
119
+ retryable: false,
120
+ },
121
+ };
122
+ }
107
123
  function invalidRequest() {
108
124
  return {
109
125
  kind: "failed",
@@ -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
  }
@@ -2,7 +2,7 @@ export type SignInLink = Readonly<{
2
2
  url: string;
3
3
  close: () => Promise<void>;
4
4
  }>;
5
- /** Serve one single-use page that signs the owner in to `oysterUrl`. */
5
+ /** Serve one single-use page that signs the owner in to `oysterUrl`, until closed. */
6
6
  export declare function startSignInLink(input: Readonly<{
7
7
  oysterUrl: string;
8
8
  key: string;