@finalai/agent-provider 0.9.0 → 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 (200) hide show
  1. package/HOSTING.md +334 -245
  2. package/README.md +93 -14
  3. package/dist/modules/canonical-json.d.mts +4 -0
  4. package/dist/modules/canonical-json.mjs +33 -0
  5. package/dist/modules/canonical-json.mjs.map +7 -0
  6. package/dist/modules/channel.d.mts +0 -3
  7. package/dist/modules/channel.mjs.map +1 -1
  8. package/dist/modules/code-host/host.d.mts +10 -0
  9. package/dist/modules/code-host/host.mjs +88 -0
  10. package/dist/modules/code-host/host.mjs.map +7 -0
  11. package/dist/modules/code-host/in-process.d.mts +24 -0
  12. package/dist/modules/code-host/in-process.mjs +89 -0
  13. package/dist/modules/code-host/in-process.mjs.map +7 -0
  14. package/dist/modules/code-host/index.d.mts +4 -0
  15. package/dist/modules/code-host/index.mjs +5 -0
  16. package/dist/modules/code-host/index.mjs.map +7 -0
  17. package/dist/modules/code-host/serverless.d.mts +63 -0
  18. package/dist/modules/code-host/serverless.mjs +27 -0
  19. package/dist/modules/code-host/serverless.mjs.map +7 -0
  20. package/dist/modules/code-host/types.d.mts +152 -0
  21. package/dist/modules/code-host/types.mjs +85 -0
  22. package/dist/modules/code-host/types.mjs.map +7 -0
  23. package/dist/modules/conformance/agent.mjs +72 -6
  24. package/dist/modules/conformance/agent.mjs.map +2 -2
  25. package/dist/modules/conformance/harness-kit.d.mts +9 -2
  26. package/dist/modules/conformance/harness-kit.mjs +224 -63
  27. package/dist/modules/conformance/harness-kit.mjs.map +3 -3
  28. package/dist/modules/conformance/local-harness.d.mts +1 -4
  29. package/dist/modules/conformance/local-harness.mjs +21 -22
  30. package/dist/modules/conformance/local-harness.mjs.map +2 -2
  31. package/dist/modules/conformance/protocol.d.mts +1 -0
  32. package/dist/modules/conformance/protocol.mjs +2 -0
  33. package/dist/modules/conformance/protocol.mjs.map +2 -2
  34. package/dist/modules/conformance/sandbox-kit.d.mts +12 -4
  35. package/dist/modules/conformance/sandbox-kit.mjs +189 -103
  36. package/dist/modules/conformance/sandbox-kit.mjs.map +2 -2
  37. package/dist/modules/conformance/scripted-model/chat-completions.mjs +1 -0
  38. package/dist/modules/conformance/scripted-model/chat-completions.mjs.map +2 -2
  39. package/dist/modules/conformance/scripted-model/directives.d.mts +3 -0
  40. package/dist/modules/conformance/scripted-model/directives.mjs +26 -10
  41. package/dist/modules/conformance/scripted-model/directives.mjs.map +2 -2
  42. package/dist/modules/conformance/scripted-model/messages.mjs +1 -0
  43. package/dist/modules/conformance/scripted-model/messages.mjs.map +2 -2
  44. package/dist/modules/conformance/scripted-model/responses.mjs +2 -0
  45. package/dist/modules/conformance/scripted-model/responses.mjs.map +2 -2
  46. package/dist/modules/conformance/stdio.d.mts +21 -0
  47. package/dist/modules/conformance/stdio.mjs +158 -0
  48. package/dist/modules/conformance/stdio.mjs.map +7 -0
  49. package/dist/modules/credential-routes.d.mts +2 -0
  50. package/dist/modules/credential-routes.mjs +2 -0
  51. package/dist/modules/credential-routes.mjs.map +2 -2
  52. package/dist/modules/document.d.mts +376 -0
  53. package/dist/modules/document.mjs +208 -0
  54. package/dist/modules/document.mjs.map +7 -0
  55. package/dist/modules/harness-configuration.d.mts +16 -0
  56. package/dist/modules/harness-configuration.mjs +83 -0
  57. package/dist/modules/harness-configuration.mjs.map +7 -0
  58. package/dist/modules/harness-definition.d.mts +280 -0
  59. package/dist/modules/harness-definition.mjs +430 -0
  60. package/dist/modules/harness-definition.mjs.map +7 -0
  61. package/dist/modules/harness-provider.d.mts +197 -0
  62. package/dist/modules/harness-provider.mjs +108 -0
  63. package/dist/modules/harness-provider.mjs.map +7 -0
  64. package/dist/modules/harness-requirements.d.mts +19 -0
  65. package/dist/modules/harness-requirements.mjs +40 -0
  66. package/dist/modules/harness-requirements.mjs.map +7 -0
  67. package/dist/modules/harness-start.d.mts +33 -0
  68. package/dist/modules/harness-start.mjs +107 -0
  69. package/dist/modules/harness-start.mjs.map +7 -0
  70. package/dist/modules/harness.d.mts +84 -109
  71. package/dist/modules/harness.mjs +56 -111
  72. package/dist/modules/harness.mjs.map +3 -3
  73. package/dist/modules/identity.d.mts +1 -0
  74. package/dist/modules/identity.mjs +2 -0
  75. package/dist/modules/identity.mjs.map +7 -0
  76. package/dist/modules/index.d.mts +12 -6
  77. package/dist/modules/index.mjs +12 -6
  78. package/dist/modules/index.mjs.map +2 -2
  79. package/dist/modules/inference.d.mts +35 -0
  80. package/dist/modules/inference.mjs +74 -0
  81. package/dist/modules/inference.mjs.map +7 -0
  82. package/dist/modules/local-channel-context.mjs +1 -1
  83. package/dist/modules/local-channel-context.mjs.map +2 -2
  84. package/dist/modules/requirements-check.d.mts +30 -0
  85. package/dist/modules/requirements-check.mjs +164 -0
  86. package/dist/modules/requirements-check.mjs.map +7 -0
  87. package/dist/modules/room-surface.d.mts +0 -5
  88. package/dist/modules/room-surface.mjs.map +2 -2
  89. package/dist/modules/sandbox/client.d.mts +3 -0
  90. package/dist/modules/sandbox/client.mjs +101 -18
  91. package/dist/modules/sandbox/client.mjs.map +2 -2
  92. package/dist/modules/sandbox/grant.d.mts +78 -0
  93. package/dist/modules/sandbox/grant.mjs +134 -0
  94. package/dist/modules/sandbox/grant.mjs.map +7 -0
  95. package/dist/modules/sandbox/index.d.mts +3 -3
  96. package/dist/modules/sandbox/index.mjs +4 -5
  97. package/dist/modules/sandbox/index.mjs.map +2 -2
  98. package/dist/modules/sandbox/mcp-hosted.d.mts +1 -1
  99. package/dist/modules/sandbox/mcp-hosted.mjs +4 -7
  100. package/dist/modules/sandbox/mcp-hosted.mjs.map +2 -2
  101. package/dist/modules/sandbox/mcp.d.mts +4 -2
  102. package/dist/modules/sandbox/mcp.mjs +14 -7
  103. package/dist/modules/sandbox/mcp.mjs.map +2 -2
  104. package/dist/modules/sandbox/memory-sandbox.d.mts +2 -1
  105. package/dist/modules/sandbox/memory-sandbox.mjs +71 -41
  106. package/dist/modules/sandbox/memory-sandbox.mjs.map +2 -2
  107. package/dist/modules/sandbox/networking.d.mts +7 -7
  108. package/dist/modules/sandbox/networking.mjs +16 -9
  109. package/dist/modules/sandbox/networking.mjs.map +2 -2
  110. package/dist/modules/sandbox/remote/adapter.d.mts +30 -0
  111. package/dist/modules/sandbox/remote/adapter.mjs +381 -0
  112. package/dist/modules/sandbox/remote/adapter.mjs.map +7 -0
  113. package/dist/modules/sandbox/remote/errors.d.mts +10 -0
  114. package/dist/modules/sandbox/remote/errors.mjs +62 -0
  115. package/dist/modules/sandbox/remote/errors.mjs.map +7 -0
  116. package/dist/modules/sandbox/remote/index.d.mts +5 -0
  117. package/dist/modules/sandbox/remote/index.mjs +6 -0
  118. package/dist/modules/sandbox/remote/index.mjs.map +7 -0
  119. package/dist/modules/sandbox/remote/ndjson.d.mts +6 -0
  120. package/dist/modules/sandbox/remote/ndjson.mjs +80 -0
  121. package/dist/modules/sandbox/remote/ndjson.mjs.map +7 -0
  122. package/dist/modules/sandbox/remote/platform-api.d.mts +8 -0
  123. package/dist/modules/sandbox/remote/platform-api.mjs +15 -0
  124. package/dist/modules/sandbox/remote/platform-api.mjs.map +7 -0
  125. package/dist/modules/sandbox/remote/preamble.d.mts +7 -0
  126. package/dist/modules/sandbox/remote/preamble.mjs +51 -0
  127. package/dist/modules/sandbox/remote/preamble.mjs.map +7 -0
  128. package/dist/modules/sandbox/remote/serve.d.mts +34 -0
  129. package/dist/modules/sandbox/remote/serve.mjs +519 -0
  130. package/dist/modules/sandbox/remote/serve.mjs.map +7 -0
  131. package/dist/modules/sandbox/remote/testing.d.mts +34 -0
  132. package/dist/modules/sandbox/remote/testing.mjs +275 -0
  133. package/dist/modules/sandbox/remote/testing.mjs.map +7 -0
  134. package/dist/modules/sandbox/seeds.d.mts +2 -2
  135. package/dist/modules/sandbox/seeds.mjs +2 -2
  136. package/dist/modules/sandbox/seeds.mjs.map +2 -2
  137. package/dist/modules/sandbox/server.d.mts +4 -6
  138. package/dist/modules/sandbox/server.mjs +93 -49
  139. package/dist/modules/sandbox/server.mjs.map +2 -2
  140. package/dist/modules/sandbox/setup/apply.d.mts +41 -0
  141. package/dist/modules/sandbox/setup/apply.mjs +204 -0
  142. package/dist/modules/sandbox/setup/apply.mjs.map +7 -0
  143. package/dist/modules/sandbox/setup/describe.d.mts +10 -0
  144. package/dist/modules/sandbox/setup/describe.mjs +62 -0
  145. package/dist/modules/sandbox/setup/describe.mjs.map +7 -0
  146. package/dist/modules/sandbox/setup/index.d.mts +6 -0
  147. package/dist/modules/sandbox/setup/index.mjs +17 -0
  148. package/dist/modules/sandbox/setup/index.mjs.map +7 -0
  149. package/dist/modules/sandbox/setup/paths.d.mts +8 -0
  150. package/dist/modules/sandbox/setup/paths.mjs +18 -0
  151. package/dist/modules/sandbox/setup/paths.mjs.map +7 -0
  152. package/dist/modules/sandbox/setup/schema.d.mts +42 -0
  153. package/dist/modules/sandbox/setup/schema.mjs +58 -0
  154. package/dist/modules/sandbox/setup/schema.mjs.map +7 -0
  155. package/dist/modules/sandbox/tool-policy.d.mts +1 -1
  156. package/dist/modules/sandbox/tool-policy.mjs +1 -1
  157. package/dist/modules/sandbox/tool-policy.mjs.map +2 -2
  158. package/dist/modules/sandbox/types.d.mts +117 -130
  159. package/dist/modules/sandbox/types.mjs +46 -50
  160. package/dist/modules/sandbox/types.mjs.map +3 -3
  161. package/dist/modules/sandbox/wire.d.mts +93 -6
  162. package/dist/modules/sandbox/wire.mjs +61 -38
  163. package/dist/modules/sandbox/wire.mjs.map +2 -2
  164. package/dist/modules/schemas.d.mts +5 -76
  165. package/dist/modules/schemas.mjs +18 -85
  166. package/dist/modules/schemas.mjs.map +2 -2
  167. package/dist/modules/tool-annotations.d.mts +15 -6
  168. package/dist/modules/tool-annotations.mjs +9 -3
  169. package/dist/modules/tool-annotations.mjs.map +2 -2
  170. package/dist/modules/tool-descriptor.d.mts +16 -0
  171. package/dist/modules/tool-descriptor.mjs +19 -0
  172. package/dist/modules/tool-descriptor.mjs.map +7 -0
  173. package/dist/modules/tool-patterns.d.mts +7 -7
  174. package/dist/modules/tool-patterns.mjs +10 -9
  175. package/dist/modules/tool-patterns.mjs.map +2 -2
  176. package/package.json +86 -36
  177. package/dist/modules/credentials.d.mts +0 -206
  178. package/dist/modules/credentials.mjs +0 -207
  179. package/dist/modules/credentials.mjs.map +0 -7
  180. package/dist/modules/dynamic.d.mts +0 -40
  181. package/dist/modules/dynamic.mjs +0 -79
  182. package/dist/modules/dynamic.mjs.map +0 -7
  183. package/dist/modules/hosted-bindings.d.mts +0 -15
  184. package/dist/modules/hosted-bindings.mjs +0 -21
  185. package/dist/modules/hosted-bindings.mjs.map +0 -7
  186. package/dist/modules/manifest.d.mts +0 -791
  187. package/dist/modules/manifest.mjs +0 -322
  188. package/dist/modules/manifest.mjs.map +0 -7
  189. package/dist/modules/provider-ref.d.mts +0 -29
  190. package/dist/modules/provider-ref.mjs +0 -55
  191. package/dist/modules/provider-ref.mjs.map +0 -7
  192. package/dist/modules/sandbox/open-scope-node.d.mts +0 -4
  193. package/dist/modules/sandbox/open-scope-node.mjs +0 -19
  194. package/dist/modules/sandbox/open-scope-node.mjs.map +0 -7
  195. package/dist/modules/sandbox/open-scope.d.mts +0 -16
  196. package/dist/modules/sandbox/open-scope.mjs +0 -66
  197. package/dist/modules/sandbox/open-scope.mjs.map +0 -7
  198. package/dist/modules/sandbox/workspace-identity.d.mts +0 -5
  199. package/dist/modules/sandbox/workspace-identity.mjs +0 -14
  200. package/dist/modules/sandbox/workspace-identity.mjs.map +0 -7
@@ -0,0 +1,519 @@
1
+ import { platformIdentityExchangeResponseSchema } from "@finalai/agent-protocol/agent-platform/sandbox-providers";
2
+ import {
3
+ JWKS_PATH,
4
+ PlatformIdentityVariant,
5
+ verifyPlatformIdentity
6
+ } from "@finalai/agent-protocol/identity";
7
+ import {
8
+ SANDBOX_PROVIDER_DISCOVERY_PATH,
9
+ SANDBOX_PROVIDER_HEARTBEAT_INTERVAL_MS,
10
+ SANDBOX_PROVIDER_MAX_BODY_BYTES,
11
+ SANDBOX_PROVIDER_WIRE_VERSION,
12
+ SandboxProviderErrorCode,
13
+ SandboxProviderWirePath,
14
+ sandboxArtifactKeyRequestSchema,
15
+ sandboxAttachFrameSchema,
16
+ sandboxCapabilityOfferSchema,
17
+ sandboxAwaitRunningRequestSchema,
18
+ sandboxCreateRequestSchema,
19
+ sandboxEditorRequestSchema,
20
+ sandboxOfferRequestSchema,
21
+ sandboxParkRequestSchema,
22
+ sandboxPrepareRequestSchema,
23
+ sandboxProcessesRequestSchema,
24
+ sandboxReadSnapshotRequestSchema,
25
+ sandboxStateRequestSchema
26
+ } from "@finalai/agent-protocol/sandbox-provider-wire";
27
+ import * as z from "zod";
28
+ import { jsonValueSchema } from "../../json.mjs";
29
+ import { sandboxEditorRequestSchema as editorRequestSchema } from "../editor.mjs";
30
+ import { FULL_SANDBOX_GRANT } from "../grant.mjs";
31
+ import { serveSandboxHandle } from "../server.mjs";
32
+ import { sandboxSnapshotRequestSchema } from "../snapshots.mjs";
33
+ import {
34
+ sandboxRuntimesOf
35
+ } from "../types.mjs";
36
+ import {
37
+ frameChannelFromWebSocket,
38
+ HandleRpcCloseCode,
39
+ handleRpcTokenFromRequest
40
+ } from "../wire.mjs";
41
+ import { SANDBOX_PROVIDER_ERROR_STATUS, sandboxProviderWireError, wireErrorOf } from "./errors.mjs";
42
+ import { ndjsonResponse } from "./ndjson.mjs";
43
+ import {
44
+ platformIdentityExchangeUrl,
45
+ sandboxProviderArtifactBodySchema,
46
+ sandboxProviderArtifactUrl
47
+ } from "./platform-api.mjs";
48
+ import { preambleChannel } from "./preamble.mjs";
49
+ const json = (value) => jsonValueSchema.parse(value);
50
+ const IDENTITY_REUSE_MARGIN_MS = 6e4;
51
+ const errorResponse = (error, status) => Response.json({ error }, { status: status ?? SANDBOX_PROVIDER_ERROR_STATUS[error.code] });
52
+ const refused = (message) => ({
53
+ code: SandboxProviderErrorCode.Forbidden,
54
+ message,
55
+ retryable: false
56
+ });
57
+ const invalid = (message) => ({
58
+ code: SandboxProviderErrorCode.InvalidEnvironment,
59
+ message,
60
+ retryable: false
61
+ });
62
+ const LONG_CALLS = /* @__PURE__ */ new Set([
63
+ SandboxProviderWirePath.Prepare,
64
+ SandboxProviderWirePath.Create,
65
+ SandboxProviderWirePath.AwaitRunning
66
+ ]);
67
+ const featuresOf = (implementation) => ({
68
+ readSnapshot: implementation?.readSnapshot != null,
69
+ processes: implementation?.processes != null,
70
+ editor: implementation?.editor != null,
71
+ attachPassive: implementation?.attachPassive != null
72
+ });
73
+ const serveSandboxProvider = (args) => {
74
+ const now = args.now ?? Date.now;
75
+ const doFetch = args.fetch ?? fetch;
76
+ const heartbeatMs = args.heartbeatMs ?? SANDBOX_PROVIDER_HEARTBEAT_INTERVAL_MS / 2;
77
+ const keys = args.jwks != null ? { jwks: args.jwks } : { jwksUrl: args.jwksUrl ?? new URL(JWKS_PATH, args.issuer).toString() };
78
+ const mounts = Object.entries(args.providers).map(([name, served]) => {
79
+ const audience = args.publicUrl(name);
80
+ return { name, served, audience, prefix: new URL(audience).pathname.replace(/\/+$/u, "") };
81
+ });
82
+ const route = (url) => {
83
+ let best = null;
84
+ for (const mount of mounts) {
85
+ if (url.pathname !== mount.prefix && !url.pathname.startsWith(`${mount.prefix}/`)) continue;
86
+ if (best != null && best.mount.prefix.length >= mount.prefix.length) continue;
87
+ best = { mount, path: url.pathname.slice(mount.prefix.length) };
88
+ }
89
+ return best;
90
+ };
91
+ const verify = async (mount, token) => {
92
+ if (token == null) return null;
93
+ const verified = await verifyPlatformIdentity({
94
+ token,
95
+ audience: mount.audience,
96
+ variant: PlatformIdentityVariant.SandboxProvider,
97
+ issuer: args.issuer,
98
+ now: now(),
99
+ ...keys
100
+ });
101
+ return verified.ok ? verified.claims : null;
102
+ };
103
+ const identityFor = (caller) => {
104
+ const cache = /* @__PURE__ */ new Map();
105
+ return async ({ audience, refresh }) => {
106
+ const { token: subject } = caller();
107
+ const cached = cache.get(audience);
108
+ if (refresh !== true && cached != null && cached.subject === subject && Date.parse(cached.token.expiresAt) - now() > IDENTITY_REUSE_MARGIN_MS)
109
+ return cached.token;
110
+ const response = await doFetch(platformIdentityExchangeUrl(args.issuer), {
111
+ method: "POST",
112
+ headers: { "content-type": "application/json" },
113
+ body: JSON.stringify({ subjectToken: subject, audience })
114
+ });
115
+ const text = await response.text();
116
+ if (!response.ok)
117
+ throw sandboxProviderWireError(
118
+ refused(
119
+ `identity for ${audience} was refused (${response.status}): ${text.slice(0, 200)}`
120
+ )
121
+ );
122
+ const parsed = platformIdentityExchangeResponseSchema.safeParse(JSON.parse(text));
123
+ if (!parsed.success) throw new Error(`unexpected identity exchange answer for ${audience}`);
124
+ cache.set(audience, { subject, token: parsed.data });
125
+ return parsed.data;
126
+ };
127
+ };
128
+ const contextFor = (caller, secrets) => ({
129
+ organizationId: caller().identity.organizationId,
130
+ projectId: caller().identity.projectId,
131
+ credentials: { secret: async ({ secretRef }) => secrets[secretRef] ?? null },
132
+ actingUser: { current: async () => caller().identity.userId },
133
+ identity: identityFor(caller),
134
+ log: args.log
135
+ });
136
+ const artifactsFor = (caller) => ({
137
+ get: async (key) => {
138
+ const response = await doFetch(sandboxProviderArtifactUrl(args.issuer, key), {
139
+ headers: { authorization: `Bearer ${caller().token}` }
140
+ });
141
+ const text = await response.text();
142
+ if (response.status === 404) return null;
143
+ if (!response.ok) throw new Error(`reading artifact ${key} failed (${response.status})`);
144
+ return sandboxProviderArtifactBodySchema.parse(JSON.parse(text)).artifact;
145
+ },
146
+ put: async (key, artifact) => {
147
+ const response = await doFetch(sandboxProviderArtifactUrl(args.issuer, key), {
148
+ method: "PUT",
149
+ headers: { authorization: `Bearer ${caller().token}`, "content-type": "application/json" },
150
+ body: JSON.stringify({ artifact })
151
+ });
152
+ await response.text();
153
+ if (!response.ok) throw new Error(`storing artifact ${key} failed (${response.status})`);
154
+ }
155
+ });
156
+ const storagePathOf = (identity, sandboxId) => `${identity.organizationId}/${sandboxId ?? "preparations"}`;
157
+ const implementationOf = (mount, environment) => mount.served.provider.definition.environment(json(environment));
158
+ const discoveryOf = (mount) => {
159
+ let implementation = null;
160
+ if (mount.served.discovery.features == null)
161
+ try {
162
+ implementation = mount.served.provider.definition.environment(void 0);
163
+ } catch {
164
+ implementation = null;
165
+ }
166
+ return {
167
+ wire: SANDBOX_PROVIDER_WIRE_VERSION,
168
+ name: mount.name,
169
+ title: mount.served.discovery.title ?? null,
170
+ formFactor: mount.served.discovery.formFactor,
171
+ environmentSchema: mount.served.discovery.environmentSchema ?? null,
172
+ capabilities: sandboxCapabilityOfferSchema.parse(mount.served.discovery.capabilities),
173
+ runtimes: mount.served.discovery.runtimes ?? [],
174
+ features: mount.served.discovery.features ?? featuresOf(implementation),
175
+ stateProtocolVersion: mount.served.provider.definition.stateProtocolVersion ?? null
176
+ };
177
+ };
178
+ const readBody = async (request) => {
179
+ const declared = Number(request.headers.get("content-length") ?? "0");
180
+ if (declared > SANDBOX_PROVIDER_MAX_BODY_BYTES)
181
+ throw sandboxProviderWireError(invalid("the request body is over the size limit"));
182
+ const text = await request.text();
183
+ if (new TextEncoder().encode(text).byteLength > SANDBOX_PROVIDER_MAX_BODY_BYTES)
184
+ throw sandboxProviderWireError(invalid("the request body is over the size limit"));
185
+ try {
186
+ return JSON.parse(text);
187
+ } catch {
188
+ throw sandboxProviderWireError(invalid("the request body is not JSON"));
189
+ }
190
+ };
191
+ const parse = (schema, body) => {
192
+ const parsed = schema.safeParse(body);
193
+ if (!parsed.success) throw sandboxProviderWireError(invalid(z.prettifyError(parsed.error)));
194
+ return parsed.data;
195
+ };
196
+ const requireSandbox = (identity, sandboxId) => {
197
+ if (identity.sandboxId !== sandboxId)
198
+ throw sandboxProviderWireError(refused("the assertion is for another sandbox"));
199
+ };
200
+ const unsupported = (what) => sandboxProviderWireError({
201
+ code: SandboxProviderErrorCode.NotFound,
202
+ message: `this provider has no ${what}`,
203
+ retryable: false
204
+ });
205
+ const dispatch = async (mount, path, caller, body) => {
206
+ const { identity } = caller;
207
+ const callerOf = () => caller;
208
+ const base = (secrets) => contextFor(callerOf, secrets);
209
+ const resourceContext = (fields) => ({
210
+ ...base(fields.secrets),
211
+ sandboxId: fields.sandboxId,
212
+ storagePath: storagePathOf(identity, fields.sandboxId),
213
+ lifecycle: fields.lifecycle ?? { parkAfterIdleMs: null },
214
+ platformEgressHosts: fields.platformEgressHosts,
215
+ // Lifecycle calls apply no network policy; attach reports it on the socket.
216
+ platformNetworkPolicy: async () => void 0
217
+ });
218
+ switch (path) {
219
+ case SandboxProviderWirePath.Offer: {
220
+ const request = parse(sandboxOfferRequestSchema, body);
221
+ if (request.sandboxId != null) requireSandbox(identity, request.sandboxId);
222
+ const implementation = implementationOf(mount, request.environment);
223
+ const ctx = {
224
+ ...base(request.secrets),
225
+ ...request.sandboxId == null ? {} : { sandboxId: request.sandboxId }
226
+ };
227
+ const [capabilities, runtimes, features, additionalFeatures, mcpCatalog] = await Promise.all([
228
+ implementation.capabilities(ctx),
229
+ sandboxRuntimesOf(implementation, ctx),
230
+ implementation.features?.(ctx) ?? null,
231
+ implementation.additionalFeatures?.(ctx) ?? [],
232
+ implementation.mcpCatalog?.(ctx) ?? null
233
+ ]);
234
+ return {
235
+ capabilities: { ...capabilities },
236
+ runtimes,
237
+ features,
238
+ additionalFeatures,
239
+ mcpCatalog: mcpCatalog == null ? null : {
240
+ computerUse: mcpCatalog.computerUse,
241
+ localMcp: mcpCatalog.localMcp,
242
+ ...mcpCatalog.localMcpIncomplete == null ? {} : { localMcpIncomplete: mcpCatalog.localMcpIncomplete }
243
+ }
244
+ };
245
+ }
246
+ case SandboxProviderWirePath.ArtifactKey:
247
+ case SandboxProviderWirePath.Prepare: {
248
+ const request = parse(
249
+ path === SandboxProviderWirePath.Prepare ? sandboxPrepareRequestSchema : sandboxArtifactKeyRequestSchema,
250
+ body
251
+ );
252
+ const implementation = implementationOf(mount, request.environment);
253
+ const ctx = {
254
+ ...base(request.secrets),
255
+ files: request.files,
256
+ resources: z.record(z.string(), jsonValueSchema).parse(request.resources),
257
+ sourceRevision: request.sourceRevision,
258
+ storagePath: storagePathOf(identity, identity.sandboxId),
259
+ artifacts: artifactsFor(callerOf)
260
+ };
261
+ if (path === SandboxProviderWirePath.ArtifactKey)
262
+ return { key: await implementation.artifactKey(ctx) };
263
+ return { artifact: await implementation.prepare(ctx) };
264
+ }
265
+ case SandboxProviderWirePath.Create: {
266
+ const request = parse(sandboxCreateRequestSchema, body);
267
+ requireSandbox(identity, request.sandboxId);
268
+ const implementation = implementationOf(mount, request.environment);
269
+ const created = await implementation.create(
270
+ resourceContext({
271
+ sandboxId: request.sandboxId,
272
+ secrets: request.secrets,
273
+ platformEgressHosts: request.platformEgressHosts,
274
+ lifecycle: request.lifecycle
275
+ }),
276
+ { artifact: json(request.artifact), setup: request.setup }
277
+ );
278
+ return { state: created.state, region: created.region ?? null };
279
+ }
280
+ case SandboxProviderWirePath.AwaitRunning: {
281
+ const request = parse(sandboxAwaitRunningRequestSchema, body);
282
+ requireSandbox(identity, request.sandboxId);
283
+ await implementationOf(mount, request.environment).awaitRunning(
284
+ resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets }),
285
+ json(request.state),
286
+ { timeoutMs: request.timeoutMs }
287
+ );
288
+ return {};
289
+ }
290
+ case SandboxProviderWirePath.Detach:
291
+ case SandboxProviderWirePath.Delete: {
292
+ const request = parse(sandboxStateRequestSchema, body);
293
+ requireSandbox(identity, request.sandboxId);
294
+ const implementation = implementationOf(mount, request.environment);
295
+ const ctx = resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets });
296
+ if (path === SandboxProviderWirePath.Delete) {
297
+ await implementation.delete(ctx, { state: json(request.state) });
298
+ return {};
299
+ }
300
+ return { state: await implementation.detach(ctx, { state: json(request.state) }) };
301
+ }
302
+ case SandboxProviderWirePath.Park: {
303
+ const request = parse(sandboxParkRequestSchema, body);
304
+ requireSandbox(identity, request.sandboxId);
305
+ const implementation = implementationOf(mount, request.environment);
306
+ return {
307
+ state: await implementation.park(
308
+ resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets }),
309
+ { artifact: json(request.artifact), state: json(request.state) }
310
+ )
311
+ };
312
+ }
313
+ case SandboxProviderWirePath.ReadSnapshot: {
314
+ const request = parse(sandboxReadSnapshotRequestSchema, body);
315
+ requireSandbox(identity, request.sandboxId);
316
+ const implementation = implementationOf(mount, request.environment);
317
+ if (implementation.readSnapshot == null) throw unsupported("snapshot reads");
318
+ const response = await implementation.readSnapshot(
319
+ { ...base(request.secrets), sandboxId: request.sandboxId },
320
+ json(request.state),
321
+ parse(sandboxSnapshotRequestSchema, request.request)
322
+ );
323
+ return response == null ? null : { ...response };
324
+ }
325
+ case SandboxProviderWirePath.Processes: {
326
+ const request = parse(sandboxProcessesRequestSchema, body);
327
+ requireSandbox(identity, request.sandboxId);
328
+ const implementation = implementationOf(mount, request.environment);
329
+ if (implementation.processes == null) throw unsupported("process inspection");
330
+ return {
331
+ ...await implementation.processes(
332
+ { ...base(request.secrets), sandboxId: request.sandboxId },
333
+ json(request.state),
334
+ request.request
335
+ )
336
+ };
337
+ }
338
+ case SandboxProviderWirePath.Editor: {
339
+ const request = parse(sandboxEditorRequestSchema, body);
340
+ requireSandbox(identity, request.sandboxId);
341
+ const implementation = implementationOf(mount, request.environment);
342
+ if (implementation.editor == null) throw unsupported("editor");
343
+ return {
344
+ ...await implementation.editor(
345
+ { ...base(request.secrets), sandboxId: request.sandboxId },
346
+ json(request.state),
347
+ parse(editorRequestSchema, request.request)
348
+ )
349
+ };
350
+ }
351
+ default:
352
+ throw unsupported(`call ${path}`);
353
+ }
354
+ };
355
+ const fetchHandler = async (request) => {
356
+ const url = new URL(request.url);
357
+ const routed = route(url);
358
+ if (routed == null)
359
+ return errorResponse({
360
+ code: SandboxProviderErrorCode.NotFound,
361
+ message: "no sandbox provider is served here",
362
+ retryable: false
363
+ });
364
+ const { mount, path } = routed;
365
+ if (request.method === "GET" && path === SANDBOX_PROVIDER_DISCOVERY_PATH)
366
+ return Response.json(discoveryOf(mount));
367
+ if (request.method !== "POST" || path === SandboxProviderWirePath.Attach)
368
+ return errorResponse(invalid(`${request.method} ${path} is not a provider call`), 405);
369
+ const token = /^Bearer\s+(.+)$/iu.exec(request.headers.get("authorization")?.trim() ?? "")?.[1];
370
+ const identity = await verify(mount, token ?? null);
371
+ if (identity == null || token == null)
372
+ return errorResponse(refused("a valid sandbox-provider assertion is required"), 401);
373
+ const caller = { token, identity };
374
+ let body;
375
+ try {
376
+ body = await readBody(request);
377
+ } catch (cause) {
378
+ return errorResponse(wireErrorOf(cause));
379
+ }
380
+ if (LONG_CALLS.has(path))
381
+ return ndjsonResponse({ work: () => dispatch(mount, path, caller, body), heartbeatMs });
382
+ try {
383
+ return Response.json(await dispatch(mount, path, caller, body));
384
+ } catch (cause) {
385
+ return errorResponse(wireErrorOf(cause));
386
+ }
387
+ };
388
+ const upgrade = (request, socket) => {
389
+ const { channel } = frameChannelFromWebSocket(socket);
390
+ const preamble = preambleChannel(channel);
391
+ const fail = (error, code = HandleRpcCloseCode.Normal) => {
392
+ channel.send(JSON.stringify({ type: "error", error }));
393
+ channel.close(code, error.message.slice(0, 120));
394
+ };
395
+ void (async () => {
396
+ const routed = route(new URL(request.url));
397
+ if (routed == null || routed.path !== SandboxProviderWirePath.Attach) {
398
+ fail({
399
+ code: SandboxProviderErrorCode.NotFound,
400
+ message: "no sandbox provider attaches here",
401
+ retryable: false
402
+ });
403
+ return;
404
+ }
405
+ const { mount } = routed;
406
+ const token = handleRpcTokenFromRequest(request);
407
+ const identity = await verify(mount, token);
408
+ if (identity == null || token == null) {
409
+ fail(
410
+ refused("a valid sandbox-provider assertion is required"),
411
+ HandleRpcCloseCode.Unauthorized
412
+ );
413
+ return;
414
+ }
415
+ let caller = { token, identity };
416
+ let frame;
417
+ try {
418
+ const first = await preamble.next();
419
+ if (typeof first !== "string") throw new Error("the attach request must be a text frame");
420
+ frame = parse(sandboxAttachFrameSchema, JSON.parse(first));
421
+ requireSandbox(identity, frame.sandboxId);
422
+ } catch (cause) {
423
+ fail(wireErrorOf(cause));
424
+ return;
425
+ }
426
+ const heartbeat = setInterval(
427
+ () => channel.send(JSON.stringify({ type: "heartbeat" })),
428
+ heartbeatMs
429
+ );
430
+ let reported = null;
431
+ const ctx = {
432
+ ...contextFor(() => caller, frame.secrets),
433
+ sandboxId: frame.sandboxId,
434
+ storagePath: storagePathOf(identity, frame.sandboxId),
435
+ lifecycle: frame.lifecycle,
436
+ platformEgressHosts: frame.platformEgressHosts,
437
+ platformNetworkPolicy: async (policy) => {
438
+ reported = policy;
439
+ }
440
+ };
441
+ let handle;
442
+ let attached;
443
+ try {
444
+ const implementation = implementationOf(mount, frame.environment);
445
+ if (frame.passive) {
446
+ if (implementation.attachPassive == null) throw unsupported("passive attach");
447
+ handle = await implementation.attachPassive(ctx, {
448
+ artifact: json(frame.artifact),
449
+ state: json(frame.state)
450
+ });
451
+ attached = {
452
+ type: "attached",
453
+ state: json(frame.state),
454
+ fresh: false,
455
+ booted: false,
456
+ region: null,
457
+ networkPolicy: null
458
+ };
459
+ } else {
460
+ const attachment = await implementation.attach(ctx, {
461
+ artifact: json(frame.artifact),
462
+ state: json(frame.state)
463
+ });
464
+ handle = attachment.handle;
465
+ attached = {
466
+ type: "attached",
467
+ state: attachment.state,
468
+ fresh: attachment.fresh,
469
+ booted: attachment.booted,
470
+ region: attachment.region ?? null,
471
+ networkPolicy: reported
472
+ };
473
+ }
474
+ } catch (cause) {
475
+ clearInterval(heartbeat);
476
+ fail(wireErrorOf(cause));
477
+ return;
478
+ }
479
+ clearInterval(heartbeat);
480
+ let shutdown = null;
481
+ const lifecycle = {
482
+ onSandboxStop: () => handle.onSandboxStop(),
483
+ onSandboxDelete: (options) => handle.onSandboxDelete(options),
484
+ onRuntimeShutdown: () => {
485
+ shutdown ??= handle.onRuntimeShutdown();
486
+ return shutdown;
487
+ }
488
+ };
489
+ const authorize = async ({ identity: assertion }) => {
490
+ const next = await verify(mount, assertion ?? null);
491
+ if (next == null || assertion == null || next.providerId !== identity.providerId || next.sandboxId !== identity.sandboxId || next.organizationId !== identity.organizationId || next.projectId !== identity.projectId)
492
+ return null;
493
+ caller = { token: assertion, identity: next };
494
+ return { expiresAt: new Date(next.expiresAt).toISOString() };
495
+ };
496
+ channel.send(JSON.stringify(attached));
497
+ serveSandboxHandle({
498
+ sandbox: handle.sandbox,
499
+ handle: lifecycle,
500
+ authorize,
501
+ access: { grant: FULL_SANDBOX_GRANT, lifecycle: true },
502
+ mcpChannels: true
503
+ }).attach(preamble.rest());
504
+ await preamble.closed;
505
+ await lifecycle.onRuntimeShutdown().catch(
506
+ (cause) => args.log?.("sandbox provider handle shutdown failed", {
507
+ provider: mount.name,
508
+ sandboxId: frame.sandboxId,
509
+ error: cause instanceof Error ? cause.message : String(cause)
510
+ })
511
+ );
512
+ })();
513
+ };
514
+ return { fetch: fetchHandler, upgrade };
515
+ };
516
+ export {
517
+ serveSandboxProvider
518
+ };
519
+ //# sourceMappingURL=serve.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../src/sandbox/remote/serve.ts"],
4
+ "sourcesContent": ["import type { RuntimeKind } from '@finalai/agent-protocol';\nimport { platformIdentityExchangeResponseSchema } from '@finalai/agent-protocol/agent-platform/sandbox-providers';\nimport {\n JWKS_PATH,\n PlatformIdentityVariant,\n verifyPlatformIdentity,\n type JwksIface,\n type JwksKeySourceIface,\n type SandboxProviderIdentityIface,\n} from '@finalai/agent-protocol/identity';\nimport {\n SANDBOX_PROVIDER_DISCOVERY_PATH,\n SANDBOX_PROVIDER_HEARTBEAT_INTERVAL_MS,\n SANDBOX_PROVIDER_MAX_BODY_BYTES,\n SANDBOX_PROVIDER_WIRE_VERSION,\n SandboxProviderErrorCode,\n SandboxProviderWirePath,\n sandboxArtifactKeyRequestSchema,\n sandboxAttachFrameSchema,\n sandboxCapabilityOfferSchema,\n sandboxAwaitRunningRequestSchema,\n sandboxCreateRequestSchema,\n sandboxEditorRequestSchema,\n sandboxOfferRequestSchema,\n sandboxParkRequestSchema,\n sandboxPrepareRequestSchema,\n sandboxProcessesRequestSchema,\n sandboxReadSnapshotRequestSchema,\n sandboxStateRequestSchema,\n type SandboxAttachFrameIface,\n type SandboxAttachedFrameIface,\n type SandboxFormFactor,\n type SandboxProviderDiscoveryIface,\n type SandboxProviderErrorIface,\n type SandboxProviderFeaturesIface,\n} from '@finalai/agent-protocol/sandbox-provider-wire';\nimport * as z from 'zod';\nimport { jsonValueSchema, type JsonObject, type JsonValue } from \"../../json.mjs\";\nimport { sandboxEditorRequestSchema as editorRequestSchema } from \"../editor.mjs\";\nimport { FULL_SANDBOX_GRANT } from \"../grant.mjs\";\nimport { serveSandboxHandle, type HandleAuthorizeFn, type HandleLifecycle } from \"../server.mjs\";\nimport { sandboxSnapshotRequestSchema } from \"../snapshots.mjs\";\nimport {\n sandboxRuntimesOf,\n type AnySandboxProviderIface,\n type NetworkPolicyIface,\n type NetworkSandboxSessionIface,\n type SandboxCapabilityOffer,\n type SandboxEnvironmentImplementationIface,\n type SandboxIdentityFn,\n type SandboxIdentityTokenIface,\n type SandboxOfferContextIface,\n type SandboxPrepareContextIface,\n type SandboxProviderContextIface,\n type SandboxProviderHandleIface,\n type SandboxResourceContextIface,\n} from \"../types.mjs\";\nimport {\n frameChannelFromWebSocket,\n HandleRpcCloseCode,\n handleRpcTokenFromRequest,\n type WebSocketLikeIface,\n} from \"../wire.mjs\";\nimport { SANDBOX_PROVIDER_ERROR_STATUS, sandboxProviderWireError, wireErrorOf } from \"./errors.mjs\";\nimport { ndjsonResponse } from \"./ndjson.mjs\";\nimport {\n platformIdentityExchangeUrl,\n sandboxProviderArtifactBodySchema,\n sandboxProviderArtifactUrl,\n} from \"./platform-api.mjs\";\nimport { preambleChannel } from \"./preamble.mjs\";\n\n// Serves sandbox providers over the sandbox-provider wire\n// (`@finalai/agent-protocol/sandbox-provider-wire`), so a platform drives them\n// by URL exactly as it would in process. Each provider is mounted at its\n// registered URL (`publicUrl(name)`): lifecycle calls are HTTP, and `/v1/attach`\n// is a WebSocket whose frames, after the attach reply, are the handle RPC.\n//\n// Every call is authenticated by a sandbox-provider assertion the platform\n// signed for that URL, verified against the platform's JWKS. The provider's\n// context comes from it: the organization, project and sandbox it names, the\n// acting user it carries (replaced on the attach socket by\n// `identity/refresh`), the secrets the call forwards, and `identity`, which\n// exchanges the assertion for one to a backend the registration was granted.\n// Platform environment variables and files never reach the provider: the\n// platform's adapter applies them through the handle.\n\n// What a provider's discovery document says beyond what its definition does.\nexport interface SandboxProviderDiscoveryInputIface {\n title?: string | null;\n formFactor: SandboxFormFactor;\n // JSON Schema of the environment options.\n environmentSchema?: JsonObject | null;\n capabilities: SandboxCapabilityOffer;\n runtimes?: RuntimeKind[];\n // The optional calls it serves; by default, those its environment without\n // options implements.\n features?: SandboxProviderFeaturesIface;\n}\n\nexport interface ServedSandboxProviderIface {\n provider: AnySandboxProviderIface;\n discovery: SandboxProviderDiscoveryInputIface;\n}\n\nexport interface ServeSandboxProviderArgsIface {\n // Path segment (the name a project registers it under) \u2192 provider.\n providers: Record<string, ServedSandboxProviderIface>;\n // The platform's origin: the assertions' issuer, and where the exchange and\n // artifact routes are.\n issuer: string;\n // Defaults to the issuer's `/.well-known/jwks.json`.\n jwksUrl?: string;\n // A key set to verify against instead of fetching one.\n jwks?: JwksIface | JwksKeySourceIface;\n // The URL a provider is registered at: its assertions' audience.\n publicUrl: (name: string) => string;\n // For calls to the platform (exchange, artifacts).\n fetch?: typeof fetch;\n heartbeatMs?: number;\n now?: () => number;\n log?: (message: string, fields?: Record<string, string | number | boolean | null>) => void;\n}\n\nexport interface SandboxProviderServerIface {\n fetch(request: Request): Promise<Response>;\n // `/v1/attach`: the host accepted the upgrade; `request` is the upgrade request.\n upgrade(request: Request, socket: WebSocketLikeIface): void;\n}\n\n// Wire JSON as this package's JSON.\nconst json = (value: unknown): JsonValue => jsonValueSchema.parse(value);\n\n// An identity exchanged this long before it expires is asked for again.\nconst IDENTITY_REUSE_MARGIN_MS = 60_000;\n\nconst errorResponse = (error: SandboxProviderErrorIface, status?: number): Response =>\n Response.json({ error }, { status: status ?? SANDBOX_PROVIDER_ERROR_STATUS[error.code] });\n\nconst refused = (message: string): SandboxProviderErrorIface => ({\n code: SandboxProviderErrorCode.Forbidden,\n message,\n retryable: false,\n});\n\nconst invalid = (message: string): SandboxProviderErrorIface => ({\n code: SandboxProviderErrorCode.InvalidEnvironment,\n message,\n retryable: false,\n});\n\nconst LONG_CALLS: ReadonlySet<string> = new Set([\n SandboxProviderWirePath.Prepare,\n SandboxProviderWirePath.Create,\n SandboxProviderWirePath.AwaitRunning,\n]);\n\ninterface MountIface {\n name: string;\n served: ServedSandboxProviderIface;\n audience: string;\n // The URL's path without its trailing slash.\n prefix: string;\n}\n\n// The caller a call or an attach socket acts for: its assertion in force.\ninterface CallerIface {\n token: string;\n identity: SandboxProviderIdentityIface;\n}\n\ntype ImplementationType = SandboxEnvironmentImplementationIface<\n JsonValue,\n JsonValue,\n NetworkSandboxSessionIface\n>;\n\nconst featuresOf = (implementation: ImplementationType | null): SandboxProviderFeaturesIface => ({\n readSnapshot: implementation?.readSnapshot != null,\n processes: implementation?.processes != null,\n editor: implementation?.editor != null,\n attachPassive: implementation?.attachPassive != null,\n});\n\nexport const serveSandboxProvider = (\n args: ServeSandboxProviderArgsIface,\n): SandboxProviderServerIface => {\n const now = args.now ?? Date.now;\n const doFetch = args.fetch ?? fetch;\n const heartbeatMs = args.heartbeatMs ?? SANDBOX_PROVIDER_HEARTBEAT_INTERVAL_MS / 2;\n const keys =\n args.jwks != null\n ? { jwks: args.jwks }\n : { jwksUrl: args.jwksUrl ?? new URL(JWKS_PATH, args.issuer).toString() };\n const mounts: MountIface[] = Object.entries(args.providers).map(([name, served]) => {\n const audience = args.publicUrl(name);\n return { name, served, audience, prefix: new URL(audience).pathname.replace(/\\/+$/u, '') };\n });\n\n // The mount a request path is under, longest first, and the path within it.\n const route = (url: URL): { mount: MountIface; path: string } | null => {\n let best: { mount: MountIface; path: string } | null = null;\n for (const mount of mounts) {\n if (url.pathname !== mount.prefix && !url.pathname.startsWith(`${mount.prefix}/`)) continue;\n if (best != null && best.mount.prefix.length >= mount.prefix.length) continue;\n best = { mount, path: url.pathname.slice(mount.prefix.length) };\n }\n return best;\n };\n\n const verify = async (\n mount: MountIface,\n token: string | null,\n ): Promise<SandboxProviderIdentityIface | null> => {\n if (token == null) return null;\n const verified = await verifyPlatformIdentity({\n token,\n audience: mount.audience,\n variant: PlatformIdentityVariant.SandboxProvider,\n issuer: args.issuer,\n now: now(),\n ...keys,\n });\n return verified.ok ? verified.claims : null;\n };\n\n // `ctx.identity`: the current assertion exchanged for one to `audience`,\n // reused while the assertion it came from is in force.\n const identityFor = (caller: () => CallerIface): SandboxIdentityFn => {\n const cache = new Map<string, { subject: string; token: SandboxIdentityTokenIface }>();\n return async ({ audience, refresh }) => {\n const { token: subject } = caller();\n const cached = cache.get(audience);\n if (\n refresh !== true &&\n cached != null &&\n cached.subject === subject &&\n Date.parse(cached.token.expiresAt) - now() > IDENTITY_REUSE_MARGIN_MS\n )\n return cached.token;\n const response = await doFetch(platformIdentityExchangeUrl(args.issuer), {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ subjectToken: subject, audience }),\n });\n const text = await response.text();\n if (!response.ok)\n throw sandboxProviderWireError(\n refused(\n `identity for ${audience} was refused (${response.status}): ${text.slice(0, 200)}`,\n ),\n );\n const parsed = platformIdentityExchangeResponseSchema.safeParse(JSON.parse(text));\n if (!parsed.success) throw new Error(`unexpected identity exchange answer for ${audience}`);\n cache.set(audience, { subject, token: parsed.data });\n return parsed.data;\n };\n };\n\n const contextFor = (\n caller: () => CallerIface,\n secrets: Record<string, string>,\n ): SandboxProviderContextIface => ({\n organizationId: caller().identity.organizationId,\n projectId: caller().identity.projectId,\n credentials: { secret: async ({ secretRef }) => secrets[secretRef] ?? null },\n actingUser: { current: async () => caller().identity.userId },\n identity: identityFor(caller),\n log: args.log,\n });\n\n const artifactsFor = (caller: () => CallerIface): SandboxPrepareContextIface['artifacts'] => ({\n get: async (key) => {\n const response = await doFetch(sandboxProviderArtifactUrl(args.issuer, key), {\n headers: { authorization: `Bearer ${caller().token}` },\n });\n const text = await response.text();\n if (response.status === 404) return null;\n if (!response.ok) throw new Error(`reading artifact ${key} failed (${response.status})`);\n return sandboxProviderArtifactBodySchema.parse(JSON.parse(text)).artifact;\n },\n put: async (key, artifact) => {\n const response = await doFetch(sandboxProviderArtifactUrl(args.issuer, key), {\n method: 'PUT',\n headers: { authorization: `Bearer ${caller().token}`, 'content-type': 'application/json' },\n body: JSON.stringify({ artifact }),\n });\n await response.text();\n if (!response.ok) throw new Error(`storing artifact ${key} failed (${response.status})`);\n },\n });\n\n const storagePathOf = (identity: SandboxProviderIdentityIface, sandboxId: string | null) =>\n `${identity.organizationId}/${sandboxId ?? 'preparations'}`;\n\n const implementationOf = (mount: MountIface, environment: unknown): ImplementationType =>\n mount.served.provider.definition.environment(json(environment));\n\n const discoveryOf = (mount: MountIface): SandboxProviderDiscoveryIface => {\n let implementation: ImplementationType | null = null;\n if (mount.served.discovery.features == null)\n try {\n implementation = mount.served.provider.definition.environment(undefined);\n } catch {\n implementation = null;\n }\n return {\n wire: SANDBOX_PROVIDER_WIRE_VERSION,\n name: mount.name,\n title: mount.served.discovery.title ?? null,\n formFactor: mount.served.discovery.formFactor,\n environmentSchema: mount.served.discovery.environmentSchema ?? null,\n capabilities: sandboxCapabilityOfferSchema.parse(mount.served.discovery.capabilities),\n runtimes: mount.served.discovery.runtimes ?? [],\n features: mount.served.discovery.features ?? featuresOf(implementation),\n stateProtocolVersion: mount.served.provider.definition.stateProtocolVersion ?? null,\n };\n };\n\n const readBody = async (request: Request): Promise<unknown> => {\n const declared = Number(request.headers.get('content-length') ?? '0');\n if (declared > SANDBOX_PROVIDER_MAX_BODY_BYTES)\n throw sandboxProviderWireError(invalid('the request body is over the size limit'));\n const text = await request.text();\n if (new TextEncoder().encode(text).byteLength > SANDBOX_PROVIDER_MAX_BODY_BYTES)\n throw sandboxProviderWireError(invalid('the request body is over the size limit'));\n try {\n return JSON.parse(text);\n } catch {\n throw sandboxProviderWireError(invalid('the request body is not JSON'));\n }\n };\n\n const parse = <S extends z.ZodType>(schema: S, body: unknown): z.output<S> => {\n const parsed = schema.safeParse(body);\n if (!parsed.success) throw sandboxProviderWireError(invalid(z.prettifyError(parsed.error)));\n return parsed.data;\n };\n\n // A call about one sandbox must carry that sandbox's assertion.\n const requireSandbox = (identity: SandboxProviderIdentityIface, sandboxId: string) => {\n if (identity.sandboxId !== sandboxId)\n throw sandboxProviderWireError(refused('the assertion is for another sandbox'));\n };\n\n const unsupported = (what: string) =>\n sandboxProviderWireError({\n code: SandboxProviderErrorCode.NotFound,\n message: `this provider has no ${what}`,\n retryable: false,\n });\n\n // One wire call; the result is the JSON the answer carries.\n const dispatch = async (\n mount: MountIface,\n path: string,\n caller: CallerIface,\n body: unknown,\n ): Promise<JsonValue> => {\n const { identity } = caller;\n const callerOf = () => caller;\n const base = (secrets: Record<string, string>) => contextFor(callerOf, secrets);\n const resourceContext = (fields: {\n sandboxId: string;\n secrets: Record<string, string>;\n platformEgressHosts?: string[];\n lifecycle?: SandboxResourceContextIface['lifecycle'];\n }): SandboxResourceContextIface => ({\n ...base(fields.secrets),\n sandboxId: fields.sandboxId,\n storagePath: storagePathOf(identity, fields.sandboxId),\n lifecycle: fields.lifecycle ?? { parkAfterIdleMs: null },\n platformEgressHosts: fields.platformEgressHosts,\n // Lifecycle calls apply no network policy; attach reports it on the socket.\n platformNetworkPolicy: async () => undefined,\n });\n switch (path) {\n case SandboxProviderWirePath.Offer: {\n const request = parse(sandboxOfferRequestSchema, body);\n if (request.sandboxId != null) requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n const ctx: SandboxOfferContextIface = {\n ...base(request.secrets),\n ...(request.sandboxId == null ? {} : { sandboxId: request.sandboxId }),\n };\n const [capabilities, runtimes, features, additionalFeatures, mcpCatalog] =\n await Promise.all([\n implementation.capabilities(ctx),\n sandboxRuntimesOf(implementation, ctx),\n implementation.features?.(ctx) ?? null,\n implementation.additionalFeatures?.(ctx) ?? [],\n implementation.mcpCatalog?.(ctx) ?? null,\n ]);\n return {\n capabilities: { ...capabilities },\n runtimes,\n features,\n additionalFeatures,\n mcpCatalog:\n mcpCatalog == null\n ? null\n : {\n computerUse: mcpCatalog.computerUse,\n localMcp: mcpCatalog.localMcp,\n ...(mcpCatalog.localMcpIncomplete == null\n ? {}\n : { localMcpIncomplete: mcpCatalog.localMcpIncomplete }),\n },\n };\n }\n case SandboxProviderWirePath.ArtifactKey:\n case SandboxProviderWirePath.Prepare: {\n const request = parse(\n path === SandboxProviderWirePath.Prepare\n ? sandboxPrepareRequestSchema\n : sandboxArtifactKeyRequestSchema,\n body,\n );\n const implementation = implementationOf(mount, request.environment);\n const ctx: SandboxPrepareContextIface = {\n ...base(request.secrets),\n files: request.files,\n resources: z.record(z.string(), jsonValueSchema).parse(request.resources),\n sourceRevision: request.sourceRevision,\n storagePath: storagePathOf(identity, identity.sandboxId),\n artifacts: artifactsFor(callerOf),\n };\n if (path === SandboxProviderWirePath.ArtifactKey)\n return { key: await implementation.artifactKey(ctx) };\n return { artifact: await implementation.prepare(ctx) };\n }\n case SandboxProviderWirePath.Create: {\n const request = parse(sandboxCreateRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n const created = await implementation.create(\n resourceContext({\n sandboxId: request.sandboxId,\n secrets: request.secrets,\n platformEgressHosts: request.platformEgressHosts,\n lifecycle: request.lifecycle,\n }),\n { artifact: json(request.artifact), setup: request.setup },\n );\n return { state: created.state, region: created.region ?? null };\n }\n case SandboxProviderWirePath.AwaitRunning: {\n const request = parse(sandboxAwaitRunningRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n await implementationOf(mount, request.environment).awaitRunning(\n resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets }),\n json(request.state),\n { timeoutMs: request.timeoutMs },\n );\n return {};\n }\n case SandboxProviderWirePath.Detach:\n case SandboxProviderWirePath.Delete: {\n const request = parse(sandboxStateRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n const ctx = resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets });\n if (path === SandboxProviderWirePath.Delete) {\n await implementation.delete(ctx, { state: json(request.state) });\n return {};\n }\n return { state: await implementation.detach(ctx, { state: json(request.state) }) };\n }\n case SandboxProviderWirePath.Park: {\n const request = parse(sandboxParkRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n return {\n state: await implementation.park(\n resourceContext({ sandboxId: request.sandboxId, secrets: request.secrets }),\n { artifact: json(request.artifact), state: json(request.state) },\n ),\n };\n }\n case SandboxProviderWirePath.ReadSnapshot: {\n const request = parse(sandboxReadSnapshotRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n if (implementation.readSnapshot == null) throw unsupported('snapshot reads');\n const response = await implementation.readSnapshot(\n { ...base(request.secrets), sandboxId: request.sandboxId },\n json(request.state),\n parse(sandboxSnapshotRequestSchema, request.request),\n );\n return response == null ? null : { ...response };\n }\n case SandboxProviderWirePath.Processes: {\n const request = parse(sandboxProcessesRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n if (implementation.processes == null) throw unsupported('process inspection');\n return {\n ...(await implementation.processes(\n { ...base(request.secrets), sandboxId: request.sandboxId },\n json(request.state),\n request.request,\n )),\n };\n }\n case SandboxProviderWirePath.Editor: {\n const request = parse(sandboxEditorRequestSchema, body);\n requireSandbox(identity, request.sandboxId);\n const implementation = implementationOf(mount, request.environment);\n if (implementation.editor == null) throw unsupported('editor');\n return {\n ...(await implementation.editor(\n { ...base(request.secrets), sandboxId: request.sandboxId },\n json(request.state),\n parse(editorRequestSchema, request.request),\n )),\n };\n }\n default:\n throw unsupported(`call ${path}`);\n }\n };\n\n const fetchHandler = async (request: Request): Promise<Response> => {\n const url = new URL(request.url);\n const routed = route(url);\n if (routed == null)\n return errorResponse({\n code: SandboxProviderErrorCode.NotFound,\n message: 'no sandbox provider is served here',\n retryable: false,\n });\n const { mount, path } = routed;\n if (request.method === 'GET' && path === SANDBOX_PROVIDER_DISCOVERY_PATH)\n return Response.json(discoveryOf(mount));\n if (request.method !== 'POST' || path === SandboxProviderWirePath.Attach)\n return errorResponse(invalid(`${request.method} ${path} is not a provider call`), 405);\n const token = /^Bearer\\s+(.+)$/iu.exec(request.headers.get('authorization')?.trim() ?? '')?.[1];\n const identity = await verify(mount, token ?? null);\n if (identity == null || token == null)\n return errorResponse(refused('a valid sandbox-provider assertion is required'), 401);\n const caller: CallerIface = { token, identity };\n let body: unknown;\n try {\n body = await readBody(request);\n } catch (cause) {\n return errorResponse(wireErrorOf(cause));\n }\n if (LONG_CALLS.has(path))\n return ndjsonResponse({ work: () => dispatch(mount, path, caller, body), heartbeatMs });\n try {\n return Response.json(await dispatch(mount, path, caller, body));\n } catch (cause) {\n return errorResponse(wireErrorOf(cause));\n }\n };\n\n const upgrade = (request: Request, socket: WebSocketLikeIface): void => {\n const { channel } = frameChannelFromWebSocket(socket);\n const preamble = preambleChannel(channel);\n const fail = (error: SandboxProviderErrorIface, code: number = HandleRpcCloseCode.Normal) => {\n channel.send(JSON.stringify({ type: 'error', error }));\n channel.close(code, error.message.slice(0, 120));\n };\n void (async () => {\n const routed = route(new URL(request.url));\n if (routed == null || routed.path !== SandboxProviderWirePath.Attach) {\n fail({\n code: SandboxProviderErrorCode.NotFound,\n message: 'no sandbox provider attaches here',\n retryable: false,\n });\n return;\n }\n const { mount } = routed;\n const token = handleRpcTokenFromRequest(request);\n const identity = await verify(mount, token);\n if (identity == null || token == null) {\n fail(\n refused('a valid sandbox-provider assertion is required'),\n HandleRpcCloseCode.Unauthorized,\n );\n return;\n }\n let caller: CallerIface = { token, identity };\n let frame: SandboxAttachFrameIface;\n try {\n const first = await preamble.next();\n if (typeof first !== 'string') throw new Error('the attach request must be a text frame');\n frame = parse(sandboxAttachFrameSchema, JSON.parse(first));\n requireSandbox(identity, frame.sandboxId);\n } catch (cause) {\n fail(wireErrorOf(cause));\n return;\n }\n const heartbeat = setInterval(\n () => channel.send(JSON.stringify({ type: 'heartbeat' })),\n heartbeatMs,\n );\n let reported: NetworkPolicyIface | null = null;\n const ctx: SandboxResourceContextIface = {\n ...contextFor(() => caller, frame.secrets),\n sandboxId: frame.sandboxId,\n storagePath: storagePathOf(identity, frame.sandboxId),\n lifecycle: frame.lifecycle,\n platformEgressHosts: frame.platformEgressHosts,\n platformNetworkPolicy: async (policy) => {\n reported = policy;\n },\n };\n let handle: SandboxProviderHandleIface<NetworkSandboxSessionIface>;\n let attached: SandboxAttachedFrameIface;\n try {\n const implementation = implementationOf(mount, frame.environment);\n if (frame.passive) {\n if (implementation.attachPassive == null) throw unsupported('passive attach');\n handle = await implementation.attachPassive(ctx, {\n artifact: json(frame.artifact),\n state: json(frame.state),\n });\n attached = {\n type: 'attached',\n state: json(frame.state),\n fresh: false,\n booted: false,\n region: null,\n networkPolicy: null,\n };\n } else {\n const attachment = await implementation.attach(ctx, {\n artifact: json(frame.artifact),\n state: json(frame.state),\n });\n handle = attachment.handle;\n attached = {\n type: 'attached',\n state: attachment.state,\n fresh: attachment.fresh,\n booted: attachment.booted,\n region: attachment.region ?? null,\n networkPolicy: reported,\n };\n }\n } catch (cause) {\n clearInterval(heartbeat);\n fail(wireErrorOf(cause));\n return;\n }\n clearInterval(heartbeat);\n // The handle is released once, by the platform or when the socket goes.\n let shutdown: Promise<void> | null = null;\n const lifecycle: HandleLifecycle = {\n onSandboxStop: () => handle.onSandboxStop(),\n onSandboxDelete: (options) => handle.onSandboxDelete(options),\n onRuntimeShutdown: () => {\n shutdown ??= handle.onRuntimeShutdown();\n return shutdown;\n },\n };\n // `initialize { identity }` and `identity/refresh`: an assertion for the\n // same provider and sandbox, which becomes the caller's.\n const authorize: HandleAuthorizeFn = async ({ identity: assertion }) => {\n const next = await verify(mount, assertion ?? null);\n if (\n next == null ||\n assertion == null ||\n next.providerId !== identity.providerId ||\n next.sandboxId !== identity.sandboxId ||\n next.organizationId !== identity.organizationId ||\n next.projectId !== identity.projectId\n )\n return null;\n caller = { token: assertion, identity: next };\n return { expiresAt: new Date(next.expiresAt).toISOString() };\n };\n channel.send(JSON.stringify(attached));\n serveSandboxHandle({\n sandbox: handle.sandbox,\n handle: lifecycle,\n authorize,\n access: { grant: FULL_SANDBOX_GRANT, lifecycle: true },\n mcpChannels: true,\n }).attach(preamble.rest());\n await preamble.closed;\n await lifecycle.onRuntimeShutdown().catch((cause: unknown) =>\n args.log?.('sandbox provider handle shutdown failed', {\n provider: mount.name,\n sandboxId: frame.sandboxId,\n error: cause instanceof Error ? cause.message : String(cause),\n }),\n );\n })();\n };\n\n return { fetch: fetchHandler, upgrade };\n};\n"],
5
+ "mappings": "AACA,SAAS,8CAA8C;AACvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP,YAAY,OAAO;AACnB,SAAS,uBAAwD;AACjE,SAAS,8BAA8B,2BAA2B;AAClE,SAAS,0BAA0B;AACnC,SAAS,0BAAwE;AACjF,SAAS,oCAAoC;AAC7C;AAAA,EACE;AAAA,OAaK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,+BAA+B,0BAA0B,mBAAmB;AACrF,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP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AM,SAAS;AACf,YAAM,UAAU,kBAAkB,EAAE;AAAA,QAAM,CAAC,UACzC,KAAK,MAAM,2CAA2C;AAAA,UACpD,UAAU,MAAM;AAAA,UAChB,WAAW,MAAM;AAAA,UACjB,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;AAAA,QAC9D,CAAC;AAAA,MACH;AAAA,IACF,GAAG;AAAA,EACL;AAEA,SAAO,EAAE,OAAO,cAAc,QAAQ;AACxC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,34 @@
1
+ import type { AnySandboxProviderIface } from "../types.mjs";
2
+ import { type SandboxProviderAssertionArgsIface } from "./adapter.mjs";
3
+ import { type SandboxProviderDiscoveryInputIface } from "./serve.mjs";
4
+ export declare const IN_MEMORY_PLATFORM_ISSUER = "https://platform.sandbox-wire.test";
5
+ export declare const IN_MEMORY_PROVIDER_ORIGIN = "https://providers.sandbox-wire.test";
6
+ export interface InMemoryExchangeIface {
7
+ audience: string;
8
+ sandboxId: string | null;
9
+ userId: string | null;
10
+ }
11
+ export interface InMemorySandboxProviderWireIface {
12
+ provider: AnySandboxProviderIface;
13
+ calls(): string[];
14
+ exchanges(): InMemoryExchangeIface[];
15
+ assertions(): SandboxProviderAssertionArgsIface[];
16
+ dropSockets(): void;
17
+ mintAssertion(claims: SandboxProviderAssertionArgsIface): Promise<string>;
18
+ fetchProvider(request: Request): Promise<Response>;
19
+ readonly url: string;
20
+ }
21
+ export interface ConnectSandboxProviderInMemoryArgsIface {
22
+ provider: AnySandboxProviderIface;
23
+ name?: string;
24
+ discovery?: Partial<SandboxProviderDiscoveryInputIface>;
25
+ forwardedSecrets?: Record<string, string>;
26
+ grants?: string[];
27
+ heartbeatMs?: number;
28
+ downstreamToken?: (args: {
29
+ audience: string;
30
+ userId: string | null;
31
+ }) => string;
32
+ proxy?: (request: Request, next: (request: Request) => Promise<Response>) => Promise<Response>;
33
+ }
34
+ export declare const connectSandboxProviderInMemory: (args: ConnectSandboxProviderInMemoryArgsIface) => Promise<InMemorySandboxProviderWireIface>;