@fungi.computer/oyster 0.10.0 → 0.12.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 (107) hide show
  1. package/README.md +103 -12
  2. package/dist/agents.d.ts +66 -22
  3. package/dist/agents.js +128 -38
  4. package/dist/app-builds.d.ts +2 -0
  5. package/dist/app-builds.js +17 -6
  6. package/dist/authorization.d.ts +25 -3
  7. package/dist/authorization.js +47 -14
  8. package/dist/browser/capability-source.d.ts +23 -5
  9. package/dist/browser/capability-source.js +19 -22
  10. package/dist/browser/index.d.ts +2 -1
  11. package/dist/browser/index.js +1 -0
  12. package/dist/browser/live-view.d.ts +38 -0
  13. package/dist/browser/live-view.js +179 -0
  14. package/dist/build/artifact-writer.d.ts +11 -2
  15. package/dist/build/artifact-writer.js +42 -24
  16. package/dist/build/candidate-cli.mjs +26 -18
  17. package/dist/build/content-objects.d.ts +29 -14
  18. package/dist/build/content-objects.js +57 -19
  19. package/dist/build/local-build.js +3 -0
  20. package/dist/build/submission-contract.d.ts +1 -1
  21. package/dist/build/submission-contract.js +5 -5
  22. package/dist/build-egress.d.ts +8 -7
  23. package/dist/build-egress.js +4 -3
  24. package/dist/build.d.ts +1 -1
  25. package/dist/channels/binding.d.ts +2 -0
  26. package/dist/channels/run-decision.d.ts +33 -0
  27. package/dist/channels/run-decision.js +25 -0
  28. package/dist/channels/visitor-channel.d.ts +84 -14
  29. package/dist/channels/visitor-channel.js +55 -32
  30. package/dist/channels/visitor-edge.d.ts +18 -2
  31. package/dist/channels/visitor-edge.js +67 -5
  32. package/dist/channels/visitors.d.ts +4 -0
  33. package/dist/channels/visitors.js +22 -1
  34. package/dist/channels/web-binding.d.ts +117 -0
  35. package/dist/channels/web-binding.js +227 -0
  36. package/dist/embed-metafiles.d.ts +8 -0
  37. package/dist/embed-metafiles.js +2 -0
  38. package/dist/embed-scripts.d.ts +8 -0
  39. package/dist/embed-scripts.js +3 -0
  40. package/dist/host.d.ts +3 -1
  41. package/dist/host.js +6 -1
  42. package/dist/install-release-cli.d.ts +2 -1
  43. package/dist/install-release-cli.js +18 -10
  44. package/dist/installation-client.d.ts +1 -0
  45. package/dist/installation-operations.d.ts +2 -0
  46. package/dist/installation-operations.js +1 -0
  47. package/dist/pack.d.ts +5 -2
  48. package/dist/pack.js +3 -1
  49. package/dist/page/embed-challenge.d.ts +19 -0
  50. package/dist/page/embed-challenge.js +45 -0
  51. package/dist/page/embed-error.d.ts +2 -0
  52. package/dist/page/embed-error.js +16 -0
  53. package/dist/page/embed-loader-protocol.d.ts +12 -0
  54. package/dist/page/embed-loader-protocol.js +29 -0
  55. package/dist/standalone/agent-connections.d.ts +22 -19
  56. package/dist/standalone/agent-connections.js +150 -106
  57. package/dist/standalone/agents.d.ts +174 -16
  58. package/dist/standalone/agents.js +331 -21
  59. package/dist/standalone/browser.d.ts +14 -2
  60. package/dist/standalone/browser.js +52 -4
  61. package/dist/standalone/channel-session-door.d.ts +4 -0
  62. package/dist/standalone/channel-session-door.js +72 -0
  63. package/dist/standalone/computer-egress.d.ts +5 -3
  64. package/dist/standalone/computer-egress.js +1 -1
  65. package/dist/standalone/hello-app.d.ts +9 -0
  66. package/dist/standalone/hello-app.js +78 -0
  67. package/dist/standalone/install-apps-cli.d.ts +2 -1
  68. package/dist/standalone/install-apps-cli.js +36 -14
  69. package/dist/standalone/instance.js +2 -2
  70. package/dist/standalone/local-desktop.d.ts +11 -0
  71. package/dist/standalone/local-desktop.js +75 -0
  72. package/dist/standalone/owner-routes.d.ts +4 -3
  73. package/dist/standalone/owner-routes.js +7 -1
  74. package/dist/standalone/registry.d.ts +2 -0
  75. package/dist/standalone/sign-in-link.d.ts +9 -0
  76. package/dist/standalone/sign-in-link.js +49 -0
  77. package/dist/standalone/try-cli.d.ts +52 -0
  78. package/dist/standalone/try-cli.js +404 -0
  79. package/dist/standalone/visitor-edge.d.ts +36 -0
  80. package/dist/standalone/visitor-edge.js +67 -0
  81. package/dist/standalone/visitor-proof.d.ts +23 -0
  82. package/dist/standalone/visitor-proof.js +67 -0
  83. package/dist/standalone/website-channels.d.ts +134 -0
  84. package/dist/standalone/website-channels.js +262 -0
  85. package/dist/standalone/worker-routes.d.ts +4 -1
  86. package/dist/standalone/worker-routes.js +3 -0
  87. package/dist/standalone/worker.d.ts +2 -1
  88. package/dist/standalone/worker.js +5 -1
  89. package/dist/testing/capabilities.d.ts +3 -0
  90. package/dist/testing/capabilities.js +1 -0
  91. package/dist/testing/installation.d.ts +4 -2
  92. package/dist/testing/installation.js +7 -2
  93. package/dist/webhook-abuse.d.ts +7 -1
  94. package/dist/webhook-abuse.js +8 -2
  95. package/dist/workers-git.js +2 -2
  96. package/dist/workers.d.ts +7 -2
  97. package/dist/workers.js +1 -1
  98. package/docs/api/agents.md +103 -36
  99. package/docs/api/authorization.md +56 -11
  100. package/docs/api/browser.md +115 -8
  101. package/docs/api/build-contract.md +52 -10
  102. package/docs/api/build.md +16 -2
  103. package/docs/api/host.md +1 -0
  104. package/docs/api/pack.md +179 -3
  105. package/docs/api/workers-git.md +6 -6
  106. package/docs/site/agent-quickstart.mdx +8 -0
  107. package/package.json +34 -8
package/README.md CHANGED
@@ -18,6 +18,70 @@ raw bytes; if output exceeds 2 MiB it retains the head and tail and reports
18
18
  Deploy one Worker, run `npx oyster install-apps`, and your Oyster builds seven
19
19
  Apps on its own Computer and opens on the Tourtois desktop.
20
20
 
21
+ ## Quick start: try it on your computer
22
+
23
+ No Cloudflare account, Docker or payment. You need Node 24 or newer and Git.
24
+
25
+ ```sh
26
+ npx @fungi.computer/oyster try
27
+ ```
28
+
29
+ That creates `./my-oyster`, installs it, starts Oyster at
30
+ `http://127.0.0.1:8787`, builds the Oyster desktop (Tourtois) from its public
31
+ source, installs a one-page Hello App and opens your browser through a one-time
32
+ sign-in link (the key is never put in a URL). You land on the desktop with Hello
33
+ in the launcher; the page it opens reads **Hello from my first Oyster App**. The
34
+ owner key is saved in `my-oyster/.oyster-owner` and never printed. Press Ctrl-C
35
+ to stop, and run the same command again in `my-oyster` to restart. Use
36
+ `--port <number>` for another port and `--no-open` to keep the browser closed.
37
+ Output is quiet: install and server logs go to `my-oyster/.oyster/`, and
38
+ `--verbose` streams them instead. Piped or CI output is plain lines.
39
+
40
+ <details>
41
+ <summary>What it does under the hood</summary>
42
+
43
+ `try` runs these steps (shown for pnpm 11; with npm, skip the
44
+ `pnpm-workspace.yaml`). Wrangler is an ordinary dependency; nothing is hidden.
45
+
46
+ ```sh
47
+ mkdir my-oyster && cd my-oyster
48
+ cat > pnpm-workspace.yaml <<'YAML'
49
+ allowBuilds:
50
+ "@google/genai": false
51
+ "@mongodb-js/zstd": false
52
+ esbuild: true
53
+ exifreader: false
54
+ node-liblzma: false
55
+ protobufjs: false
56
+ workerd: true
57
+ YAML
58
+ pnpm add @fungi.computer/oyster @fungi.computer/computer react@^19.2.0 react-dom@^19.2.0
59
+ pnpm add -D wrangler
60
+ cp node_modules/@fungi.computer/oyster/examples/standalone/{worker.ts,wrangler.jsonc} .
61
+ export OYSTER_OWNER_KEY=$(openssl rand -hex 24)
62
+ echo "$OYSTER_OWNER_KEY" > .oyster-owner
63
+ npx wrangler dev --local --enable-containers=false --ip 127.0.0.1 --port 8787 \
64
+ --local-upstream oyster.test --upstream-protocol https \
65
+ --var OYSTER_OWNER_KEY:$OYSTER_OWNER_KEY --var OYSTER_ORIGIN:https://oyster.test
66
+ ```
67
+
68
+ Then it builds Tourtois from `github.com/fungi-computer/tourtois` the same way
69
+ (`src/standalone/local-desktop.ts`), and packs a committed one-page
70
+ `bundled-html` App with `packRelease` and installs it as `hello` with
71
+ `installRelease` (both from `@fungi.computer/oyster/pack`) against
72
+ `OYSTER_URL=http://127.0.0.1:8787`; the source is `src/standalone/hello-app.ts`
73
+ in this package.
74
+
75
+ </details>
76
+
77
+ Locally there is no Computer, git storage or Workers AI, so you install your own
78
+ App rather than the seven starter Apps below. The
79
+ [short quick start](https://docs.fungi.computer/oyster-quickstart/) walks the
80
+ same path; the
81
+ [agent quick start](https://docs.fungi.computer/oyster/agent-quickstart/) adds
82
+ MCP and deployment. For the full desktop, continue to the
83
+ [guide to running your own Oyster](https://docs.fungi.computer/guides/run-your-own-oyster/#deploy-it).
84
+
21
85
  ## What you get
22
86
 
23
87
  `oyster install-apps` installs these Apps. Each one lives in its own repository
@@ -63,7 +127,7 @@ git through Cloudflare Artifacts, a Computer (a Linux workspace in a Cloudflare
63
127
  Container) that builds Apps and runs their terminals and files, Agents on
64
128
  Workers AI, Workflows and media.
65
129
 
66
- ## Quick start: deploy your own Oyster
130
+ ## Deploy to Cloudflare
67
131
 
68
132
  Deciding what to run?
69
133
  [Is Oyster for you?](https://docs.fungi.computer/is-oyster-for-you/) compares
@@ -183,16 +247,12 @@ Wrangler version rather than silently adding unrelated token permissions.
183
247
 
184
248
  ### Upgrading Oyster
185
249
 
186
- Oyster's version is not Fungi's: Fungi 0.9.0 ships Oyster 0.8.2 with
187
- `@fungi.computer/computer` 0.4.2. Find the versions for each Fungi release on
188
- the
250
+ Oyster's version is not Fungi's. Find the Oyster and Computer versions for your
251
+ Fungi release on the
189
252
  [Open source page](https://docs.fungi.computer/reference/packages/#package-versions-in-each-fungi-release),
190
- then run the upgrade in your Oyster project with the same pnpm and store that
191
- installed it:
192
-
193
- ```sh
194
- pnpm add @fungi.computer/oyster@0.8.2 @fungi.computer/computer@0.4.2
195
- ```
253
+ then run the upgrade command in
254
+ [Upgrade Oyster](https://docs.fungi.computer/guides/run-your-own-oyster/#upgrade-oyster)
255
+ in your Oyster project, with the same pnpm and store that installed it.
196
256
 
197
257
  Redeploy with the same `npx wrangler deploy` command you deployed with, then run
198
258
  `npx oyster install-apps`. If pnpm stops with `ERR_PNPM_UNEXPECTED_STORE`, rerun
@@ -531,8 +591,39 @@ deploy with `wrangler deploy`. Sign in at `/login`.
531
591
  Oyster is owner-only. A browser signs in only with the owner key, through
532
592
  `/login` and its `SameSite=Strict` session cookie. Named keys sign in only by
533
593
  header (`Authorization`), for MCP, Git and the API; no cookie admits a named
534
- key. Anonymous requests reach only `/login`, `robots.txt` and digest-pinned
535
- shell and App UI bytes.
594
+ key. Anonymous requests reach only `/login`, `robots.txt`, digest-pinned shell
595
+ and App UI bytes, and the website chat described next.
596
+
597
+ ### Website chat on a separate site
598
+
599
+ Owner-only means only the owner signs in to Oyster; it does not stop you from
600
+ putting an Agent on a public website. In Settings, choose Channels, then Add
601
+ website: pick the Agent, give the address of your site and a brief, and paste
602
+ the script tag Oyster shows you into that site:
603
+
604
+ ```html
605
+ <script
606
+ src="https://your-oyster.example/embed/v1.js"
607
+ data-site="site_pk_…"
608
+ data-theme="auto"
609
+ async
610
+ ></script>
611
+ ```
612
+
613
+ Visitors are anonymous channel parties of that one Agent, never Oyster
614
+ principals, keys or App callers. They talk to the Agent itself, with its own
615
+ tools and permissions and the persona you wrote added to its instructions; they
616
+ cannot sign in to Oyster or reach your account. Each site has its own key, a
617
+ list of allowed origins, rate limits per visitor and per network address, and a
618
+ pause switch; a new site key stops the old code at once. The same page can
619
+ require a Cloudflare Turnstile check before a visitor can chat, and shows the
620
+ conversations so you can read what visitors said.
621
+
622
+ The surface is closed until you set two host secrets, each at least 32 bytes:
623
+ `OYSTER_WEBSITE_PROOF_KEY` signs a visitor's identity between the public edge
624
+ and the website Agent, and `OYSTER_WEBSITE_ADDRESS_KEY` salts the hashed network
625
+ address used for rate limits. For Turnstile, set `TURNSTILE_SITE_KEY` and
626
+ `TURNSTILE_SECRET_KEY` (or `TURNSTILE=off` for local use over `http`).
536
627
 
537
628
  The celld example is a limited trial, not the full Cloudflare setup above. It
538
629
  requires access to Fungi's private celld fork. Use
package/dist/agents.d.ts CHANGED
@@ -40,27 +40,51 @@ export type PendingAgentPolicy = Readonly<{
40
40
  status: "pending";
41
41
  revision: string;
42
42
  }>;
43
- /** One remote MCP server connected to an Agent; its bearer token is never returned. */
44
- export type AgentMcpServer = Readonly<{
45
- serverId: string;
46
- /** The guest calls this server's tools as `env.mcp.<name>.<tool>()`. */
43
+ /** What an Agent may do with one connection: everything, only reads, or named tools. */
44
+ export type ConnectionAccess = "all" | "read" | readonly string[];
45
+ /** One connection as its owner sees it; no secret, locator or token ever appears. */
46
+ export type OysterConnection = Readonly<{
47
+ connectionId: string;
48
+ /** The guest calls an MCP server's tools as `env.mcp.<name>.<tool>()`. */
47
49
  name: string;
50
+ label: string;
51
+ kind: "mcp" | "openapi";
48
52
  url: string;
49
- hasBearer: boolean;
53
+ auth: "none" | "token" | "oauth";
54
+ /** `pending` waits for the owner to sign in at the server; `reconnect_required` needs a new sign-in. */
55
+ state: "connected" | "pending" | "reconnect_required";
56
+ grants: readonly Readonly<{
57
+ agentId: string;
58
+ access: ConnectionAccess;
59
+ }>[];
50
60
  }>;
51
- /** An owner's request to connect one remote MCP server to an Agent. */
52
- export type AgentMcpServerInput = typeof agentMcpServerInputSchema.Type;
53
- /** Why connecting an MCP server was refused. */
54
- export type AgentMcpServerRefusal = Readonly<{
61
+ /** A newly added connection; `authorizeUrl` is where the owner signs in, when the server uses OAuth. */
62
+ export type ConnectionAdded = Readonly<{
63
+ connectionId: string;
64
+ authorizeUrl: string | null;
65
+ }>;
66
+ /** Why a connection change was refused. */
67
+ export type ConnectionRefusal = Readonly<{
55
68
  error: "not_found" | "duplicate_name" | "limit" | "invalid_endpoint";
56
69
  }>;
57
- /** At most this many MCP servers per Agent. */
58
- export declare const maxAgentMcpServers = 16;
59
- /** Owner input for one MCP server: a guest identifier, an `https:` endpoint and an optional bearer. */
60
- export declare const agentMcpServerInputSchema: Schema.Struct<{
70
+ /** An owner's request to connect one remote MCP server. */
71
+ export type ConnectionInput = typeof connectionInputSchema.Type;
72
+ /** At most this many connections per Agent. */
73
+ export declare const maxAgentConnections = 16;
74
+ /** Owner input for one MCP connection: a guest identifier, an `https:` endpoint and an optional bearer. */
75
+ export declare const connectionInputSchema: Schema.Struct<{
61
76
  readonly name: Schema.String;
62
77
  readonly url: Schema.String;
63
78
  readonly bearer: Schema.NullOr<Schema.String>;
79
+ /**
80
+ * Sign in at the server instead of pasting a token. Without a client the
81
+ * server's dynamic registration is used; with one, the secret is sealed.
82
+ */
83
+ readonly oauth: Schema.optional<Schema.Struct<{
84
+ readonly clientId: Schema.optional<Schema.String>;
85
+ readonly clientSecret: Schema.optional<Schema.String>;
86
+ readonly scope: Schema.optional<Schema.String>;
87
+ }>>;
64
88
  }>;
65
89
  /** This Agent's App-tool policy, in the shape Apps read it. */
66
90
  export type AgentToolPolicyStatus = Readonly<{
@@ -133,12 +157,32 @@ export type OysterAgents = Readonly<{
133
157
  }>>;
134
158
  /** Remove one key; Agents that chose it then fail with `key_removed`. */
135
159
  removeModelKey(keyId: string): Promise<"deleted" | "absent">;
136
- /** An Agent's connected MCP servers, or `null` when there is no such Agent. */
137
- mcpServers(agentId: string): Promise<readonly AgentMcpServer[] | null>;
138
- /** Connect one remote MCP server; the Agent's next run sees its tools. */
139
- addMcpServer(agentId: string, input: AgentMcpServerInput): Promise<AgentMcpServer | AgentMcpServerRefusal>;
140
- /** Disconnect one MCP server; `false` when the Agent or server is unknown. */
141
- removeMcpServer(agentId: string, serverId: string): Promise<boolean>;
160
+ /** Every connection with the Agents that may use it. */
161
+ connections(): Promise<readonly OysterConnection[]>;
162
+ /** Connect one remote MCP server; no Agent has it until the owner grants it. */
163
+ addConnection(input: ConnectionInput): Promise<ConnectionAdded | ConnectionRefusal>;
164
+ /** Give an Agent access to a connection, or change how much it has. */
165
+ grantConnection(connectionId: string, agentId: string, access: ConnectionAccess): Promise<Readonly<{
166
+ ok: true;
167
+ }> | ConnectionRefusal>;
168
+ /** End one Agent's access; `false` when it had none. */
169
+ ungrantConnection(connectionId: string, agentId: string): Promise<boolean>;
170
+ /** Disconnect for everyone; `false` when the connection is unknown. */
171
+ removeConnection(connectionId: string): Promise<boolean>;
172
+ /** The tool names an MCP connection offers, for choosing a narrower grant. */
173
+ connectionTools(connectionId: string): Promise<readonly string[] | ConnectionRefusal>;
174
+ /** Settle a sign-in: the authorization server's redirect, by state and code. */
175
+ completeMcpConnection(query: Readonly<{
176
+ state: string;
177
+ code: string;
178
+ iss: string | undefined;
179
+ }>): Promise<Readonly<{
180
+ ok: true;
181
+ }> | Readonly<{
182
+ error: string;
183
+ }>>;
184
+ /** The exact redirect URL an owner registers with an OAuth app. */
185
+ mcpCallbackUrl(): string;
142
186
  /** Serve this Agent's Shiitake and Knapsack Session browser transports. */
143
187
  fetch(agentId: string, request: Request): Promise<Response | null>;
144
188
  /** This member's Session and Workflow review rows, admitted by the host. */
@@ -158,7 +202,7 @@ export declare function agentApprovalRoutes(agents: OysterAgents): Routes<Oyster
158
202
  */
159
203
  export declare function modelKeyRoutes(agents: OysterAgents): Routes<OysterEnv>;
160
204
  /**
161
- * Host-owned Agent MCP server custody for the owner directly; never an App
162
- * capability. Bearer tokens go in and never come back out.
205
+ * Host-owned connection custody for the owner directly; never an App
206
+ * capability. Tokens go in and never come back out.
163
207
  */
164
- export declare function agentMcpServerRoutes(agents: OysterAgents): Routes<OysterEnv>;
208
+ export declare function connectionRoutes(agents: OysterAgents): Routes<OysterEnv>;
package/dist/agents.js CHANGED
@@ -5,10 +5,10 @@ import {} from "./host.js";
5
5
  import { agentAvatarSchema } from "./agent-avatars.js";
6
6
  import { computerTargetParam } from "./computer-target.js";
7
7
  import { agentAvatar, agentList, agentManage, agentRename, agentSessionRead, agentSessionWrite, agentToolPolicy, } from "@fungi.computer/agar/agents";
8
- /** At most this many MCP servers per Agent. */
9
- export const maxAgentMcpServers = 16;
10
- /** Owner input for one MCP server: a guest identifier, an `https:` endpoint and an optional bearer. */
11
- export const agentMcpServerInputSchema = Schema.Struct({
8
+ /** At most this many connections per Agent. */
9
+ export const maxAgentConnections = 16;
10
+ /** Owner input for one MCP connection: a guest identifier, an `https:` endpoint and an optional bearer. */
11
+ export const connectionInputSchema = Schema.Struct({
12
12
  name: Schema.String.check(Schema.isPattern(/^[a-z][a-z0-9_]{0,31}$/u)),
13
13
  url: Schema.String.check(Schema.isMaxLength(2_048), Schema.makeFilter((value) => {
14
14
  if (!URL.canParse(value))
@@ -22,6 +22,15 @@ export const agentMcpServerInputSchema = Schema.Struct({
22
22
  : "Use an https:// MCP endpoint without credentials or a fragment";
23
23
  })),
24
24
  bearer: Schema.NullOr(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4_096), Schema.isPattern(/^[\x21-\x7e]+$/u))),
25
+ /**
26
+ * Sign in at the server instead of pasting a token. Without a client the
27
+ * server's dynamic registration is used; with one, the secret is sealed.
28
+ */
29
+ oauth: Schema.optional(Schema.Struct({
30
+ clientId: Schema.optional(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512))),
31
+ clientSecret: Schema.optional(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(4_096), Schema.isPattern(/^[\x21-\x7e]+$/u))),
32
+ scope: Schema.optional(Schema.String.check(Schema.isMaxLength(512), Schema.isPattern(/^[\x21-\x7e ]+$/u))),
33
+ })),
25
34
  });
26
35
  const createSchema = Schema.Struct({
27
36
  name: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256)),
@@ -64,7 +73,9 @@ export function agentCapabilities(agents) {
64
73
  {
65
74
  ...shared,
66
75
  id: "agent.manage",
67
- ownerDirect: ownerAgentRoutes(agents, "direct"),
76
+ ownerDirect: routes()
77
+ .include(ownerAgentRoutes(agents, "direct"))
78
+ .include(cloudBrowserViewRoutes(agents)),
68
79
  permission: "agent.manage",
69
80
  version: agentManage.version,
70
81
  methods: {
@@ -135,6 +146,21 @@ export function agentCapabilities(agents) {
135
146
  },
136
147
  ];
137
148
  }
149
+ /**
150
+ * The person's live view of a paused cloud-browser lease: the owner, direct
151
+ * only (never an App acting for them), served by the Agent that holds the lease.
152
+ */
153
+ function cloudBrowserViewRoutes(agents) {
154
+ return routes().on(["GET", "POST"], "/agents/:agentId/cloud-browser/*", owner("direct"), async (context) => {
155
+ const agentId = context.req.param("agentId");
156
+ if (!agentIdPattern.test(agentId))
157
+ return refusal(404, "No such agent");
158
+ const incoming = context.req.raw;
159
+ const path = new URL(incoming.url).pathname.slice(`/agents/${agentId}`.length);
160
+ const response = await agents.fetch(agentId, new Request(`https://agent.internal${path}`, incoming));
161
+ return response ?? refusal(404, "No such agent");
162
+ });
163
+ }
138
164
  /** The owner capability: create, archive and restore, never Session transport. */
139
165
  function ownerAgentRoutes(agents, via) {
140
166
  return routes()
@@ -151,8 +177,8 @@ function ownerAgentRoutes(agents, via) {
151
177
  // are approved the same way direct owner approval is, with no second path.
152
178
  return Response.json(await agents.create(body.value.name, body.value.requestId, principal, "owner-direct", avatar?.data));
153
179
  })
154
- .post("/agents/:agentId/archive", owner(via), (context, { principal }) => changeArchive(agents, context.req.param("agentId"), true, principal))
155
- .post("/agents/:agentId/unarchive", owner(via), (context, { principal }) => changeArchive(agents, context.req.param("agentId"), false, principal));
180
+ .post("/agents/:agentId/archive", owner(via), (context, admission) => changeArchive(agents, context.req.param("agentId"), true, admission))
181
+ .post("/agents/:agentId/unarchive", owner(via), (context, admission) => changeArchive(agents, context.req.param("agentId"), false, admission));
156
182
  }
157
183
  function createAgentRoutes(agents) {
158
184
  return (routes()
@@ -230,9 +256,9 @@ function createAgentRoutes(agents) {
230
256
  const response = await agents.fetch(agentId, new Request(target, incoming));
231
257
  return response ?? refusal(404, "No such agent");
232
258
  })
233
- .get("/member/inbox", agentCollection(), async (_context, { authority, reaches }) => {
259
+ .get("/member/inbox", agentCollection(), async (_context, { authority, everyAgent, reaches }) => {
234
260
  const inbox = await agents.inbox();
235
- if (authority.kind === "owner")
261
+ if (everyAgent)
236
262
  return Response.json({
237
263
  items: inbox.items,
238
264
  next: null,
@@ -247,7 +273,9 @@ function createAgentRoutes(agents) {
247
273
  next: null,
248
274
  // The global revision changes for ungranted Agents too. Key feeds have
249
275
  // no scoped event stream, so expose neither that revision nor its events.
250
- cursor: 0,
276
+ // An owner's narrowed App keeps the owner's change stream, which
277
+ // announces only a `reset`, so it keeps the revision that stream resumes from.
278
+ cursor: authority.kind === "owner" ? inbox.revision : 0,
251
279
  });
252
280
  })
253
281
  .get("/member/inbox/notices", owner("direct-or-app"), () => Response.json({ items: [], next: null }))
@@ -292,9 +320,11 @@ function createAgentRoutes(agents) {
292
320
  }));
293
321
  }
294
322
  /** Owner-only archive transition; creator Agents use their own control tool. */
295
- async function changeArchive(agents, agentId, archived, principal) {
323
+ async function changeArchive(agents, agentId, archived, { principal, delegatesAgent }) {
296
324
  if (!agentIdPattern.test(agentId))
297
325
  return refusal(404, "No such agent");
326
+ if (!delegatesAgent(agentId))
327
+ return refusal(403, "Agent access denied");
298
328
  const result = await agents.setArchived(agentId, archived, principal);
299
329
  if ("error" in result)
300
330
  return Response.json(result, {
@@ -419,50 +449,110 @@ export function modelKeyRoutes(agents) {
419
449
  : refusal(404, "No such key");
420
450
  });
421
451
  }
422
- const serverIdPattern = /^[a-z0-9_-]{1,64}$/u;
423
- const mcpRefusalStatus = {
452
+ const connectionIdPattern = /^[A-Za-z0-9_.:-]{1,128}$/u;
453
+ const connectionRefusalStatus = {
424
454
  not_found: 404,
425
455
  duplicate_name: 409,
426
456
  limit: 409,
427
457
  invalid_endpoint: 400,
428
458
  };
459
+ const accessSchema = Schema.Struct({
460
+ access: Schema.Union([
461
+ Schema.Literal("all"),
462
+ Schema.Literal("read"),
463
+ Schema.Array(Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(256))).check(Schema.isMaxLength(256)),
464
+ ]),
465
+ });
429
466
  /**
430
- * Host-owned Agent MCP server custody for the owner directly; never an App
431
- * capability. Bearer tokens go in and never come back out.
467
+ * Host-owned connection custody for the owner directly; never an App
468
+ * capability. Tokens go in and never come back out.
432
469
  */
433
- export function agentMcpServerRoutes(agents) {
470
+ export function connectionRoutes(agents) {
434
471
  return (routes()
435
- // One owner read for the settings panel: every Agent with its servers.
436
- .get("/api/agent-mcp-servers", owner("direct"), async () => {
437
- const listed = await agents.list();
438
- const rows = await Promise.all(listed.map(async (item) => ({
439
- agentId: item.agentId,
440
- name: item.name,
441
- servers: (await agents.mcpServers(item.agentId)) ?? [],
442
- })));
443
- return Response.json({ agents: rows });
472
+ // One owner read for the settings panel: every connection and every Agent.
473
+ .get("/api/connections", owner("direct"), async () => {
474
+ const [connections, listed] = await Promise.all([
475
+ agents.connections(),
476
+ agents.list(),
477
+ ]);
478
+ return Response.json({
479
+ callbackUrl: agents.mcpCallbackUrl(),
480
+ agents: listed.map(({ agentId, name }) => ({ agentId, name })),
481
+ connections,
482
+ });
444
483
  })
445
- .post("/api/agent-mcp-servers/:agentId", owner("direct"), async (context) => {
446
- if (!agentIdPattern.test(context.req.param("agentId")))
447
- return refusal(404, "No such agent");
484
+ .post("/api/connections", owner("direct"), async (context) => {
448
485
  const length = Number(context.req.header("content-length") ?? "0");
449
486
  if (length > 16 * 1024)
450
487
  return refusal(413, "Request too large");
451
- const input = Schema.decodeUnknownOption(Schema.fromJsonString(agentMcpServerInputSchema), { onExcessProperty: "error" })(await context.req.text());
488
+ const input = Schema.decodeUnknownOption(Schema.fromJsonString(connectionInputSchema), { onExcessProperty: "error" })(await context.req.text());
452
489
  if (input._tag === "None")
453
490
  return refusal(400, "Name the server (lowercase letters, digits, _) and give its https:// endpoint");
454
- const added = await agents.addMcpServer(context.req.param("agentId"), input.value);
491
+ if (input.value.oauth !== undefined && input.value.bearer !== null)
492
+ return refusal(400, "Choose a token or sign-in, not both");
493
+ const added = await agents.addConnection(input.value);
455
494
  return "error" in added
456
- ? refusal(mcpRefusalStatus[added.error], added.error)
495
+ ? refusal(connectionRefusalStatus[added.error], added.error)
457
496
  : Response.json(added, { status: 201 });
458
497
  })
459
- .delete("/api/agent-mcp-servers/:agentId/:serverId", owner("direct"), async (context) => {
460
- const serverId = context.req.param("serverId");
461
- if (!agentIdPattern.test(context.req.param("agentId")) ||
462
- !serverIdPattern.test(serverId))
463
- return refusal(404, "No such server");
464
- return (await agents.removeMcpServer(context.req.param("agentId"), serverId))
498
+ // The authorization server's redirect: the owner's browser, signed in.
499
+ .get("/api/connections/callback", owner("direct"), async (context) => {
500
+ const query = context.req.query();
501
+ if (query.error !== undefined ||
502
+ query.state === undefined ||
503
+ query.code === undefined)
504
+ return refusal(400, "The sign-in was not completed");
505
+ const settled = await agents.completeMcpConnection({
506
+ state: query.state,
507
+ code: query.code,
508
+ iss: query.iss,
509
+ });
510
+ return "error" in settled
511
+ ? refusal(400, "The sign-in could not be completed")
512
+ : new Response(null, { status: 303, headers: { location: "/" } });
513
+ })
514
+ .get("/api/connections/:connectionId/tools", owner("direct"), async (context) => {
515
+ const connectionId = context.req.param("connectionId");
516
+ if (!connectionIdPattern.test(connectionId))
517
+ return refusal(404, "No such connection");
518
+ const tools = await agents.connectionTools(connectionId);
519
+ return "error" in tools
520
+ ? refusal(connectionRefusalStatus[tools.error], tools.error)
521
+ : Response.json({ tools });
522
+ })
523
+ .put("/api/connections/:connectionId/agents/:agentId", owner("direct"), async (context) => {
524
+ const connectionId = context.req.param("connectionId");
525
+ const agentId = context.req.param("agentId");
526
+ if (!connectionIdPattern.test(connectionId) ||
527
+ !agentIdPattern.test(agentId))
528
+ return refusal(404, "No such connection");
529
+ const length = Number(context.req.header("content-length") ?? "0");
530
+ if (length > 64 * 1024)
531
+ return refusal(413, "Request too large");
532
+ const input = Schema.decodeUnknownOption(Schema.fromJsonString(accessSchema), { onExcessProperty: "error" })(await context.req.text());
533
+ if (input._tag === "None")
534
+ return refusal(400, "Choose all, read, or a list of tools");
535
+ const granted = await agents.grantConnection(connectionId, agentId, input.value.access);
536
+ return "error" in granted
537
+ ? refusal(connectionRefusalStatus[granted.error], granted.error)
538
+ : new Response(null, { status: 204 });
539
+ })
540
+ .delete("/api/connections/:connectionId/agents/:agentId", owner("direct"), async (context) => {
541
+ const connectionId = context.req.param("connectionId");
542
+ const agentId = context.req.param("agentId");
543
+ if (!connectionIdPattern.test(connectionId) ||
544
+ !agentIdPattern.test(agentId))
545
+ return refusal(404, "No such connection");
546
+ return (await agents.ungrantConnection(connectionId, agentId))
547
+ ? new Response(null, { status: 204 })
548
+ : refusal(404, "No such access");
549
+ })
550
+ .delete("/api/connections/:connectionId", owner("direct"), async (context) => {
551
+ const connectionId = context.req.param("connectionId");
552
+ if (!connectionIdPattern.test(connectionId))
553
+ return refusal(404, "No such connection");
554
+ return (await agents.removeConnection(connectionId))
465
555
  ? new Response(null, { status: 204 })
466
- : refusal(404, "No such server");
556
+ : refusal(404, "No such connection");
467
557
  }));
468
558
  }
@@ -22,6 +22,7 @@ import { type BuildJobLog } from "./build/job-log.js";
22
22
  import { type Release } from "@fungi.computer/puffball";
23
23
  import { type AppPublisherCoreConfigInput } from "./build/effect.js";
24
24
  import { type TeamAppCandidateManifest } from "./build/submission-contract.js";
25
+ import { type ContentObjectOwner } from "./build/content-objects.js";
25
26
  import { type ArtifactHeads, type ArtifactStore } from "./release.js";
26
27
  import type { PublisherTemplateSeedReceipts } from "./source/seed-receipt.js";
27
28
  /** A Computer's whole-build budget: a cold build on a 6 GiB Computer measured 185-270 s. */
@@ -273,6 +274,7 @@ export declare function createOysterAppBuilds(options: OysterAppBuildOptions): R
273
274
  */
274
275
  admitObjectUpload(jobId: string, computerObjectId: string, grant: string): Promise<Readonly<{
275
276
  maxObjectBytes: number;
277
+ owner: ContentObjectOwner;
276
278
  }> | null>;
277
279
  /**
278
280
  * The Computer's candidate manifest for a live job: checked against the
@@ -25,7 +25,7 @@ import { parseArtifactRef, parseReleaseId, } from "@fungi.computer/puffball";
25
25
  import { appIdSchema, releaseSchema, sha256DigestSchema, sourceRevisionSchema, } from "@fungi.computer/puffball/effect";
26
26
  import { capturedPinnedRecipeSchema, normalizeAppPublisherRecipe, digestPinnedRecipe, fitsPinnedRecipe, pinnedRecipeObjectBound, } from "./build/effect.js";
27
27
  import { candidateManifestObjects, decodeCandidateBackend, digestTeamAppCandidateManifest, } from "./build/submission-contract.js";
28
- import { contentObjectRef } from "./build/content-objects.js";
28
+ import { contentObjectOwner, contentObjectRef, } from "./build/content-objects.js";
29
29
  import { createTeamBuildPublisher, teamAppBuildCommand, } from "./build/build-jobs.js";
30
30
  import { writeArtifactRoot, } from "./build/artifact-writer.js";
31
31
  import { buildGitPassPrefix } from "./git-auth.js";
@@ -191,6 +191,8 @@ export function createOysterAppBuilds(options) {
191
191
  read: (artifactRef) => options.artifacts.get(artifactRef),
192
192
  };
193
193
  migrateOysterAppBuilds(owner);
194
+ // This tenant's uploads, keyed apart from every other tenant's.
195
+ const objectOwner = contentObjectOwner(options.tenantId);
194
196
  // A job outlives the owner instance that started it: the Computer keeps
195
197
  // building and its own reports (objects, candidate, status) settle the
196
198
  // job, so an owner restart must not fail it. A job that reaches its expiry
@@ -611,6 +613,7 @@ export function createOysterAppBuilds(options) {
611
613
  return null;
612
614
  return {
613
615
  maxObjectBytes: pinnedRecipeObjectBound(decodeRecipe(job.recipe)),
616
+ owner: objectOwner,
614
617
  };
615
618
  },
616
619
  /**
@@ -639,15 +642,23 @@ export function createOysterAppBuilds(options) {
639
642
  if (!fitsPinnedRecipe(manifest.output, recipe))
640
643
  throw new Error("Candidate exceeds its pinned recipe");
641
644
  for (const object of candidateManifestObjects(manifest.output)) {
642
- const head = await options.artifacts.head(contentObjectRef(object.digest));
645
+ const artifactRef = contentObjectRef(objectOwner, object.digest, object.mediaType);
646
+ const head = await options.artifacts.head(artifactRef);
643
647
  if (head?.byteLength !== object.byteLength ||
644
- head.digest !== object.digest)
648
+ (head.digest !== null && head.digest !== object.digest))
645
649
  throw new Error("Candidate object is not stored as named");
650
+ // Bytes the store never checksummed (a packed upload's plain
651
+ // object) are read and hashed, one object at a time.
652
+ if (head.digest === null)
653
+ await readVerified(options.artifacts, artifactRef, object.digest);
646
654
  }
647
655
  if (manifest.output.kind !== "ui")
648
- decodeCandidateBackend(await readVerified(options.artifacts, contentObjectRef(manifest.output.backend.digest), manifest.output.backend.digest));
656
+ decodeCandidateBackend(await readVerified(options.artifacts, contentObjectRef(objectOwner, manifest.output.backend.digest, "application/vnd.fungi.app-backend+json"), manifest.output.backend.digest));
657
+ // The root is named by the manifest (one candidate, one root),
658
+ // outside the namespace uploads are stored in.
649
659
  const root = await writeArtifactRoot(manifest.output, storeObjects, {
650
- rootArtifactRef: parseArtifactRef(`artifact:sha256-${await digestTeamAppCandidateManifest(manifest)}`),
660
+ owner: objectOwner,
661
+ rootArtifactRef: parseArtifactRef(`artifact:${await digestTeamAppCandidateManifest(manifest)}`),
651
662
  assetPolicy: recipe.assets,
652
663
  });
653
664
  release = Schema.decodeUnknownSync(releaseSchema)({
@@ -659,7 +670,7 @@ export function createOysterAppBuilds(options) {
659
670
  provenance: manifest.provenance,
660
671
  },
661
672
  });
662
- // Each object was checked by its stored digest above.
673
+ // Each object was checked by its digest above.
663
674
  await verifyRelease(options.artifacts, release, defaultAssetPolicy, false);
664
675
  }
665
676
  catch {