@fungi.computer/oyster 0.8.2 → 0.10.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 (72) hide show
  1. package/README.md +34 -17
  2. package/dist/agents.d.ts +16 -1
  3. package/dist/agents.js +63 -3
  4. package/dist/apps/catalog.d.ts +11 -0
  5. package/dist/apps/catalog.js +1 -0
  6. package/dist/apps/gate.d.ts +2 -2
  7. package/dist/apps/installation.d.ts +7 -7
  8. package/dist/apps/permissions.d.ts +5 -5
  9. package/dist/boot-host-script.js +1 -1
  10. package/dist/build/candidate-cli.mjs +1 -0
  11. package/dist/computer-control-port.d.ts +20 -1
  12. package/dist/host.js +11 -4
  13. package/dist/installation-client.d.ts +6 -5
  14. package/dist/installation-client.js +21 -17
  15. package/dist/installation-execution.js +41 -8
  16. package/dist/installation-operations.d.ts +30 -8
  17. package/dist/installation-operations.js +122 -24
  18. package/dist/instance-refusal.d.ts +4 -2
  19. package/dist/instance-refusal.js +5 -1
  20. package/dist/mcp.d.ts +132 -2
  21. package/dist/mcp.js +63 -1
  22. package/dist/page/mount.d.ts +8 -1
  23. package/dist/page/mount.js +72 -6
  24. package/dist/page-script.js +3 -3
  25. package/dist/standalone/agent-computers.d.ts +12 -1
  26. package/dist/standalone/agent-computers.js +35 -0
  27. package/dist/standalone/agent-connections.d.ts +47 -0
  28. package/dist/standalone/agent-connections.js +170 -0
  29. package/dist/standalone/agent-model-choice.d.ts +7 -3
  30. package/dist/standalone/agent-model-choice.js +33 -4
  31. package/dist/standalone/agents.d.ts +70 -9
  32. package/dist/standalone/agents.js +187 -110
  33. package/dist/standalone/app-set.js +6 -7
  34. package/dist/standalone/browser.d.ts +4 -3
  35. package/dist/standalone/browser.js +4 -3
  36. package/dist/standalone/computer-control.js +55 -1
  37. package/dist/standalone/computer-fleet.d.ts +29 -2
  38. package/dist/standalone/computer-fleet.js +51 -23
  39. package/dist/standalone/computer.d.ts +20 -1
  40. package/dist/standalone/computer.js +63 -1
  41. package/dist/standalone/model-key-vault.d.ts +50 -0
  42. package/dist/standalone/model-key-vault.js +147 -0
  43. package/dist/standalone/registry.d.ts +23 -0
  44. package/dist/standalone/registry.js +39 -0
  45. package/dist/standalone/web.d.ts +10 -0
  46. package/dist/standalone/web.js +34 -0
  47. package/dist/standalone/worker-routes.d.ts +3 -1
  48. package/dist/standalone/worker-routes.js +1 -0
  49. package/dist/standalone/worker.js +9 -1
  50. package/dist/standalone/workflow-host.d.ts +5 -5
  51. package/dist/standalone/workflow-trigger-host.d.ts +1 -1
  52. package/dist/web/index.d.ts +3 -0
  53. package/dist/web/index.js +3 -0
  54. package/dist/web/search-contract.d.ts +19 -0
  55. package/dist/web/search-contract.js +14 -0
  56. package/dist/web/search.d.ts +25 -0
  57. package/dist/web/search.js +123 -0
  58. package/dist/web/source.d.ts +46 -0
  59. package/dist/web/source.js +335 -0
  60. package/dist/workers-git.js +2 -1
  61. package/docs/api/agents.md +81 -3
  62. package/docs/api/apps.md +160 -142
  63. package/docs/api/build-contract.md +27 -21
  64. package/docs/api/build.md +55 -54
  65. package/docs/api/git.md +3 -3
  66. package/docs/api/host.md +226 -60
  67. package/docs/api/mcp.md +83 -44
  68. package/docs/api/page/mount.md +6 -1
  69. package/docs/api/workers-git.md +6 -6
  70. package/docs/api/workers.md +53 -47
  71. package/docs/site/agent-quickstart.mdx +4 -2
  72. package/package.json +27 -22
@@ -20,16 +20,18 @@ import { memberInboxItemSchema } from "@fungi.computer/puffball/inbox";
20
20
  import { agentDirectoryForScope } from "./agent-directory.js";
21
21
  import { createAgentComputers, } from "../agent-computers.js";
22
22
  import { createAgentComputerSource, readAgentComputerConnections, } from "../agent-computer-source.js";
23
- import { standaloneAgentComputerPorts, } from "./agent-computers.js";
23
+ import { standaloneAgentComputerPorts, standaloneBrowserSave, } from "./agent-computers.js";
24
24
  import { FleetGrantRefused, } from "@fungi.computer/computer/fleet";
25
25
  import { homeExtension, homeGrant, } from "@fungi.computer/shiitake-extensions/home/host";
26
26
  import { homeContract } from "@fungi.computer/shiitake-extensions/home";
27
27
  import { DurableObject } from "cloudflare:workers";
28
28
  import { ShiitakeDO } from "@fungi.computer/shiitake/cloudflare";
29
29
  import { agentStoreKeeping } from "./agent-store.js";
30
+ import { createInstanceCredentialStore, createModelKeyVault, ModelKeyRefused, } from "./model-key-vault.js";
30
31
  import { agentArchiveOwner } from "./agent-archive-owner.js";
31
32
  import { agentArchiveProjection } from "../agent-archive-projection.js";
32
33
  import { standaloneBrowserSource } from "./browser.js";
34
+ import { standaloneWebSource } from "./web.js";
33
35
  import { configuredProviderEgress, providerFetch, } from "@fungi.computer/veil/gatekeeper";
34
36
  import { createAssistantMessageEventStream } from "@earendil-works/pi-ai/utils/event-stream";
35
37
  import { agentModelChoice, agentModelChoiceSchema, AgentModelRefused, selectAgentModel, } from "./agent-model-choice.js";
@@ -43,7 +45,6 @@ import { agentScheduleBindingArgs, appAgentScheduleListInputSchema, agentSchedul
43
45
  import { readAgentSchedulePage, controlAgentSchedule, } from "@fungi.computer/shiitake-extensions/schedules/client";
44
46
  import { agentScheduleTargetSchema } from "@fungi.computer/shiitake-extensions/schedules";
45
47
  import { createAgentAvatarStore, } from "../agent-avatars.js";
46
- import { defineIdFamily } from "@fungi.computer/cairn";
47
48
  import { agentIds, createAgentDirectory, createFleetSessions, commandSettlementSchema, DirectoryError, } from "@fungi.computer/shiitake/fleet";
48
49
  import { appToolPolicySchema } from "../apps/index.js";
49
50
  import { oysterPrincipalId } from "../host.js";
@@ -51,7 +52,6 @@ import { oysterPrincipalIsOwner } from "../authorization.js";
51
52
  import { defaultTenant, tenantIdSchema, tenantScope, } from "../tenant.js";
52
53
  import { createCodemodeSandbox } from "@fungi.computer/mycelium/workers";
53
54
  import { forageDiscoveryInstructions } from "@fungi.computer/mycelium/effect";
54
- import { maxAgentMcpServers, } from "../agents.js";
55
55
  /** Own transport evidence and exact-message decisions for one model lease. */
56
56
  function observedModels(model, defaults) {
57
57
  return {
@@ -191,39 +191,6 @@ const policyDirectorySchema = Schema.Struct({
191
191
  directoryName: Schema.NonEmptyString,
192
192
  tenantId: tenantIdSchema,
193
193
  });
194
- /** This Agent's remote MCP servers; the bearer stays in this Durable Object. */
195
- const storedMcpServersSchema = Schema.Array(Schema.Struct({
196
- serverId: Schema.NonEmptyString,
197
- name: Schema.NonEmptyString,
198
- url: Schema.NonEmptyString,
199
- bearer: Schema.NullOr(Schema.NonEmptyString),
200
- }));
201
- const mcpServersKey = "agent-mcp-servers";
202
- const mcpServerIds = defineIdFamily({
203
- family: "oyster-mcp",
204
- version: 1,
205
- kinds: { server: { prefix: "mcp" } },
206
- });
207
- /** The Knapsack connection for one stored server; its bearer goes only to that endpoint. */
208
- function mcpConnection(server) {
209
- const connection = {
210
- id: `mcp.${server.serverId}`,
211
- name: server.name,
212
- url: new URL(server.url),
213
- };
214
- if (server.bearer === null)
215
- return connection;
216
- return {
217
- ...connection,
218
- headers: { authorization: `Bearer ${server.bearer}` },
219
- };
220
- }
221
- const toMcpServer = (stored) => ({
222
- serverId: stored.serverId,
223
- name: stored.name,
224
- url: stored.url,
225
- hasBearer: stored.bearer !== null,
226
- });
227
194
  const instructions = [
228
195
  forageDiscoveryInstructions,
229
196
  "Attached Computers are independent env.computers.<name> modules, including their Files and execute operations; no App is needed. Discover their exact operations before calling.",
@@ -304,22 +271,25 @@ export class StandaloneAgentBase extends ShiitakeDO {
304
271
  for (const invalidate of this.computerInvalidations)
305
272
  invalidate();
306
273
  }
274
+ computerAccess() {
275
+ return {
276
+ computer: (computerId) => this.env.COMPUTER.getByName(computerId),
277
+ admit: async (captured) => {
278
+ const pin = await this.policyDirectory();
279
+ if (pin?.directoryName !== captured.scopeId)
280
+ throw new FleetGrantRefused();
281
+ return this.env.AGENT_DIRECTORY.getByName(pin.directoryName).admitAgentComputer({
282
+ scopeId: captured.scopeId,
283
+ agentId: captured.agentId,
284
+ attachment: captured.attachment,
285
+ }, pin.tenantId);
286
+ },
287
+ };
288
+ }
307
289
  computerConnections() {
308
290
  return {
309
291
  read: () => this.computerSnapshot,
310
- connect: (connection) => standaloneAgentComputerPorts({
311
- computer: (computerId) => this.env.COMPUTER.getByName(computerId),
312
- admit: async (captured) => {
313
- const pin = await this.policyDirectory();
314
- if (pin?.directoryName !== captured.scopeId)
315
- throw new FleetGrantRefused();
316
- return this.env.AGENT_DIRECTORY.getByName(pin.directoryName).admitAgentComputer({
317
- scopeId: captured.scopeId,
318
- agentId: captured.agentId,
319
- attachment: captured.attachment,
320
- }, pin.tenantId);
321
- },
322
- }, connection),
292
+ connect: (connection) => standaloneAgentComputerPorts(this.computerAccess(), connection),
323
293
  };
324
294
  }
325
295
  /** Revalidate the owner's generation before reusing a Home or tool snapshot. */
@@ -590,8 +560,39 @@ export class StandaloneAgentBase extends ShiitakeDO {
590
560
  ? this.hostFor(scope)
591
561
  : null;
592
562
  }
563
+ /** The instance directory that owns this Agent's sealed model keys. */
564
+ async keyDirectory() {
565
+ const pin = await this.policyDirectory();
566
+ if (pin === null)
567
+ throw new AgentModelRefused("key_not_connected");
568
+ return this.env.AGENT_DIRECTORY.getByName(pin.directoryName);
569
+ }
570
+ /** The instance directory that owns this Agent's MCP connections and their credentials. */
571
+ async mcpDirectory() {
572
+ const pin = await this.policyDirectory();
573
+ if (pin === null)
574
+ throw new Error("Agent directory is unavailable");
575
+ return this.env.AGENT_DIRECTORY.getByName(pin.directoryName);
576
+ }
577
+ agentName() {
578
+ const name = this.ctx.id.name;
579
+ if (name === undefined)
580
+ throw new Error("Agent has no name");
581
+ return name;
582
+ }
583
+ /** A byok choice must name a stored key of the chosen provider. */
584
+ async admitKey(choice) {
585
+ if (choice.keySource !== "byok" || choice.keyId === undefined)
586
+ return;
587
+ const record = await (await this.keyDirectory()).modelKey(choice.keyId);
588
+ if (record === null)
589
+ throw new AgentModelRefused("key_removed");
590
+ if (record.provider !== choice.model.providerId)
591
+ throw new AgentModelRefused("key_source_mismatch");
592
+ }
593
593
  choice() {
594
- return agentModelChoice(this.ctx.storage, (choice) => {
594
+ return agentModelChoice(this.ctx.storage, async (choice) => {
595
+ await this.admitKey(choice);
595
596
  if (choice.keySource === "ai-gateway" &&
596
597
  configuredProviderEgress(this.env).baseUrl("ai-gateway") === null)
597
598
  throw new AgentModelRefused("key_not_connected");
@@ -640,6 +641,32 @@ export class StandaloneAgentBase extends ShiitakeDO {
640
641
  }
641
642
  async sourceFor(choice) {
642
643
  const modelChoice = await selectAgentModel(choice);
644
+ if (choice.keySource === "byok" && choice.keyId !== undefined) {
645
+ await this.admitKey(choice);
646
+ const directory = await this.keyDirectory();
647
+ const keyId = choice.keyId;
648
+ const streamOptions = {
649
+ // Pi needs some credential to build its request; the vault replaces it.
650
+ apiKey: "oyster-model-key",
651
+ fetch: async (input, init) => {
652
+ const request = new Request(input, init);
653
+ const sent = await directory.sendModelKey(keyId, {
654
+ url: request.url,
655
+ method: request.method,
656
+ headers: [...request.headers],
657
+ body: request.body === null ? null : await request.text(),
658
+ });
659
+ if (!(sent instanceof Response))
660
+ throw new AgentModelRefused(sent.error === "key_removed"
661
+ ? "key_removed"
662
+ : "key_not_connected");
663
+ return sent;
664
+ },
665
+ };
666
+ if (choice.model.reasoning !== undefined)
667
+ streamOptions.reasoning = choice.model.reasoning;
668
+ return observedModels(normalizeModel(modelChoice), streamOptions);
669
+ }
643
670
  if (choice.keySource === "ai-gateway") {
644
671
  const egress = configuredProviderEgress(this.env);
645
672
  const baseUrl = egress.baseUrl("ai-gateway");
@@ -712,50 +739,16 @@ export class StandaloneAgentBase extends ShiitakeDO {
712
739
  }
713
740
  /** Listeners from live codemode acquisitions, told when the server list changes. */
714
741
  mcpInvalidations = new Set();
715
- async storedMcpServers() {
716
- const stored = await this.ctx.storage.get(mcpServersKey);
717
- return stored === undefined
718
- ? []
719
- : Schema.decodeUnknownSync(storedMcpServersSchema)(stored);
720
- }
721
- async writeMcpServers(servers) {
722
- await this.ctx.storage.put(mcpServersKey, servers);
742
+ /** Host-only: the directory told us this Agent's connections changed. */
743
+ invalidateMcpConnections() {
723
744
  for (const invalidate of this.mcpInvalidations)
724
745
  invalidate();
725
746
  }
726
- /** Host-only: this Agent's MCP servers, without their bearer tokens. */
727
- async mcpServers() {
728
- return (await this.storedMcpServers()).map(toMcpServer);
729
- }
730
- /** Host-only: connect one remote MCP server, admitted by the owner route. */
731
- async addMcpServer(input) {
732
- const servers = await this.storedMcpServers();
733
- if (servers.some((server) => server.name === input.name))
734
- return { error: "duplicate_name" };
735
- if (servers.length >= maxAgentMcpServers)
736
- return { error: "limit" };
737
- const added = {
738
- serverId: mcpServerIds.server.generate(),
739
- name: input.name,
740
- url: new URL(input.url).href,
741
- bearer: input.bearer,
742
- };
743
- await this.writeMcpServers([...servers, added]);
744
- return toMcpServer(added);
745
- }
746
- /** Host-only: disconnect one MCP server. */
747
- async removeMcpServer(serverId) {
748
- const servers = await this.storedMcpServers();
749
- const kept = servers.filter((server) => server.serverId !== serverId);
750
- if (kept.length === servers.length)
751
- return false;
752
- await this.writeMcpServers(kept);
753
- return true;
754
- }
755
747
  async shiitakeOptions() {
756
- const [{ oysterAgentExtensions }, { Knapsack }] = await Promise.all([
748
+ const [{ oysterAgentExtensions }, { Knapsack }, { agentMcpSourceOptions, mcpRequestData },] = await Promise.all([
757
749
  import("@fungi.computer/shiitake-extensions/roster/conversation-agents"),
758
750
  import("@fungi.computer/knapsack"),
751
+ import("./agent-connections.js"),
759
752
  ]);
760
753
  const conversationAgents = await this.conversationAgents();
761
754
  const computerSource = createAgentComputerSource({
@@ -810,16 +803,8 @@ export class StandaloneAgentBase extends ShiitakeDO {
810
803
  return computerSource.acquire(context);
811
804
  },
812
805
  },
813
- Knapsack.mcpServers({
814
- id: "agent-mcp",
815
- read: async () => {
816
- const servers = await this.storedMcpServers();
817
- return {
818
- // Secret-free: ids and endpoints, never the bearer.
819
- version: JSON.stringify(servers.map((server) => [server.serverId, server.url])),
820
- servers: servers.map(mcpConnection),
821
- };
822
- },
806
+ Knapsack.mcpServers(agentMcpSourceOptions({
807
+ read: async () => (await this.mcpDirectory()).mcpProjection(this.agentName()),
823
808
  subscribe: (invalidate) => {
824
809
  this.mcpInvalidations.add(invalidate);
825
810
  return () => this.mcpInvalidations.delete(invalidate);
@@ -830,15 +815,24 @@ export class StandaloneAgentBase extends ShiitakeDO {
830
815
  reason: error.reason,
831
816
  });
832
817
  },
833
- // The Worker's own egress: public internet only.
834
- fetch: (url, init) => fetch(url, init),
835
- }),
818
+ // Completed by the owner, which holds the credential.
819
+ fetch: async (ref, request) => {
820
+ const answer = await (await this.mcpDirectory()).mcpFetch(this.agentName(), ref, await mcpRequestData(request));
821
+ if ("error" in answer)
822
+ throw new Error(`MCP connection refused: ${answer.error}`);
823
+ return answer;
824
+ },
825
+ })),
836
826
  conversationAgents.control(() => this.controlDirectory()),
837
827
  (await this.ui()).source,
828
+ standaloneWebSource(this.env),
838
829
  standaloneBrowserSource(this.env.BROWSER, () => ({
839
830
  teamId: this.env.OYSTER_ORIGIN,
840
831
  agentId: principal.actor.agentId,
841
- })),
832
+ }), standaloneBrowserSave({
833
+ admit: this.computerAccess().admit,
834
+ write: (computerId, grant, path, bytes) => this.env.COMPUTER.getByName(computerId).fileWrite(grant, path, bytes),
835
+ }, () => this.computerSnapshot)),
842
836
  ],
843
837
  sandbox: createCodemodeSandbox(this.env.LOADER, "oyster-workerd"),
844
838
  },
@@ -955,6 +949,84 @@ export class AgentDirectory extends DurableObject {
955
949
  archived(agentId) {
956
950
  return this.archiveProjection().archived(agentId);
957
951
  }
952
+ modelKeys() {
953
+ const storage = this.ctx.storage;
954
+ return createModelKeyVault({
955
+ credentialKey: this.env.OYSTER_CREDENTIAL_KEY,
956
+ storage: credentialStorage(storage),
957
+ });
958
+ }
959
+ /** Domain refusals cross the DO RPC boundary as data, not as Error prototypes. */
960
+ async sealModelKey(input) {
961
+ try {
962
+ return await this.modelKeys().seal(input);
963
+ }
964
+ catch (error) {
965
+ if (error instanceof ModelKeyRefused)
966
+ return { error: error.reason };
967
+ throw error;
968
+ }
969
+ }
970
+ listModelKeys() {
971
+ return this.modelKeys().list();
972
+ }
973
+ modelKey(keyId) {
974
+ return this.modelKeys().get(keyId);
975
+ }
976
+ removeModelKey(keyId) {
977
+ return this.modelKeys().remove(keyId);
978
+ }
979
+ /** Host-only: the one place a stored key meets a provider request. */
980
+ async sendModelKey(keyId, request) {
981
+ try {
982
+ return await this.modelKeys().send(keyId, new Request(request.url, {
983
+ method: request.method,
984
+ headers: request.headers.map(([name, value]) => [name, value]),
985
+ body: request.body,
986
+ }));
987
+ }
988
+ catch (error) {
989
+ if (error instanceof ModelKeyRefused)
990
+ return { error: error.reason };
991
+ throw error;
992
+ }
993
+ }
994
+ mcpOwner;
995
+ /** Loaded on the first MCP request: the SDK and OpenAPI decoders stay out of startup. */
996
+ async mcpConnections() {
997
+ const { createAgentMcpConnections } = await import("./agent-connections.js");
998
+ const storage = this.ctx.storage;
999
+ return (this.mcpOwner ??= createAgentMcpConnections({
1000
+ ownerId: this.ctx.id.name ?? "agents",
1001
+ store: storage,
1002
+ vault: createInstanceCredentialStore({
1003
+ credentialKey: this.env.OYSTER_CREDENTIAL_KEY,
1004
+ storage: credentialStorage(storage),
1005
+ }),
1006
+ // The Worker's own egress: public internet only.
1007
+ send: (request) => fetch(request),
1008
+ hasAgent: (agentId) => this.has(agentId),
1009
+ notify: (agentId) => this.env.AGENTS.getByName(agentId).invalidateMcpConnections(),
1010
+ }));
1011
+ }
1012
+ /** Host-only: an Agent's granted MCP servers, never their credentials. */
1013
+ async mcpServers(agentId) {
1014
+ return (await this.mcpConnections()).servers(agentId);
1015
+ }
1016
+ async addMcpServer(agentId, input) {
1017
+ return (await this.mcpConnections()).add(agentId, input);
1018
+ }
1019
+ async removeMcpServer(agentId, serverId) {
1020
+ return (await this.mcpConnections()).remove(agentId, serverId);
1021
+ }
1022
+ /** Secret-free grants for one Agent: ids, versions and endpoints. */
1023
+ async mcpProjection(agentId) {
1024
+ return (await this.mcpConnections()).projection(agentId);
1025
+ }
1026
+ /** Host-only: complete one Agent MCP request; the credential opens only here. */
1027
+ async mcpFetch(agentId, ref, request) {
1028
+ return (await this.mcpConnections()).fetch(agentId, ref, request);
1029
+ }
958
1030
  computers;
959
1031
  computerNames = new Map();
960
1032
  directory;
@@ -1560,6 +1632,13 @@ export class AgentDirectory extends DurableObject {
1560
1632
  this.ctx.storage.sql.exec("INSERT INTO counters(name, value) VALUES('revision', 1) ON CONFLICT(name) DO UPDATE SET value=value+1");
1561
1633
  }
1562
1634
  }
1635
+ /** The directory's Durable Object storage as the credential store's key-value port. */
1636
+ const credentialStorage = (storage) => ({
1637
+ get: (key) => storage.get(key),
1638
+ put: (key, value) => storage.put(key, value),
1639
+ delete: (key) => storage.delete(key),
1640
+ list: async (prefix) => new Map(await storage.list({ prefix })),
1641
+ });
1563
1642
  const everyOperation = [
1564
1643
  "agent.read",
1565
1644
  "agent.send",
@@ -1631,6 +1710,9 @@ export function standaloneAgents(env, scope) {
1631
1710
  return { error: "not_found" };
1632
1711
  return env.AGENTS.getByName(agentId).setModelChoice(choice);
1633
1712
  },
1713
+ modelKeys: () => directory().listModelKeys(),
1714
+ sealModelKey: (input) => directory().sealModelKey(input),
1715
+ removeModelKey: (keyId) => directory().removeModelKey(keyId),
1634
1716
  policyStatus: async (agentId) => directory().policyStatus(agentId),
1635
1717
  appToolPolicy: (actor) => directory().appToolPolicy(actor, scope?.tenantId ?? defaultTenant),
1636
1718
  policyRevision: (agentId) => directory().policyRevision(agentId),
@@ -1643,14 +1725,9 @@ export function standaloneAgents(env, scope) {
1643
1725
  return { error: "not_found" };
1644
1726
  return directory().approveAppToolPolicy(agentId, principal, level, expectedRevision, actor, scope?.tenantId ?? defaultTenant);
1645
1727
  },
1646
- mcpServers: async (agentId) => (await directory().has(agentId))
1647
- ? await env.AGENTS.getByName(agentId).mcpServers()
1648
- : null,
1649
- addMcpServer: async (agentId, input) => (await directory().has(agentId))
1650
- ? await env.AGENTS.getByName(agentId).addMcpServer(input)
1651
- : { error: "not_found" },
1652
- removeMcpServer: async (agentId, serverId) => (await directory().has(agentId)) &&
1653
- (await env.AGENTS.getByName(agentId).removeMcpServer(serverId)),
1728
+ mcpServers: (agentId) => directory().mcpServers(agentId),
1729
+ addMcpServer: (agentId, input) => directory().addMcpServer(agentId, input),
1730
+ removeMcpServer: (agentId, serverId) => directory().removeMcpServer(agentId, serverId),
1654
1731
  fetch: async (agentId, request) => {
1655
1732
  const home = await directory().agentHome(agentId);
1656
1733
  if (home?.kind === "machine") {
@@ -5,6 +5,7 @@ import { setTimeout as sleep } from "node:timers/promises";
5
5
  import * as Option from "effect/Option";
6
6
  import * as Schema from "effect/Schema";
7
7
  import { olderOysterStoreCode } from "../older-oyster-store.js";
8
+ import { installationNotAppliedMessage } from "../instance-refusal.js";
8
9
  import { publishSource } from "../pack.js";
9
10
  import { appBuildRecipe, readBuildManifest } from "../build/workspace-build.js";
10
11
  import { parseSourceRevision } from "@fungi.computer/puffball";
@@ -311,21 +312,19 @@ export async function installStandaloneAppSet(options) {
311
312
  if (release.appId !== next.app.appId)
312
313
  throw new Error(`${name} build belongs to another App`);
313
314
  const installStarted = performance.now();
314
- let installation = {
315
+ const operation = await installOnOyster({
315
316
  url: options.url,
316
317
  key: options.key,
317
318
  release,
318
319
  installationId: name,
319
320
  signal: AbortSignal.timeout(options.waitMs ?? appBuildWaitMs),
320
- idle,
321
- };
322
- if (options.pollMs !== undefined)
323
- installation = { ...installation, pollMs: options.pollMs };
324
- const operation = await installOnOyster(installation);
321
+ });
325
322
  if (operation.state === "unconfirmed")
326
323
  throw new InstallationObservationError(operation.requestId);
327
324
  if (operation.state === "refused")
328
- throw new Error(`${name} installation refused (${operation.code})`);
325
+ throw new Error(operation.code === "installation_not_applied"
326
+ ? `${name}: ${installationNotAppliedMessage}`
327
+ : `${name} installation refused (${operation.code})`);
329
328
  const record = operation.installation;
330
329
  if (record === null)
331
330
  throw new Error(`${name} completed installation version is unavailable`);
@@ -1,11 +1,12 @@
1
1
  import type { CapabilitySource } from "@fungi.computer/mycelium";
2
- import { type BrowserBinding } from "../browser/index.js";
2
+ import { type BrowserBinding, type SaveBrowserFile } from "../browser/index.js";
3
3
  /**
4
4
  * The agent's `cloudBrowser` tool on a standalone Oyster, or an empty source
5
5
  * when the deployment declares no BROWSER binding. Driven sessions only: no
6
- * Quick Reads, no Computer save, no member handoff on this host.
6
+ * Quick Reads and no member handoff on this host. Screenshots and PDFs save
7
+ * to an attached Computer through `saveFile`.
7
8
  */
8
9
  export declare function standaloneBrowserSource(binding: BrowserBinding | undefined, identity: () => Readonly<{
9
10
  teamId: string;
10
11
  agentId: string;
11
- }>): CapabilitySource;
12
+ }>, saveFile: SaveBrowserFile): CapabilitySource;
@@ -44,9 +44,10 @@ function standaloneBrowser(binding) {
44
44
  /**
45
45
  * The agent's `cloudBrowser` tool on a standalone Oyster, or an empty source
46
46
  * when the deployment declares no BROWSER binding. Driven sessions only: no
47
- * Quick Reads, no Computer save, no member handoff on this host.
47
+ * Quick Reads and no member handoff on this host. Screenshots and PDFs save
48
+ * to an attached Computer through `saveFile`.
48
49
  */
49
- export function standaloneBrowserSource(binding, identity) {
50
+ export function standaloneBrowserSource(binding, identity, saveFile) {
50
51
  if (binding === undefined)
51
52
  return {
52
53
  id: "cloud-browser",
@@ -66,7 +67,7 @@ export function standaloneBrowserSource(binding, identity) {
66
67
  },
67
68
  },
68
69
  quickReads: false,
69
- saveFile: null,
70
+ saveFile,
70
71
  requestHandoff: null,
71
72
  });
72
73
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { computerStateSchema, } from "@fungi.computer/computer/fleet";
2
+ import { computerBackendViewSchema, computerStateSchema, } from "@fungi.computer/computer/fleet";
3
3
  import { teamComputerDirectorySchema } from "@fungi.computer/nacre/workbench";
4
4
  const inventoryComputer = z.strictObject({
5
5
  computerId: z.string(),
@@ -14,6 +14,26 @@ const inventoryPage = z.strictObject({
14
14
  const inventoryError = z.strictObject({
15
15
  error: z.string(),
16
16
  });
17
+ const backendList = z.strictObject({
18
+ backends: z.array(computerBackendViewSchema),
19
+ });
20
+ const attachedBackend = z.strictObject({ backendId: z.string() });
21
+ const detachedBackend = z.strictObject({ detached: z.boolean() });
22
+ /** A typed refusal from the owner-admitted fleet, as the MCP result kinds. */
23
+ function refusedKind(result) {
24
+ const error = inventoryError.safeParse(result);
25
+ if (!error.success)
26
+ return undefined;
27
+ switch (error.data.error) {
28
+ case "request_conflict":
29
+ return "conflict";
30
+ case "invalid":
31
+ case "not_enabled":
32
+ return "invalid";
33
+ default:
34
+ return "denied";
35
+ }
36
+ }
17
37
  /** MCP control speaks to the same owner-admitted durable fleet as HTTP. */
18
38
  export function standaloneComputerControl(registry, memberId) {
19
39
  const fleet = (request) => registry.computerFleet(memberId, request);
@@ -58,5 +78,39 @@ export function standaloneComputerControl(registry, memberId) {
58
78
  computer: { computerId: computer.computerId, name: computer.name },
59
79
  };
60
80
  },
81
+ backends: async (computerId) => backendList.parse(available(await fleet({ operation: "backends", computerId }))).backends,
82
+ attachLocal: async (input) => {
83
+ let result;
84
+ try {
85
+ result = await fleet({ operation: "attach-local", request: input });
86
+ }
87
+ catch {
88
+ // The attachment may have committed; the caller retries its requestId.
89
+ return { kind: "uncertain" };
90
+ }
91
+ if (result === null)
92
+ return { kind: "denied" };
93
+ const refused = refusedKind(result);
94
+ if (refused !== undefined)
95
+ return { kind: refused };
96
+ return { kind: "attached", ...attachedBackend.parse(result) };
97
+ },
98
+ detachLocal: async (input) => {
99
+ let result;
100
+ try {
101
+ result = await fleet({ operation: "detach-local", request: input });
102
+ }
103
+ catch {
104
+ return { kind: "uncertain" };
105
+ }
106
+ if (result === null)
107
+ return { kind: "denied" };
108
+ const refused = refusedKind(result);
109
+ if (refused === "conflict")
110
+ return { kind: "uncertain" };
111
+ if (refused !== undefined)
112
+ return { kind: refused };
113
+ return { kind: "detached", ...detachedBackend.parse(result) };
114
+ },
61
115
  };
62
116
  }
@@ -27,10 +27,37 @@ export declare const standaloneFleetRequestSchema: z.ZodDiscriminatedUnion<[z.Zo
27
27
  }>;
28
28
  computerId: z.ZodString;
29
29
  }, z.core.$strict>, z.ZodObject<{
30
- operation: z.ZodLiteral<"read-internet-access">;
30
+ operation: z.ZodLiteral<"backends">;
31
31
  computerId: z.ZodString;
32
32
  }, z.core.$strict>, z.ZodObject<{
33
- operation: z.ZodLiteral<"set-internet-access">;
33
+ operation: z.ZodLiteral<"attach-local">;
34
+ request: z.ZodObject<{
35
+ computerId: z.ZodString;
36
+ publicKey: z.ZodBase64;
37
+ hostLabel: z.ZodLazy<z.ZodString>;
38
+ folderLabel: z.ZodLazy<z.ZodString>;
39
+ requestId: z.ZodString;
40
+ }, z.core.$strict>;
41
+ }, z.core.$strict>, z.ZodObject<{
42
+ operation: z.ZodLiteral<"detach-local">;
43
+ request: z.ZodUnion<readonly [z.ZodLazy<z.ZodObject<{
44
+ computerId: z.ZodString;
45
+ backendId: z.ZodString;
46
+ }, z.core.$strict>>, z.ZodObject<{
47
+ computerId: z.ZodString;
48
+ requestId: z.ZodString;
49
+ }, z.core.$strict>]>;
50
+ }, z.core.$strict>, z.ZodObject<{
51
+ operation: z.ZodEnum<{
52
+ "read-internet-access": "read-internet-access";
53
+ "read-keep-awake": "read-keep-awake";
54
+ }>;
55
+ computerId: z.ZodString;
56
+ }, z.core.$strict>, z.ZodObject<{
57
+ operation: z.ZodEnum<{
58
+ "set-internet-access": "set-internet-access";
59
+ "set-keep-awake": "set-keep-awake";
60
+ }>;
34
61
  computerId: z.ZodString;
35
62
  enabled: z.ZodBoolean;
36
63
  }, z.core.$strict>], "operation">;