@fungi.computer/oyster 0.57.0 → 0.57.2

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.
@@ -1,6 +1,7 @@
1
1
  import { type AppPermissionsViewData } from "./apps/permissions.js";
2
+ import { type PortPreviewEntry } from "./port-preview-entry.js";
2
3
  /** Human-facing states only. API refusals keep their original wire format. */
3
- export type HostPageState = "preview" | "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
4
+ export type HostPageState = "preview" | "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "open-preview" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
4
5
  export type HostPageOptions = Readonly<{
5
6
  state: HostPageState;
6
7
  preview?: Readonly<{
@@ -25,6 +26,8 @@ export type HostPageOptions = Readonly<{
25
26
  returning?: boolean;
26
27
  /** Login only: the visitor arrived through a one-time link that was already used. */
27
28
  usedLink?: boolean;
29
+ /** Open preview only: the port and Computer it opens, and where the owner's own click posts. */
30
+ previewEntry?: PortPreviewEntry;
28
31
  /** Only the single-use helper passes a key, in a POST field, never a URL. */
29
32
  signIn?: Readonly<{
30
33
  action: string;
package/dist/host-page.js CHANGED
@@ -10,6 +10,7 @@ import { loadPageAssets } from "./page-assets.js";
10
10
  import { fungiFaviconHref } from "@fungi.computer/sigils/favicon";
11
11
  import { permissionScreen, } from "./apps/permissions.js";
12
12
  import { permissionCatalog } from "./apps/catalog.js";
13
+ import { portPreviewReferrerPolicy, portPreviewRefusalMessage, } from "./port-preview-entry.js";
13
14
  const docs = "https://docs.fungi.computer";
14
15
  const copy = {
15
16
  preview: ["Preview", "Oyster · Preview", "Opening preview…"],
@@ -48,6 +49,11 @@ const copy = {
48
49
  "One-time sign-in",
49
50
  "This private link signs you in on this computer. It works once. Continue to your Oyster below if it does not open automatically.",
50
51
  ],
52
+ "open-preview": [
53
+ "Open this preview?",
54
+ "Private port preview",
55
+ "An App asked to open a port on your Computer, signed in as you. Nothing opens until you choose Open preview.",
56
+ ],
51
57
  "not-found": [
52
58
  "Nothing growing here.",
53
59
  "404",
@@ -118,6 +124,12 @@ const abilities = {
118
124
  "Continue below if it does not.",
119
125
  "Use your saved key if needed.",
120
126
  ],
127
+ "open-preview": [
128
+ "You choose what opens",
129
+ "Check this is the preview you expected.",
130
+ "Choose Open preview to continue.",
131
+ "Close this tab if you did not ask for it.",
132
+ ],
121
133
  "not-found": [
122
134
  "Find an available page",
123
135
  "Return to your Oyster.",
@@ -217,6 +229,17 @@ function pageContent(options, url) {
217
229
  else if (state === "signing-in" && signIn) {
218
230
  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))));
219
231
  }
232
+ else if (state === "open-preview" && options.previewEntry) {
233
+ content.push(h("div", {
234
+ "data-port-preview-entry": true,
235
+ "data-action": options.previewEntry.action,
236
+ "data-port": options.previewEntry.port,
237
+ "data-computer-id": options.previewEntry.computerId,
238
+ "data-refusal": options.previewEntry.refusal,
239
+ }, h("form", { method: "post", action: options.previewEntry.action }, h("div", { className: "actions" }, h(Button, { type: "submit" }, "Open preview"), link("Back to your Oyster", url("/"), true))), options.previewEntry.refusal === undefined
240
+ ? null
241
+ : h("noscript", null, portPreviewRefusalMessage(options.previewEntry.refusal))));
242
+ }
220
243
  else if (state === "key-help") {
221
244
  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."));
222
245
  actions.push(link("Back to sign-in", url("/login")), link("Read recovery steps", `${docs}/guides/run-your-own-oyster`, true));
@@ -254,6 +277,7 @@ function illustration(state, assetUrl) {
254
277
  "login-invalid",
255
278
  "key-help",
256
279
  "signing-in",
280
+ "open-preview",
257
281
  "access-denied",
258
282
  ].includes(state);
259
283
  const art = keyArt
@@ -297,7 +321,11 @@ function illustration(state, assetUrl) {
297
321
  /** One server-rendered Caps composition, usable without styles, art or JS. */
298
322
  export async function hostPage(options) {
299
323
  const { state, title = "Oyster" } = options;
300
- const [baseHeading, eyebrow, description] = copy[state];
324
+ const referrerPolicy = state === "open-preview" ? portPreviewReferrerPolicy : "no-referrer";
325
+ const [baseHeading, eyebrow, baseDescription] = copy[state];
326
+ const description = state === "open-preview" && options.previewEntry
327
+ ? `An App asked to open port ${String(options.previewEntry.port)} on Computer ${options.previewEntry.computerId}, signed in as you. Nothing opens until you choose Open preview.`
328
+ : baseDescription;
301
329
  const heading = state === "preview"
302
330
  ? (options.preview?.appName ?? "Opening preview…")
303
331
  : state === "login" && options.returning === true
@@ -318,10 +346,11 @@ export async function hostPage(options) {
318
346
  return asset ? url(asset.path) : undefined;
319
347
  };
320
348
  const { content, actions } = pageContent(options, url);
349
+ const script = state === "open-preview" ? "port-preview.js" : "host-page.js";
321
350
  const body = renderToStaticMarkup(h("html", { lang: "en" }, h("head", null, h("meta", { charSet: "utf-8" }), h("meta", {
322
351
  name: "viewport",
323
352
  content: "width=device-width,initial-scale=1",
324
- }), h("meta", { name: "referrer", content: "no-referrer" }), h("title", null, `${heading} · ${title}`), h("link", {
353
+ }), h("meta", { name: "referrer", content: referrerPolicy }), h("title", null, `${heading} · ${title}`), h("link", {
325
354
  rel: "icon",
326
355
  type: "image/svg+xml",
327
356
  href: fungiFaviconHref,
@@ -339,14 +368,14 @@ export async function hostPage(options) {
339
368
  : "Opening preview…"
340
369
  : description), ...content, actions.length
341
370
  ? h("div", { className: "actions" }, ...actions)
342
- : null, h("p", { className: "helper" }, state === "preview"
343
- ? null
344
- : state === "login" || state === "login-invalid"
345
- ? "Your key is sent only to this Oyster."
346
- : state === "not-found"
347
- ? null
348
- : 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")), state !== "preview" && assetUrl("host-page.js")
349
- ? h("script", { type: "module", src: assetUrl("host-page.js") })
371
+ : null, h("p", { className: "helper" }, state === "login" || state === "login-invalid"
372
+ ? "Your key is sent only to this Oyster."
373
+ : state === "not-found" ||
374
+ state === "open-preview" ||
375
+ state === "preview"
376
+ ? null
377
+ : 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")), state !== "preview" && assetUrl(script)
378
+ ? h("script", { type: "module", src: assetUrl(script) })
350
379
  : null, options.preview?.preparing
351
380
  ? h("script", {
352
381
  dangerouslySetInnerHTML: {
@@ -370,7 +399,7 @@ export async function hostPage(options) {
370
399
  "Content-Type": "text/html; charset=utf-8",
371
400
  "Cache-Control": "no-store",
372
401
  "X-Content-Type-Options": "nosniff",
373
- "Referrer-Policy": "no-referrer",
402
+ "Referrer-Policy": referrerPolicy,
374
403
  "X-Robots-Tag": "noindex, nofollow",
375
404
  Vary: "Accept",
376
405
  },
package/dist/host.d.ts CHANGED
@@ -250,6 +250,12 @@ export type OysterHost = Readonly<{
250
250
  /** Further routes the host adds (keys, webhooks, builds); each declares
251
251
  * its own requirement and receives the admitted principal from it. */
252
252
  ownerRoutes?: Routes<OysterEnv>;
253
+ /**
254
+ * Serve the owner's confirm page for private port previews at
255
+ * `/computers/:computerId/ports/:port`. Only the owner's own click on it
256
+ * posts to the owner route that issues the preview; nothing submits it.
257
+ */
258
+ portPreviewEntry?: boolean;
253
259
  /** Adapters granted only when the Release declares them and admission passes. */
254
260
  capabilities?: readonly OysterCapability[];
255
261
  /**
package/dist/host.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { parsePortPreviewPort, portPreviewReferrerPolicy, portPreviewRefusalEntry, } from "./port-preview-entry.js";
1
2
  import { hostGateFacts, releaseCache } from "./internal/host-gate.js";
2
3
  import { InstallationOperationError, installationCommandIds, installationRequestIdSchema, installationRecoverySelectionSchema, installationWaitQuerySchema, maxSettlementWaitMs, } from "./installation-operations.js";
3
4
  import { completedInstallationResponse, observeInstallation, InstallationObservationError, } from "./installation-client.js";
@@ -384,11 +385,42 @@ export function oysterRouteTable(host) {
384
385
  ...options,
385
386
  });
386
387
  };
388
+ const previewHeaders = {
389
+ "Cache-Control": "no-store",
390
+ "Referrer-Policy": portPreviewReferrerPolicy,
391
+ "Cross-Origin-Opener-Policy": "same-origin",
392
+ // Chromium applies form-action to the POST redirect too.
393
+ "Content-Security-Policy": "default-src 'none'; script-src 'self'; connect-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src data:; form-action 'self' https:; frame-ancestors 'none'; base-uri 'none'",
394
+ };
395
+ const previewPage = async (entry, status = 200) => {
396
+ const response = await page("open-preview", {
397
+ previewEntry: entry,
398
+ status,
399
+ });
400
+ for (const [name, value] of Object.entries(previewHeaders))
401
+ response.headers.set(name, value);
402
+ return response;
403
+ };
387
404
  table.get("/_oyster/host-assets/*", publicRoute("content-addressed host illustrations and layout"), (context) => serveHostPageAsset(new URL(context.req.url).pathname));
388
405
  table.get("/login", publicRoute("the sign-in form"), (context) => page("login", {
389
406
  returning: getCookie(context, returningCookieName) === "1",
390
407
  usedLink: context.req.query("link") === "used",
391
408
  }));
409
+ if (host.portPreviewEntry === true)
410
+ table.get("/computers/:computerId/ports/:port", publicRoute("the owner's preview confirm page; only their own click posts to the owner route"), async (context) => {
411
+ // Only route text is shown: this public page reads nothing about the
412
+ // Computer, so a visitor learns nothing from it.
413
+ const computerId = context.req.param("computerId");
414
+ const portParam = context.req.param("port");
415
+ const port = parsePortPreviewPort(portParam);
416
+ if (port === undefined)
417
+ return context.body(null, 404);
418
+ return previewPage({
419
+ action: context.req.path,
420
+ port,
421
+ computerId,
422
+ });
423
+ });
392
424
  table.get("/login/key-help", publicRoute("owner key recovery instructions, without a reset"), () => page("key-help"));
393
425
  table.post("/login", door("the host's own sign-in checks the posted key"), (context) => host.auth.login === undefined
394
426
  ? refusal(404, "Sign-in is not available")
@@ -1579,8 +1611,10 @@ export function oysterRouteTable(host) {
1579
1611
  // Present errors only at the host's document boundary. App assets, transports
1580
1612
  // and API responses retain their status, headers and machine-readable body.
1581
1613
  const appEntry = match("/apps/:installationId/", { decode: false });
1614
+ const previewEntryPath = match("/computers/:computerId/ports/:port", { decode: false });
1582
1615
  const documentResponse = async (request, response) => {
1583
1616
  const path = new URL(request.url).pathname;
1617
+ const previewTarget = host.portPreviewEntry === true ? previewEntryPath(path) : false;
1584
1618
  if (capabilityRoutes.some((route) => route.matches(path)))
1585
1619
  return response;
1586
1620
  const document = parseAccept(request.headers.get("Accept") ?? "").find((entry) => entry.q > 0 && ["text/html", "application/json"].includes(entry.type))?.type === "text/html" &&
@@ -1595,9 +1629,17 @@ export function oysterRouteTable(host) {
1595
1629
  "/mcp",
1596
1630
  "/git",
1597
1631
  ].some((prefix) => path === prefix || path.startsWith(`${prefix}/`)))) ||
1598
- (request.method === "POST" && path === "/login"));
1632
+ (request.method === "POST" &&
1633
+ (path === "/login" || Boolean(previewTarget))));
1599
1634
  if (!document || response.status < 400)
1600
1635
  return response;
1636
+ const previewEntry = request.method === "POST" && previewTarget
1637
+ ? await portPreviewRefusalEntry(response, {
1638
+ action: path,
1639
+ computerId: previewTarget.params.computerId,
1640
+ port: previewTarget.params.port,
1641
+ })
1642
+ : undefined;
1601
1643
  const state = path === "/login" && [400, 401].includes(response.status)
1602
1644
  ? "login-invalid"
1603
1645
  : response.status === 403
@@ -1607,17 +1649,22 @@ export function oysterRouteTable(host) {
1607
1649
  : "not-found";
1608
1650
  let rendered;
1609
1651
  try {
1610
- rendered = await page(state, { status: response.status });
1652
+ rendered = previewEntry
1653
+ ? await previewPage(previewEntry, response.status)
1654
+ : await page(state, { status: response.status });
1611
1655
  }
1612
1656
  catch (cause) {
1613
1657
  if (!(cause instanceof PageAssetsLoadError))
1614
1658
  throw cause;
1615
1659
  console.error("Host page assets unavailable; serving recovery document", cause);
1616
- rendered = await renderHostPage({
1617
- state,
1618
- title,
1619
- status: response.status,
1620
- });
1660
+ rendered = await renderHostPage(previewEntry
1661
+ ? {
1662
+ state: "open-preview",
1663
+ title,
1664
+ status: response.status,
1665
+ previewEntry,
1666
+ }
1667
+ : { state, title, status: response.status });
1621
1668
  }
1622
1669
  // Keep timing, robots and retry metadata from the original refusal.
1623
1670
  response.headers.forEach((value, name) => {
@@ -1631,6 +1678,9 @@ export function oysterRouteTable(host) {
1631
1678
  ].includes(name))
1632
1679
  rendered.headers.set(name, value);
1633
1680
  });
1681
+ if (previewEntry)
1682
+ for (const [name, value] of Object.entries(previewHeaders))
1683
+ rendered.headers.set(name, value);
1634
1684
  return rendered;
1635
1685
  };
1636
1686
  return {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { useEffect } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { Button } from "@fungi.computer/caps/components/button";
5
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@fungi.computer/caps/components/dialog";
6
+ import { Toaster, toast } from "@fungi.computer/caps/components/toaster";
7
+ import { portPreviewEntrySchema, portPreviewRefusalMessage, } from "../port-preview-entry.js";
8
+ import { bootstrapIsolatedPageTheme } from "./isolated-page-theme.js";
9
+ const root = document.querySelector("[data-port-preview-entry]");
10
+ if (root === null)
11
+ throw new Error("Port preview confirmation is missing");
12
+ const entry = portPreviewEntrySchema.parse({
13
+ action: root.dataset.action,
14
+ computerId: root.dataset.computerId,
15
+ port: Number(root.dataset.port),
16
+ refusal: root.dataset.refusal,
17
+ });
18
+ const toasterId = "port-preview";
19
+ function PortPreviewDialog() {
20
+ useEffect(() => {
21
+ if (entry.refusal !== undefined)
22
+ toast.error(portPreviewRefusalMessage(entry.refusal), { toasterId });
23
+ }, []);
24
+ return (_jsxs(_Fragment, { children: [_jsx(Dialog, { defaultOpen: true, onOpenChange: (open) => {
25
+ if (!open)
26
+ window.location.assign("/");
27
+ }, children: _jsx(DialogContent, { children: _jsxs("form", { method: "post", action: entry.action, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Open this preview?" }), _jsx(DialogDescription, { children: "An App asked to open a private preview using your Oyster sign-in. Only continue if you expected it." })] }), _jsxs("dl", { className: "mt-md text-sm", children: [_jsxs("div", { className: "flex h-8 items-center justify-between gap-sm", "data-preview-fact": true, children: [_jsx("dt", { children: "Computer" }), _jsx("dd", { className: "min-w-0 truncate font-mono", children: entry.computerId })] }), _jsxs("div", { className: "flex h-8 items-center justify-between gap-sm", "data-preview-fact": true, children: [_jsx("dt", { children: "Port" }), _jsx("dd", { className: "font-mono", children: entry.port })] })] }), _jsxs(DialogFooter, { className: "mt-lg", children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", size: "sm" }), children: "Cancel" }), _jsx(Button, { type: "submit", size: "sm", children: "Open preview" })] })] }) }) }), _jsx(Toaster, { id: toasterId })] }));
28
+ }
29
+ // The native form remains usable without JavaScript. Enhance it with Caps;
30
+ // no script submits the form or requests preview credentials.
31
+ bootstrapIsolatedPageTheme();
32
+ document.body.replaceChildren(root);
33
+ createRoot(root).render(_jsx(PortPreviewDialog, {}));