@fungi.computer/oyster 0.9.0 → 0.11.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 (96) hide show
  1. package/README.md +46 -2
  2. package/dist/agents.d.ts +82 -23
  3. package/dist/agents.js +187 -40
  4. package/dist/authorization.d.ts +25 -3
  5. package/dist/authorization.js +47 -14
  6. package/dist/browser/capability-source.d.ts +23 -5
  7. package/dist/browser/capability-source.js +19 -22
  8. package/dist/browser/index.d.ts +2 -1
  9. package/dist/browser/index.js +1 -0
  10. package/dist/browser/live-view.d.ts +38 -0
  11. package/dist/browser/live-view.js +179 -0
  12. package/dist/channels/binding.d.ts +2 -0
  13. package/dist/channels/run-decision.d.ts +33 -0
  14. package/dist/channels/run-decision.js +25 -0
  15. package/dist/channels/visitor-channel.d.ts +84 -14
  16. package/dist/channels/visitor-channel.js +55 -32
  17. package/dist/channels/visitor-edge.d.ts +18 -2
  18. package/dist/channels/visitor-edge.js +67 -5
  19. package/dist/channels/visitors.d.ts +4 -0
  20. package/dist/channels/visitors.js +22 -1
  21. package/dist/channels/web-binding.d.ts +117 -0
  22. package/dist/channels/web-binding.js +227 -0
  23. package/dist/computer-control-port.d.ts +20 -1
  24. package/dist/embed-metafiles.d.ts +8 -0
  25. package/dist/embed-metafiles.js +2 -0
  26. package/dist/embed-scripts.d.ts +8 -0
  27. package/dist/embed-scripts.js +3 -0
  28. package/dist/host.d.ts +3 -1
  29. package/dist/host.js +6 -1
  30. package/dist/mcp.d.ts +128 -0
  31. package/dist/mcp.js +63 -1
  32. package/dist/page/embed-challenge.d.ts +19 -0
  33. package/dist/page/embed-challenge.js +45 -0
  34. package/dist/page/embed-error.d.ts +2 -0
  35. package/dist/page/embed-error.js +16 -0
  36. package/dist/page/embed-loader-protocol.d.ts +12 -0
  37. package/dist/page/embed-loader-protocol.js +29 -0
  38. package/dist/standalone/agent-computers.d.ts +12 -1
  39. package/dist/standalone/agent-computers.js +35 -0
  40. package/dist/standalone/agent-connections.d.ts +50 -0
  41. package/dist/standalone/agent-connections.js +214 -0
  42. package/dist/standalone/agent-model-choice.d.ts +7 -3
  43. package/dist/standalone/agent-model-choice.js +33 -4
  44. package/dist/standalone/agents.d.ts +224 -9
  45. package/dist/standalone/agents.js +485 -115
  46. package/dist/standalone/browser.d.ts +16 -3
  47. package/dist/standalone/browser.js +54 -5
  48. package/dist/standalone/channel-session-door.d.ts +4 -0
  49. package/dist/standalone/channel-session-door.js +72 -0
  50. package/dist/standalone/computer-control.js +55 -1
  51. package/dist/standalone/computer-fleet.d.ts +21 -0
  52. package/dist/standalone/computer-fleet.js +30 -6
  53. package/dist/standalone/computer.d.ts +20 -1
  54. package/dist/standalone/computer.js +63 -1
  55. package/dist/standalone/model-key-vault.d.ts +50 -0
  56. package/dist/standalone/model-key-vault.js +147 -0
  57. package/dist/standalone/owner-routes.d.ts +4 -3
  58. package/dist/standalone/owner-routes.js +7 -1
  59. package/dist/standalone/registry.d.ts +23 -0
  60. package/dist/standalone/registry.js +30 -0
  61. package/dist/standalone/visitor-edge.d.ts +36 -0
  62. package/dist/standalone/visitor-edge.js +67 -0
  63. package/dist/standalone/visitor-proof.d.ts +23 -0
  64. package/dist/standalone/visitor-proof.js +67 -0
  65. package/dist/standalone/web.d.ts +10 -0
  66. package/dist/standalone/web.js +34 -0
  67. package/dist/standalone/website-channels.d.ts +134 -0
  68. package/dist/standalone/website-channels.js +262 -0
  69. package/dist/standalone/worker-routes.d.ts +6 -1
  70. package/dist/standalone/worker-routes.js +4 -0
  71. package/dist/standalone/worker.d.ts +2 -1
  72. package/dist/standalone/worker.js +13 -1
  73. package/dist/testing/capabilities.d.ts +3 -0
  74. package/dist/testing/capabilities.js +1 -0
  75. package/dist/testing/installation.d.ts +4 -2
  76. package/dist/testing/installation.js +7 -2
  77. package/dist/web/index.d.ts +3 -0
  78. package/dist/web/index.js +3 -0
  79. package/dist/web/search-contract.d.ts +19 -0
  80. package/dist/web/search-contract.js +14 -0
  81. package/dist/web/search.d.ts +25 -0
  82. package/dist/web/search.js +123 -0
  83. package/dist/web/source.d.ts +46 -0
  84. package/dist/web/source.js +335 -0
  85. package/dist/workers-git.js +3 -2
  86. package/docs/api/agents.md +184 -39
  87. package/docs/api/apps.md +129 -111
  88. package/docs/api/browser.md +115 -8
  89. package/docs/api/build-contract.md +27 -21
  90. package/docs/api/build.md +55 -54
  91. package/docs/api/git.md +3 -3
  92. package/docs/api/host.md +69 -60
  93. package/docs/api/mcp.md +81 -44
  94. package/docs/api/workers-git.md +6 -6
  95. package/docs/api/workers.md +53 -47
  96. package/package.json +52 -22
package/dist/host.d.ts CHANGED
@@ -16,7 +16,7 @@ export type { GuestLimits } from "./guest-policy.js";
16
16
  import { type TimingVariables } from "hono/timing";
17
17
  import * as Schema from "effect/Schema";
18
18
  import { type BackgroundSyncRefusal } from "@fungi.computer/puffball/background-replay";
19
- import { type Installation, type InstallationReader } from "./apps/installation.js";
19
+ import { type ApprovedGrant, type Installation, type InstallationReader } from "./apps/installation.js";
20
20
  import { type ResourceOption } from "./apps/permissions.js";
21
21
  import type { AppToolPolicy } from "./apps/tools.js";
22
22
  import type { LiveOysterKey } from "./keys.js";
@@ -144,6 +144,8 @@ export type CapabilityAdmission = Readonly<{
144
144
  principal: TenantPrincipal;
145
145
  /** The enabled installation the gate admitted for this capability. */
146
146
  installation: Installation;
147
+ /** The installation's approved grant for this capability: its operations and selected resources. */
148
+ grant: ApprovedGrant;
147
149
  }>;
148
150
  /** Capability routes read the host's admission from `c.env`; they never authenticate. */
149
151
  export type CapabilityEnv = {
package/dist/host.js CHANGED
@@ -492,8 +492,13 @@ export function oysterRouteTable(host) {
492
492
  : "write",
493
493
  }).kind === "refused")
494
494
  continue;
495
+ // The route names its exact resource; the table decides it within this
496
+ // grant's selection, never the principal's wider reach alone.
497
+ const grant = grantsFor(facts.installation, facts.declaration, facts.declaredOperations, capability.permission);
498
+ if (grant === null)
499
+ continue;
495
500
  url.pathname = `/${url.pathname.slice(capability.base.length)}`;
496
- return capabilityTable(capability).fetch(new Request(url, context.req.raw), { principal, installation });
501
+ return capabilityTable(capability).fetch(new Request(url, context.req.raw), { principal, installation, grant });
497
502
  }
498
503
  return refusal(403, "Capability permission denied");
499
504
  };
package/dist/mcp.d.ts CHANGED
@@ -3,6 +3,7 @@ import { type AppToolPolicy } from "./apps/tools.js";
3
3
  import type { DeclaredOperations, Installation } from "./apps/installation.js";
4
4
  import { type CapabilitySource, type Grants, type ModuleRegistration } from "@fungi.computer/mycelium";
5
5
  import { computerPageSchema } from "@fungi.computer/computer/fleet/inventory-wire";
6
+ import { localBackendDetachSchema } from "@fungi.computer/computer/fleet/wire";
6
7
  import type { InvocationContext } from "@fungi.computer/mycelium";
7
8
  import type { ComputerControlPort } from "./computer-control-port.js";
8
9
  export type { ComputerControlPort } from "./computer-control-port.js";
@@ -25,6 +26,57 @@ declare const fleetCreate: z.ZodObject<{
25
26
  name: z.ZodDefault<z.ZodNullable<z.ZodString>>;
26
27
  requestId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
27
28
  }, z.core.$strict>;
29
+ declare const fleetBackends: z.ZodObject<{
30
+ backends: z.ZodArray<z.ZodObject<{
31
+ id: z.ZodString;
32
+ kind: z.ZodEnum<{
33
+ "platform-container": "platform-container";
34
+ "on-box-vm": "on-box-vm";
35
+ local: "local";
36
+ }>;
37
+ status: z.ZodEnum<{
38
+ ready: "ready";
39
+ online: "online";
40
+ offline: "offline";
41
+ queued: "queued";
42
+ }>;
43
+ queuePosition: z.ZodNullable<z.ZodNumber>;
44
+ hostId: z.ZodNullable<z.ZodString>;
45
+ hostLabel: z.ZodNullable<z.ZodString>;
46
+ folderLabel: z.ZodNullable<z.ZodString>;
47
+ detachable: z.ZodBoolean;
48
+ }, z.core.$strict>>;
49
+ }, z.core.$strict>;
50
+ declare const fleetAttachInput: z.ZodObject<{
51
+ computerId: z.ZodString;
52
+ publicKey: z.ZodBase64;
53
+ hostLabel: z.ZodLazy<z.ZodString>;
54
+ folderLabel: z.ZodLazy<z.ZodString>;
55
+ requestId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
56
+ }, z.core.$strict>;
57
+ declare const fleetAttachment: z.ZodDiscriminatedUnion<[z.ZodObject<{
58
+ kind: z.ZodLiteral<"attached">;
59
+ requestId: z.ZodString;
60
+ backendId: z.ZodString;
61
+ }, z.core.$strict>, z.ZodObject<{
62
+ kind: z.ZodEnum<{
63
+ invalid: "invalid";
64
+ denied: "denied";
65
+ uncertain: "uncertain";
66
+ conflict: "conflict";
67
+ }>;
68
+ requestId: z.ZodString;
69
+ }, z.core.$strict>], "kind">;
70
+ declare const fleetDetachment: z.ZodDiscriminatedUnion<[z.ZodObject<{
71
+ kind: z.ZodLiteral<"detached">;
72
+ detached: z.ZodBoolean;
73
+ }, z.core.$strict>, z.ZodObject<{
74
+ kind: z.ZodEnum<{
75
+ invalid: "invalid";
76
+ denied: "denied";
77
+ uncertain: "uncertain";
78
+ }>;
79
+ }, z.core.$strict>], "kind">;
28
80
  declare const fleetCreation: z.ZodDiscriminatedUnion<[z.ZodObject<{
29
81
  kind: z.ZodLiteral<"created">;
30
82
  requestId: z.ZodString;
@@ -148,6 +200,82 @@ export declare function computerControlSpecs(port: ComputerControlPort): {
148
200
  /** Mint one identity or preserve the requestId for an uncertain retry. */
149
201
  execute: (input: z.output<typeof fleetCreate>, context: InvocationContext) => Promise<z.output<typeof fleetCreation>>;
150
202
  };
203
+ backends: {
204
+ replay: "safe";
205
+ description: string;
206
+ input: z.ZodObject<{
207
+ computerId: z.ZodString;
208
+ }, z.core.$strict>;
209
+ output: z.ZodObject<{
210
+ backends: z.ZodArray<z.ZodObject<{
211
+ id: z.ZodString;
212
+ kind: z.ZodEnum<{
213
+ "platform-container": "platform-container";
214
+ "on-box-vm": "on-box-vm";
215
+ local: "local";
216
+ }>;
217
+ status: z.ZodEnum<{
218
+ ready: "ready";
219
+ online: "online";
220
+ offline: "offline";
221
+ queued: "queued";
222
+ }>;
223
+ queuePosition: z.ZodNullable<z.ZodNumber>;
224
+ hostId: z.ZodNullable<z.ZodString>;
225
+ hostLabel: z.ZodNullable<z.ZodString>;
226
+ folderLabel: z.ZodNullable<z.ZodString>;
227
+ detachable: z.ZodBoolean;
228
+ }, z.core.$strict>>;
229
+ }, z.core.$strict>;
230
+ /** Return the attached list without waking any backend. */
231
+ execute: (input: z.output<typeof fleetComputerId>, context: InvocationContext) => Promise<z.output<typeof fleetBackends>>;
232
+ };
233
+ attachLocal: {
234
+ replay: "unsafe";
235
+ description: string;
236
+ input: z.ZodObject<{
237
+ computerId: z.ZodString;
238
+ publicKey: z.ZodBase64;
239
+ hostLabel: z.ZodLazy<z.ZodString>;
240
+ folderLabel: z.ZodLazy<z.ZodString>;
241
+ requestId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
242
+ }, z.core.$strict>;
243
+ output: z.ZodDiscriminatedUnion<[z.ZodObject<{
244
+ kind: z.ZodLiteral<"attached">;
245
+ requestId: z.ZodString;
246
+ backendId: z.ZodString;
247
+ }, z.core.$strict>, z.ZodObject<{
248
+ kind: z.ZodEnum<{
249
+ invalid: "invalid";
250
+ denied: "denied";
251
+ uncertain: "uncertain";
252
+ conflict: "conflict";
253
+ }>;
254
+ requestId: z.ZodString;
255
+ }, z.core.$strict>], "kind">;
256
+ /** Mint one identity or preserve the requestId for an uncertain retry. */
257
+ execute: (input: z.output<typeof fleetAttachInput>, context: InvocationContext) => Promise<z.output<typeof fleetAttachment>>;
258
+ };
259
+ detachLocal: {
260
+ replay: "unsafe";
261
+ description: string;
262
+ input: z.ZodLazy<z.ZodObject<{
263
+ computerId: z.ZodString;
264
+ backendId: z.ZodString;
265
+ }, z.core.$strict>>;
266
+ output: z.ZodDiscriminatedUnion<[z.ZodObject<{
267
+ kind: z.ZodLiteral<"detached">;
268
+ detached: z.ZodBoolean;
269
+ }, z.core.$strict>, z.ZodObject<{
270
+ kind: z.ZodEnum<{
271
+ invalid: "invalid";
272
+ denied: "denied";
273
+ uncertain: "uncertain";
274
+ }>;
275
+ }, z.core.$strict>], "kind">;
276
+ /** Close the attachment and its live connection; a gone one settles. */
277
+ execute: (input: z.output<typeof localBackendDetachSchema>, context: InvocationContext) => Promise<z.output<typeof fleetDetachment>>;
278
+ };
151
279
  };
152
280
  /** An installation ID as a guest binding name: `spawn-git` becomes `SPAWN_GIT`. */
153
281
  export declare function appBindingName(installationId: string): string;
package/dist/mcp.js CHANGED
@@ -15,6 +15,7 @@ import { Knapsack } from "@fungi.computer/knapsack";
15
15
  import * as Schema from "effect/Schema";
16
16
  import { defineIdFamily } from "@fungi.computer/cairn/id";
17
17
  import { computerCreateRequestSchema, computerPageSchema, } from "@fungi.computer/computer/fleet/inventory-wire";
18
+ import { computerBackendViewSchema, localBackendAttachSchema, localBackendDetachSchema, } from "@fungi.computer/computer/fleet/wire";
18
19
  import { computerStateSchema } from "@fungi.computer/computer/fleet/wire";
19
20
  import { teamComputerDirectorySchema } from "@fungi.computer/nacre/workbench";
20
21
  import { appToolAccess, authorityOf, hostAuthorityPorts, } from "./authorization.js";
@@ -48,6 +49,31 @@ const fleetComputer = z.strictObject({
48
49
  computerId: z.string(),
49
50
  name: z.string(),
50
51
  });
52
+ const fleetBackends = z.strictObject({
53
+ backends: z.array(computerBackendViewSchema),
54
+ });
55
+ const fleetAttachInput = z.strictObject({
56
+ computerId: localBackendAttachSchema.shape.computerId,
57
+ publicKey: localBackendAttachSchema.shape.publicKey,
58
+ hostLabel: localBackendAttachSchema.shape.hostLabel,
59
+ folderLabel: localBackendAttachSchema.shape.folderLabel,
60
+ requestId: localBackendAttachSchema.shape.requestId.nullable().default(null),
61
+ });
62
+ const fleetAttachment = z.discriminatedUnion("kind", [
63
+ z.strictObject({
64
+ kind: z.literal("attached"),
65
+ requestId: z.string(),
66
+ backendId: z.string(),
67
+ }),
68
+ z.strictObject({
69
+ kind: z.enum(["uncertain", "denied", "conflict", "invalid"]),
70
+ requestId: z.string(),
71
+ }),
72
+ ]);
73
+ const fleetDetachment = z.discriminatedUnion("kind", [
74
+ z.strictObject({ kind: z.literal("detached"), detached: z.boolean() }),
75
+ z.strictObject({ kind: z.enum(["denied", "uncertain", "invalid"]) }),
76
+ ]);
51
77
  const fleetCreation = z.discriminatedUnion("kind", [
52
78
  z.strictObject({
53
79
  kind: z.literal("created"),
@@ -100,6 +126,36 @@ export function computerControlSpecs(port) {
100
126
  return { ...result, requestId };
101
127
  },
102
128
  },
129
+ backends: {
130
+ replay: "safe",
131
+ description: "List one Computer's attached execution backends (platform container, on-box VM, members' machines) with live status.",
132
+ input: fleetComputerId,
133
+ output: fleetBackends,
134
+ /** Return the attached list without waking any backend. */
135
+ execute: async (input, context) => ({
136
+ backends: await port.backends(input.computerId, context),
137
+ }),
138
+ },
139
+ attachLocal: {
140
+ replay: "unsafe",
141
+ description: "Attach this authenticated member's machine to a Computer as an execution backend. Send only the device public key and labels; the folder path and private key stay on the machine. Retry an uncertain outcome with its returned requestId.",
142
+ input: fleetAttachInput,
143
+ output: fleetAttachment,
144
+ /** Mint one identity or preserve the requestId for an uncertain retry. */
145
+ execute: async (input, context) => {
146
+ const requestId = input.requestId ?? fleetIds.request.generate();
147
+ const result = await port.attachLocal({ ...input, requestId }, context);
148
+ return { ...result, requestId };
149
+ },
150
+ },
151
+ detachLocal: {
152
+ replay: "unsafe",
153
+ description: "Detach a machine this member attached from a Computer. Its live connection closes and the Computer keeps its files. Safe to retry.",
154
+ input: localBackendDetachSchema,
155
+ output: fleetDetachment,
156
+ /** Close the attachment and its live connection; a gone one settles. */
157
+ execute: (input, context) => port.detachLocal(input, context),
158
+ },
103
159
  };
104
160
  }
105
161
  /** Mints the requestId a tool family tool sends on the caller's behalf to its
@@ -388,7 +444,10 @@ export async function oysterAppSnapshot(host, surfaces, principal, installations
388
444
  fences[id] = await sha256(new TextEncoder().encode(JSON.stringify({
389
445
  installation,
390
446
  generation,
391
- principal,
447
+ // The canonical caller facts, never the raw principal: a resolver may
448
+ // carry extra registry fields (membershipVersion) that the submit-time
449
+ // principal lacks, which would fence a legitimate approval.
450
+ caller,
392
451
  access: captured,
393
452
  api,
394
453
  family: familyFacts,
@@ -552,6 +611,9 @@ export function oysterMcpCatalogLoad(host) {
552
611
  ...fleetSpecs.create,
553
612
  confirm: true,
554
613
  }),
614
+ backends: Mycelium.operation(fleetSpecs.backends),
615
+ attachLocal: Mycelium.operation(fleetSpecs.attachLocal),
616
+ detachLocal: Mycelium.operation(fleetSpecs.detachLocal),
555
617
  },
556
618
  }),
557
619
  ],
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The Turnstile check a site can require before it mints a visitor. The
3
+ * embed document carries the public site key only when the owner asked for the
4
+ * check and the host holds its keys; the token goes back with the first mint.
5
+ */
6
+ type Turnstile = {
7
+ render(container: HTMLElement, options: {
8
+ sitekey: string;
9
+ callback: (token: string) => void;
10
+ "error-callback": () => void;
11
+ }): string;
12
+ remove(widgetId: string): void;
13
+ };
14
+ declare global {
15
+ var turnstile: Turnstile | undefined;
16
+ }
17
+ /** Show the check over the chat until it passes, then hand back its token. */
18
+ export declare function requestChallenge(siteKey: string): Promise<string>;
19
+ export {};
@@ -0,0 +1,45 @@
1
+ const scriptUrl = "https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit";
2
+ function loadTurnstile() {
3
+ const loaded = globalThis.turnstile;
4
+ if (loaded !== undefined)
5
+ return Promise.resolve(loaded);
6
+ return new Promise((resolve, reject) => {
7
+ const script = document.createElement("script");
8
+ script.src = scriptUrl;
9
+ script.async = true;
10
+ script.addEventListener("load", () => {
11
+ const api = globalThis.turnstile;
12
+ if (api === undefined)
13
+ reject(new Error("turnstile_unavailable"));
14
+ else
15
+ resolve(api);
16
+ });
17
+ script.addEventListener("error", () => {
18
+ reject(new Error("turnstile_unavailable"));
19
+ });
20
+ document.head.append(script);
21
+ });
22
+ }
23
+ /** Show the check over the chat until it passes, then hand back its token. */
24
+ export async function requestChallenge(siteKey) {
25
+ const api = await loadTurnstile();
26
+ const surface = document.createElement("div");
27
+ surface.setAttribute("aria-label", "Security check");
28
+ surface.className =
29
+ "fixed inset-0 z-10 flex items-center justify-center bg-base-100";
30
+ document.body.append(surface);
31
+ try {
32
+ return await new Promise((resolve, reject) => {
33
+ api.render(surface, {
34
+ sitekey: siteKey,
35
+ callback: resolve,
36
+ "error-callback": () => {
37
+ reject(new Error("turnstile_failed"));
38
+ },
39
+ });
40
+ });
41
+ }
42
+ finally {
43
+ surface.remove();
44
+ }
45
+ }
@@ -0,0 +1,2 @@
1
+ /** Report a widget failure without writing exception messages or visitor data. */
2
+ export declare function reportEmbedCatchFailure(operation: string, cause: unknown): void;
@@ -0,0 +1,16 @@
1
+ function describeCause(cause, depth = 0) {
2
+ if (!(cause instanceof Error))
3
+ return { kind: "non-error" };
4
+ const description = { kind: "error" };
5
+ if (cause.cause !== undefined && depth < 3)
6
+ description.cause = describeCause(cause.cause, depth + 1);
7
+ return description;
8
+ }
9
+ /** Report a widget failure without writing exception messages or visitor data. */
10
+ export function reportEmbedCatchFailure(operation, cause) {
11
+ console.error(JSON.stringify({
12
+ event: "hub_catch_failure",
13
+ operation,
14
+ cause: describeCause(cause),
15
+ }));
16
+ }
@@ -0,0 +1,12 @@
1
+ import * as z from "zod";
2
+ /** The parent accepts this constant only from its own iframe and serving origin. */
3
+ export declare const CLOSE_MESSAGE = "fungi-embed:close";
4
+ /** Decode the snippet's presentation choice; absent means the visitor's OS. */
5
+ export declare function parseEmbedTheme(value: string | undefined): "auto" | "light" | "dark" | null;
6
+ declare const siteThemeSchema: z.ZodObject<{
7
+ accent: z.ZodNullable<z.ZodString>;
8
+ originAllowed: z.ZodBoolean;
9
+ }, z.core.$strict>;
10
+ /** Decode the bounded public accent, without taking host-page CSS or fonts. */
11
+ export declare function parseSiteTheme(body: string): z.infer<typeof siteThemeSchema> | null;
12
+ export {};
@@ -0,0 +1,29 @@
1
+ import * as Schema from "effect/Schema";
2
+ import * as Option from "effect/Option";
3
+ import * as z from "zod";
4
+ /** The parent accepts this constant only from its own iframe and serving origin. */
5
+ export const CLOSE_MESSAGE = "fungi-embed:close";
6
+ const embedThemeSchema = z.enum(["light", "dark", "auto"]).default("auto");
7
+ /** Decode the snippet's presentation choice; absent means the visitor's OS. */
8
+ export function parseEmbedTheme(value) {
9
+ const parsed = embedThemeSchema.safeParse(value);
10
+ return parsed.success ? parsed.data : null;
11
+ }
12
+ const decodeJson = Schema.decodeUnknownOption(Schema.fromJsonString(Schema.Json));
13
+ const siteThemeSchema = z.strictObject({
14
+ accent: z
15
+ .string()
16
+ .regex(/^#[0-9a-f]{6}$/iu)
17
+ .nullable(),
18
+ originAllowed: z.boolean(),
19
+ });
20
+ /** Decode the bounded public accent, without taking host-page CSS or fonts. */
21
+ export function parseSiteTheme(body) {
22
+ if (body.length > 128)
23
+ return null;
24
+ const decoded = decodeJson(body);
25
+ if (Option.isNone(decoded))
26
+ return null;
27
+ const parsed = siteThemeSchema.safeParse(decoded.value);
28
+ return parsed.success ? parsed.data : null;
29
+ }
@@ -1,7 +1,8 @@
1
1
  import type { TenantPrincipal } from "../tenant.js";
2
2
  import { type ComputerGrant } from "@fungi.computer/computer/fleet";
3
3
  import { type AgentComputerProjection, type ComputerAttachmentInput } from "../agent-computers.js";
4
- import type { AgentComputerConnection, AgentComputerPorts } from "../agent-computer-source.js";
4
+ import type { SaveBrowserFile } from "../browser/index.js";
5
+ import type { AgentComputerConnection, AgentComputerPorts, AgentComputerSnapshot } from "../agent-computer-source.js";
5
6
  import { type OysterEnv } from "../host.js";
6
7
  import { type Routes } from "../authorization.js";
7
8
  import type { StandaloneAgentComputerRpc } from "./computer.js";
@@ -10,6 +11,16 @@ export type StandaloneAgentComputerAccess = Readonly<{
10
11
  admit: (connection: AgentComputerConnection) => Promise<ComputerGrant>;
11
12
  computer: (computerId: string) => Rpc.Provider<StandaloneAgentComputerRpc>;
12
13
  }>;
14
+ /**
15
+ * `cloudBrowser.screenshot`/`pdf` bytes go straight to one attached Computer's
16
+ * file system, never through the model. The destination must be a Computer in
17
+ * the Agent's current attachments, and the directory re-admits it for
18
+ * `files.writeBytes` on every save, so a detached or revoked Computer refuses.
19
+ */
20
+ export declare function standaloneBrowserSave(access: Readonly<{
21
+ admit: StandaloneAgentComputerAccess["admit"];
22
+ write: (computerId: string, grant: ComputerGrant, path: string, bytes: Uint8Array) => Promise<void>;
23
+ }>, read: () => AgentComputerSnapshot | null): SaveBrowserFile;
13
24
  /** Native operations use the captured Computer, never the mutable workspace selection. */
14
25
  export declare function standaloneAgentComputerPorts(access: StandaloneAgentComputerAccess, connection: AgentComputerConnection): AgentComputerPorts;
15
26
  /** Persisted command outcome, with no fabricated attachment result on refusal. */
@@ -4,6 +4,41 @@ import { computerCapabilities, computerValueSchema, } from "@fungi.computer/comp
4
4
  import { attachComputerInputSchema, detachComputerInputSchema, readAgentComputersInputSchema, } from "../agent-computers.js";
5
5
  import {} from "../host.js";
6
6
  import { owner, routes as routeTable } from "../authorization.js";
7
+ /** A save named a Computer this Agent is not attached to, or the directory refused it. */
8
+ class BrowserSaveDenied extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "BrowserSaveDenied";
12
+ }
13
+ }
14
+ /**
15
+ * `cloudBrowser.screenshot`/`pdf` bytes go straight to one attached Computer's
16
+ * file system, never through the model. The destination must be a Computer in
17
+ * the Agent's current attachments, and the directory re-admits it for
18
+ * `files.writeBytes` on every save, so a detached or revoked Computer refuses.
19
+ */
20
+ export function standaloneBrowserSave(access, read) {
21
+ return async ({ computerId, path, bytes }) => {
22
+ const snapshot = read();
23
+ const attachment = snapshot?.projection.attachments.find((candidate) => candidate.computerId === computerId);
24
+ if (snapshot === null || attachment === undefined)
25
+ throw new BrowserSaveDenied(`${computerId} is not a Computer this Agent is attached to`);
26
+ const grant = await access.admit({
27
+ scopeId: snapshot.scopeId,
28
+ agentId: snapshot.agentId,
29
+ attachment,
30
+ admission: () => attachment.admission,
31
+ });
32
+ if (checkComputerGrant(grant, {
33
+ computerId,
34
+ action: "files.writeBytes",
35
+ now: Date.now(),
36
+ }).kind !== "admitted")
37
+ throw new FleetGrantRefused();
38
+ await access.write(computerId, grant, path, bytes);
39
+ return { computerId, path, bytes: bytes.byteLength };
40
+ };
41
+ }
7
42
  /** Native operations use the captured Computer, never the mutable workspace selection. */
8
43
  export function standaloneAgentComputerPorts(access, connection) {
9
44
  const { computerId } = connection.attachment;
@@ -0,0 +1,50 @@
1
+ import type { McpServersConnectionOptions } from "@fungi.computer/knapsack";
2
+ import { createSealedCustody, type ConnectionProjection, type EgressRef, type McpRefusal, type McpRequestData, type SqlStore } from "@fungi.computer/veil/connections";
3
+ import { type ConnectionAccess, type ConnectionAdded, type ConnectionInput, type ConnectionRefusal, type OysterConnection } from "../agents.js";
4
+ /**
5
+ * This instance's Agent MCP connections over Veil's connections core. The
6
+ * owner holds every credential; an Agent receives a secret-free projection and
7
+ * a fetch that only the owner side can complete.
8
+ */
9
+ export declare function createAgentMcpConnections(options: {
10
+ store: SqlStore;
11
+ vault: Parameters<typeof createSealedCustody>[0]["vault"];
12
+ /** The checked public transport; credentials ride only on this one hop. */
13
+ send: (request: Request) => Promise<Response>;
14
+ hasAgent: (agentId: string) => boolean;
15
+ /** Told after a change so the Agent drops captured tools. */
16
+ notify: (agentId: string) => Promise<void>;
17
+ ownerId: string;
18
+ /** Where an authorization server returns the owner; shown to them to register their own app. */
19
+ callbackUrl: string;
20
+ }): {
21
+ list: () => Promise<readonly OysterConnection[]>;
22
+ add: (input: ConnectionInput) => Promise<ConnectionAdded | ConnectionRefusal>;
23
+ grant: (connectionId: string, agentId: string, access: ConnectionAccess) => Promise<Readonly<{
24
+ ok: true;
25
+ }> | ConnectionRefusal>;
26
+ ungrant: (connectionId: string, agentId: string) => Promise<boolean>;
27
+ remove: (connectionId: string) => Promise<boolean>;
28
+ tools: (connectionId: string) => Promise<readonly string[] | ConnectionRefusal>;
29
+ complete: (query: {
30
+ state: string;
31
+ code: string;
32
+ iss: string | undefined;
33
+ }) => Promise<Readonly<{
34
+ ok: true;
35
+ }> | McpRefusal>;
36
+ projection: (agentId: string) => Promise<ConnectionProjection>;
37
+ fetch: (agentId: string, ref: EgressRef, data: McpRequestData) => Promise<Response | Readonly<{
38
+ error: string;
39
+ }>>;
40
+ };
41
+ /**
42
+ * The Agent half: Knapsack connects to each granted server through a fetch that
43
+ * is completed by the owner. No header, token or locator is ever held here.
44
+ */
45
+ export declare function agentMcpSourceOptions(input: {
46
+ read: () => Promise<ConnectionProjection>;
47
+ subscribe: McpServersConnectionOptions["subscribe"];
48
+ onUnavailable: McpServersConnectionOptions["onUnavailable"];
49
+ fetch: (ref: EgressRef, request: Request) => Promise<Response>;
50
+ }): McpServersConnectionOptions;