@fungi.computer/oyster 0.8.2 → 0.9.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.
@@ -12,8 +12,12 @@ export function instanceRefusalStatus(code) {
12
12
  return 422;
13
13
  return conflicts.has(code) ? 409 : 403;
14
14
  }
15
- /** Only closed host-authored boot reasons produce a caller-facing message. */
15
+ /** The host-authored settlement for an installation that changed nothing. */
16
+ export const installationNotAppliedMessage = "The new release was not applied: Oyster could not prepare it. The previous release is still installed; install again to retry.";
17
+ /** Only closed host-authored reasons produce a caller-facing message. */
16
18
  export function instanceRefusalBody(code) {
19
+ if (code === "installation_not_applied")
20
+ return { error: code, message: installationNotAppliedMessage };
17
21
  const boot = bootFailureSchema.safeParse(code);
18
22
  return boot.success
19
23
  ? { error: boot.data, message: new BootGateError(boot.data).message }
package/dist/mcp.d.ts CHANGED
@@ -83,6 +83,7 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
83
83
  running: "running";
84
84
  sleeping: "sleeping";
85
85
  starting: "starting";
86
+ start_failed: "start_failed";
86
87
  }>;
87
88
  }, z.core.$strict>, z.ZodObject<{
88
89
  state: z.ZodLiteral<"queued">;
@@ -90,7 +91,7 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
90
91
  }, z.core.$strict>], "state">;
91
92
  /** Return liveness without waking the runtime. */
92
93
  execute: (input: z.output<typeof fleetComputerId>, context: InvocationContext) => Promise<{
93
- state: "running" | "sleeping" | "starting";
94
+ state: "running" | "sleeping" | "starting" | "start_failed";
94
95
  } | {
95
96
  state: "queued";
96
97
  position: number;
@@ -107,6 +108,7 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
107
108
  running: "running";
108
109
  sleeping: "sleeping";
109
110
  starting: "starting";
111
+ start_failed: "start_failed";
110
112
  }>;
111
113
  }, z.core.$strict>, z.ZodObject<{
112
114
  state: z.ZodLiteral<"queued">;
@@ -114,7 +116,7 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
114
116
  }, z.core.$strict>], "state">;
115
117
  /** Admit and start this Computer. */
116
118
  execute: (input: z.output<typeof fleetComputerId>, context: InvocationContext) => Promise<{
117
- state: "running" | "sleeping" | "starting";
119
+ state: "running" | "sleeping" | "starting" | "start_failed";
118
120
  } | {
119
121
  state: "queued";
120
122
  position: number;
@@ -160,7 +160,14 @@ export type OysterAppConnectionOptions = Readonly<{
160
160
  reservedChords: readonly import("@fungi.computer/agar/host").AppHostReservedChord[];
161
161
  theme: string;
162
162
  }>;
163
- /** Connect a child or home App using the same admitted Oyster slot handles. */
163
+ /**
164
+ * Connect a child or home App using the same admitted Oyster slot handles.
165
+ * The host navigates the App's frame (`config.uiUrl`) only once it listens for
166
+ * the App's ready signal, so slow capability resolution on a cold Oyster can
167
+ * never outlast that signal. Opening is bounded: the capabilities and the
168
+ * document get the shared cold-document budget, and the handshake after the
169
+ * document loads gets the App's own ready window.
170
+ */
164
171
  export declare function connectOysterApp(options: OysterAppConnectionOptions): Promise<AppHost>;
165
172
  export { oysterStorageHandle } from "./storage.js";
166
173
  export { appSandbox } from "../app-sandbox.js";
@@ -2,6 +2,7 @@ import { appOpenInputSchema, appsCall, appsOpen, } from "@fungi.computer/agar/ap
2
2
  import { appApiMethodNameSchema } from "@fungi.computer/puffball/app";
3
3
  import { appIdSchema } from "@fungi.computer/puffball/effect";
4
4
  import { createBrowserActionHandler } from "@fungi.computer/nacre";
5
+ import { APP_SURFACE_DOCUMENT_TIMEOUT_MS } from "@fungi.computer/nacre/window-manager";
5
6
  import { createAppSurfaceCommandHost } from "@fungi.computer/nacre/command-host";
6
7
  // App page: mounts one installed App's sandboxed frame and gives it the
7
8
  // capabilities this Oyster host provides. Bundled into `shellScript`.
@@ -251,20 +252,83 @@ export async function mountOysterPage() {
251
252
  },
252
253
  });
253
254
  }
254
- /** Connect a child or home App using the same admitted Oyster slot handles. */
255
+ /** The App's own ready window: once its document loads, it announces itself for 10 s. */
256
+ const APP_CONNECT_TIMEOUT_MS = 10_000;
257
+ /** Resolve `work`, or reject with the signal's reason once it aborts. */
258
+ function untilAborted(work, signal) {
259
+ const stopped = () => signal.reason instanceof Error
260
+ ? signal.reason
261
+ : new Error("App open was stopped", { cause: signal.reason });
262
+ if (signal.aborted)
263
+ return Promise.reject(stopped());
264
+ return new Promise((resolve, reject) => {
265
+ const stop = () => {
266
+ reject(stopped());
267
+ };
268
+ signal.addEventListener("abort", stop, { once: true });
269
+ work.then((value) => {
270
+ signal.removeEventListener("abort", stop);
271
+ resolve(value);
272
+ }, (cause) => {
273
+ signal.removeEventListener("abort", stop);
274
+ reject(cause instanceof Error
275
+ ? cause
276
+ : new Error("App open failed", { cause }));
277
+ });
278
+ });
279
+ }
280
+ /**
281
+ * Connect a child or home App using the same admitted Oyster slot handles.
282
+ * The host navigates the App's frame (`config.uiUrl`) only once it listens for
283
+ * the App's ready signal, so slow capability resolution on a cold Oyster can
284
+ * never outlast that signal. Opening is bounded: the capabilities and the
285
+ * document get the shared cold-document budget, and the handshake after the
286
+ * document loads gets the App's own ready window.
287
+ */
255
288
  export async function connectOysterApp(options) {
256
289
  const { config, frame } = options;
257
290
  if (frame.contentWindow === null)
258
291
  throw new Error("App frame is unavailable");
259
- const capabilities = await oysterAppCapabilities(options);
292
+ const deadline = new AbortController();
293
+ const expire = () => {
294
+ deadline.abort();
295
+ };
296
+ let timer = setTimeout(expire, APP_SURFACE_DOCUMENT_TIMEOUT_MS);
297
+ const opening = AbortSignal.any([options.signal, deadline.signal]);
298
+ const documentLoaded = () => {
299
+ clearTimeout(timer);
300
+ timer = setTimeout(expire, APP_CONNECT_TIMEOUT_MS);
301
+ };
302
+ try {
303
+ return await openOysterApp(options, frame.contentWindow, opening, () => {
304
+ frame.addEventListener("load", documentLoaded, { once: true });
305
+ frame.src = config.uiUrl;
306
+ });
307
+ }
308
+ catch (cause) {
309
+ if (deadline.signal.aborted && !options.signal.aborted)
310
+ throw new AppError("App did not open in time", {
311
+ code: "TIMEOUT",
312
+ retryable: true,
313
+ });
314
+ throw cause;
315
+ }
316
+ finally {
317
+ clearTimeout(timer);
318
+ frame.removeEventListener("load", documentLoaded);
319
+ }
320
+ }
321
+ async function openOysterApp(options, appWindow, opening, navigate) {
322
+ const { config, frame } = options;
323
+ const capabilities = await untilAborted(oysterAppCapabilities(options), opening);
260
324
  const agents = agentDirectory(capabilities);
261
325
  const releaseBrowser = options.agentBrowser.mount(frame, options.agentCommands);
262
326
  options.signal.addEventListener("abort", releaseBrowser, { once: true });
263
- const host = await connectAppHost({
264
- appWindow: frame.contentWindow,
327
+ const connecting = connectAppHost({
328
+ appWindow,
265
329
  expectedAppOrigin: "null",
266
330
  hostWindow: window,
267
- signal: options.signal,
331
+ signal: opening,
268
332
  launch: {
269
333
  identity: {
270
334
  appId: config.appId,
@@ -301,7 +365,9 @@ export async function connectOysterApp(options) {
301
365
  signal: options.signal,
302
366
  }),
303
367
  },
304
- }).catch((cause) => {
368
+ });
369
+ navigate();
370
+ const host = await connecting.catch((cause) => {
305
371
  releaseBrowser();
306
372
  throw cause;
307
373
  });