@fungi.computer/oyster 0.12.1 → 0.13.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.
@@ -0,0 +1,26 @@
1
+ /** Human-facing states only. API refusals keep their original wire format. */
2
+ export type HostPageState = "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "link-expired" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
3
+ export type HostPageOptions = Readonly<{
4
+ state: HostPageState;
5
+ title?: string;
6
+ status?: number;
7
+ stylesheets?: readonly string[];
8
+ /** The one-time helper obtains all decorative assets from the live Oyster. */
9
+ oysterUrl?: string;
10
+ /** Reachable installations only; no forbidden App metadata enters the view. */
11
+ apps?: readonly Readonly<{
12
+ id: string;
13
+ name: string;
14
+ accessHref?: string;
15
+ }>[];
16
+ reset?: boolean;
17
+ /** Only the single-use helper passes a key, in a POST field, never a URL. */
18
+ signIn?: Readonly<{
19
+ action: string;
20
+ key: string;
21
+ }>;
22
+ }>;
23
+ /** Serve only qualified build outputs; no filesystem or runtime image tools. */
24
+ export declare function hostPageAsset(path: string): Promise<Response>;
25
+ /** One server-rendered Caps composition, usable without styles, art or JS. */
26
+ export declare function hostPage(options: HostPageOptions): Promise<Response>;
@@ -0,0 +1,302 @@
1
+ import { createElement as h } from "react";
2
+ import { renderToStaticMarkup } from "react-dom/server";
3
+ import { TradingCard } from "@fungi.computer/caps/components/trading-card";
4
+ import { Button } from "@fungi.computer/caps/components/button";
5
+ import { Input } from "@fungi.computer/caps/components/input";
6
+ import { Card, CardHeader, CardTitle, CardContent, } from "@fungi.computer/caps/components/card";
7
+ import { fungiFaviconHref } from "@fungi.computer/sigils/favicon";
8
+ const docs = "https://docs.fungi.computer";
9
+ const copy = {
10
+ root: [
11
+ "Your Apps, all together.",
12
+ "Oyster · App directory",
13
+ "Open an installed App, or return to your desktop. These Apps belong to this Oyster.",
14
+ ],
15
+ empty: [
16
+ "A little room to grow.",
17
+ "No Apps installed yet.",
18
+ "Your Oyster is running. Install an App to give it something to open.",
19
+ ],
20
+ login: [
21
+ "Welcome back.",
22
+ "Your Oyster · sign in",
23
+ "Use the owner key saved with this Oyster. It stays private; it never belongs in a shared link.",
24
+ ],
25
+ "login-invalid": [
26
+ "That key didn’t open it.",
27
+ "Sign-in needs another try",
28
+ "Check that this is the key for this Oyster. Your saved Apps are unchanged.",
29
+ ],
30
+ "key-help": [
31
+ "Let’s find your key.",
32
+ "Owner access",
33
+ "For a local trial, the key is saved in .oyster-owner inside your Oyster project. Open that file privately and paste the key into sign-in.",
34
+ ],
35
+ "signing-in": [
36
+ "Opening your Oyster…",
37
+ "One-time sign-in",
38
+ "This private link signs you in on this computer. It works once. Continue to your Oyster below if it does not open automatically.",
39
+ ],
40
+ "link-expired": [
41
+ "This link has had its turn.",
42
+ "One-time link · expired or already used",
43
+ "Start your local Oyster again with the same project directory to get a fresh link, or sign in with your saved owner key.",
44
+ ],
45
+ "not-found": [
46
+ "Nothing growing here.",
47
+ "404 · page not found",
48
+ "This address doesn’t point to an available page. Your desktop is a good place to start again.",
49
+ ],
50
+ "server-error": [
51
+ "That didn’t go through.",
52
+ "Oyster · request failed",
53
+ "Oyster couldn’t finish this request. Check its status before retrying a change; the result may still be unknown.",
54
+ ],
55
+ "access-denied": [
56
+ "This App is out of reach.",
57
+ "403 · access unavailable",
58
+ "The current sign-in cannot open this App. Ask its owner for access, or return to your desktop.",
59
+ ],
60
+ "desktop-missing": [
61
+ "Your desktop needs a hand.",
62
+ "Desktop · unavailable",
63
+ "Oyster is running, but your selected desktop is missing, disabled or awaiting approval. See the terminal for the build error if local setup failed.",
64
+ ],
65
+ };
66
+ const abilities = {
67
+ root: [
68
+ "Choose your next App",
69
+ "Open an App from the directory.",
70
+ "Review App access if approval is needed.",
71
+ "Read the quickstart to install another.",
72
+ ],
73
+ empty: [
74
+ "Install your first App",
75
+ "Follow the quickstart for this host.",
76
+ "Build and install your first App.",
77
+ "Return here after installation succeeds.",
78
+ ],
79
+ login: [
80
+ "Unlock this Oyster",
81
+ "Open .oyster-owner in your project.",
82
+ "Paste the key into sign-in.",
83
+ "Keep the key out of shared links.",
84
+ ],
85
+ "login-invalid": [
86
+ "Check the owner key",
87
+ "Use this Oyster’s owner key.",
88
+ "Copy the full key without extra spaces.",
89
+ "Try again or find your key.",
90
+ ],
91
+ "key-help": [
92
+ "Recover owner access",
93
+ "Check your project’s .oyster-owner file.",
94
+ "Paste its key into sign-in.",
95
+ "If it is gone, read recovery steps.",
96
+ ],
97
+ "signing-in": [
98
+ "Finish signing in",
99
+ "Let this single-use link finish.",
100
+ "Continue below if it does not.",
101
+ "Use your saved key if needed.",
102
+ ],
103
+ "link-expired": [
104
+ "Get back into Oyster",
105
+ "Sign in with your saved key.",
106
+ "Or restart the same local trial.",
107
+ "Open the fresh link once.",
108
+ ],
109
+ "not-found": [
110
+ "Find an available page",
111
+ "Return to your Oyster.",
112
+ "Choose an installed App.",
113
+ "Check docs for an old address.",
114
+ ],
115
+ "server-error": [
116
+ "Check before retrying",
117
+ "Check that Oyster is running.",
118
+ "Read the terminal’s diagnostic.",
119
+ "Confirm the result before retrying.",
120
+ ],
121
+ "access-denied": [
122
+ "Find the right access",
123
+ "Check which sign-in you are using.",
124
+ "Ask the owner for App access.",
125
+ "Switch sign-in or return home.",
126
+ ],
127
+ "desktop-missing": [
128
+ "Repair your desktop",
129
+ "Read the terminal’s build error.",
130
+ "Review desktop App access.",
131
+ "Retry the same trial after fixing it.",
132
+ ],
133
+ };
134
+ function link(label, href, secondary = false) {
135
+ return h(Button, { asChild: true, variant: secondary ? "outline" : "primary" }, h("a", { href }, label));
136
+ }
137
+ /** The optional, content-addressed illustration/layout assets. */
138
+ async function pageAssets() {
139
+ return (await import("#host-page-assets")).hostPageAssets;
140
+ }
141
+ /** Serve only qualified build outputs; no filesystem or runtime image tools. */
142
+ export async function hostPageAsset(path) {
143
+ const found = Object.values(await pageAssets()).find((asset) => asset.path === path);
144
+ if (!found)
145
+ return new Response("Not found", { status: 404 });
146
+ const body = found.encoding === "base64"
147
+ ? Uint8Array.from(atob(found.source), (character) => character.charCodeAt(0))
148
+ : found.source;
149
+ return new Response(body, {
150
+ headers: {
151
+ "Content-Type": found.contentType,
152
+ "Cache-Control": "public, max-age=31536000, immutable",
153
+ "X-Content-Type-Options": "nosniff",
154
+ "Access-Control-Allow-Origin": "*",
155
+ },
156
+ });
157
+ }
158
+ function pageContent(options, url) {
159
+ const { state, signIn } = options;
160
+ const content = [];
161
+ const actions = [];
162
+ if (state === "login" || state === "login-invalid") {
163
+ content.push(h("form", { method: "post", action: url("/login"), className: "form-stack" }, state === "login-invalid"
164
+ ? h("p", { className: "error-copy", role: "alert" }, "The key wasn’t accepted. Please check it and try again.")
165
+ : null, h("label", { htmlFor: "owner-key" }, "Owner key"), h(Input, {
166
+ id: "owner-key",
167
+ name: "key",
168
+ type: "password",
169
+ required: true,
170
+ autoComplete: "current-password",
171
+ placeholder: "Paste your owner key",
172
+ "aria-invalid": state === "login-invalid" ? true : undefined,
173
+ }), h("p", { className: "helper" }, "For a local trial: .oyster-owner in your Oyster project."), h("div", { className: "actions" }, h(Button, { type: "submit" }, state === "login" ? "Sign in" : "Try again"), link("Find my key", url("/login/key-help"), true))));
174
+ }
175
+ else if (state === "signing-in" && signIn) {
176
+ content.push(h("form", { method: "post", action: signIn.action, "data-auto-sign-in": true }, h("input", { type: "hidden", name: "key", value: signIn.key }), h("div", { className: "actions" }, h(Button, { type: "submit" }, "Continue to Oyster"), link("Having trouble?", url("/login/key-help"), true))));
177
+ }
178
+ else if (state === "key-help") {
179
+ content.push(h("p", { className: "detail" }, "If the original key is gone, follow the owner recovery instructions. Oyster cannot reveal or reconstruct it. No key reset happens from this page."));
180
+ actions.push(link("Back to sign-in", url("/login")), link("Read recovery steps", `${docs}/guides/run-your-own-oyster`, true));
181
+ }
182
+ else if (state === "link-expired") {
183
+ actions.push(link("Sign in with my key", url("/login")), link("Read restart steps", `${docs}/oyster-quickstart`, true));
184
+ }
185
+ else if (state === "root" ||
186
+ state === "empty" ||
187
+ state === "desktop-missing") {
188
+ if (options.reset)
189
+ content.push(h("p", { className: "detail" }, "This update reset your installed Apps. Reinstall them with npx oyster install-apps."));
190
+ if (state === "empty")
191
+ content.push(h("p", { className: "detail" }, "Install Apps with ", h("code", null, "npx oyster install-apps"), ". Follow the quickstart for your local or hosted Oyster."));
192
+ if ((options.apps?.length ?? 0) > 0)
193
+ content.push(h("div", { className: "app-grid" }, ...(options.apps ?? []).map((app) => h(Card, { key: app.id, variant: "interactive" }, h(CardHeader, null, h(CardTitle, null, h("a", { href: url(`/apps/${encodeURIComponent(app.id)}/`) }, app.name))), app.accessHref
194
+ ? h(CardContent, null, h("a", { href: url(app.accessHref) }, "App access"))
195
+ : null))));
196
+ if (state === "desktop-missing")
197
+ content.push(h("p", { className: "detail" }, "For a local trial, retry the original try command in your terminal with the same project directory and port. If approval was revoked, use App access to review the desktop’s permissions."));
198
+ actions.push(link("Read the quickstart", `${docs}/oyster-quickstart`), link("Install an App", `${docs}/agents/build-an-app.md`, true));
199
+ }
200
+ else {
201
+ if (state === "server-error")
202
+ content.push(h("details", { className: "detail" }, h("summary", null, "Show details"), h("p", null, "Diagnostic: REQUEST_FAILED. Check the terminal or host logs for the original error. No credentials are shown here.")));
203
+ actions.push(link(state === "server-error" ? "Check Oyster" : "Back to desktop", url("/")), link(state === "access-denied" ? "Switch sign-in" : "Open the docs", state === "access-denied" ? url("/login") : docs, true));
204
+ }
205
+ return { content, actions };
206
+ }
207
+ function illustration(state, assetUrl) {
208
+ const eyebrow = copy[state][1];
209
+ const [ability, ...steps] = abilities[state];
210
+ const keyArt = [
211
+ "login",
212
+ "login-invalid",
213
+ "key-help",
214
+ "signing-in",
215
+ "link-expired",
216
+ "access-denied",
217
+ ].includes(state);
218
+ const art = keyArt
219
+ ? "key"
220
+ : state === "not-found"
221
+ ? "offline"
222
+ : "desktop-build";
223
+ return h(TradingCard, {
224
+ name: keyArt
225
+ ? "A little help"
226
+ : art === "offline"
227
+ ? "We’ll reconnect"
228
+ : "Room to grow",
229
+ stage: "OYSTER",
230
+ stat: "✦",
231
+ finish: "holo",
232
+ style: { aspectRatio: "5 / 7" },
233
+ art: h("div", {
234
+ className: "ink-art",
235
+ "data-ink": assetUrl(`${art}.json`),
236
+ "aria-hidden": true,
237
+ }, h("picture", null, h("source", {
238
+ "data-light-plate": assetUrl(`${art}-light.avif`),
239
+ "data-dark-plate": assetUrl(`${art}-dark.avif`),
240
+ media: "(prefers-color-scheme: light)",
241
+ srcSet: assetUrl(`${art}-light.avif`),
242
+ }), h("img", {
243
+ className: "ink-fallback",
244
+ src: assetUrl(`${art}-dark.avif`),
245
+ alt: "",
246
+ })), h("div", { className: "ink-live" })),
247
+ typeLine: eyebrow,
248
+ move: {
249
+ name: ability,
250
+ children: h("ol", { className: "ability-steps" }, ...steps.map((step) => h("li", { key: step }, step))),
251
+ },
252
+ setNumber: "Oyster",
253
+ rarity: "✦ Companion",
254
+ });
255
+ }
256
+ /** One server-rendered Caps composition, usable without styles, art or JS. */
257
+ export async function hostPage(options) {
258
+ const { state, title = "Oyster" } = options;
259
+ const [heading, eyebrow, description] = copy[state];
260
+ const url = (path) => options.oysterUrl ? new URL(path, options.oysterUrl).href : path;
261
+ // A failed decorative module must still leave the form and recovery readable.
262
+ let assets;
263
+ try {
264
+ assets = await pageAssets();
265
+ }
266
+ catch (cause) {
267
+ console.error("Host page decoration unavailable", cause);
268
+ assets = {};
269
+ }
270
+ const assetUrl = (name) => {
271
+ const asset = assets[name];
272
+ return asset ? url(asset.path) : undefined;
273
+ };
274
+ const { content, actions } = pageContent(options, url);
275
+ const body = renderToStaticMarkup(h("html", { lang: "en" }, h("head", null, h("meta", { charSet: "utf-8" }), h("meta", {
276
+ name: "viewport",
277
+ content: "width=device-width,initial-scale=1",
278
+ }), h("meta", { name: "referrer", content: "no-referrer" }), h("title", null, `${heading} · ${title}`), h("link", {
279
+ rel: "icon",
280
+ type: "image/svg+xml",
281
+ href: fungiFaviconHref,
282
+ }), ...(options.stylesheets ?? []).map((href) => h("link", { key: href, rel: "stylesheet", href: url(href) })), assetUrl("layout.css")
283
+ ? h("link", { rel: "stylesheet", href: assetUrl("layout.css") })
284
+ : null), h("body", null, h("header", { className: "page-header" }, h("div", { className: "brand" }, "oyster", h("small", null, "by fungi.computer")), h("nav", { className: "page-nav", "aria-label": "Oyster" }, h("a", { href: url("/") }, "Your Oyster"), h("a", { href: docs }, "Help & docs"))), h("main", { className: "stage" }, h("div", { className: "card-holder" }, illustration(state, assetUrl)), h("section", { className: "copy", "aria-labelledby": "page-heading" }, h("p", { className: "eyebrow" }, eyebrow), h("h1", { className: "heading", id: "page-heading" }, heading), h("p", { className: "description" }, description), ...content, actions.length
285
+ ? h("div", { className: "actions" }, ...actions)
286
+ : null, h("p", { className: "helper" }, state === "login" || state === "login-invalid"
287
+ ? "Your key is sent only to this Oyster."
288
+ : h("a", { href: `${docs}/agents/index.md` }, "Hand your LLM the setup guide →")))), h("footer", { className: "page-footer" }, h("span", null, "Oyster · A home for your Apps")), assetUrl("host-page.js")
289
+ ? h("script", { type: "module", src: assetUrl("host-page.js") })
290
+ : null)));
291
+ return new Response(`<!doctype html>${body}`, {
292
+ status: options.status ?? 200,
293
+ headers: {
294
+ "Content-Type": "text/html; charset=utf-8",
295
+ "Cache-Control": "no-store",
296
+ "X-Content-Type-Options": "nosniff",
297
+ "Referrer-Policy": "no-referrer",
298
+ "X-Robots-Tag": "noindex, nofollow",
299
+ Vary: "Accept",
300
+ },
301
+ });
302
+ }
package/dist/host.js CHANGED
@@ -32,12 +32,8 @@ import { buildGitPassPrefix, presentedGitKey } from "./git-auth.js";
32
32
  import { workflowGitPassPrefix } from "@fungi.computer/braid/runtime";
33
33
  import { loadPageAssets, PageAssetsLoadError, } from "./page-assets.js";
34
34
  import { fungiFaviconHref } from "@fungi.computer/sigils/favicon";
35
- import { createElement } from "react";
36
- import { renderToStaticMarkup } from "react-dom/server";
37
- import { CenteredCard, CardHeader, CardTitle, CardContent, } from "@fungi.computer/caps/components/card";
38
- import { Form, Field, FormFooter } from "@fungi.computer/caps/components/field";
39
- import { Input } from "@fungi.computer/caps/components/input";
40
- import { Button } from "@fungi.computer/caps/components/button";
35
+ import { hostPage, hostPageAsset } from "./host-page.js";
36
+ import { parseAccept } from "hono/utils/accept";
41
37
  import { parseArtifactRef } from "@fungi.computer/puffball";
42
38
  import { isBuildJobLogRef } from "./build/job-log.js";
43
39
  export { ReleaseError, defaultAssetPolicy, parseRelease, resolveBackend, sha256, verifyRelease, } from "./release.js";
@@ -366,25 +362,18 @@ export function oysterRouteTable(host) {
366
362
  },
367
363
  });
368
364
  });
369
- table.get("/login", publicRoute("the sign-in form"), async () => {
365
+ const page = async (state, options = {}) => {
370
366
  const { loginFonts, styles } = await assets();
371
- const form = renderToStaticMarkup(createElement(CenteredCard, null, createElement(CardHeader, null, createElement(CardTitle, { level: 2 }, "Sign in")), createElement(CardContent, null, createElement(Form, { method: "post", action: "/login" }, createElement(Field, {
372
- label: "Owner key",
373
- required: true,
374
- children: createElement(Input, {
375
- name: "key",
376
- type: "password",
377
- autoComplete: "current-password",
378
- required: true,
379
- }),
380
- }), createElement(FormFooter, { layout: "stretch", divider: false }, createElement(Button, { type: "submit" }, "Sign in"))))));
381
- return new Response(`<!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>Sign in · ${escapeHtml(title)}</title>${tabIcon}<link rel="stylesheet" href="${styles.path}"><link rel="stylesheet" href="${loginFonts.path}"></head><body class="px-lg">${form}</body></html>`, {
382
- headers: {
383
- "Content-Type": "text/html; charset=utf-8",
384
- "Cache-Control": "no-store",
385
- },
367
+ return hostPage({
368
+ state,
369
+ title,
370
+ stylesheets: [styles.path, loginFonts.path],
371
+ ...options,
386
372
  });
387
- });
373
+ };
374
+ table.get("/_oyster/host-assets/*", publicRoute("content-addressed host illustrations and layout"), (context) => hostPageAsset(new URL(context.req.url).pathname));
375
+ table.get("/login", publicRoute("the sign-in form"), () => page("login"));
376
+ table.get("/login/key-help", publicRoute("owner key recovery instructions, without a reset"), () => page("key-help"));
388
377
  table.post("/login", door("the host's own sign-in checks the posted key"), (context) => host.auth.login === undefined
389
378
  ? refusal(404, "Sign-in is not available")
390
379
  : host.auth.login(context.req.raw));
@@ -439,6 +428,7 @@ export function oysterRouteTable(host) {
439
428
  matches: match(`${capability.base}${method.path}`, {
440
429
  end: method.kind !== "transport",
441
430
  sensitive: true,
431
+ decode: false,
442
432
  }),
443
433
  })));
444
434
  // Each capability's own declared table, served once; it reads the
@@ -527,22 +517,29 @@ export function oysterRouteTable(host) {
527
517
  if (installation.status === "enabled" &&
528
518
  (await admitted.reaches(installation)))
529
519
  installations.push(installation);
530
- const items = installations
531
- .map((installation) => `<li><a href="/apps/${escapeHtml(installation.installationId)}/">${escapeHtml(installation.installationId)}</a> <small>${escapeHtml(installation.release.releaseId)}</small>${admitted.authority.kind === "owner" ? ` <a href="/api/installations/${encodeURIComponent(installation.installationId)}/grants">App access</a>` : ""}</li>`)
532
- .join("");
533
520
  const resetAt = await host.installations.resetAt?.();
534
- const resetNotice = resetAt !== undefined &&
521
+ const reset = resetAt !== undefined &&
535
522
  resetAt !== null &&
536
- !stored.some((installation) => installation.status === "enabled")
537
- ? "<p>This update reset your installed Apps. Reinstall them with npx oyster install-apps.</p>"
538
- : "";
539
- return new Response(`<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>${escapeHtml(title)}</title>${tabIcon}<h1>${escapeHtml(title)}</h1>${resetNotice}<ul>${items || "<li>No Apps installed yet.</li><li>Install Apps with <code>npx oyster install-apps</code></li>"}</ul>`, {
540
- headers: {
541
- "Content-Type": "text/html; charset=utf-8",
542
- "Cache-Control": "no-store",
543
- "X-Content-Type-Options": "nosniff",
544
- },
523
+ !stored.some((installation) => installation.status === "enabled");
524
+ const directory = host.workbench ? await host.workbench.directory() : null;
525
+ const names = new Map(directory?.apps.map((app) => [app.installationId, app.displayName]));
526
+ const apps = installations.map((installation) => {
527
+ const app = {
528
+ id: installation.installationId,
529
+ name: names.get(installation.installationId) ?? installation.installationId,
530
+ };
531
+ return admitted.authority.kind === "owner"
532
+ ? {
533
+ ...app,
534
+ accessHref: `/api/installations/${encodeURIComponent(installation.installationId)}/grants`,
535
+ }
536
+ : app;
545
537
  });
538
+ return page(host.homeInstallationId !== undefined
539
+ ? "desktop-missing"
540
+ : apps.length === 0
541
+ ? "empty"
542
+ : "root", { apps, reset });
546
543
  });
547
544
  if (host.ownerRoutes !== undefined)
548
545
  table.include(host.ownerRoutes);
@@ -1139,12 +1136,82 @@ export function oysterRouteTable(host) {
1139
1136
  };
1140
1137
  return executeMethod(target, release, principal, method, context.req.raw, recheck);
1141
1138
  });
1139
+ // Present errors only at the host's document boundary. App assets, transports
1140
+ // and API responses retain their status, headers and machine-readable body.
1141
+ const appEntry = match("/apps/:installationId/", { decode: false });
1142
+ const documentResponse = async (request, response) => {
1143
+ const path = new URL(request.url).pathname;
1144
+ if (capabilityRoutes.some((route) => route.matches(path)))
1145
+ return response;
1146
+ const document = parseAccept(request.headers.get("Accept") ?? "").find((entry) => entry.q > 0 && ["text/html", "application/json"].includes(entry.type))?.type === "text/html" &&
1147
+ ((request.method === "GET" &&
1148
+ (Boolean(appEntry(path)) ||
1149
+ ![
1150
+ "/api",
1151
+ "/ui",
1152
+ "/ui-entry",
1153
+ "/_oyster",
1154
+ "/apps",
1155
+ "/mcp",
1156
+ "/git",
1157
+ ].some((prefix) => path === prefix || path.startsWith(`${prefix}/`)))) ||
1158
+ (request.method === "POST" && path === "/login"));
1159
+ if (!document || response.status < 400)
1160
+ return response;
1161
+ const state = path === "/login" && [400, 401].includes(response.status)
1162
+ ? "login-invalid"
1163
+ : response.status === 403
1164
+ ? "access-denied"
1165
+ : response.status >= 500
1166
+ ? "server-error"
1167
+ : "not-found";
1168
+ let rendered;
1169
+ try {
1170
+ rendered = await page(state, { status: response.status });
1171
+ }
1172
+ catch (cause) {
1173
+ if (!(cause instanceof PageAssetsLoadError))
1174
+ throw cause;
1175
+ console.error("Host page assets unavailable; serving recovery document", cause);
1176
+ rendered = await hostPage({ state, title, status: response.status });
1177
+ }
1178
+ // Keep timing, robots and retry metadata from the original refusal.
1179
+ response.headers.forEach((value, name) => {
1180
+ if (![
1181
+ "content-type",
1182
+ "content-length",
1183
+ "content-encoding",
1184
+ "cache-control",
1185
+ "etag",
1186
+ "vary",
1187
+ ].includes(name))
1188
+ rendered.headers.set(name, value);
1189
+ });
1190
+ return rendered;
1191
+ };
1142
1192
  return {
1143
1193
  declarations: () => table.declarations(),
1144
- serve: () => serveHost(table, authenticate, ports, {
1145
- // Server-Timing names the Durable Object hops a request waited on.
1146
- serverTiming: { totalDescription: "Oyster" },
1147
- headers: [noIndex],
1148
- }),
1194
+ serve: () => {
1195
+ const served = serveHost(table, authenticate, ports, {
1196
+ serverTiming: { totalDescription: "Oyster" },
1197
+ headers: [noIndex],
1198
+ });
1199
+ return {
1200
+ ...served,
1201
+ fetch: async (...args) => documentResponse(args[0], await served.fetch(...args)),
1202
+ request: async (...args) => {
1203
+ const [input, init] = args;
1204
+ const request = {
1205
+ url: input instanceof Request
1206
+ ? input.url
1207
+ : new URL(input, "http://localhost").href,
1208
+ method: init?.method ?? (input instanceof Request ? input.method : "GET"),
1209
+ headers: new Headers(init?.headers ??
1210
+ (input instanceof Request ? input.headers : undefined)),
1211
+ };
1212
+ return documentResponse(request, await served.request(...args));
1213
+ },
1214
+ };
1215
+ },
1149
1216
  };
1150
1217
  }
@@ -4,7 +4,7 @@ export declare const pageScript: string;
4
4
  /** Shared host fonts, served once as a digest-pinned stylesheet. */
5
5
  export declare const fontStyles: string;
6
6
 
7
- /** The sans family alone, for the sign-in page. */
7
+ /** Nunito and Maple Mono, for host entry and recovery pages. */
8
8
  export declare const loginFontStyles: string;
9
9
 
10
10
  /** Caps styles for server-rendered host pages. */