@fungi.computer/oyster 0.37.2 → 0.38.1

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 (88) hide show
  1. package/README.md +5 -4
  2. package/dist/agents.js +9 -2
  3. package/dist/app-builds.d.ts +1 -1
  4. package/dist/app-region.d.ts +94 -0
  5. package/dist/app-region.js +316 -0
  6. package/dist/authorization.d.ts +58 -9
  7. package/dist/authorization.js +56 -11
  8. package/dist/backend-request.d.ts +4 -0
  9. package/dist/backend-request.js +3 -10
  10. package/dist/boot-host-script.js +1 -1
  11. package/dist/build/candidate-builder.d.ts +1 -1
  12. package/dist/build/candidate-cli.mjs +284 -17
  13. package/dist/build/effect.d.ts +3 -3
  14. package/dist/build/submission-contract.d.ts +1 -1
  15. package/dist/build/workspace-build.d.ts +2 -2
  16. package/dist/channels/discord-replies.d.ts +8 -1
  17. package/dist/channels/discord-replies.js +80 -29
  18. package/dist/cloudflare.d.ts +1 -0
  19. package/dist/cloudflare.js +12 -2
  20. package/dist/credential-migration-001.d.ts +14 -0
  21. package/dist/credential-migration-001.js +13 -0
  22. package/dist/credential-migration-002.d.ts +38 -0
  23. package/dist/credential-migration-002.js +74 -0
  24. package/dist/embed-metafiles.js +2 -2
  25. package/dist/embed-scripts.js +1 -1
  26. package/dist/host.d.ts +2 -0
  27. package/dist/host.js +23 -13
  28. package/dist/index.d.ts +15 -1
  29. package/dist/index.js +19 -0
  30. package/dist/invocation.d.ts +165 -0
  31. package/dist/invocation.js +67 -0
  32. package/dist/keys.d.ts +4 -3
  33. package/dist/keys.js +5 -4
  34. package/dist/mcp-owner.d.ts +4 -3
  35. package/dist/mcp-owner.js +3 -2
  36. package/dist/page/mount.js +5 -1
  37. package/dist/page/region.d.ts +6 -0
  38. package/dist/page/region.js +12 -0
  39. package/dist/page-config.d.ts +2 -0
  40. package/dist/page-config.js +2 -0
  41. package/dist/page-script.js +2 -2
  42. package/dist/source/seed-receipt.d.ts +1 -1
  43. package/dist/source/template-seed.d.ts +1 -1
  44. package/dist/standalone/agent-connections.d.ts +49 -1
  45. package/dist/standalone/agent-connections.js +101 -12
  46. package/dist/standalone/agent-self.js +2 -1
  47. package/dist/standalone/agents.d.ts +7 -3
  48. package/dist/standalone/agents.js +42 -19
  49. package/dist/standalone/computer-fleet.d.ts +12 -6
  50. package/dist/standalone/computer-fleet.js +70 -29
  51. package/dist/standalone/computer.js +39 -14
  52. package/dist/standalone/instance.d.ts +3 -1
  53. package/dist/standalone/instance.js +8 -0
  54. package/dist/standalone/model-key-vault.d.ts +33 -4
  55. package/dist/standalone/model-key-vault.js +74 -17
  56. package/dist/standalone/preview.js +11 -10
  57. package/dist/standalone/try-cli.d.ts +12 -2
  58. package/dist/standalone/try-cli.js +170 -32
  59. package/dist/standalone/try-worker.d.ts +2 -0
  60. package/dist/standalone/try-worker.js +15 -0
  61. package/dist/standalone/worker.js +3 -3
  62. package/dist/standalone/workflow-host.d.ts +1 -1
  63. package/dist/standalone/workflows.d.ts +3 -3
  64. package/dist/standalone/workflows.js +7 -0
  65. package/dist/testing/capabilities.d.ts +2 -0
  66. package/dist/testing/capabilities.js +2 -0
  67. package/dist/webhook-custody.d.ts +14 -3
  68. package/dist/webhook-custody.js +165 -43
  69. package/dist/webhooks.d.ts +1 -1
  70. package/dist/webhooks.js +15 -3
  71. package/dist/workers-git.d.ts +24 -8
  72. package/dist/workers-git.js +105 -15
  73. package/dist/workers.d.ts +16 -0
  74. package/dist/workers.js +95 -5
  75. package/docs/api/apps.md +31 -31
  76. package/docs/api/authorization.md +119 -17
  77. package/docs/api/build-contract.md +8 -8
  78. package/docs/api/build.md +163 -174
  79. package/docs/api/cloudflare.md +171 -0
  80. package/docs/api/host.md +1 -0
  81. package/docs/api/index.md +23 -0
  82. package/docs/api/invocation.md +623 -23
  83. package/docs/api/keys.md +6 -6
  84. package/docs/api/pack.md +3 -3
  85. package/docs/api/page/mount.md +22 -20
  86. package/docs/api/workers-git.md +273 -157
  87. package/docs/api/workers.md +257 -175
  88. package/package.json +19 -18
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Who may reach what is decided here once, from one {@link Authority}: the
8
8
  * owner reaches everything; a named key reaches exactly its Ear Tag grants
9
- * (Apps, Agents, the Computer); an Agent reaches its App tool policy. An
9
+ * (Apps, Agents, Computers); an Agent reaches its App tool policy. An
10
10
  * anonymous request reaches only the public routes: sign-in, robots.txt and
11
11
  * digest-pinned assets. The App gate
12
12
  * (`apps/gate.ts`) still owns App-declaration rules; it asks this module for a
@@ -43,19 +43,63 @@ export function keyAppAccess(key, installationId) {
43
43
  export function keyAgentAccess(key, agentId) {
44
44
  return oysterKeyVocabulary.grantsAllow(key.grants, "agents.use", agentId);
45
45
  }
46
- /** Whether a live key's own grants turn its Computer access on. Off by default. */
47
- export function keyAllowsComputerUse(key) {
48
- return oysterKeyVocabulary.grantsAllow(key.grants, "computer.use");
46
+ /**
47
+ * Whether a live key's `computer.use` grant reaches this Computer: every
48
+ * Computer (`all`), or one its selected ids name. Off by default. A host with
49
+ * no Computer id (`null`) is reached only by an `all` grant.
50
+ */
51
+ export function keyComputer(key, computerId) {
52
+ return oysterKeyVocabulary.grantsAllow(key.grants, "computer.use", computerId ?? undefined);
53
+ }
54
+ /** Decide {@link KeyFrameComputer} for one live key; a dead key is refused. */
55
+ export function keyFrameComputer(key, computerId) {
56
+ if (key === null)
57
+ return { kind: "refused" };
58
+ if (!key.grants.some((grant) => grant.capability === "computer.use"))
59
+ return { kind: "owner-computer" };
60
+ return keyComputer(key, computerId)
61
+ ? { kind: "granted", owner: key.owner }
62
+ : { kind: "refused" };
63
+ }
64
+ /** Decide {@link KeyComputerChoice} from a key's live grants; a dead key names nothing. */
65
+ export function keyComputerChoice(key, requested) {
66
+ const grants = (key?.grants ?? []).filter((grant) => grant.capability === "computer.use");
67
+ const everyComputer = grants.some((grant) => grant.targets.kind === "all");
68
+ const granted = [
69
+ ...new Set(grants.flatMap((grant) => grant.targets.kind === "selected" ? grant.targets.ids : [])),
70
+ ];
71
+ if (requested !== null) {
72
+ if (everyComputer || key === null)
73
+ return { kind: "refused", status: 403, error: "Owner only" };
74
+ return granted.includes(requested)
75
+ ? { kind: "granted", computerId: requested, owner: key.owner }
76
+ : {
77
+ kind: "refused",
78
+ status: 403,
79
+ error: "This key can't use that Computer",
80
+ };
81
+ }
82
+ const [only, ...others] = granted;
83
+ if (key === null || everyComputer || only === undefined)
84
+ return { kind: "owner-selection" };
85
+ if (others.length === 0)
86
+ return { kind: "granted", computerId: only, owner: key.owner };
87
+ return {
88
+ kind: "refused",
89
+ status: 400,
90
+ error: "This key reaches several Computers; name one with ?computerId=",
91
+ };
49
92
  }
50
93
  /** True only for a member admitted with the owner role. */
51
94
  export function oysterPrincipalIsOwner(principal) {
52
95
  return "role" in principal && principal.role === "owner";
53
96
  }
54
- /** A host's own ports: its key store's liveness and its Agents' tool policy. */
97
+ /** A host's own ports: its key store's liveness, its Agents' tool policy and its Computer. */
55
98
  export function hostAuthorityPorts(host) {
56
99
  return {
57
100
  liveKey: async (keyId) => (await host.keys?.live(keyId)) ?? null,
58
101
  appToolPolicy: async (actor) => (await host.appToolPolicy?.(actor)) ?? null,
102
+ computerId: host.computerId ?? null,
59
103
  };
60
104
  }
61
105
  /** Resolve one principal's authority through the live key port. */
@@ -89,17 +133,18 @@ export function reachesAgent(authority, agentId) {
89
133
  }
90
134
  }
91
135
  /**
92
- * Whether this authority reaches the host's Computer, its workspace files and
93
- * the media written there. Members do; a key only with `computer.use`;
94
- * Agents reach a Computer only through their own attachment owner.
136
+ * Whether this authority reaches one Computer, its workspace files and the
137
+ * media written there. Members do; a key only with `computer.use` naming that
138
+ * Computer or all of them; Agents reach a Computer only through their own
139
+ * attachment owner.
95
140
  */
96
- export function reachesComputer(authority) {
141
+ export function reachesComputer(authority, computerId) {
97
142
  switch (authority.kind) {
98
143
  case "owner":
99
144
  case "member":
100
145
  return true;
101
146
  case "key":
102
- return authority.key !== null && keyAllowsComputerUse(authority.key);
147
+ return authority.key !== null && keyComputer(authority.key, computerId);
103
148
  case "agent":
104
149
  return false;
105
150
  }
@@ -322,7 +367,7 @@ export function computer() {
322
367
  const authority = await signedInAuthority(facts);
323
368
  if (authority instanceof Response)
324
369
  return authority;
325
- if (!reachesComputer(authority))
370
+ if (!reachesComputer(authority, facts.ports.computerId ?? null))
326
371
  return refused(403, "Computer access requires an owner or key");
327
372
  return { principal: authority.principal };
328
373
  });
@@ -1,3 +1,7 @@
1
+ /** Second boundary before an admitted request enters customer backend code.
2
+ * Hub normally builds this shape itself; callers of the App runtime must not
3
+ * be able to pass their own headers through the facet.
4
+ */
1
5
  export declare function appFacetRequest(request: Request): Request;
2
6
  /** Only content metadata crosses back from a guest; origin policy is host-owned. */
3
7
  export declare function appFacetResponse(response: Response): Response;
@@ -2,18 +2,11 @@
2
2
  * Hub normally builds this shape itself; callers of the App runtime must not
3
3
  * be able to pass their own headers through the facet.
4
4
  */
5
- import { appBackendActorHeader, appBackendComputerHeader, } from "@fungi.computer/agar/backend";
6
5
  export function appFacetRequest(request) {
7
6
  const headers = new Headers();
8
- for (const name of [
9
- "Content-Type",
10
- appBackendActorHeader,
11
- appBackendComputerHeader,
12
- ]) {
13
- const value = request.headers.get(name);
14
- if (value !== null)
15
- headers.set(name, value);
16
- }
7
+ const contentType = request.headers.get("Content-Type");
8
+ if (contentType !== null)
9
+ headers.set("Content-Type", contentType);
17
10
  const init = {
18
11
  method: request.method,
19
12
  headers,