@fungi.computer/oyster 0.13.1 → 0.14.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.
package/dist/host.js CHANGED
@@ -447,6 +447,10 @@ export function oysterRouteTable(host) {
447
447
  // resource (an Agent, the Computer) under the same principal.
448
448
  const dispatchCapability = async (context, principal) => {
449
449
  const url = new URL(context.req.url);
450
+ // A send/manage transport also matches GET requests. The Agent's model
451
+ // catalog is an agent.read projection, not a write-capability side door.
452
+ const agentModelRead = context.req.method === "GET" &&
453
+ /^\/agents\/[^/]+\/models$/u.test(url.pathname);
450
454
  const candidates = capabilityRoutes.filter((route) => (route.method === "ANY" || route.method === context.req.method) &&
451
455
  route.matches(url.pathname));
452
456
  if (candidates.length === 0)
@@ -472,6 +476,8 @@ export function oysterRouteTable(host) {
472
476
  return refusal(403, "Capability permission denied");
473
477
  const facts = await gateFacts(installation, await releaseOf(installation.release), principal);
474
478
  for (const { capability, operation } of candidates) {
479
+ if (agentModelRead && capability.id !== "agent.read")
480
+ continue;
475
481
  if (admits(facts, {
476
482
  kind: "capability-route",
477
483
  capability: capability.permission,
@@ -879,7 +885,16 @@ export function oysterRouteTable(host) {
879
885
  return Response.json(config, {
880
886
  headers: { "Cache-Control": "no-store", Vary: "Accept" },
881
887
  });
882
- const head = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>${escapeHtml(installation.installationId)} · ${escapeHtml(title)}</title>${tabIcon}<link rel="stylesheet" href="${(await assets()).fonts.path}">`;
888
+ // The shell module imports its chunks a few levels deep; naming every
889
+ // digest-pinned chunk up front fetches them side by side instead.
890
+ const shellPreloads = config.shellModuleUrl !== null && release.ui?.kind === "assets"
891
+ ? release.ui.build.assets
892
+ .filter((asset) => asset.contentType.startsWith("text/javascript") &&
893
+ asset.path !== shellModuleAssetPath)
894
+ .map((asset) => `<link rel="modulepreload" href="${escapeHtml(`${uiUrl.slice(0, -1)}${asset.path}`)}">`)
895
+ .join("")
896
+ : "";
897
+ const head = `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>${escapeHtml(installation.installationId)} · ${escapeHtml(title)}</title>${tabIcon}<link rel="stylesheet" href="${(await assets()).fonts.path}">${shellPreloads}`;
883
898
  const tail = `<script type="application/json" id="oyster-config">${JSON.stringify(config).replaceAll("<", "\\u003c")}</script><script type="module" src="${(await assets()).page.path}"></script>`;
884
899
  // The home shell is trusted: the host's page script renders it in this
885
900
  // top-level document, and it mounts each App's sandboxed frame inside
@@ -746,7 +746,7 @@ export async function createInstallationOperations(ports) {
746
746
  for (const requestId of settledInTick)
747
747
  wake(requestId);
748
748
  settledInTick.clear();
749
- if (await watchdog.hasPendingWork())
749
+ if ((await watchdog.wakeState(Date.now())).pending)
750
750
  await ports.scheduleWake(Date.now());
751
751
  else {
752
752
  const due = nextRetentionWake();
@@ -270,7 +270,7 @@ export class MachineLinkHost {
270
270
  ? recipientOffline
271
271
  : previousCustodyReceipt(raced);
272
272
  }
273
- await this.options.scheduleWake(post.nextWake() ?? Date.now());
273
+ await this.options.scheduleWake(Date.now());
274
274
  if (socket === undefined)
275
275
  return recipientOffline;
276
276
  await this.publishDirectory(socket, deviceId);
@@ -386,16 +386,24 @@ export class MachineLinkHost {
386
386
  const watchdog = await Watchdog.make({
387
387
  owner: this.owner,
388
388
  isAlive: () => Promise.resolve(false),
389
- execute: (job) => {
389
+ retryPolicy: (job) => {
390
390
  const post = postRef.current;
391
391
  if (post === undefined)
392
392
  throw new Error("Carrier Post runtime is not initialized");
393
- return post.execute(job);
393
+ return post.retryPolicy(job);
394
+ },
395
+ execute: (job, signal, attempt) => {
396
+ const post = postRef.current;
397
+ if (post === undefined)
398
+ throw new Error("Carrier Post runtime is not initialized");
399
+ return post.execute(job, attempt, signal);
394
400
  },
395
401
  wake: {
396
402
  recompute: async () => {
397
- const at = postRef.current?.nextWake();
398
- if (at !== null && at !== undefined)
403
+ const now = Date.now();
404
+ const state = await watchdog.wakeState(now);
405
+ const at = state.pending ? now : state.nextWakeAt;
406
+ if (at !== null)
399
407
  await this.options.scheduleWake(at);
400
408
  },
401
409
  },
@@ -404,7 +412,6 @@ export class MachineLinkHost {
404
412
  routes: this.custodyRoutes,
405
413
  owner: this.owner,
406
414
  transactional: watchdog.transactional,
407
- readJob: watchdog.read,
408
415
  now: Date.now,
409
416
  scheduleWake: this.options.scheduleWake,
410
417
  });
@@ -419,17 +426,15 @@ export class MachineLinkHost {
419
426
  } while (cursor !== undefined);
420
427
  }
421
428
  async drainCustody() {
422
- const { post, watchdog } = await this.custody();
423
- let cursor;
424
- do {
425
- cursor = await post.enqueueDue(64, cursor);
426
- } while (cursor !== undefined);
429
+ const { watchdog } = await this.custody();
427
430
  for (let count = 0; count < 64; count += 1) {
428
431
  const tick = await watchdog.tick();
429
- if (tick.status !== "settled")
432
+ if (tick.status !== "settled" && tick.status !== "requeued")
430
433
  break;
431
434
  }
432
- const at = post.nextWake();
435
+ const now = Date.now();
436
+ const state = await watchdog.wakeState(now);
437
+ const at = state.pending ? now : state.nextWakeAt;
433
438
  if (at !== null)
434
439
  await this.options.scheduleWake(at);
435
440
  }