@fungi.computer/oyster 0.10.0 → 0.12.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 (107) hide show
  1. package/README.md +103 -12
  2. package/dist/agents.d.ts +66 -22
  3. package/dist/agents.js +128 -38
  4. package/dist/app-builds.d.ts +2 -0
  5. package/dist/app-builds.js +17 -6
  6. package/dist/authorization.d.ts +25 -3
  7. package/dist/authorization.js +47 -14
  8. package/dist/browser/capability-source.d.ts +23 -5
  9. package/dist/browser/capability-source.js +19 -22
  10. package/dist/browser/index.d.ts +2 -1
  11. package/dist/browser/index.js +1 -0
  12. package/dist/browser/live-view.d.ts +38 -0
  13. package/dist/browser/live-view.js +179 -0
  14. package/dist/build/artifact-writer.d.ts +11 -2
  15. package/dist/build/artifact-writer.js +42 -24
  16. package/dist/build/candidate-cli.mjs +26 -18
  17. package/dist/build/content-objects.d.ts +29 -14
  18. package/dist/build/content-objects.js +57 -19
  19. package/dist/build/local-build.js +3 -0
  20. package/dist/build/submission-contract.d.ts +1 -1
  21. package/dist/build/submission-contract.js +5 -5
  22. package/dist/build-egress.d.ts +8 -7
  23. package/dist/build-egress.js +4 -3
  24. package/dist/build.d.ts +1 -1
  25. package/dist/channels/binding.d.ts +2 -0
  26. package/dist/channels/run-decision.d.ts +33 -0
  27. package/dist/channels/run-decision.js +25 -0
  28. package/dist/channels/visitor-channel.d.ts +84 -14
  29. package/dist/channels/visitor-channel.js +55 -32
  30. package/dist/channels/visitor-edge.d.ts +18 -2
  31. package/dist/channels/visitor-edge.js +67 -5
  32. package/dist/channels/visitors.d.ts +4 -0
  33. package/dist/channels/visitors.js +22 -1
  34. package/dist/channels/web-binding.d.ts +117 -0
  35. package/dist/channels/web-binding.js +227 -0
  36. package/dist/embed-metafiles.d.ts +8 -0
  37. package/dist/embed-metafiles.js +2 -0
  38. package/dist/embed-scripts.d.ts +8 -0
  39. package/dist/embed-scripts.js +3 -0
  40. package/dist/host.d.ts +3 -1
  41. package/dist/host.js +6 -1
  42. package/dist/install-release-cli.d.ts +2 -1
  43. package/dist/install-release-cli.js +18 -10
  44. package/dist/installation-client.d.ts +1 -0
  45. package/dist/installation-operations.d.ts +2 -0
  46. package/dist/installation-operations.js +1 -0
  47. package/dist/pack.d.ts +5 -2
  48. package/dist/pack.js +3 -1
  49. package/dist/page/embed-challenge.d.ts +19 -0
  50. package/dist/page/embed-challenge.js +45 -0
  51. package/dist/page/embed-error.d.ts +2 -0
  52. package/dist/page/embed-error.js +16 -0
  53. package/dist/page/embed-loader-protocol.d.ts +12 -0
  54. package/dist/page/embed-loader-protocol.js +29 -0
  55. package/dist/standalone/agent-connections.d.ts +22 -19
  56. package/dist/standalone/agent-connections.js +150 -106
  57. package/dist/standalone/agents.d.ts +174 -16
  58. package/dist/standalone/agents.js +331 -21
  59. package/dist/standalone/browser.d.ts +14 -2
  60. package/dist/standalone/browser.js +52 -4
  61. package/dist/standalone/channel-session-door.d.ts +4 -0
  62. package/dist/standalone/channel-session-door.js +72 -0
  63. package/dist/standalone/computer-egress.d.ts +5 -3
  64. package/dist/standalone/computer-egress.js +1 -1
  65. package/dist/standalone/hello-app.d.ts +9 -0
  66. package/dist/standalone/hello-app.js +78 -0
  67. package/dist/standalone/install-apps-cli.d.ts +2 -1
  68. package/dist/standalone/install-apps-cli.js +36 -14
  69. package/dist/standalone/instance.js +2 -2
  70. package/dist/standalone/local-desktop.d.ts +11 -0
  71. package/dist/standalone/local-desktop.js +75 -0
  72. package/dist/standalone/owner-routes.d.ts +4 -3
  73. package/dist/standalone/owner-routes.js +7 -1
  74. package/dist/standalone/registry.d.ts +2 -0
  75. package/dist/standalone/sign-in-link.d.ts +9 -0
  76. package/dist/standalone/sign-in-link.js +49 -0
  77. package/dist/standalone/try-cli.d.ts +52 -0
  78. package/dist/standalone/try-cli.js +404 -0
  79. package/dist/standalone/visitor-edge.d.ts +36 -0
  80. package/dist/standalone/visitor-edge.js +67 -0
  81. package/dist/standalone/visitor-proof.d.ts +23 -0
  82. package/dist/standalone/visitor-proof.js +67 -0
  83. package/dist/standalone/website-channels.d.ts +134 -0
  84. package/dist/standalone/website-channels.js +262 -0
  85. package/dist/standalone/worker-routes.d.ts +4 -1
  86. package/dist/standalone/worker-routes.js +3 -0
  87. package/dist/standalone/worker.d.ts +2 -1
  88. package/dist/standalone/worker.js +5 -1
  89. package/dist/testing/capabilities.d.ts +3 -0
  90. package/dist/testing/capabilities.js +1 -0
  91. package/dist/testing/installation.d.ts +4 -2
  92. package/dist/testing/installation.js +7 -2
  93. package/dist/webhook-abuse.d.ts +7 -1
  94. package/dist/webhook-abuse.js +8 -2
  95. package/dist/workers-git.js +2 -2
  96. package/dist/workers.d.ts +7 -2
  97. package/dist/workers.js +1 -1
  98. package/docs/api/agents.md +103 -36
  99. package/docs/api/authorization.md +56 -11
  100. package/docs/api/browser.md +115 -8
  101. package/docs/api/build-contract.md +52 -10
  102. package/docs/api/build.md +16 -2
  103. package/docs/api/host.md +1 -0
  104. package/docs/api/pack.md +179 -3
  105. package/docs/api/workers-git.md +6 -6
  106. package/docs/site/agent-quickstart.mdx +8 -0
  107. package/package.json +34 -8
@@ -1,4 +1,5 @@
1
1
  import { type BuildGitEvent } from "../build-egress.js";
2
+ import type { ContentObjectOwner } from "../build/content-objects.js";
2
3
  import type { CandidateObject, CandidateObjectMediaType, TeamAppCandidateManifest } from "../build-contract.js";
3
4
  import { type GitDoorTarget } from "../git.js";
4
5
  /** Loopback props the ComputerDO sets; a guest cannot choose them. */
@@ -13,12 +14,13 @@ export type OysterComputerBuildPort = Readonly<{
13
14
  admitBuild(jobId: string): Promise<Readonly<{
14
15
  credentialId: string;
15
16
  }> | null>;
16
- /** One object upload for a live job's grant, and its size bound. */
17
+ /** One object upload for a live job's grant, its size bound and owner. */
17
18
  admitObject(jobId: string, grant: string): Promise<Readonly<{
18
19
  maxObjectBytes: number;
20
+ owner: ContentObjectOwner;
19
21
  }> | null>;
20
- /** Stream one admitted object into the host's Release store. */
21
- storeObject(object: CandidateObject, body: ReadableStream<Uint8Array> | null, mediaType: CandidateObjectMediaType): Promise<"stored" | "refused">;
22
+ /** Stream one admitted object into the host's Release store, in its owner's namespace. */
23
+ storeObject(object: CandidateObject, body: ReadableStream<Uint8Array> | null, mediaType: CandidateObjectMediaType, owner: ContentObjectOwner): Promise<"stored" | "refused">;
22
24
  submitCandidate(jobId: string, manifest: TeamAppCandidateManifest, grant: string, credentialId: string): Promise<Response>;
23
25
  record(event: BuildGitEvent): Promise<void>;
24
26
  }>;
@@ -74,7 +74,7 @@ export async function serveOysterComputerEgress(request, options) {
74
74
  response = await createBuildEgress({
75
75
  admitBuild: (jobId) => options.build.admitBuild(jobId),
76
76
  admitObject: (jobId, grant) => options.build.admitObject(jobId, grant),
77
- storeObject: (object, body, mediaType) => options.build.storeObject(object, body, mediaType),
77
+ storeObject: (object, body, mediaType, admitted) => options.build.storeObject(object, body, mediaType, admitted.owner),
78
78
  submitCandidate: (jobId, manifest, grant, credentialId) => options.build.submitCandidate(jobId, manifest, grant, credentialId),
79
79
  record: (event) => options.build.record(event),
80
80
  }).fetch(request, url);
@@ -0,0 +1,9 @@
1
+ /** Pack the Hello App kept at `<directory>/hello-app` and install it as
2
+ * `hello`; answers the HTTP status (201 new, 200 when already installed).
3
+ * The first call writes and commits the source; later calls pack its current
4
+ * `HEAD`, so a committed edit followed by `oyster try` shows the change. */
5
+ export declare function installHelloApp(input: Readonly<{
6
+ directory: string;
7
+ url: string;
8
+ key: string;
9
+ }>): Promise<number>;
@@ -0,0 +1,78 @@
1
+ // The starter Hello App for a local Oyster: a one-page bundled-html App,
2
+ // committed to git, packed into a Release and installed as `hello`. The
3
+ // quick start and `oyster try` install the same App through this module;
4
+ // `try` keeps its source at `<project>/hello-app` for the person to edit.
5
+ import { execFileSync } from "node:child_process";
6
+ import { access, mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
7
+ import { tmpdir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { installRelease, packRelease } from "../pack.js";
10
+ const manifest = {
11
+ name: "hello-app",
12
+ private: true,
13
+ fungi: { app: { displayName: "Hello", icon: "fungi", capabilities: [] } },
14
+ };
15
+ const page = "<!doctype html>\n<title>Hello</title>\n<h1>Hello from my first Oyster App</h1>\n";
16
+ const exists = (path) => access(path).then(() => true, () => false);
17
+ const git = (directory, args) => execFileSync("git", [
18
+ "-C",
19
+ directory,
20
+ "-c",
21
+ "user.name=Oyster",
22
+ "-c",
23
+ "user.email=oyster@example.invalid",
24
+ ...args,
25
+ ], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
26
+ // Write `hello-app/` under `directory` and commit it; answers the commit.
27
+ async function writeHelloApp(directory) {
28
+ const source = join(directory, "hello-app");
29
+ await mkdir(join(source, "bundle"), { recursive: true });
30
+ await writeFile(join(source, "package.json"), JSON.stringify(manifest, null, 2) + "\n");
31
+ await writeFile(join(source, "bundle", "index.html"), page);
32
+ git(source, ["init", "-q"]);
33
+ git(source, ["add", "."]);
34
+ git(source, ["commit", "-qm", "Hello App"]);
35
+ return git(source, ["rev-parse", "HEAD"]);
36
+ }
37
+ /** Pack the Hello App kept at `<directory>/hello-app` and install it as
38
+ * `hello`; answers the HTTP status (201 new, 200 when already installed).
39
+ * The first call writes and commits the source; later calls pack its current
40
+ * `HEAD`, so a committed edit followed by `oyster try` shows the change. */
41
+ export async function installHelloApp(input) {
42
+ const source = join(input.directory, "hello-app");
43
+ const commit = (await exists(join(source, ".git")))
44
+ ? git(source, ["rev-parse", "HEAD"])
45
+ : await writeHelloApp(input.directory);
46
+ const scratch = await mkdtemp(join(tmpdir(), "oyster-hello-"));
47
+ try {
48
+ await packRelease({
49
+ appId: "app_hello",
50
+ sourceDirectory: source,
51
+ sourceRevision: `git:${commit}`,
52
+ recipe: {
53
+ kind: "bundled-html",
54
+ entry: "bundle/index.html",
55
+ assets: {
56
+ maxManifestBytes: 65_536,
57
+ maxObjects: 16,
58
+ maxObjectBytes: 1_048_576,
59
+ maxTotalBytes: 4_194_304,
60
+ },
61
+ assetBase: "./",
62
+ backend: null,
63
+ maxOutputBytes: 4_194_304,
64
+ },
65
+ outDirectory: join(scratch, "release"),
66
+ });
67
+ const response = await installRelease({
68
+ directory: join(scratch, "release"),
69
+ url: input.url,
70
+ key: input.key,
71
+ installationId: "hello",
72
+ });
73
+ return response.status;
74
+ }
75
+ finally {
76
+ await rm(scratch, { recursive: true, force: true });
77
+ }
78
+ }
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { Cli } from "@fungi.computer/lantern";
2
3
  import { installStandaloneAppSet } from "./app-set.js";
3
- export declare function installApps(args: readonly string[], install?: typeof installStandaloneAppSet): Promise<void>;
4
+ export declare function installApps(args: readonly string[], install?: typeof installStandaloneAppSet, ui?: Cli): Promise<void>;
4
5
  export declare function runInstallAppsCli(args?: readonly string[]): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // `oyster install-apps`: seed, build on the Oyster's own Computer, and install
2
+ // `oyster try` starts a local Oyster; `oyster install-apps`: seed, build on the Oyster's own Computer, and install
3
3
  // the seven starter Apps (Tourtois, Bonsai, Shed, Inkcap, Trellis, Prints,
4
4
  // and Grove). Each comes from its own public repository by default,
5
5
  // or from a Botanical checkout with `--from <directory>`.
@@ -13,6 +13,8 @@ import { tmpdir } from "node:os";
13
13
  import { join, resolve } from "node:path";
14
14
  import process from "node:process";
15
15
  import { parseArgs } from "node:util";
16
+ import { Cli } from "@fungi.computer/lantern";
17
+ import { createTryCli, reportTryFailure, tryOyster, tryUsage, } from "./try-cli.js";
16
18
  import { installReleaseCommand, installReleaseUsage, } from "../install-release-cli.js";
17
19
  import { defaultStarterBuildConcurrency, installStandaloneAppSet, } from "./app-set.js";
18
20
  /** The starter Apps' public source repositories. */
@@ -74,9 +76,14 @@ function timingTable(results) {
74
76
  "upload",
75
77
  "install",
76
78
  ];
77
- return [header, ...rows].map((row) => row.join("\t")).join("\n");
79
+ const table = [header, ...rows];
80
+ const widths = header.map((_, column) => Math.max(...table.map((row) => row[column]?.length ?? 0)));
81
+ return table.map((row) => row
82
+ .map((cell, column) => cell.padEnd(widths[column] ?? 0))
83
+ .join(" ")
84
+ .trimEnd());
78
85
  }
79
- export async function installApps(args, install = installStandaloneAppSet) {
86
+ export async function installApps(args, install = installStandaloneAppSet, ui = new Cli({ brand: "fungi" })) {
80
87
  const { values } = parseArgs({
81
88
  args: [...args],
82
89
  options: {
@@ -93,6 +100,7 @@ export async function installApps(args, install = installStandaloneAppSet) {
93
100
  process.stdout.write(helpText);
94
101
  return;
95
102
  }
103
+ ui.welcome("Oyster: install the starter Apps");
96
104
  const url = process.env.OYSTER_URL;
97
105
  const key = process.env.OYSTER_OWNER_KEY;
98
106
  if (!url || !key)
@@ -126,18 +134,23 @@ export async function installApps(args, install = installStandaloneAppSet) {
126
134
  url,
127
135
  key,
128
136
  concurrency,
137
+ // Builds run side by side, so each report is its own line, not a spinner.
129
138
  report: (message) => {
130
- process.stdout.write(`${message}\n`);
139
+ ui.step(message);
131
140
  },
132
141
  });
133
142
  const elapsed = performance.now() - started;
134
- process.stdout.write(`\n${timingTable(installed)}\n`);
135
- process.stdout.write("\nApp\tResult\n");
136
- for (const app of installed)
137
- process.stdout.write(`${app.installationId}\tinstalled\n`);
138
- for (const app of failed)
139
- process.stdout.write(`${app.installationId}\tfailed: ${app.reason}\n`);
140
- process.stdout.write(`\nInstalled ${String(installed.length)} Apps; failed ${String(failed.length)} in ${seconds(elapsed)}.${installed.length > 0 ? ` Open ${url}/ to use the installed Apps.` : ""}\n`);
143
+ if (installed.length > 0)
144
+ ui.note("Build timings", timingTable(installed));
145
+ ui.note("Apps", [
146
+ ...installed.map((app) => `${app.installationId} installed`),
147
+ ...failed.map((app) => `${app.installationId} failed: ${app.reason}`),
148
+ ]);
149
+ const summary = `Installed ${String(installed.length)} Apps; failed ${String(failed.length)} in ${seconds(elapsed)}.`;
150
+ if (failed.length > 0)
151
+ ui.warn(summary, `Fix the failed Apps above and run oyster install-apps again.`);
152
+ else
153
+ ui.outro(`${summary} Open ${url}/ to use the installed Apps.`);
141
154
  if (values.timings !== undefined)
142
155
  await writeFile(values.timings, JSON.stringify({
143
156
  concurrency,
@@ -159,15 +172,24 @@ export async function installApps(args, install = installStandaloneAppSet) {
159
172
  export async function runInstallAppsCli(args = process.argv.slice(2)) {
160
173
  const [command, ...rest] = args;
161
174
  if (command === "--help" || command === "-h") {
162
- process.stdout.write(usage + "\n" + installReleaseUsage + "\n");
175
+ process.stdout.write(tryUsage + "\n" + usage + "\n" + installReleaseUsage + "\n");
163
176
  }
164
- else if (command !== "install-apps" && command !== "install") {
177
+ else if (command !== "try" &&
178
+ command !== "install-apps" &&
179
+ command !== "install") {
165
180
  process.stderr.write(`${usage}\n`);
166
181
  process.exitCode = 2;
167
182
  }
183
+ else if (command === "try") {
184
+ const ui = createTryCli(rest);
185
+ await tryOyster(rest, undefined, ui).catch((cause) => {
186
+ reportTryFailure(cause, ui);
187
+ process.exitCode = 1;
188
+ });
189
+ }
168
190
  else
169
191
  await (command === "install" ? installReleaseCommand(rest) : installApps(rest)).catch((cause) => {
170
- process.stderr.write(`${cause instanceof Error ? cause.message : String(cause)}\n`);
192
+ new Cli({ brand: "fungi", output: process.stderr }).problem(cause instanceof Error ? cause.message : String(cause), `Run \`oyster ${command} --help\` for the options.`);
171
193
  process.exitCode = 1;
172
194
  });
173
195
  }
@@ -38,11 +38,11 @@ export const standaloneBindings = {
38
38
  },
39
39
  INBOX: {
40
40
  methods: agentFrameMethods.INBOX,
41
- dispatch: (context, frame, props, method, args) => dispatchAgentBinding(context.env, context.scope(), frame, props, method, args),
41
+ dispatch: (context, frame, props, method, args, admitted) => dispatchAgentBinding(context.env, context.scope(), frame, props, method, args, admitted),
42
42
  },
43
43
  AGENTS: {
44
44
  methods: agentFrameMethods.AGENTS,
45
- dispatch: (context, frame, props, method, args) => dispatchAgentBinding(context.env, context.scope(), frame, props, method, args),
45
+ dispatch: (context, frame, props, method, args, admitted) => dispatchAgentBinding(context.env, context.scope(), frame, props, method, args, admitted),
46
46
  },
47
47
  /** The emit commits to the delivery owner; Workflows libraries receive it afterwards. */
48
48
  EVENTS: eventsBindingFor(async (context) => {
@@ -0,0 +1,11 @@
1
+ /** Whether the Oyster already has an installation with this id. */
2
+ export declare function isInstalled(input: Readonly<{
3
+ url: string;
4
+ key: string;
5
+ installationId: string;
6
+ }>): Promise<boolean>;
7
+ /** Build Tourtois from source on this machine and install it as `tourtois`. */
8
+ export declare function installLocalDesktop(input: Readonly<{
9
+ url: string;
10
+ key: string;
11
+ }>): Promise<void>;
@@ -0,0 +1,75 @@
1
+ // The Tourtois desktop for a local Oyster. The standalone Oyster builds its
2
+ // starter Apps on its own Computer, which a laptop does not have, so `oyster
3
+ // try` builds Tourtois here from its public source with the ordinary local
4
+ // packer and installs it as the home installation, approving its shell the
5
+ // same way `install-apps` does.
6
+ import { execFileSync } from "node:child_process";
7
+ import { mkdtemp, rm } from "node:fs/promises";
8
+ import { tmpdir } from "node:os";
9
+ import { join } from "node:path";
10
+ import * as Schema from "effect/Schema";
11
+ import * as z from "zod";
12
+ import { installRelease, packRelease } from "../pack.js";
13
+ import { appBuildRecipe, readBuildManifest } from "../build/workspace-build.js";
14
+ import { approveChosenDashboard } from "./dashboard-approval.js";
15
+ const tourtoisRepository = "https://github.com/fungi-computer/tourtois.git";
16
+ const installationRowsSchema = z.array(z.object({ installationId: z.string() }).loose());
17
+ const git = (cwd, args) => execFileSync("git", [...args], {
18
+ cwd,
19
+ encoding: "utf8",
20
+ stdio: ["ignore", "pipe", "pipe"],
21
+ }).trim();
22
+ /** Whether the Oyster already has an installation with this id. */
23
+ export async function isInstalled(input) {
24
+ const response = await fetch(new URL("/api/installations", input.url), {
25
+ headers: { Authorization: `Bearer ${input.key}` },
26
+ });
27
+ if (!response.ok)
28
+ return false;
29
+ const rows = installationRowsSchema.parse(await response.json());
30
+ return rows.some((row) => row.installationId === input.installationId);
31
+ }
32
+ /** Build Tourtois from source on this machine and install it as `tourtois`. */
33
+ export async function installLocalDesktop(input) {
34
+ const scratch = await mkdtemp(join(tmpdir(), "oyster-tourtois-"));
35
+ try {
36
+ const source = join(scratch, "tourtois");
37
+ git(scratch, ["clone", "--quiet", "--depth=1", tourtoisRepository, source]);
38
+ const commit = git(source, ["rev-parse", "HEAD"]);
39
+ const release = join(scratch, "release");
40
+ await packRelease({
41
+ appId: "app_tourtois",
42
+ sourceDirectory: source,
43
+ sourceRevision: `git:${commit}`,
44
+ recipe: appBuildRecipe(readBuildManifest(git(source, ["show", `${commit}:package.json`])), ""),
45
+ outDirectory: release,
46
+ });
47
+ const owner = (method, path, body) => {
48
+ const headers = new Headers({
49
+ Authorization: `Bearer ${input.key}`,
50
+ Accept: "application/json",
51
+ });
52
+ const init = { method, headers };
53
+ if (body !== undefined) {
54
+ headers.set("Content-Type", "application/json");
55
+ init.body = JSON.stringify(body);
56
+ }
57
+ return fetch(new URL(path, input.url), init);
58
+ };
59
+ const response = await installRelease({
60
+ directory: release,
61
+ url: input.url,
62
+ key: input.key,
63
+ installationId: "tourtois",
64
+ onCompleted: async (operation) => {
65
+ if (operation.state === "succeeded")
66
+ await approveChosenDashboard(operation, owner);
67
+ },
68
+ });
69
+ if (!response.ok)
70
+ throw new Error(`Tourtois install failed (${String(response.status)})`);
71
+ }
72
+ finally {
73
+ await rm(scratch, { recursive: true, force: true });
74
+ }
75
+ }
@@ -1,16 +1,17 @@
1
1
  /**
2
2
  * The standalone root's owner routes: App source seeding, builds, the Computer
3
- * fleet, Agent Computer attachment and Workflow webhook controls. The Worker
3
+ * fleet, Agent Computer attachment, website channels and Workflow webhook
4
+ * controls. The Worker
4
5
  * and the authorization law both compose them from this one function.
5
6
  */
6
7
  import type { OysterEnv, OysterHost } from "../host.js";
7
8
  import type { Routes } from "../authorization.js";
8
- import type { TenantScope } from "../tenant.js";
9
+ import { type TenantScope } from "../tenant.js";
9
10
  import type { StandaloneAgentsEnv } from "./agents.js";
10
11
  import { type AppSourceBindingEnv } from "./app-source.js";
11
12
  import type { StandaloneComputerEnv } from "./computer.js";
12
13
  import type { StandaloneWorkflowEnv } from "./workflows.js";
13
14
  /** The bindings the standalone owner routes reach, resolved per request. */
14
- export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneComputerEnv, "REGISTRY"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
15
+ export type StandaloneOwnerRoutesEnv = AppSourceBindingEnv & Pick<StandaloneAgentsEnv, "AGENTS" | "OYSTER_ORIGIN"> & Pick<StandaloneComputerEnv, "REGISTRY"> & Pick<StandaloneAgentsEnv, "AGENT_DIRECTORY"> & Pick<StandaloneWorkflowEnv, "WORKFLOW_RUNS">;
15
16
  /** Every owner route the standalone root adds to its tenant host. */
16
17
  export declare function standaloneOwnerRoutes(env: StandaloneOwnerRoutesEnv, scope: TenantScope, hostFor: () => Promise<Pick<OysterHost, "installations">>): Routes<OysterEnv>;
@@ -1,15 +1,17 @@
1
+ import { defaultTenant } from "../tenant.js";
1
2
  import { agentDirectoryForScope } from "./agent-directory.js";
2
3
  import { standaloneAgentComputerRoutes } from "./agent-computers.js";
3
4
  import { appSourceOwnerRoutes, } from "./app-source.js";
4
5
  import { standaloneBuildRoutes } from "./builds.js";
5
6
  import { standaloneComputerFleetRoutes } from "./computer-fleet.js";
6
7
  import { standaloneWorkflowWebhookControls } from "./workflow-webhooks.js";
8
+ import { standaloneWebsiteControl, standaloneWebsiteRoutes, } from "./website-channels.js";
7
9
  /** Every owner route the standalone root adds to its tenant host. */
8
10
  export function standaloneOwnerRoutes(env, scope, hostFor) {
9
11
  // A tenant's registry owns its installations, builds and Computer fleet.
10
12
  const registry = () => env.REGISTRY.getByName(scope.durableName("registry"));
11
13
  const directory = () => agentDirectoryForScope(env, scope);
12
- return appSourceOwnerRoutes(env, scope)
14
+ const owned = appSourceOwnerRoutes(env, scope)
13
15
  .include(standaloneBuildRoutes(registry))
14
16
  .include(standaloneComputerFleetRoutes(registry))
15
17
  .include(standaloneAgentComputerRoutes({
@@ -18,4 +20,8 @@ export function standaloneOwnerRoutes(env, scope, hostFor) {
18
20
  read: (principal, agentId) => directory().readAgentComputers(agentId, principal, scope.tenantId),
19
21
  }))
20
22
  .include(standaloneWorkflowWebhookControls(env, hostFor));
23
+ // A website is served from the default tenant's directory, which owns it.
24
+ return scope.tenantId === defaultTenant
25
+ ? owned.include(standaloneWebsiteRoutes(standaloneWebsiteControl(env, directory)))
26
+ : owned;
21
27
  }
@@ -8,6 +8,7 @@ import { type CloudflareArtifactsOptions } from "@fungi.computer/burrow/cloudfla
8
8
  import { type OysterBuildStartResult, type OysterBuildView } from "../app-builds.js";
9
9
  import type { TeamAppCandidateManifest } from "../build-contract.js";
10
10
  import type { BuildGitEvent } from "../build-egress.js";
11
+ import type { ContentObjectOwner } from "../build/content-objects.js";
11
12
  import { type StandaloneTenancyEnv } from "./tenancy.js";
12
13
  import type { ComputerDO } from "./computer.js";
13
14
  import type { ComputerEnv } from "@fungi.computer/computer";
@@ -280,6 +281,7 @@ export declare abstract class StandaloneRegistry extends OysterRegistry implemen
280
281
  /** The egress: may this Computer's live job upload one object, how large? */
281
282
  admitBuildObject(jobId: string, computerObjectId: string, grant: string): Promise<Readonly<{
282
283
  maxObjectBytes: number;
284
+ owner: ContentObjectOwner;
283
285
  }> | null>;
284
286
  /** The egress: a live job's candidate manifest; its objects are stored. */
285
287
  submitBuildCandidate(jobId: string, manifest: TeamAppCandidateManifest, grant: string, credentialId: string): Promise<Response>;
@@ -0,0 +1,9 @@
1
+ export type SignInLink = Readonly<{
2
+ url: string;
3
+ close: () => void;
4
+ }>;
5
+ /** Serve one single-use page that signs the owner in to `oysterUrl`. */
6
+ export declare function startSignInLink(input: Readonly<{
7
+ oysterUrl: string;
8
+ key: string;
9
+ }>): Promise<SignInLink>;
@@ -0,0 +1,49 @@
1
+ // A one-time sign-in link for `oyster try`. The owner key never goes in a URL:
2
+ // the link opens a page served by this process that posts the key to the local
3
+ // Oyster's own /login form, then the server forgets the link.
4
+ import { randomBytes } from "node:crypto";
5
+ import { createServer } from "node:http";
6
+ import * as z from "zod";
7
+ const addressSchema = z.object({ port: z.number() });
8
+ const lifetimeMs = 10 * 60_000;
9
+ const escapeAttribute = (text) => text.replace(/[&"<>]/gu, (character) => `&#${String(character.codePointAt(0))};`);
10
+ /** Serve one single-use page that signs the owner in to `oysterUrl`. */
11
+ export async function startSignInLink(input) {
12
+ const nonce = Array.from(randomBytes(18), (byte) => byte.toString(16).padStart(2, "0")).join("");
13
+ let used = false;
14
+ const page = `<!doctype html><meta charset="utf-8"><meta name="referrer" content="no-referrer"><title>Signing in to Oyster</title>` +
15
+ `<form method="post" action="${escapeAttribute(new URL("/login", input.oysterUrl).href)}">` +
16
+ `<input type="hidden" name="key" value="${escapeAttribute(input.key)}"></form>` +
17
+ `<p>Signing in to Oyster...</p><script>document.forms[0].submit()</script>`;
18
+ const server = createServer((request, response) => {
19
+ if (used || request.method !== "GET" || request.url !== `/${nonce}`) {
20
+ response.writeHead(404, { "Cache-Control": "no-store" }).end("Not found");
21
+ return;
22
+ }
23
+ used = true;
24
+ response
25
+ .writeHead(200, {
26
+ "Content-Type": "text/html; charset=utf-8",
27
+ "Cache-Control": "no-store",
28
+ "Referrer-Policy": "no-referrer",
29
+ })
30
+ .end(page);
31
+ setTimeout(() => {
32
+ server.close();
33
+ }, 1_000).unref();
34
+ });
35
+ await new Promise((done, fail) => {
36
+ server.once("error", fail);
37
+ server.listen(0, "127.0.0.1", done);
38
+ });
39
+ setTimeout(() => {
40
+ server.close();
41
+ }, lifetimeMs).unref();
42
+ const { port } = addressSchema.parse(server.address());
43
+ return {
44
+ url: `http://127.0.0.1:${String(port)}/${nonce}`,
45
+ close: () => {
46
+ server.close();
47
+ },
48
+ };
49
+ }
@@ -0,0 +1,52 @@
1
+ import { Cli } from "@fungi.computer/lantern";
2
+ import { type SignInLink } from "./sign-in-link.js";
3
+ export declare const tryUsage = "Usage: oyster try [directory] [--port 8787] [--no-open] [--verbose] [--package <npm spec>]";
4
+ /**
5
+ * Streaming logs and a redrawing spinner cannot share a terminal, so
6
+ * --verbose prints plain lines instead of spinners.
7
+ */
8
+ export declare function createTryCli(args: readonly string[]): Cli;
9
+ /** Show a failed `oyster try` as an error with its next step. */
10
+ export declare function reportTryFailure(cause: unknown, ui: Cli): void;
11
+ /** The injectable effects of `oyster try`; tests replace them. */
12
+ export type TryEffects = Readonly<{
13
+ /** Install the scaffolded project's dependencies. */
14
+ installDependencies: (directory: string, manager: Manager, verbose: boolean) => Promise<void>;
15
+ /** Start Oyster and resolve once it answers; `stop` ends it. */
16
+ startServer: (input: {
17
+ directory: string;
18
+ port: number;
19
+ key: string;
20
+ verbose: boolean;
21
+ }) => Promise<{
22
+ stop: () => Promise<void>;
23
+ exited: Promise<number | null>;
24
+ }>;
25
+ /** Install the Hello App on the running Oyster. */
26
+ installHello: (input: {
27
+ directory: string;
28
+ url: string;
29
+ key: string;
30
+ }) => Promise<number>;
31
+ /** Build and install the Tourtois desktop unless it is already there. */
32
+ installDesktop: (input: {
33
+ directory: string;
34
+ url: string;
35
+ key: string;
36
+ }) => Promise<void>;
37
+ /** A one-time page that signs the owner in without the key in a URL. */
38
+ signInLink: (input: {
39
+ oysterUrl: string;
40
+ key: string;
41
+ }) => Promise<SignInLink>;
42
+ /** Open the browser. */
43
+ open: (url: string) => void;
44
+ /** Resolve when the user asks to stop. */
45
+ interrupted: () => Promise<void>;
46
+ /** Check that the port is free. */
47
+ portFree: (port: number) => Promise<boolean>;
48
+ }>;
49
+ export type Manager = "npm" | "pnpm";
50
+ /** pnpm when it ran this command (`pnpm dlx`), otherwise npm. */
51
+ export declare function detectManager(userAgent: string | undefined): "pnpm" | "npm";
52
+ export declare function tryOyster(args: readonly string[], effects?: TryEffects, ui?: Cli): Promise<void>;