@fungi.computer/oyster 0.56.1 → 0.57.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 (50) hide show
  1. package/dist/agent-computer-source.js +4 -1
  2. package/dist/auth.d.ts +12 -4
  3. package/dist/auth.js +85 -24
  4. package/dist/boot-capability-route.js +5 -1
  5. package/dist/boot-gate.d.ts +5 -0
  6. package/dist/boot-gate.js +12 -2
  7. package/dist/boot-host-script.js +1 -1
  8. package/dist/boot-mount.d.ts +7 -1
  9. package/dist/boot-mount.js +11 -5
  10. package/dist/computer-api.d.ts +2 -0
  11. package/dist/embed-metafiles.js +2 -2
  12. package/dist/embed-scripts.js +1 -1
  13. package/dist/hello-app-script.js +1 -1
  14. package/dist/host-page-assets.js +1 -1
  15. package/dist/host-page-lazy.d.ts +2 -0
  16. package/dist/host-page-lazy.js +8 -0
  17. package/dist/host-page.d.ts +19 -1
  18. package/dist/host-page.js +61 -11
  19. package/dist/host.d.ts +2 -0
  20. package/dist/host.js +4 -1
  21. package/dist/owner-sessions.d.ts +25 -0
  22. package/dist/owner-sessions.js +50 -0
  23. package/dist/page/boot-host.js +20 -2
  24. package/dist/page-script.js +1 -1
  25. package/dist/platform-skills.generated.d.ts +1 -1
  26. package/dist/platform-skills.generated.js +1 -1
  27. package/dist/standalone/agent-computers.js +1 -1
  28. package/dist/standalone/agents.js +1 -0
  29. package/dist/standalone/builds.js +5 -0
  30. package/dist/standalone/candidate-preview.d.ts +25 -0
  31. package/dist/standalone/candidate-preview.js +265 -0
  32. package/dist/standalone/computer-api.js +4 -1
  33. package/dist/standalone/computer-fleet.js +3 -1
  34. package/dist/standalone/tenancy.d.ts +1 -1
  35. package/dist/standalone/tenancy.js +9 -1
  36. package/dist/standalone/worker.js +12 -2
  37. package/dist/starter-agent.js +5 -2
  38. package/dist/tenancy/owner-key.d.ts +4 -1
  39. package/dist/tenancy/owner-key.js +27 -2
  40. package/dist/upgrade/old-worker-http.js +2 -6
  41. package/dist/workers-git.js +10 -2
  42. package/dist/workers.d.ts +11 -0
  43. package/dist/workers.js +33 -1
  44. package/docs/api/README.md +5 -3
  45. package/docs/api/auth.md +96 -8
  46. package/docs/api/computer-api.md +9 -6
  47. package/docs/api/host.md +1 -0
  48. package/docs/api/tenancy/owner-key.md +1 -0
  49. package/docs/api/workers.md +81 -0
  50. package/package.json +17 -17
@@ -3,3 +3,5 @@ import type { HostPageOptions } from "./host-page.js";
3
3
  export declare function renderHostPage(options: HostPageOptions): Promise<Response>;
4
4
  /** Serve one content-addressed host page asset, loading the renderer on first use. */
5
5
  export declare function serveHostPageAsset(path: string): Promise<Response>;
6
+ export declare function renderPreviewStyles(): Promise<string>;
7
+ export declare function renderPreviewChrome(notice: import("./host-page.js").PreviewNotice): Promise<string>;
@@ -13,3 +13,11 @@ export async function serveHostPageAsset(path) {
13
13
  const serve = await loadLazily(() => import("./host-page.js").then(({ hostPageAsset }) => hostPageAsset), renderer);
14
14
  return serve(path);
15
15
  }
16
+ export async function renderPreviewStyles() {
17
+ const render = await loadLazily(() => import("./host-page.js").then((module) => module.previewStyles), renderer);
18
+ return render();
19
+ }
20
+ export async function renderPreviewChrome(notice) {
21
+ const render = await loadLazily(() => import("./host-page.js").then((module) => module.previewChrome), renderer);
22
+ return render(notice);
23
+ }
@@ -1,8 +1,14 @@
1
1
  import { type AppPermissionsViewData } from "./apps/permissions.js";
2
2
  /** Human-facing states only. API refusals keep their original wire format. */
3
- export type HostPageState = "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
3
+ export type HostPageState = "preview" | "permissions" | "root" | "empty" | "login" | "login-invalid" | "key-help" | "signing-in" | "not-found" | "server-error" | "access-denied" | "desktop-missing";
4
4
  export type HostPageOptions = Readonly<{
5
5
  state: HostPageState;
6
+ preview?: Readonly<{
7
+ appName?: string;
8
+ action: string;
9
+ preparing: boolean;
10
+ }>;
11
+ inlineStyles?: string;
6
12
  title?: string;
7
13
  status?: number;
8
14
  stylesheets?: readonly string[];
@@ -33,3 +39,15 @@ export type HostPageOptions = Readonly<{
33
39
  export declare function hostPageAsset(path: string): Promise<Response>;
34
40
  /** One server-rendered Caps composition, usable without styles, art or JS. */
35
41
  export declare function hostPage(options: HostPageOptions): Promise<Response>;
42
+ /** Maintained Caps and Oyster page tokens, embedded for the private preview. */
43
+ export declare function previewStyles(): Promise<string>;
44
+ export type PreviewNotice = Readonly<{
45
+ appName: string;
46
+ revision: string;
47
+ status: string;
48
+ explanation: string;
49
+ expiresAt: number;
50
+ entry: string;
51
+ }>;
52
+ /** Trusted preview chrome; the candidate cannot supply HTML or host authority. */
53
+ export declare function previewChrome(notice: PreviewNotice): Promise<string>;
package/dist/host-page.js CHANGED
@@ -6,11 +6,13 @@ import { Status } from "@fungi.computer/caps/components/status";
6
6
  import { Button } from "@fungi.computer/caps/components/button";
7
7
  import { Input } from "@fungi.computer/caps/components/input";
8
8
  import { Card, CardHeader, CardTitle, CardContent, } from "@fungi.computer/caps/components/card";
9
+ import { loadPageAssets } from "./page-assets.js";
9
10
  import { fungiFaviconHref } from "@fungi.computer/sigils/favicon";
10
11
  import { permissionScreen, } from "./apps/permissions.js";
11
12
  import { permissionCatalog } from "./apps/catalog.js";
12
13
  const docs = "https://docs.fungi.computer";
13
14
  const copy = {
15
+ preview: ["Preview", "Oyster · Preview", "Opening preview…"],
14
16
  permissions: [
15
17
  "Choose what this App can do.",
16
18
  "Oyster · App permissions",
@@ -68,6 +70,12 @@ const copy = {
68
70
  ],
69
71
  };
70
72
  const abilities = {
73
+ preview: [
74
+ "Preview a change",
75
+ "Open the page.",
76
+ "Check the change.",
77
+ "Merge in Bonsai when ready.",
78
+ ],
71
79
  permissions: [
72
80
  "You choose the access",
73
81
  "Check the App and Release below.",
@@ -163,6 +171,12 @@ function pageContent(options, url) {
163
171
  const { state, signIn } = options;
164
172
  const content = [];
165
173
  const actions = [];
174
+ if (state === "preview" && options.preview) {
175
+ content.push(h("form", { method: "post", action: options.preview.action }, options.preview.preparing
176
+ ? h("input", { type: "hidden", name: "intent", value: "prepare" })
177
+ : null, h(Button, { type: "submit", size: "sm" }, options.preview.preparing ? "Continue" : "Open preview")));
178
+ return { content, actions };
179
+ }
166
180
  if (state === "permissions" && options.permissions) {
167
181
  const { config } = options.permissions;
168
182
  const screen = permissionScreen({
@@ -220,7 +234,9 @@ function pageContent(options, url) {
220
234
  : null))));
221
235
  if (state === "desktop-missing")
222
236
  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."));
223
- actions.push(link("Read the quickstart", `${docs}/oyster-quickstart`), link("Install an App", `${docs}/agents/build-an-app.md`, true));
237
+ actions.push(link("Read the quickstart", `${docs}/oyster-quickstart`), link("Install an App", `${docs}/agents/build-an-app.md`, true),
238
+ // Ends this browser's session on the server, then returns to sign-in.
239
+ h("form", { method: "post", action: url("/logout") }, h(Button, { type: "submit", variant: "outline" }, "Sign out")));
224
240
  }
225
241
  else {
226
242
  if (state === "server-error")
@@ -282,9 +298,11 @@ function illustration(state, assetUrl) {
282
298
  export async function hostPage(options) {
283
299
  const { state, title = "Oyster" } = options;
284
300
  const [baseHeading, eyebrow, description] = copy[state];
285
- const heading = state === "login" && options.returning === true
286
- ? "Welcome back."
287
- : baseHeading;
301
+ const heading = state === "preview"
302
+ ? (options.preview?.appName ?? "Opening preview…")
303
+ : state === "login" && options.returning === true
304
+ ? "Welcome back."
305
+ : baseHeading;
288
306
  const url = (path) => options.oysterUrl ? new URL(path, options.oysterUrl).href : path;
289
307
  // A failed decorative module must still leave the form and recovery readable.
290
308
  let assets;
@@ -307,16 +325,34 @@ export async function hostPage(options) {
307
325
  rel: "icon",
308
326
  type: "image/svg+xml",
309
327
  href: fungiFaviconHref,
310
- }), ...(options.stylesheets ?? []).map((href) => h("link", { key: href, rel: "stylesheet", href: url(href) })), assetUrl("layout.css")
328
+ }), ...(options.stylesheets ?? []).map((href) => h("link", { key: href, rel: "stylesheet", href: url(href) })), options.inlineStyles
329
+ ? h("style", {
330
+ dangerouslySetInnerHTML: { __html: options.inlineStyles },
331
+ })
332
+ : null, !options.inlineStyles && assetUrl("layout.css")
311
333
  ? h("link", { rel: "stylesheet", href: assetUrl("layout.css") })
312
- : 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
334
+ : null), h("body", { className: state === "preview" ? "preview-entry" : undefined }, 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" }, state === "preview"
335
+ ? null
336
+ : 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" }, state === "preview"
337
+ ? options.preview?.appName
338
+ ? `Preview this change to ${options.preview.appName} before you merge it.`
339
+ : "Opening preview…"
340
+ : description), ...content, actions.length
313
341
  ? h("div", { className: "actions" }, ...actions)
314
- : null, h("p", { className: "helper" }, state === "login" || state === "login-invalid"
315
- ? "Your key is sent only to this Oyster."
316
- : state === "not-found"
317
- ? null
318
- : 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")
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")
319
349
  ? h("script", { type: "module", src: assetUrl("host-page.js") })
350
+ : null, options.preview?.preparing
351
+ ? h("script", {
352
+ dangerouslySetInnerHTML: {
353
+ __html: "document.forms[0].requestSubmit()",
354
+ },
355
+ })
320
356
  : null, options.permissions
321
357
  ? h("script", {
322
358
  type: "application/json",
@@ -340,3 +376,17 @@ export async function hostPage(options) {
340
376
  },
341
377
  });
342
378
  }
379
+ /** Maintained Caps and Oyster page tokens, embedded for the private preview. */
380
+ export async function previewStyles() {
381
+ const [assets, sources] = await Promise.all([pageAssets(), loadPageAssets()]);
382
+ const layout = assets["layout.css"];
383
+ if (layout === undefined)
384
+ throw new Error("Oyster page styles unavailable");
385
+ return sources.shellStyles + sources.loginFontStyles + layout.source;
386
+ }
387
+ /** Trusted preview chrome; the candidate cannot supply HTML or host authority. */
388
+ export async function previewChrome(notice) {
389
+ return (`<style>${await previewStyles()}</style>` +
390
+ renderToStaticMarkup(h("header", { className: "preview-bar", "data-preview-bar": "" }, h("span", null, "Preview"), h("span", { "aria-hidden": true }, "·"), h("span", { className: "preview-app", title: notice.appName }, notice.appName), h("span", { className: "preview-build" }, `build ${notice.revision}`), h("span", { "aria-hidden": true }, "·"), h("span", { id: "preview-state" }, notice.status), h("details", { className: "preview-details" }, h(Button, { asChild: true, size: "xs", variant: "ghost" }, h("summary", null, "Details")), h(Card, { className: "preview-explanation" }, h(CardContent, null, h("p", null, notice.explanation), h("p", null, "This preview only shows the page. It cannot use your files or run commands."), h("p", null, "Merge in Bonsai to build and install the change. Reload this page to open the preview again.")))))) +
391
+ renderToStaticMarkup(h("section", { id: "preview-expired", hidden: true, role: "status" }, h("p", null, "This preview expired. Reload to open it again."), h(Button, { asChild: true, size: "sm" }, h("a", { href: notice.entry }, "Reload")))));
392
+ }
package/dist/host.d.ts CHANGED
@@ -56,6 +56,8 @@ export type OysterAuth = Readonly<{
56
56
  authenticate: (request: Request) => Promise<OysterAuthResult>;
57
57
  /** Handle the browser sign-in form post; returns the response to send. */
58
58
  login?: (request: Request) => Promise<Response>;
59
+ /** End this browser's session on the server and clear its cookie. */
60
+ logout?: (request: Request) => Promise<Response>;
59
61
  }>;
60
62
  /** A serializable registry commit result, including across native DO RPC. */
61
63
  export type InstallationCommit = Readonly<{
package/dist/host.js CHANGED
@@ -393,6 +393,9 @@ export function oysterRouteTable(host) {
393
393
  table.post("/login", door("the host's own sign-in checks the posted key"), (context) => host.auth.login === undefined
394
394
  ? refusal(404, "Sign-in is not available")
395
395
  : host.auth.login(context.req.raw));
396
+ table.post("/logout", door("the host's own sign-out revokes the presented session"), (context) => host.auth.logout === undefined
397
+ ? refusal(404, "Sign-out is not available")
398
+ : host.auth.logout(context.req.raw));
396
399
  if (host.mcp !== undefined) {
397
400
  const mcp = host.mcp;
398
401
  table.all("/mcp", door("MCP authenticates every request; tools read this module's reach"), (context) => mcp.handleRequest(context.req.raw));
@@ -565,7 +568,7 @@ export function oysterRouteTable(host) {
565
568
  });
566
569
  if (host.ownerRoutes !== undefined)
567
570
  table.include(host.ownerRoutes);
568
- table.get("/api/workbench/directory", owner("direct-or-app"), async (context) => {
571
+ table.get("/api/workbench/directory", owner("direct"), async (context) => {
569
572
  if (host.workbench === undefined)
570
573
  return refusal(404, "Not found");
571
574
  startTime(context, "registry");
@@ -0,0 +1,25 @@
1
+ /** How long one browser sign-in lasts, absolutely: no sliding renewal. */
2
+ export declare const ownerSessionLifetimeMs: number;
3
+ /**
4
+ * The server side of owner browser sessions. The cookie carries a random
5
+ * session id; the store keeps only its digest, the owner it signs in, and an
6
+ * expiry. Logging out revokes the row, so a copied cookie stops working.
7
+ */
8
+ export type OwnerSessions = Readonly<{
9
+ /** Record a new session for `owner` opened at `now`; it ends `ownerSessionLifetimeMs` later. */
10
+ open(owner: string, digest: string, now: number): Promise<void>;
11
+ /** The owner a live session signs in, or null for an unknown, expired or revoked one. */
12
+ owner(digest: string, now: number): Promise<string | null>;
13
+ /** Revoke one session; revoking an unknown session does nothing. */
14
+ revoke(digest: string): Promise<void>;
15
+ }>;
16
+ /** The synchronous SQL a Durable Object or SQLite host gives the store. */
17
+ export type OwnerSessionSql = Readonly<{
18
+ /** Run one statement with positional bindings. */
19
+ exec(query: string, ...bindings: (string | number | null)[]): {
20
+ /** The statement's rows, decoded by the store. */
21
+ toArray(): readonly object[];
22
+ };
23
+ }>;
24
+ /** Owner sessions over one store's SQL. */
25
+ export declare function ownerSessionStore(sql: OwnerSessionSql): OwnerSessions;
@@ -0,0 +1,50 @@
1
+ import * as Schema from "effect/Schema";
2
+ /** How long one browser sign-in lasts, absolutely: no sliding renewal. */
3
+ export const ownerSessionLifetimeMs = 30 * 24 * 60 * 60 * 1000;
4
+ const sessionRows = Schema.Array(Schema.Struct({ owner: Schema.String, expires_at: Schema.Number }));
5
+ /**
6
+ * The session table, created on first use. Older stores have no sessions,
7
+ * so the browser cookies they issued (a digest of the owner key) match no
8
+ * row here and fail closed to the sign-in page.
9
+ */
10
+ function ensureOwnerSessions(sql) {
11
+ sql.exec(`CREATE TABLE IF NOT EXISTS oyster_owner_sessions (
12
+ session_digest TEXT PRIMARY KEY, owner TEXT NOT NULL,
13
+ expires_at INTEGER NOT NULL) STRICT`);
14
+ }
15
+ /** Owner sessions over one store's SQL. */
16
+ export function ownerSessionStore(sql) {
17
+ let ready = false;
18
+ const table = () => {
19
+ if (!ready)
20
+ ensureOwnerSessions(sql);
21
+ ready = true;
22
+ return sql;
23
+ };
24
+ return {
25
+ open(owner, digest, now) {
26
+ const store = table();
27
+ // Expired rows go when a new session opens, so the table stays small.
28
+ store.exec("DELETE FROM oyster_owner_sessions WHERE expires_at <= ?", now);
29
+ store.exec("INSERT INTO oyster_owner_sessions (session_digest, owner, expires_at) VALUES (?, ?, ?)", digest, owner, now + ownerSessionLifetimeMs);
30
+ return Promise.resolve();
31
+ },
32
+ owner(digest, now) {
33
+ const store = table();
34
+ const [row] = Schema.decodeUnknownSync(sessionRows)(store
35
+ .exec("SELECT owner, expires_at FROM oyster_owner_sessions WHERE session_digest = ?", digest)
36
+ .toArray());
37
+ if (row === undefined)
38
+ return Promise.resolve(null);
39
+ if (row.expires_at <= now) {
40
+ store.exec("DELETE FROM oyster_owner_sessions WHERE session_digest = ?", digest);
41
+ return Promise.resolve(null);
42
+ }
43
+ return Promise.resolve(row.owner);
44
+ },
45
+ revoke(digest) {
46
+ table().exec("DELETE FROM oyster_owner_sessions WHERE session_digest = ?", digest);
47
+ return Promise.resolve();
48
+ },
49
+ };
50
+ }
@@ -11,12 +11,30 @@ async function bootHost() {
11
11
  throw new Error("Host boot configuration unavailable");
12
12
  const config = bootUiSchema
13
13
  .pick({ identity: true })
14
- .extend({ entry: z.url() })
14
+ .extend({
15
+ identity: bootUiSchema.shape.identity.extend({
16
+ surfaceId: z.string().min(1).max(256),
17
+ }),
18
+ entry: z.url(),
19
+ expiresAt: z.number().optional(),
20
+ })
15
21
  .parse(JSON.parse(element.textContent));
16
22
  const frame = document.getElementById("candidate");
17
23
  if (!(frame instanceof HTMLIFrameElement) || frame.contentWindow === null)
18
24
  throw new Error("Host candidate frame unavailable");
19
- const denied = () => Promise.reject(new Error("No grants during host boot"));
25
+ if (config.expiresAt !== undefined) {
26
+ window.setTimeout(() => {
27
+ frame.hidden = true;
28
+ document.querySelector(".preview-details")?.removeAttribute("open");
29
+ const expired = document.getElementById("preview-expired");
30
+ if (expired !== null)
31
+ expired.hidden = false;
32
+ const state = document.getElementById("preview-state");
33
+ if (state !== null)
34
+ state.textContent = "expired";
35
+ }, Math.max(0, config.expiresAt - Date.now()));
36
+ }
37
+ const denied = () => Promise.reject(new Error("No grants in this preview"));
20
38
  const connection = connectAppHost({
21
39
  appWindow: frame.contentWindow,
22
40
  expectedAppOrigin: "null",