@finalai/final-agent-provider 0.3.2 → 0.3.3
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.
- package/dist/modules/sandboxes/computer.mjs +21 -2
- package/dist/modules/sandboxes/computer.mjs.map +2 -2
- package/dist/modules/sandboxes/testing/fake-backends.d.mts +1 -0
- package/dist/modules/sandboxes/testing/fake-backends.mjs +11 -0
- package/dist/modules/sandboxes/testing/fake-backends.mjs.map +2 -2
- package/package.json +2 -2
|
@@ -43,6 +43,7 @@ import { readComputerSnapshot } from "./computer-snapshots.mjs";
|
|
|
43
43
|
import {
|
|
44
44
|
createComputersApiClient,
|
|
45
45
|
createComputersApiCredentials,
|
|
46
|
+
isComputersApiError,
|
|
46
47
|
isComputersApiStatus
|
|
47
48
|
} from "./computers-api.mjs";
|
|
48
49
|
import { createComputerUseEndpoint } from "./computers-api-mcp.mjs";
|
|
@@ -158,6 +159,8 @@ const sandboxWorkspaceOf = {
|
|
|
158
159
|
[ComputerWorkspacePolicy.Ephemeral]: SandboxWorkspace.Ephemeral
|
|
159
160
|
};
|
|
160
161
|
const isRunningState = (state) => state === ComputerState.Running || state === ComputerState.Paused || state === ComputerState.Resuming;
|
|
162
|
+
const hasNothingToPause = (state) => state === ComputerState.Stopped || state === ComputerState.Shelved || state === ComputerState.Error || state === ComputerState.Deleted;
|
|
163
|
+
const pauseMayHaveSettled = (error) => isComputersApiError(error) && error.statusCode != null && (error.statusCode === 404 || error.statusCode === 409 || error.statusCode >= 500);
|
|
161
164
|
const RUNNING_POLL_MAX_MS = 5e3;
|
|
162
165
|
const createComputerSandboxProvider = (config) => {
|
|
163
166
|
const log = config.log ?? (() => void 0);
|
|
@@ -874,10 +877,26 @@ ${step.run}`,
|
|
|
874
877
|
park: async (ctx, _artifact, rawState) => {
|
|
875
878
|
const state = computerStateSchema.parse(rawState);
|
|
876
879
|
await closeComputerMcp(state.computerId);
|
|
880
|
+
const client = clientFor(ctx.session.organizationId);
|
|
881
|
+
const current = await client.getComputer(state.computerId);
|
|
882
|
+
if (current == null || hasNothingToPause(current.state)) {
|
|
883
|
+
log("computer_sandbox.park_at_rest", {
|
|
884
|
+
computerId: state.computerId,
|
|
885
|
+
state: current?.state ?? null
|
|
886
|
+
});
|
|
887
|
+
return state;
|
|
888
|
+
}
|
|
877
889
|
try {
|
|
878
|
-
await
|
|
890
|
+
await client.action(state.computerId, "pause");
|
|
879
891
|
} catch (error) {
|
|
880
|
-
if (!
|
|
892
|
+
if (!pauseMayHaveSettled(error)) throw error;
|
|
893
|
+
const settled = await client.getComputer(state.computerId);
|
|
894
|
+
if (settled != null && settled.state !== ComputerState.Paused && !hasNothingToPause(settled.state))
|
|
895
|
+
throw error;
|
|
896
|
+
log("computer_sandbox.park_at_rest", {
|
|
897
|
+
computerId: state.computerId,
|
|
898
|
+
state: settled?.state ?? null
|
|
899
|
+
});
|
|
881
900
|
}
|
|
882
901
|
return state;
|
|
883
902
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/sandboxes/computer.ts"],
|
|
4
|
-
"sourcesContent": ["import { ProcessInspectionOperation } from '@finalai/agent-protocol/process-inspection';\nimport {\n formatProviderRef,\n NetworkPolicy,\n packageRef,\n SandboxAccess,\n type JsonValue,\n} from '@finalai/agent-provider';\nimport {\n defineSandboxProvider,\n materializeSandboxSeeds,\n PLATFORM_ENVIRONMENT_NAMES,\n platformProcessEnvironment,\n PortProtocol,\n reportPlatformNetworkPolicy,\n SandboxCapability,\n sandboxSeedArtifact,\n sandboxSeedArtifactSchema,\n sandboxSeedFiles,\n sandboxSeedFilesForStart,\n sandboxSeedIdentity,\n SandboxWorkspace,\n withPlatformEgressHosts,\n writePlatformFiles,\n type NetworkPolicyIface,\n type NetworkSandboxSessionIface,\n type SandboxGuidesIface,\n type SandboxPrepareContextIface,\n type SandboxProviderHandleIface,\n type SandboxProviderIface,\n type SandboxProviderImplementationIface,\n type SandboxStartContextIface,\n} from '@finalai/agent-provider/sandbox';\nimport {\n ComputerBaseState,\n ComputerCommandMode,\n ComputerEgressPolicy,\n ComputerIdlePolicy,\n ComputerImageState,\n ComputerState,\n type ComputerBaseIface,\n type ComputerImageIface,\n type ComputerInfoIface,\n} from '@finalai/computers';\nimport * as z from 'zod';\nimport {\n HOME_BASELINE_MISSING_EXIT_CODE,\n HOME_BASELINE_ROOT,\n homeBaselineScript,\n homeContentScript,\n} from \"./build-scripts.mjs\";\nimport { sleep as defaultSleep, sha256Hex } from \"./bytes.mjs\";\nimport { computerEditor } from \"./computer-editor.mjs\";\nimport { readComputerSnapshot } from \"./computer-snapshots.mjs\";\nimport {\n createComputersApiClient,\n createComputersApiCredentials,\n isComputersApiStatus,\n type ComputersApiClientIface,\n type ComputersApiConfigIface,\n type CreateComputerBodyIface,\n} from \"./computers-api.mjs\";\nimport { createComputerUseEndpoint } from \"./computers-api-mcp.mjs\";\nimport { createComputersApiTransport } from \"./computers-api-transport.mjs\";\nimport {\n COMPUTER_SANDBOX_SPECIFIER,\n computerEnvironmentSchema,\n computerOpenOptionsSchema,\n ComputerWorkspacePolicy,\n} from \"./environment.mjs\";\nimport {\n computeComputerArtifactKey,\n computerNeedsBuild,\n DEFAULT_COMPUTER_IMAGE,\n resolveComputerSpec,\n type ResolvedComputerSpecIface,\n} from \"./guide.mjs\";\nimport { createTransportSession, sessionForAccess } from \"./session.mjs\";\nimport type { SandboxTransportIface } from \"./transport.mjs\";\nimport {\n guideCommands,\n installGuideCommands,\n mountRepositories,\n repositoryPath,\n runWorkspaceSetup,\n startServices,\n WORKSPACE_ROOT,\n type GuideCommandIface,\n type SetupLogIface,\n} from \"./workspace-setup.mjs\";\n\nexport type { ComputersApiConfigIface, ComputersApiCredentialIface } from \"./computers-api.mjs\";\nexport {\n COMPUTER_SANDBOX_SPECIFIER,\n COMPUTERS_API_KEY_SECRET,\n COMPUTERS_API_TEAM_SECRET,\n} from \"./environment.mjs\";\nexport { computeComputerArtifactKey } from \"./guide.mjs\";\nexport type { ComputerGuideVersionIface } from \"./guide.mjs\";\nexport type { RepositoryCloneSourceIface } from \"./workspace-setup.mjs\";\n\n// The `computer` sandbox: a Final computer from the\n// public Computers API, set up from a computer setup guide, with lifecycle,\n// files and processes all through that API and the organization's own API key,\n// exactly as a third-party provider drives its vendor. Like every\n// provider, it is served by the session service, which runs this handle and\n// serves the handle RPC and MCP projection from it.\n//\n// A guide with build or verify steps is built once on a builder computer and\n// captured as a base (POST /v1/computers/:id/capture); its computers are created\n// from that base. Network and idle policies are create options, as for any\n// API customer.\n//\n// Guides, variables and repository credentials come from the contract's\n// prepare and start contexts (`guides`, `variables`, `repositories`), which the\n// session service serves to every provider alike.\n\nexport interface ComputerSandboxLogIface {\n (message: string, fields?: Record<string, string | number | boolean | null>): void;\n}\n\nexport interface ComputerSandboxProviderConfigIface {\n // The public Computers API, and each organization's credential for it.\n computersApi: ComputersApiConfigIface;\n // A registry credential (`creg_...`) the organization stored for private image references.\n registryCredentialId?: string;\n // Image for an empty environment without an organization default guide.\n defaultImage?: string;\n regionSlug?: string;\n machine?: { vcpu?: number; memoryMb?: number; diskGb?: number };\n idleTimeoutSeconds?: number;\n // How long `start` waits for a registered image version to finish building.\n imageWaitMs?: number;\n imagePollMs?: number;\n // How long `prepare` waits for a guide's base capture to publish.\n buildWaitMs?: number;\n buildPollMs?: number;\n // How long ending a conversation workspace waits for its computer to shelve.\n shelveWaitMs?: number;\n shelvePollMs?: number;\n // How long start, resume and a guide build wait for a computer to run before\n // touching it (default 5 min); polled from runningPollMs (default 250 ms), doubling to 5 s.\n runningWaitMs?: number;\n runningPollMs?: number;\n log?: ComputerSandboxLogIface;\n randomUuid?: () => string;\n now?: () => number;\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n}\n\n// An `image` base: `imageVersionId` is the registered version (`cimv_...`) of an\n// image reference, registered at prepare; a `lineage:` image resolves its newest\n// version at start. A `captured` base is a guide's build, captured as a base\n// (`part_...`) that computers are created from.\nconst computerArtifactSchema = sandboxSeedArtifactSchema.extend({\n version: z.literal(1),\n key: z.string(),\n image: z.string(),\n diskGb: z.number().nullable(),\n base: z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal('image'),\n image: z.string(),\n imageVersionId: z.string().nullable().default(null),\n }),\n z.object({ kind: z.literal('captured'), baseId: z.string() }),\n ]),\n});\n\nconst computerStateSchema = z.object({\n version: z.literal(1),\n computerId: z.string(),\n computerName: z.string(),\n workspace: z.nativeEnum(ComputerWorkspacePolicy),\n access: z.nativeEnum(SandboxAccess),\n guideVersionId: z.string().nullable(),\n setupHash: z.string().nullable(),\n});\n\n// The provider's own view of a computer while it sets it up.\ninterface SetupSessionIface {\n sandbox: NetworkSandboxSessionIface;\n transport: SandboxTransportIface;\n}\n\nexport type ComputerSandboxArtifact = z.infer<typeof computerArtifactSchema>;\nexport type ComputerSandboxState = z.infer<typeof computerStateSchema>;\n\n// What Build needs to know about a started computer beyond the handle.\nexport interface ComputerSandboxDescriptionIface {\n provider: 'computer';\n computerId: string;\n computerName: string;\n workspaceRoot: string;\n transport: string;\n guide: { slug: string; number: number } | null;\n repositories: { alias: string; path: string; repository: string }[];\n services: { name: string; readyUrl: string | null }[];\n commands: GuideCommandIface[];\n capabilities: SandboxCapability[];\n}\n\nexport interface ComputerSandboxSessionIface extends NetworkSandboxSessionIface {\n describe(): ComputerSandboxDescriptionIface;\n // What this computer's handle offers (the session service reports it).\n readonly capabilities: readonly SandboxCapability[];\n}\n\nexport type ComputerSandboxProviderIface = SandboxProviderIface<\n JsonValue,\n JsonValue,\n ComputerSandboxArtifact,\n ComputerSandboxState,\n ComputerSandboxSessionIface\n>;\n\nexport interface ComputerSandboxErrorIface extends Error {\n code:\n | 'artifact_unavailable'\n | 'computer_gone'\n | 'computer_not_running'\n | 'invalid_environment'\n | 'build_failed';\n}\n\nconst computerSandboxError = (\n code: ComputerSandboxErrorIface['code'],\n message: string,\n): ComputerSandboxErrorIface =>\n Object.assign(new Error(message), { name: 'ComputerSandboxError', code });\n\n// FINAL_NODE_* and the session basics belong to the platform (shared/src/sandbox-templates/reserved.ts),\n// as do the platform environment's variables (the egress proxy and its placeholders).\nconst RESERVED_ENV = new Set([\n ...PLATFORM_ENVIRONMENT_NAMES,\n 'DISPLAY',\n 'XDG_RUNTIME_DIR',\n 'PATH',\n 'HOME',\n 'USER',\n 'SHELL',\n 'HOSTNAME',\n]);\nconst isReservedEnvName = (name: string): boolean =>\n name.startsWith('FINAL_NODE_') || RESERVED_ENV.has(name);\n\nconst HTTP_TOKEN_LIFETIME_MS = 60 * 60_000;\nconst HTTP_TOKEN_RENEW_MS = 5 * 60_000;\n\n// Builds run from here; the capture scrub removes /tmp/*.\nconst BUILD_ROOT = '/tmp/final-build';\n// Guide publication supplies build inputs in files; agent revisions supply workspace seeds.\nconst seedsFor = (ctx: SandboxPrepareContextIface): Record<string, string> =>\n sandboxSeedFiles({\n files: ctx.resources.guide == null ? ctx.files : {},\n resources: ctx.resources,\n });\n// What the Computers API's capture scrub removes, so the home check skips it.\nconst CAPTURE_SCRUBBED_PATHS = [\n '/home/user/.bash_history',\n '/home/user/.zsh_history',\n '/home/user/.sh_history',\n '/home/user/.git-credentials',\n '/home/user/.config/gh/hosts.yml',\n '/home/user/.npmrc',\n '/home/user/.pypirc',\n '/home/user/.cargo/credentials',\n '/home/user/.cargo/credentials.toml',\n '/home/user/.aws',\n '/home/user/.config/gcloud',\n '/home/user/.azure',\n '/home/user/.docker/config.json',\n '/home/user/.netrc',\n '/home/user/.ssh',\n];\nconst BUILDER_IDLE_TIMEOUT_SECONDS = 2 * 60 * 60;\n\ninterface ComputerEgressConfigIface {\n egress: ComputerEgressPolicy;\n allow?: string[];\n}\n\nconst computerEgressOf = (policy: NetworkPolicyIface): ComputerEgressConfigIface => {\n if (policy.mode === NetworkPolicy.AllowAll) return { egress: ComputerEgressPolicy.Internet };\n if (policy.mode === NetworkPolicy.DenyAll) return { egress: ComputerEgressPolicy.None };\n return { egress: ComputerEgressPolicy.Allowlist, allow: policy.allow ?? [] };\n};\n\n// An allowlist also admits the platform's egress hosts, so its proxy stays reachable.\nconst egressFor = (\n ctx: SandboxStartContextIface,\n requested: NetworkPolicyIface,\n): ComputerEgressConfigIface => computerEgressOf(withPlatformEgressHosts(ctx, requested));\n\nconst LINEAGE_PREFIX = 'lineage:';\n\nconst portOf = (url: string): number | null => {\n try {\n const parsed = new URL(url);\n if (parsed.port !== '') return Number(parsed.port);\n return parsed.protocol === 'https:' ? 443 : 80;\n } catch {\n return null;\n }\n};\n\nconst compactId = (id: string): string => id.replaceAll('-', '');\n\nconst sandboxWorkspaceOf = {\n [ComputerWorkspacePolicy.Session]: SandboxWorkspace.Session,\n [ComputerWorkspacePolicy.Conversation]: SandboxWorkspace.Conversation,\n [ComputerWorkspacePolicy.Ephemeral]: SandboxWorkspace.Ephemeral,\n} satisfies Record<ComputerWorkspacePolicy, SandboxWorkspace>;\n\nconst isRunningState = (state: ComputerState): boolean =>\n state === ComputerState.Running ||\n state === ComputerState.Paused ||\n state === ComputerState.Resuming;\n\nconst RUNNING_POLL_MAX_MS = 5_000;\n\nexport const createComputerSandboxProvider = (\n config: ComputerSandboxProviderConfigIface,\n): ComputerSandboxProviderIface => {\n const log: SetupLogIface = config.log ?? (() => undefined);\n const randomUuid = config.randomUuid ?? (() => crypto.randomUUID());\n const now = config.now ?? (() => Date.now());\n const sleep = config.sleep ?? defaultSleep;\n const defaultImage = config.defaultImage ?? DEFAULT_COMPUTER_IMAGE;\n const credentials = createComputersApiCredentials(config.computersApi, now);\n const runningWaitMs = config.runningWaitMs ?? 5 * 60_000;\n\n const clientFor = (organizationId: string): ComputersApiClientIface =>\n createComputersApiClient({ config: config.computersApi, credentials, organizationId });\n\n const registerImage = (client: ComputersApiClientIface, reference: string) =>\n client.registerImage(\n config.registryCredentialId == null\n ? { reference }\n : { reference, registryCredentialId: config.registryCredentialId },\n );\n\n // Computers are created from registered image versions, as any API customer's are.\n // A `lineage:` image is the newest ready version of that lineage (the\n // organization's or the platform's); a reference is registered once, at prepare,\n // and registered again here when its version expired.\n const readyImageVersion = async (\n client: ComputersApiClientIface,\n base: { image: string; imageVersionId: string | null },\n ): Promise<string> => {\n if (base.image.startsWith(LINEAGE_PREFIX)) {\n const lineage = base.image.slice(LINEAGE_PREFIX.length);\n const [newest] = await client.listImages({ lineage, state: ComputerImageState.Ready });\n if (newest == null) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `the Computers API has no ready image version in lineage ${lineage}`,\n );\n }\n return newest.id;\n }\n let version: ComputerImageIface | null = null;\n if (base.imageVersionId != null) {\n try {\n version = await client.getImage(base.imageVersionId);\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n }\n if (version == null || version.state === ComputerImageState.Expired) {\n version = await registerImage(client, base.image);\n }\n const deadline = now() + (config.imageWaitMs ?? 15 * 60_000);\n while (\n version.state === ComputerImageState.Pending ||\n version.state === ComputerImageState.Building\n ) {\n if (now() >= deadline) throw new Error(`image ${base.image} is still building`);\n await sleep(config.imagePollMs ?? 5_000);\n version = await client.getImage(version.id);\n }\n if (version.state !== ComputerImageState.Ready) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `image ${base.image} is ${version.state}${version.error == null ? '' : `: ${version.error}`}`,\n );\n }\n return version.id;\n };\n\n const loadVariables = async (\n ctx: SandboxStartContextIface,\n spec: ResolvedComputerSpecIface,\n ): Promise<Record<string, string>> => {\n const env: Record<string, string> = {};\n for (const [name, value] of Object.entries(spec.parameters.env)) {\n if (isReservedEnvName(name))\n throw computerSandboxError('invalid_environment', `${name} is reserved`);\n env[name] = value;\n }\n for (const name of spec.parameters.variables) {\n if (isReservedEnvName(name))\n throw computerSandboxError('invalid_environment', `${name} is reserved`);\n const value = await ctx.variables.get(name);\n if (value == null)\n throw computerSandboxError('invalid_environment', `variable ${name} is not set`);\n env[name] = value;\n }\n return env;\n };\n\n const mcpClosers = new Map<string, Set<() => Promise<void>>>();\n const closeComputerMcp = async (computerId: string) => {\n const results = await Promise.allSettled(\n [...(mcpClosers.get(computerId) ?? [])].map((close) => close()),\n );\n for (const result of results) if (result.status === 'rejected') throw result.reason;\n };\n const buildHandle = async (args: {\n ctx: SandboxStartContextIface;\n client: ComputersApiClientIface;\n info: ComputerInfoIface;\n spec: ResolvedComputerSpecIface;\n access: SandboxAccess;\n env: () => Promise<Record<string, string>>;\n }): Promise<{ handle: SandboxProviderHandleIface<ComputerSandboxSessionIface> }> => {\n const { client, info, spec } = args;\n const commands = await guideCommands(spec.template);\n const commandHelp = commands\n .map(\n (command) =>\n `Guide command ${command.name}: bash ${command.path}${command.description == null ? '' : ` \u2014 ${command.description}`}`,\n )\n .join('\\n');\n const transport = createComputersApiTransport({ client, computerId: info.id });\n const ports = [\n ...new Set(\n spec.template.services.flatMap((service) => {\n const port = service.ready == null ? null : portOf(service.ready.url);\n return port == null ? [] : [port];\n }),\n ),\n ];\n let httpToken: { token: string; expiresAtMs: number } | null = null;\n const session = createTransportSession({\n id: info.id,\n description: `Final computer ${info.name}${spec.guide == null ? '' : ` (${spec.guide.title} v${spec.guide.number})`}${commands.length === 0 ? '' : `\\n${commandHelp}`}`,\n workspaceRoot: WORKSPACE_ROOT,\n transport,\n baseEnv: args.env,\n randomUuid,\n network: {\n ports,\n // The computer's hostname with a preview token, which opens its HTTP ports only.\n getPortEndpoint: async ({ port, protocol }) => {\n const hostname = info.hostname ?? (await client.getComputer(info.id))?.hostname ?? null;\n if (hostname == null) throw new Error(`computer ${info.name} has no public hostname`);\n if (httpToken == null || httpToken.expiresAtMs - now() < HTTP_TOKEN_RENEW_MS) {\n const expiresAtMs = now() + HTTP_TOKEN_LIFETIME_MS;\n const token = await client.createPreviewToken({\n computerId: info.id,\n name: `agent sandbox ${args.ctx.session.bindingId}`,\n expiresAt: new Date(expiresAtMs),\n });\n httpToken = { token, expiresAtMs };\n }\n const scheme = protocol === PortProtocol.Ws ? 'wss' : 'https';\n return {\n url: `${scheme}://${port === 443 ? hostname : `${hostname}:${port}`}`,\n headers: { authorization: `Bearer ${httpToken.token}` },\n };\n },\n stop: async () => {\n await closeComputerMcp(info.id);\n await client.action(info.id, 'stop');\n },\n destroy: async () => {\n await closeComputerMcp(info.id);\n transport.close();\n try {\n await client.action(info.id, 'delete');\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n },\n },\n });\n let computerUseInstalled: boolean | null = null;\n if (args.access !== SandboxAccess.Read) {\n try {\n computerUseInstalled = (await client.computerUseStatus(info.id, AbortSignal.timeout(1000)))\n .installed;\n } catch {\n /* Optional discovery must never fail the sandbox. */\n }\n }\n const computerUse =\n args.access === SandboxAccess.Read || computerUseInstalled === false\n ? null\n : createComputerUseEndpoint({ client, computerId: info.id, cwd: WORKSPACE_ROOT });\n const closeMcp = async () => {\n try {\n await computerUse?.close();\n } catch (error) {\n log('computer_use.close_failed', {\n computerId: info.id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n const closers = mcpClosers.get(info.id);\n closers?.delete(closeMcp);\n if (closers?.size === 0) mcpClosers.delete(info.id);\n };\n if (computerUse != null) {\n const closers = mcpClosers.get(info.id) ?? new Set<() => Promise<void>>();\n closers.add(closeMcp);\n mcpClosers.set(info.id, closers);\n }\n const capabilities = [SandboxCapability.Files, SandboxCapability.Ports];\n let screenAvailable = false;\n try {\n screenAvailable = (await client.screenStatus(info.id, AbortSignal.timeout(1000))).available;\n } catch {\n /* Optional desktop discovery leaves headless computers usable. */\n }\n if (screenAvailable) capabilities.push(SandboxCapability.Screen);\n if (computerUse != null) capabilities.push(SandboxCapability.ComputerUse);\n if (args.access !== SandboxAccess.Read)\n capabilities.push(SandboxCapability.Process, SandboxCapability.NetworkPolicy);\n const description: ComputerSandboxDescriptionIface = {\n provider: 'computer',\n computerId: info.id,\n computerName: info.name,\n workspaceRoot: WORKSPACE_ROOT,\n transport: transport.kind,\n guide: spec.guide == null ? null : { slug: spec.guide.slug, number: spec.guide.number },\n repositories: spec.parameters.repositories.map((repository) => ({\n alias: repository.alias,\n path: repositoryPath(repository.alias),\n repository: repository.repository,\n })),\n services: spec.template.services.map((service) => ({\n name: service.name,\n readyUrl: service.ready?.url ?? null,\n })),\n commands,\n capabilities,\n };\n const full: ComputerSandboxSessionIface = {\n ...session,\n setNetworkPolicy: async (policy) => {\n if (args.access === SandboxAccess.Read)\n throw new Error('this sandbox binding is read-only');\n await client.setNetworkPolicy(info.id, egressFor(args.ctx, policy));\n },\n describe: () => description,\n capabilities,\n };\n if (computerUse != null) full.computerUse = async () => computerUse.endpoint;\n if (screenAvailable) {\n full.screen = (options) => client.openScreen(info.id, options);\n }\n const sandbox = sessionForAccess(full, args.access);\n return {\n handle: {\n sandbox,\n onSandboxStop: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n },\n onSandboxDelete: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n try {\n await client.action(info.id, 'delete');\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n },\n onRuntimeShutdown: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n },\n },\n };\n };\n\n // Setup (repositories, workspace.setup, services) is the provider's own work, so it\n // runs with the organization's credential, never through the binding's lease: a\n // read binding still gets a set-up computer.\n const setupSession = (args: {\n client: ComputersApiClientIface;\n info: ComputerInfoIface;\n env: () => Promise<Record<string, string>>;\n }): SetupSessionIface => {\n const transport = createComputersApiTransport({\n client: args.client,\n computerId: args.info.id,\n });\n const sandbox = createTransportSession({\n id: args.info.id,\n description: `setup of ${args.info.name}`,\n workspaceRoot: WORKSPACE_ROOT,\n transport,\n baseEnv: args.env,\n randomUuid,\n network: {\n ports: [],\n getPortEndpoint: async () => {\n throw new Error('setup sessions expose no ports');\n },\n stop: async () => undefined,\n destroy: async () => undefined,\n },\n });\n return { sandbox, transport };\n };\n\n // A captured base, once it is ready; a failed or expired one must be built again.\n const awaitBase = async (\n client: ComputersApiClientIface,\n baseId: string,\n key: string,\n ): Promise<ComputerBaseIface> => {\n const deadline = now() + (config.buildWaitMs ?? 30 * 60_000);\n for (;;) {\n const base = await client.getBase(baseId);\n if (base == null || base.state === ComputerBaseState.Expired) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `computer base ${key} (${baseId}) is ${base == null ? 'gone' : 'expired'}; prepare it again`,\n );\n }\n if (base.state === ComputerBaseState.Ready) return base;\n if (base.state === ComputerBaseState.Failed) {\n throw computerSandboxError(\n 'build_failed',\n `computer base ${key} failed to capture: ${base.error ?? 'unknown error'}`,\n );\n }\n if (now() >= deadline) throw new Error(`computer base ${key} is still capturing`);\n await sleep(config.buildPollMs ?? 5_000);\n }\n };\n\n // The Computers API answers a computer it created or started before the\n // computer has a host, and refuses commands and file writes until it runs\n // (`autoResume: false`), so nothing touches it before this resolves. Only\n // Running counts: a paused computer still refuses them.\n const awaitComputerRunning = async (\n client: ComputersApiClientIface,\n computerId: string,\n timeoutMs: number,\n ): Promise<ComputerInfoIface> => {\n const deadline = now() + timeoutMs;\n let pollMs = config.runningPollMs ?? 250;\n for (;;) {\n const computer = await client.getComputer(computerId);\n if (computer == null || computer.state === ComputerState.Deleted)\n throw computerSandboxError('computer_gone', `computer ${computerId} is gone`);\n if (computer.state === ComputerState.Error)\n throw computerSandboxError(\n 'computer_gone',\n `computer ${computer.name} is in the Error state`,\n );\n if (computer.state === ComputerState.Running) return computer;\n const left = deadline - now();\n if (left <= 0)\n throw computerSandboxError(\n 'computer_not_running',\n `computer ${computer.name} was not running within ${Math.round(timeoutMs / 1000)} s (it is ${ComputerState[computer.state]})`,\n );\n await sleep(Math.min(pollMs, left));\n pollMs = Math.min(pollMs * 2, RUNNING_POLL_MAX_MS);\n }\n };\n\n const awaitShelved = async (client: ComputersApiClientIface, computerId: string) => {\n const deadline = now() + (config.shelveWaitMs ?? 5 * 60_000);\n for (;;) {\n const computer = await client.getComputer(computerId);\n if (\n computer == null ||\n computer.state === ComputerState.Shelved ||\n computer.state === ComputerState.Deleted\n )\n return;\n if (computer.state === ComputerState.Error)\n throw computerSandboxError('computer_gone', `computer ${computerId} failed to shelve`);\n if (now() >= deadline) throw new Error(`computer ${computerId} is still shelving`);\n await sleep(config.shelvePollMs ?? 2_000);\n }\n };\n\n // Run build.steps, then build.verify, on a builder computer of the guide's\n // image, captured as a base its computers are created from.\n const build = async (\n ctx: SandboxPrepareContextIface,\n spec: ResolvedComputerSpecIface,\n key: string,\n ): Promise<ComputerSandboxArtifact> => {\n const client = clientFor(ctx.organizationId);\n const diskGb = config.machine?.diskGb ?? null;\n const imageVersionId = await readyImageVersion(client, {\n image: spec.image,\n imageVersionId: null,\n });\n const body: CreateComputerBodyIface = {\n name: `ag-${key.slice(4, 20)}-${compactId(randomUuid()).slice(0, 8)}`,\n imageVersionId,\n ...config.machine,\n // The base is the root disk; a user volume would keep /home and /workspaces off it.\n userVolumeGb: null,\n // Nothing secret at create: the create env lands in the guest.\n env: {},\n commandMode: ComputerCommandMode.Custom,\n customCommand: 'sleep infinity',\n autoResume: false,\n idleTimeoutSeconds: BUILDER_IDLE_TIMEOUT_SECONDS,\n tags: ['final-agent-sandbox-build'],\n };\n if (config.regionSlug != null) body.regionSlug = config.regionSlug;\n // One builder per attempt: a retry after a failed build starts clean.\n const builder = await client.createComputer(\n body,\n `agent-guide-build-${(await sha256Hex(`${key}:${randomUuid()}`)).slice(0, 32)}`,\n );\n ctx.log?.(`building computer base ${key} on ${builder.name}`);\n try {\n await awaitComputerRunning(client, builder.id, runningWaitMs);\n const sandbox = setupSession({ client, info: builder, env: async () => ({}) }).sandbox;\n const prepared = await sandbox.run({\n command: '/bin/sh',\n args: ['-c', `mkdir -p ${BUILD_ROOT}\\n${homeBaselineScript()}`],\n cwd: '/',\n });\n if (prepared.exitCode !== 0) {\n throw computerSandboxError('build_failed', 'failed to record the pre-build home baseline');\n }\n const steps = [\n ...spec.template.build.steps.map((step) => ({ step, label: 'build step' })),\n ...spec.template.build.verify.map((step) => ({ step, label: 'verify step' })),\n ];\n for (const [index, { step, label }] of steps.entries()) {\n ctx.log?.(`${label} ${index + 1}/${steps.length}`);\n const result = await sandbox.run({\n command: `set -eu\\n${step.run}`,\n shell: true,\n cwd: BUILD_ROOT,\n timeoutMs: step.timeoutMinutes * 60_000,\n });\n if (result.exitCode !== 0) {\n throw computerSandboxError(\n 'build_failed',\n `${label} ${index + 1} failed (exit ${result.exitCode}): ${result.stderr.trim().slice(-2000)}`,\n );\n }\n }\n const homeContent = await sandbox.run({\n command: '/bin/sh',\n args: ['-c', homeContentScript({ excludedPaths: CAPTURE_SCRUBBED_PATHS })],\n cwd: '/',\n });\n if (homeContent.exitCode === HOME_BASELINE_MISSING_EXIT_CODE) {\n throw computerSandboxError(\n 'build_failed',\n `build steps removed ${HOME_BASELINE_ROOT}, which the home content check needs; leave /var/tmp/final-template-build in place.`,\n );\n }\n if (homeContent.exitCode !== 0) {\n const offending = homeContent.stdout\n .trim()\n .split('\\n')\n .filter((line) => line !== '');\n throw computerSandboxError(\n 'build_failed',\n `build steps left content under /home or /workspaces, which each computer's own volume hides: ${offending.join(', ')}. Install tools and configuration to system paths such as /usr/local, or point the tool's home there (for example CARGO_HOME=/usr/local/cargo, RUSTUP_HOME=/usr/local/rustup, NVM_DIR=/usr/local/nvm), put home files in /usr/share/final-vm/home-skel, and use /etc/gitconfig instead of git config --global.`,\n );\n }\n const captured = await client.captureComputer(builder.id, { retained: true });\n if (!captured.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the built base',\n );\n ctx.log?.(`capturing computer base ${key} as ${captured.id}`);\n const base = await awaitBase(client, captured.id, key);\n return {\n version: 1,\n key,\n image: spec.image,\n diskGb: diskGb ?? base.diskGb,\n seedFiles: {},\n base: { kind: 'captured', baseId: base.id },\n };\n } finally {\n // The capture stopped the builder; it is not part of the base.\n try {\n await client.action(builder.id, 'delete');\n } catch (error) {\n log('computer_sandbox.builder_delete_failed', {\n computerId: builder.id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n };\n\n const environment = (\n rawOptions?: JsonValue,\n ): SandboxProviderImplementationIface<\n JsonValue,\n ComputerSandboxArtifact,\n ComputerSandboxState,\n ComputerSandboxSessionIface\n > => {\n const parsed = computerEnvironmentSchema.safeParse(rawOptions ?? {});\n if (!parsed.success) {\n throw computerSandboxError(\n 'invalid_environment',\n `invalid computer environment: ${parsed.error.message}`,\n );\n }\n const options = parsed.data;\n const resolve = (guides: SandboxGuidesIface): Promise<ResolvedComputerSpecIface> =>\n resolveComputerSpec({ options, guides, defaultImage });\n const keyFor = async (\n spec: ResolvedComputerSpecIface,\n files: Record<string, string>,\n ): Promise<string> => {\n const baseKey = await computeComputerArtifactKey({\n image: spec.image,\n template: spec.template,\n diskGb: config.machine?.diskGb ?? null,\n });\n return Object.keys(files).length === 0\n ? baseKey\n : `${baseKey}-s${await sha256Hex(sandboxSeedIdentity(files))}`;\n };\n\n const startServicesFor = async (args: {\n setup: SetupSessionIface;\n spec: ResolvedComputerSpecIface;\n env: () => Promise<Record<string, string>>;\n }): Promise<void> => {\n await startServices({\n sandbox: args.setup.sandbox,\n transport: args.setup.transport,\n template: args.spec.template,\n // Services run for the computer's life, with the platform's values as they are now.\n env: await args.env(),\n randomUuid,\n log,\n });\n };\n\n const awaitRunning = (\n ctx: SandboxStartContextIface,\n rawState: Pick<ComputerSandboxState, 'computerId'>,\n options: { timeoutMs: number },\n ): Promise<ComputerInfoIface> =>\n awaitComputerRunning(\n clientFor(ctx.session.organizationId),\n computerStateSchema.pick({ computerId: true }).parse(rawState).computerId,\n options.timeoutMs,\n );\n\n return {\n processes: async (ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n if (\n request.operation === ProcessInspectionOperation.Stop &&\n state.access === SandboxAccess.Read\n )\n throw new Error('stopping processes requires execute access');\n const result = await clientFor(ctx.organizationId).inspectProcesses(\n state.computerId,\n request,\n );\n return request.operation === ProcessInspectionOperation.Available && 'available' in result\n ? { ...result, canStop: state.access !== SandboxAccess.Read }\n : result;\n },\n editor: async (_ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n if (state.access !== SandboxAccess.Write) {\n if (request.operation === 'available') return { available: false };\n throw new Error('editor requires write access');\n }\n return computerEditor({\n client: clientFor(_ctx.organizationId),\n computerId: state.computerId,\n request,\n randomUuid,\n });\n },\n readSnapshot: async (ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n return readComputerSnapshot({\n client: clientFor(ctx.organizationId),\n computerId: state.computerId,\n request,\n });\n },\n // The merged parameters' workspace: the binding's, else the saved version's default.\n workspace: async (ctx) =>\n sandboxWorkspaceOf[(await resolve(ctx.guides)).parameters.workspace],\n artifactKey: async (ctx) => keyFor(await resolve(ctx.guides), seedsFor(ctx)),\n // Registers an image reference so its version builds ahead of the first start;\n // a lineage needs nothing until then.\n prepare: async (ctx) => {\n const spec = await resolve(ctx.guides);\n const seedFiles = seedsFor(ctx);\n const key = await keyFor(spec, seedFiles);\n const seedArtifact = await sandboxSeedArtifact(ctx, seedFiles);\n if (computerNeedsBuild(spec)) {\n const baseKey = await keyFor(spec, {});\n const prepared = spec.guide?.preparedArtifact;\n if (\n prepared?.key === baseKey &&\n prepared.providerRef === formatProviderRef(packageRef(COMPUTER_SANDBOX_SPECIFIER))\n ) {\n const cached = computerArtifactSchema.safeParse(prepared.artifact);\n if (\n cached.success &&\n cached.data.key === baseKey &&\n cached.data.base.kind === 'captured'\n ) {\n const base = await clientFor(ctx.organizationId).getBase(cached.data.base.baseId);\n if (base?.state === ComputerBaseState.Ready) {\n if (!base.retained) {\n const retained = await clientFor(ctx.organizationId).setBaseRetention(\n base.id,\n true,\n );\n if (!retained.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the prepared base',\n );\n }\n return { ...cached.data, key, ...seedArtifact };\n }\n }\n }\n const cached = computerArtifactSchema.safeParse(await ctx.artifacts?.get(baseKey));\n if (\n cached.success &&\n cached.data.key === baseKey &&\n cached.data.base.kind === 'captured'\n ) {\n const base = await clientFor(ctx.organizationId).getBase(cached.data.base.baseId);\n if (base?.state === ComputerBaseState.Ready) {\n if (!base.retained) {\n const retained = await clientFor(ctx.organizationId).setBaseRetention(\n base.id,\n true,\n );\n if (!retained.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the prepared base',\n );\n }\n return { ...cached.data, key, ...seedArtifact };\n }\n }\n const built = await build(ctx, spec, baseKey);\n await ctx.artifacts?.put(baseKey, built);\n return { ...built, key, ...seedArtifact };\n }\n const imageVersionId = spec.image.startsWith(LINEAGE_PREFIX)\n ? null\n : (await registerImage(clientFor(ctx.organizationId), spec.image)).id;\n ctx.log?.(`computer base ${key} is image ${spec.image}`);\n return {\n version: 1,\n key,\n image: spec.image,\n diskGb: config.machine?.diskGb ?? null,\n ...seedArtifact,\n base: { kind: 'image', image: spec.image, imageVersionId },\n };\n },\n awaitRunning: async (ctx, state, options) => {\n await awaitRunning(ctx, state, options);\n },\n start: async (ctx, openOptions, rawArtifact) => {\n const access = computerOpenOptionsSchema.parse(openOptions ?? {}).access;\n const spec = await resolve(ctx.guides);\n const policy = withPlatformEgressHosts(ctx, spec.parameters.networkPolicy);\n const egress = computerEgressOf(policy);\n const artifact = computerArtifactSchema.safeParse(rawArtifact);\n if (!artifact.success) {\n throw computerSandboxError(\n 'artifact_unavailable',\n 'this computer base predates the public Computers API provider; prepare it again',\n );\n }\n const base = artifact.data.base;\n if (computerNeedsBuild(spec) && base.kind !== 'captured') {\n throw computerSandboxError(\n 'artifact_unavailable',\n `computer base ${artifact.data.key} was prepared without its build steps; prepare it again`,\n );\n }\n // Variables resolve before anything is created, so a missing one costs nothing.\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n const client = clientFor(ctx.session.organizationId);\n const workspace = spec.parameters.workspace;\n const name =\n workspace === ComputerWorkspacePolicy.Conversation && ctx.session.conversationId != null\n ? `ac-${(await sha256Hex(`${ctx.session.conversationId}:${ctx.session.target}`)).slice(0, 24)}`\n : `ab-${compactId(ctx.session.bindingId)}`;\n const existing = await client.getComputer(name);\n if (existing?.state === ComputerState.Error)\n throw computerSandboxError(\n 'computer_gone',\n `Computer ${existing.id} (${name}) is in the Error state. Recover it through the Computers API before retrying; its workspace is preserved.`,\n );\n let info: ComputerInfoIface;\n let fresh = true;\n if (existing != null && existing.state !== ComputerState.Deleted) {\n info = existing;\n fresh = !isRunningState(existing.state);\n if (existing.state === ComputerState.Paused) await client.action(existing.id, 'resume');\n else if (fresh) await client.action(existing.id, 'start');\n } else {\n const source: Pick<CreateComputerBodyIface, 'baseId' | 'imageVersionId'> =\n base.kind === 'captured'\n ? { baseId: (await awaitBase(client, base.baseId, artifact.data.key)).id }\n : { imageVersionId: await readyImageVersion(client, base) };\n const body: CreateComputerBodyIface = {\n name,\n ...source,\n ...config.machine,\n env: {},\n autoResume: true,\n idleTimeoutSeconds: config.idleTimeoutSeconds ?? 15 * 60,\n // Provider teardown owns deletion; VM-level ephemeral disks cannot be paused.\n ephemeral: false,\n network: egress,\n tags: [\n 'final-agent-sandbox',\n `agent-binding:${ctx.session.bindingId}`,\n 'agent-runtime-attachment:v1',\n 'agent-runtime-role:sandbox',\n ],\n };\n // Session teardown owns deletion, including ephemeral computers. Idle must preserve files.\n body.idlePolicy = ComputerIdlePolicy.Pause;\n if (config.regionSlug != null) body.regionSlug = config.regionSlug;\n // Keyed by the source too: a retry after re-registering is a different request.\n const idempotencyKey = `agent-sandbox-${(await sha256Hex(`${ctx.session.bindingId}:${name}:${source.baseId ?? source.imageVersionId}`)).slice(0, 32)}`;\n info = await client.createComputer(body, idempotencyKey);\n }\n const reused = existing != null && existing.id === info.id;\n log('computer_sandbox.started', { computerId: info.id, reused });\n try {\n info = await awaitRunning(ctx, { computerId: info.id }, { timeoutMs: runningWaitMs });\n // A reused computer keeps whatever policy it last ran under; it gets the spec's again.\n if (reused) await client.setNetworkPolicy(info.id, egress);\n await reportPlatformNetworkPolicy(ctx, policy);\n const setup = setupSession({ client, info, env });\n await writePlatformFiles(ctx, setup.sandbox);\n await mountRepositories({\n sandbox: setup.sandbox,\n repositories: spec.parameters.repositories,\n resolver: ctx.repositories,\n log,\n });\n await materializeSandboxSeeds({\n sandbox: setup.sandbox,\n root: WORKSPACE_ROOT,\n files: await sandboxSeedFilesForStart(ctx, artifact.data),\n });\n await installGuideCommands({ sandbox: setup.sandbox, template: spec.template });\n const setupHash = await runWorkspaceSetup({\n sandbox: setup.sandbox,\n template: spec.template,\n repositories: spec.parameters.repositories,\n log,\n });\n if (fresh) await startServicesFor({ setup, spec, env });\n const { handle } = await buildHandle({ ctx, client, info, spec, access, env });\n return {\n handle,\n region: info.regionSlug ?? config.regionSlug ?? null,\n state: {\n version: 1,\n computerId: info.id,\n computerName: info.name,\n workspace,\n access,\n guideVersionId: spec.guide?.versionId ?? null,\n setupHash,\n },\n };\n } catch (error) {\n // No state reaches the caller on failure; clean up only this start's new computer.\n if (!reused) {\n try {\n await client.action(info.id, 'delete');\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n `computer ${info.name} setup and cleanup failed`,\n );\n }\n }\n throw error;\n }\n },\n resumePassive: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n const info = await client.getComputer(state.computerId);\n if (info == null || info.state !== ComputerState.Running)\n throw computerSandboxError(\n 'computer_not_running',\n 'computer is not running for passive access',\n );\n await awaitRunning(ctx, state, { timeoutMs: runningWaitMs });\n const spec = await resolve(ctx.guides);\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n return (await buildHandle({ ctx, client, info, spec, access: state.access, env })).handle;\n },\n resume: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n const info = await client.getComputer(state.computerId);\n if (\n info == null ||\n info.state === ComputerState.Deleted ||\n info.state === ComputerState.Error\n ) {\n throw computerSandboxError('computer_gone', `computer ${state.computerName} is gone`);\n }\n // Computers pause when idle, so a resume usually continues in place; one the\n // platform stopped or shelved meanwhile boots again.\n const rebooted = !isRunningState(info.state);\n if (info.state === ComputerState.Paused) await client.action(info.id, 'resume');\n else if (rebooted) await client.action(info.id, 'start');\n const running = await awaitRunning(ctx, state, { timeoutMs: runningWaitMs });\n const spec = await resolve(ctx.guides);\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n // The spec's policy again, whatever the computer last ran under.\n const policy = withPlatformEgressHosts(ctx, spec.parameters.networkPolicy);\n await client.setNetworkPolicy(running.id, computerEgressOf(policy));\n await reportPlatformNetworkPolicy(ctx, policy);\n const setup = setupSession({ client, info: running, env });\n await writePlatformFiles(ctx, setup.sandbox);\n await installGuideCommands({ sandbox: setup.sandbox, template: spec.template });\n // Processes survive a pause; a stopped or shelved computer booted again.\n if (rebooted) await startServicesFor({ setup, spec, env });\n const { handle } = await buildHandle({\n ctx,\n client,\n info: running,\n spec,\n access: state.access,\n env,\n });\n return handle;\n },\n park: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n await closeComputerMcp(state.computerId);\n try {\n await clientFor(ctx.session.organizationId).action(state.computerId, 'pause');\n } catch (error) {\n // Already paused or stopped: nothing to do.\n if (!isComputersApiStatus(error, 409)) throw error;\n }\n return state;\n },\n onSessionEnd: async (ctx, _artifact, rawState, { reason }) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n // A conversation workspace outlives its binding (the conversation was\n // archived, or its workspace replaced): it is shelved, its disk backed up\n // to storage with no host held, and the next binding for the\n // conversation starts it again by name. Session and ephemeral disks end\n // with their binding.\n const action = state.workspace === ComputerWorkspacePolicy.Conversation ? 'stop' : 'delete';\n log('computer_sandbox.session_end', { computerId: state.computerId, reason, action });\n try {\n await client.action(state.computerId, action);\n } catch (error) {\n if (isComputersApiStatus(error, 404)) return;\n if (!isComputersApiStatus(error, 409)) throw error;\n // A conflict is done only when the computer is already where the action\n // takes it; one mid-transition (an idle pause committing) is retried.\n const current = await client.getComputer(state.computerId);\n const settled =\n current == null ||\n current.state === ComputerState.Deleted ||\n (action === 'stop' && current.state === ComputerState.Shelved);\n if (!settled) throw error;\n return;\n }\n // `stop` returns once the shelve is scheduled: the cleanup (and the\n // session service's fence on reusing the workspace) lasts until it is.\n if (action === 'stop') await awaitShelved(client, state.computerId);\n },\n };\n };\n\n return defineSandboxProvider({\n name: 'computer',\n stateProtocolVersion: 1,\n environment,\n });\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;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,OASK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,YAAY,OAAO;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,cAAc,iBAAiB;AACjD,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,wBAAwB,wBAAwB;AAEzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE,8BAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAAAC,mCAAkC;AAyD3C,MAAM,yBAAyB,0BAA0B,OAAO;AAAA,EAC9D,SAAS,EAAE,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AAO,KAAK,WAAW,aAAa;AACxC,cAAM,QAAQ,oBAAoB,MAAM,QAAQ;AAChD,cAAM,iBAAiB,MAAM,UAAU;AACvC,YAAI;AACF,gBAAM,UAAU,IAAI,QAAQ,cAAc,EAAE,OAAO,MAAM,YAAY,OAAO;AAAA,QAC9E,SAAS,OAAO;AAEd,cAAI,CAAC,qBAAqB,OAAO,GAAG,EAAG,OAAM;AAAA,QAC/C;AACA,eAAO;AAAA,MACT;AAAA,MACA,cAAc,OAAO,KAAK,WAAW,UAAU,EAAE,OAAO,MAAM;AAC5D,cAAM,QAAQ,oBAAoB,MAAM,QAAQ;AAChD,cAAM,SAAS,UAAU,IAAI,QAAQ,cAAc;AAMnD,cAAM,SAAS,MAAM,cAAc,wBAAwB,eAAe,SAAS;AACnF,YAAI,gCAAgC,EAAE,YAAY,MAAM,YAAY,QAAQ,OAAO,CAAC;AACpF,YAAI;AACF,gBAAM,OAAO,OAAO,MAAM,YAAY,MAAM;AAAA,QAC9C,SAAS,OAAO;AACd,cAAI,qBAAqB,OAAO,GAAG,EAAG;AACtC,cAAI,CAAC,qBAAqB,OAAO,GAAG,EAAG,OAAM;AAG7C,gBAAM,UAAU,MAAM,OAAO,YAAY,MAAM,UAAU;AACzD,gBAAM,UACJ,WAAW,QACX,QAAQ,UAAU,cAAc,WAC/B,WAAW,UAAU,QAAQ,UAAU,cAAc;AACxD,cAAI,CAAC,QAAS,OAAM;AACpB;AAAA,QACF;AAGA,YAAI,WAAW,OAAQ,OAAM,aAAa,QAAQ,MAAM,UAAU;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AAEA,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN,sBAAsB;AAAA,IACtB;AAAA,EACF,CAAC;AACH;",
|
|
4
|
+
"sourcesContent": ["import { ProcessInspectionOperation } from '@finalai/agent-protocol/process-inspection';\nimport {\n formatProviderRef,\n NetworkPolicy,\n packageRef,\n SandboxAccess,\n type JsonValue,\n} from '@finalai/agent-provider';\nimport {\n defineSandboxProvider,\n materializeSandboxSeeds,\n PLATFORM_ENVIRONMENT_NAMES,\n platformProcessEnvironment,\n PortProtocol,\n reportPlatformNetworkPolicy,\n SandboxCapability,\n sandboxSeedArtifact,\n sandboxSeedArtifactSchema,\n sandboxSeedFiles,\n sandboxSeedFilesForStart,\n sandboxSeedIdentity,\n SandboxWorkspace,\n withPlatformEgressHosts,\n writePlatformFiles,\n type NetworkPolicyIface,\n type NetworkSandboxSessionIface,\n type SandboxGuidesIface,\n type SandboxPrepareContextIface,\n type SandboxProviderHandleIface,\n type SandboxProviderIface,\n type SandboxProviderImplementationIface,\n type SandboxStartContextIface,\n} from '@finalai/agent-provider/sandbox';\nimport {\n ComputerBaseState,\n ComputerCommandMode,\n ComputerEgressPolicy,\n ComputerIdlePolicy,\n ComputerImageState,\n ComputerState,\n type ComputerBaseIface,\n type ComputerImageIface,\n type ComputerInfoIface,\n} from '@finalai/computers';\nimport * as z from 'zod';\nimport {\n HOME_BASELINE_MISSING_EXIT_CODE,\n HOME_BASELINE_ROOT,\n homeBaselineScript,\n homeContentScript,\n} from \"./build-scripts.mjs\";\nimport { sleep as defaultSleep, sha256Hex } from \"./bytes.mjs\";\nimport { computerEditor } from \"./computer-editor.mjs\";\nimport { readComputerSnapshot } from \"./computer-snapshots.mjs\";\nimport {\n createComputersApiClient,\n createComputersApiCredentials,\n isComputersApiError,\n isComputersApiStatus,\n type ComputersApiClientIface,\n type ComputersApiConfigIface,\n type CreateComputerBodyIface,\n} from \"./computers-api.mjs\";\nimport { createComputerUseEndpoint } from \"./computers-api-mcp.mjs\";\nimport { createComputersApiTransport } from \"./computers-api-transport.mjs\";\nimport {\n COMPUTER_SANDBOX_SPECIFIER,\n computerEnvironmentSchema,\n computerOpenOptionsSchema,\n ComputerWorkspacePolicy,\n} from \"./environment.mjs\";\nimport {\n computeComputerArtifactKey,\n computerNeedsBuild,\n DEFAULT_COMPUTER_IMAGE,\n resolveComputerSpec,\n type ResolvedComputerSpecIface,\n} from \"./guide.mjs\";\nimport { createTransportSession, sessionForAccess } from \"./session.mjs\";\nimport type { SandboxTransportIface } from \"./transport.mjs\";\nimport {\n guideCommands,\n installGuideCommands,\n mountRepositories,\n repositoryPath,\n runWorkspaceSetup,\n startServices,\n WORKSPACE_ROOT,\n type GuideCommandIface,\n type SetupLogIface,\n} from \"./workspace-setup.mjs\";\n\nexport type { ComputersApiConfigIface, ComputersApiCredentialIface } from \"./computers-api.mjs\";\nexport {\n COMPUTER_SANDBOX_SPECIFIER,\n COMPUTERS_API_KEY_SECRET,\n COMPUTERS_API_TEAM_SECRET,\n} from \"./environment.mjs\";\nexport { computeComputerArtifactKey } from \"./guide.mjs\";\nexport type { ComputerGuideVersionIface } from \"./guide.mjs\";\nexport type { RepositoryCloneSourceIface } from \"./workspace-setup.mjs\";\n\n// The `computer` sandbox: a Final computer from the\n// public Computers API, set up from a computer setup guide, with lifecycle,\n// files and processes all through that API and the organization's own API key,\n// exactly as a third-party provider drives its vendor. Like every\n// provider, it is served by the session service, which runs this handle and\n// serves the handle RPC and MCP projection from it.\n//\n// A guide with build or verify steps is built once on a builder computer and\n// captured as a base (POST /v1/computers/:id/capture); its computers are created\n// from that base. Network and idle policies are create options, as for any\n// API customer.\n//\n// Guides, variables and repository credentials come from the contract's\n// prepare and start contexts (`guides`, `variables`, `repositories`), which the\n// session service serves to every provider alike.\n\nexport interface ComputerSandboxLogIface {\n (message: string, fields?: Record<string, string | number | boolean | null>): void;\n}\n\nexport interface ComputerSandboxProviderConfigIface {\n // The public Computers API, and each organization's credential for it.\n computersApi: ComputersApiConfigIface;\n // A registry credential (`creg_...`) the organization stored for private image references.\n registryCredentialId?: string;\n // Image for an empty environment without an organization default guide.\n defaultImage?: string;\n regionSlug?: string;\n machine?: { vcpu?: number; memoryMb?: number; diskGb?: number };\n idleTimeoutSeconds?: number;\n // How long `start` waits for a registered image version to finish building.\n imageWaitMs?: number;\n imagePollMs?: number;\n // How long `prepare` waits for a guide's base capture to publish.\n buildWaitMs?: number;\n buildPollMs?: number;\n // How long ending a conversation workspace waits for its computer to shelve.\n shelveWaitMs?: number;\n shelvePollMs?: number;\n // How long start, resume and a guide build wait for a computer to run before\n // touching it (default 5 min); polled from runningPollMs (default 250 ms), doubling to 5 s.\n runningWaitMs?: number;\n runningPollMs?: number;\n log?: ComputerSandboxLogIface;\n randomUuid?: () => string;\n now?: () => number;\n sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;\n}\n\n// An `image` base: `imageVersionId` is the registered version (`cimv_...`) of an\n// image reference, registered at prepare; a `lineage:` image resolves its newest\n// version at start. A `captured` base is a guide's build, captured as a base\n// (`part_...`) that computers are created from.\nconst computerArtifactSchema = sandboxSeedArtifactSchema.extend({\n version: z.literal(1),\n key: z.string(),\n image: z.string(),\n diskGb: z.number().nullable(),\n base: z.discriminatedUnion('kind', [\n z.object({\n kind: z.literal('image'),\n image: z.string(),\n imageVersionId: z.string().nullable().default(null),\n }),\n z.object({ kind: z.literal('captured'), baseId: z.string() }),\n ]),\n});\n\nconst computerStateSchema = z.object({\n version: z.literal(1),\n computerId: z.string(),\n computerName: z.string(),\n workspace: z.nativeEnum(ComputerWorkspacePolicy),\n access: z.nativeEnum(SandboxAccess),\n guideVersionId: z.string().nullable(),\n setupHash: z.string().nullable(),\n});\n\n// The provider's own view of a computer while it sets it up.\ninterface SetupSessionIface {\n sandbox: NetworkSandboxSessionIface;\n transport: SandboxTransportIface;\n}\n\nexport type ComputerSandboxArtifact = z.infer<typeof computerArtifactSchema>;\nexport type ComputerSandboxState = z.infer<typeof computerStateSchema>;\n\n// What Build needs to know about a started computer beyond the handle.\nexport interface ComputerSandboxDescriptionIface {\n provider: 'computer';\n computerId: string;\n computerName: string;\n workspaceRoot: string;\n transport: string;\n guide: { slug: string; number: number } | null;\n repositories: { alias: string; path: string; repository: string }[];\n services: { name: string; readyUrl: string | null }[];\n commands: GuideCommandIface[];\n capabilities: SandboxCapability[];\n}\n\nexport interface ComputerSandboxSessionIface extends NetworkSandboxSessionIface {\n describe(): ComputerSandboxDescriptionIface;\n // What this computer's handle offers (the session service reports it).\n readonly capabilities: readonly SandboxCapability[];\n}\n\nexport type ComputerSandboxProviderIface = SandboxProviderIface<\n JsonValue,\n JsonValue,\n ComputerSandboxArtifact,\n ComputerSandboxState,\n ComputerSandboxSessionIface\n>;\n\nexport interface ComputerSandboxErrorIface extends Error {\n code:\n | 'artifact_unavailable'\n | 'computer_gone'\n | 'computer_not_running'\n | 'invalid_environment'\n | 'build_failed';\n}\n\nconst computerSandboxError = (\n code: ComputerSandboxErrorIface['code'],\n message: string,\n): ComputerSandboxErrorIface =>\n Object.assign(new Error(message), { name: 'ComputerSandboxError', code });\n\n// FINAL_NODE_* and the session basics belong to the platform (shared/src/sandbox-templates/reserved.ts),\n// as do the platform environment's variables (the egress proxy and its placeholders).\nconst RESERVED_ENV = new Set([\n ...PLATFORM_ENVIRONMENT_NAMES,\n 'DISPLAY',\n 'XDG_RUNTIME_DIR',\n 'PATH',\n 'HOME',\n 'USER',\n 'SHELL',\n 'HOSTNAME',\n]);\nconst isReservedEnvName = (name: string): boolean =>\n name.startsWith('FINAL_NODE_') || RESERVED_ENV.has(name);\n\nconst HTTP_TOKEN_LIFETIME_MS = 60 * 60_000;\nconst HTTP_TOKEN_RENEW_MS = 5 * 60_000;\n\n// Builds run from here; the capture scrub removes /tmp/*.\nconst BUILD_ROOT = '/tmp/final-build';\n// Guide publication supplies build inputs in files; agent revisions supply workspace seeds.\nconst seedsFor = (ctx: SandboxPrepareContextIface): Record<string, string> =>\n sandboxSeedFiles({\n files: ctx.resources.guide == null ? ctx.files : {},\n resources: ctx.resources,\n });\n// What the Computers API's capture scrub removes, so the home check skips it.\nconst CAPTURE_SCRUBBED_PATHS = [\n '/home/user/.bash_history',\n '/home/user/.zsh_history',\n '/home/user/.sh_history',\n '/home/user/.git-credentials',\n '/home/user/.config/gh/hosts.yml',\n '/home/user/.npmrc',\n '/home/user/.pypirc',\n '/home/user/.cargo/credentials',\n '/home/user/.cargo/credentials.toml',\n '/home/user/.aws',\n '/home/user/.config/gcloud',\n '/home/user/.azure',\n '/home/user/.docker/config.json',\n '/home/user/.netrc',\n '/home/user/.ssh',\n];\nconst BUILDER_IDLE_TIMEOUT_SECONDS = 2 * 60 * 60;\n\ninterface ComputerEgressConfigIface {\n egress: ComputerEgressPolicy;\n allow?: string[];\n}\n\nconst computerEgressOf = (policy: NetworkPolicyIface): ComputerEgressConfigIface => {\n if (policy.mode === NetworkPolicy.AllowAll) return { egress: ComputerEgressPolicy.Internet };\n if (policy.mode === NetworkPolicy.DenyAll) return { egress: ComputerEgressPolicy.None };\n return { egress: ComputerEgressPolicy.Allowlist, allow: policy.allow ?? [] };\n};\n\n// An allowlist also admits the platform's egress hosts, so its proxy stays reachable.\nconst egressFor = (\n ctx: SandboxStartContextIface,\n requested: NetworkPolicyIface,\n): ComputerEgressConfigIface => computerEgressOf(withPlatformEgressHosts(ctx, requested));\n\nconst LINEAGE_PREFIX = 'lineage:';\n\nconst portOf = (url: string): number | null => {\n try {\n const parsed = new URL(url);\n if (parsed.port !== '') return Number(parsed.port);\n return parsed.protocol === 'https:' ? 443 : 80;\n } catch {\n return null;\n }\n};\n\nconst compactId = (id: string): string => id.replaceAll('-', '');\n\nconst sandboxWorkspaceOf = {\n [ComputerWorkspacePolicy.Session]: SandboxWorkspace.Session,\n [ComputerWorkspacePolicy.Conversation]: SandboxWorkspace.Conversation,\n [ComputerWorkspacePolicy.Ephemeral]: SandboxWorkspace.Ephemeral,\n} satisfies Record<ComputerWorkspacePolicy, SandboxWorkspace>;\n\nconst isRunningState = (state: ComputerState): boolean =>\n state === ComputerState.Running ||\n state === ComputerState.Paused ||\n state === ComputerState.Resuming;\n\n// Nothing runs on these to pause, and vm-service refuses a pause of them:\n// stopped or shelved (the disk at rest), errored (resume reports it gone), or deleted.\nconst hasNothingToPause = (state: ComputerState): boolean =>\n state === ComputerState.Stopped ||\n state === ComputerState.Shelved ||\n state === ComputerState.Error ||\n state === ComputerState.Deleted;\n\n// A refusal (409), a missing computer (404) or a failed host command (5xx) can\n// mean the computer came to rest on its own; a request or auth failure cannot.\nconst pauseMayHaveSettled = (error: unknown): boolean =>\n isComputersApiError(error) &&\n error.statusCode != null &&\n (error.statusCode === 404 || error.statusCode === 409 || error.statusCode >= 500);\n\nconst RUNNING_POLL_MAX_MS = 5_000;\n\nexport const createComputerSandboxProvider = (\n config: ComputerSandboxProviderConfigIface,\n): ComputerSandboxProviderIface => {\n const log: SetupLogIface = config.log ?? (() => undefined);\n const randomUuid = config.randomUuid ?? (() => crypto.randomUUID());\n const now = config.now ?? (() => Date.now());\n const sleep = config.sleep ?? defaultSleep;\n const defaultImage = config.defaultImage ?? DEFAULT_COMPUTER_IMAGE;\n const credentials = createComputersApiCredentials(config.computersApi, now);\n const runningWaitMs = config.runningWaitMs ?? 5 * 60_000;\n\n const clientFor = (organizationId: string): ComputersApiClientIface =>\n createComputersApiClient({ config: config.computersApi, credentials, organizationId });\n\n const registerImage = (client: ComputersApiClientIface, reference: string) =>\n client.registerImage(\n config.registryCredentialId == null\n ? { reference }\n : { reference, registryCredentialId: config.registryCredentialId },\n );\n\n // Computers are created from registered image versions, as any API customer's are.\n // A `lineage:` image is the newest ready version of that lineage (the\n // organization's or the platform's); a reference is registered once, at prepare,\n // and registered again here when its version expired.\n const readyImageVersion = async (\n client: ComputersApiClientIface,\n base: { image: string; imageVersionId: string | null },\n ): Promise<string> => {\n if (base.image.startsWith(LINEAGE_PREFIX)) {\n const lineage = base.image.slice(LINEAGE_PREFIX.length);\n const [newest] = await client.listImages({ lineage, state: ComputerImageState.Ready });\n if (newest == null) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `the Computers API has no ready image version in lineage ${lineage}`,\n );\n }\n return newest.id;\n }\n let version: ComputerImageIface | null = null;\n if (base.imageVersionId != null) {\n try {\n version = await client.getImage(base.imageVersionId);\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n }\n if (version == null || version.state === ComputerImageState.Expired) {\n version = await registerImage(client, base.image);\n }\n const deadline = now() + (config.imageWaitMs ?? 15 * 60_000);\n while (\n version.state === ComputerImageState.Pending ||\n version.state === ComputerImageState.Building\n ) {\n if (now() >= deadline) throw new Error(`image ${base.image} is still building`);\n await sleep(config.imagePollMs ?? 5_000);\n version = await client.getImage(version.id);\n }\n if (version.state !== ComputerImageState.Ready) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `image ${base.image} is ${version.state}${version.error == null ? '' : `: ${version.error}`}`,\n );\n }\n return version.id;\n };\n\n const loadVariables = async (\n ctx: SandboxStartContextIface,\n spec: ResolvedComputerSpecIface,\n ): Promise<Record<string, string>> => {\n const env: Record<string, string> = {};\n for (const [name, value] of Object.entries(spec.parameters.env)) {\n if (isReservedEnvName(name))\n throw computerSandboxError('invalid_environment', `${name} is reserved`);\n env[name] = value;\n }\n for (const name of spec.parameters.variables) {\n if (isReservedEnvName(name))\n throw computerSandboxError('invalid_environment', `${name} is reserved`);\n const value = await ctx.variables.get(name);\n if (value == null)\n throw computerSandboxError('invalid_environment', `variable ${name} is not set`);\n env[name] = value;\n }\n return env;\n };\n\n const mcpClosers = new Map<string, Set<() => Promise<void>>>();\n const closeComputerMcp = async (computerId: string) => {\n const results = await Promise.allSettled(\n [...(mcpClosers.get(computerId) ?? [])].map((close) => close()),\n );\n for (const result of results) if (result.status === 'rejected') throw result.reason;\n };\n const buildHandle = async (args: {\n ctx: SandboxStartContextIface;\n client: ComputersApiClientIface;\n info: ComputerInfoIface;\n spec: ResolvedComputerSpecIface;\n access: SandboxAccess;\n env: () => Promise<Record<string, string>>;\n }): Promise<{ handle: SandboxProviderHandleIface<ComputerSandboxSessionIface> }> => {\n const { client, info, spec } = args;\n const commands = await guideCommands(spec.template);\n const commandHelp = commands\n .map(\n (command) =>\n `Guide command ${command.name}: bash ${command.path}${command.description == null ? '' : ` \u2014 ${command.description}`}`,\n )\n .join('\\n');\n const transport = createComputersApiTransport({ client, computerId: info.id });\n const ports = [\n ...new Set(\n spec.template.services.flatMap((service) => {\n const port = service.ready == null ? null : portOf(service.ready.url);\n return port == null ? [] : [port];\n }),\n ),\n ];\n let httpToken: { token: string; expiresAtMs: number } | null = null;\n const session = createTransportSession({\n id: info.id,\n description: `Final computer ${info.name}${spec.guide == null ? '' : ` (${spec.guide.title} v${spec.guide.number})`}${commands.length === 0 ? '' : `\\n${commandHelp}`}`,\n workspaceRoot: WORKSPACE_ROOT,\n transport,\n baseEnv: args.env,\n randomUuid,\n network: {\n ports,\n // The computer's hostname with a preview token, which opens its HTTP ports only.\n getPortEndpoint: async ({ port, protocol }) => {\n const hostname = info.hostname ?? (await client.getComputer(info.id))?.hostname ?? null;\n if (hostname == null) throw new Error(`computer ${info.name} has no public hostname`);\n if (httpToken == null || httpToken.expiresAtMs - now() < HTTP_TOKEN_RENEW_MS) {\n const expiresAtMs = now() + HTTP_TOKEN_LIFETIME_MS;\n const token = await client.createPreviewToken({\n computerId: info.id,\n name: `agent sandbox ${args.ctx.session.bindingId}`,\n expiresAt: new Date(expiresAtMs),\n });\n httpToken = { token, expiresAtMs };\n }\n const scheme = protocol === PortProtocol.Ws ? 'wss' : 'https';\n return {\n url: `${scheme}://${port === 443 ? hostname : `${hostname}:${port}`}`,\n headers: { authorization: `Bearer ${httpToken.token}` },\n };\n },\n stop: async () => {\n await closeComputerMcp(info.id);\n await client.action(info.id, 'stop');\n },\n destroy: async () => {\n await closeComputerMcp(info.id);\n transport.close();\n try {\n await client.action(info.id, 'delete');\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n },\n },\n });\n let computerUseInstalled: boolean | null = null;\n if (args.access !== SandboxAccess.Read) {\n try {\n computerUseInstalled = (await client.computerUseStatus(info.id, AbortSignal.timeout(1000)))\n .installed;\n } catch {\n /* Optional discovery must never fail the sandbox. */\n }\n }\n const computerUse =\n args.access === SandboxAccess.Read || computerUseInstalled === false\n ? null\n : createComputerUseEndpoint({ client, computerId: info.id, cwd: WORKSPACE_ROOT });\n const closeMcp = async () => {\n try {\n await computerUse?.close();\n } catch (error) {\n log('computer_use.close_failed', {\n computerId: info.id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n const closers = mcpClosers.get(info.id);\n closers?.delete(closeMcp);\n if (closers?.size === 0) mcpClosers.delete(info.id);\n };\n if (computerUse != null) {\n const closers = mcpClosers.get(info.id) ?? new Set<() => Promise<void>>();\n closers.add(closeMcp);\n mcpClosers.set(info.id, closers);\n }\n const capabilities = [SandboxCapability.Files, SandboxCapability.Ports];\n let screenAvailable = false;\n try {\n screenAvailable = (await client.screenStatus(info.id, AbortSignal.timeout(1000))).available;\n } catch {\n /* Optional desktop discovery leaves headless computers usable. */\n }\n if (screenAvailable) capabilities.push(SandboxCapability.Screen);\n if (computerUse != null) capabilities.push(SandboxCapability.ComputerUse);\n if (args.access !== SandboxAccess.Read)\n capabilities.push(SandboxCapability.Process, SandboxCapability.NetworkPolicy);\n const description: ComputerSandboxDescriptionIface = {\n provider: 'computer',\n computerId: info.id,\n computerName: info.name,\n workspaceRoot: WORKSPACE_ROOT,\n transport: transport.kind,\n guide: spec.guide == null ? null : { slug: spec.guide.slug, number: spec.guide.number },\n repositories: spec.parameters.repositories.map((repository) => ({\n alias: repository.alias,\n path: repositoryPath(repository.alias),\n repository: repository.repository,\n })),\n services: spec.template.services.map((service) => ({\n name: service.name,\n readyUrl: service.ready?.url ?? null,\n })),\n commands,\n capabilities,\n };\n const full: ComputerSandboxSessionIface = {\n ...session,\n setNetworkPolicy: async (policy) => {\n if (args.access === SandboxAccess.Read)\n throw new Error('this sandbox binding is read-only');\n await client.setNetworkPolicy(info.id, egressFor(args.ctx, policy));\n },\n describe: () => description,\n capabilities,\n };\n if (computerUse != null) full.computerUse = async () => computerUse.endpoint;\n if (screenAvailable) {\n full.screen = (options) => client.openScreen(info.id, options);\n }\n const sandbox = sessionForAccess(full, args.access);\n return {\n handle: {\n sandbox,\n onSandboxStop: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n },\n onSandboxDelete: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n try {\n await client.action(info.id, 'delete');\n } catch (error) {\n if (!isComputersApiStatus(error, 404)) throw error;\n }\n },\n onRuntimeShutdown: async () => {\n try {\n await closeMcp();\n } finally {\n transport.close();\n }\n },\n },\n };\n };\n\n // Setup (repositories, workspace.setup, services) is the provider's own work, so it\n // runs with the organization's credential, never through the binding's lease: a\n // read binding still gets a set-up computer.\n const setupSession = (args: {\n client: ComputersApiClientIface;\n info: ComputerInfoIface;\n env: () => Promise<Record<string, string>>;\n }): SetupSessionIface => {\n const transport = createComputersApiTransport({\n client: args.client,\n computerId: args.info.id,\n });\n const sandbox = createTransportSession({\n id: args.info.id,\n description: `setup of ${args.info.name}`,\n workspaceRoot: WORKSPACE_ROOT,\n transport,\n baseEnv: args.env,\n randomUuid,\n network: {\n ports: [],\n getPortEndpoint: async () => {\n throw new Error('setup sessions expose no ports');\n },\n stop: async () => undefined,\n destroy: async () => undefined,\n },\n });\n return { sandbox, transport };\n };\n\n // A captured base, once it is ready; a failed or expired one must be built again.\n const awaitBase = async (\n client: ComputersApiClientIface,\n baseId: string,\n key: string,\n ): Promise<ComputerBaseIface> => {\n const deadline = now() + (config.buildWaitMs ?? 30 * 60_000);\n for (;;) {\n const base = await client.getBase(baseId);\n if (base == null || base.state === ComputerBaseState.Expired) {\n throw computerSandboxError(\n 'artifact_unavailable',\n `computer base ${key} (${baseId}) is ${base == null ? 'gone' : 'expired'}; prepare it again`,\n );\n }\n if (base.state === ComputerBaseState.Ready) return base;\n if (base.state === ComputerBaseState.Failed) {\n throw computerSandboxError(\n 'build_failed',\n `computer base ${key} failed to capture: ${base.error ?? 'unknown error'}`,\n );\n }\n if (now() >= deadline) throw new Error(`computer base ${key} is still capturing`);\n await sleep(config.buildPollMs ?? 5_000);\n }\n };\n\n // The Computers API answers a computer it created or started before the\n // computer has a host, and refuses commands and file writes until it runs\n // (`autoResume: false`), so nothing touches it before this resolves. Only\n // Running counts: a paused computer still refuses them.\n const awaitComputerRunning = async (\n client: ComputersApiClientIface,\n computerId: string,\n timeoutMs: number,\n ): Promise<ComputerInfoIface> => {\n const deadline = now() + timeoutMs;\n let pollMs = config.runningPollMs ?? 250;\n for (;;) {\n const computer = await client.getComputer(computerId);\n if (computer == null || computer.state === ComputerState.Deleted)\n throw computerSandboxError('computer_gone', `computer ${computerId} is gone`);\n if (computer.state === ComputerState.Error)\n throw computerSandboxError(\n 'computer_gone',\n `computer ${computer.name} is in the Error state`,\n );\n if (computer.state === ComputerState.Running) return computer;\n const left = deadline - now();\n if (left <= 0)\n throw computerSandboxError(\n 'computer_not_running',\n `computer ${computer.name} was not running within ${Math.round(timeoutMs / 1000)} s (it is ${ComputerState[computer.state]})`,\n );\n await sleep(Math.min(pollMs, left));\n pollMs = Math.min(pollMs * 2, RUNNING_POLL_MAX_MS);\n }\n };\n\n const awaitShelved = async (client: ComputersApiClientIface, computerId: string) => {\n const deadline = now() + (config.shelveWaitMs ?? 5 * 60_000);\n for (;;) {\n const computer = await client.getComputer(computerId);\n if (\n computer == null ||\n computer.state === ComputerState.Shelved ||\n computer.state === ComputerState.Deleted\n )\n return;\n if (computer.state === ComputerState.Error)\n throw computerSandboxError('computer_gone', `computer ${computerId} failed to shelve`);\n if (now() >= deadline) throw new Error(`computer ${computerId} is still shelving`);\n await sleep(config.shelvePollMs ?? 2_000);\n }\n };\n\n // Run build.steps, then build.verify, on a builder computer of the guide's\n // image, captured as a base its computers are created from.\n const build = async (\n ctx: SandboxPrepareContextIface,\n spec: ResolvedComputerSpecIface,\n key: string,\n ): Promise<ComputerSandboxArtifact> => {\n const client = clientFor(ctx.organizationId);\n const diskGb = config.machine?.diskGb ?? null;\n const imageVersionId = await readyImageVersion(client, {\n image: spec.image,\n imageVersionId: null,\n });\n const body: CreateComputerBodyIface = {\n name: `ag-${key.slice(4, 20)}-${compactId(randomUuid()).slice(0, 8)}`,\n imageVersionId,\n ...config.machine,\n // The base is the root disk; a user volume would keep /home and /workspaces off it.\n userVolumeGb: null,\n // Nothing secret at create: the create env lands in the guest.\n env: {},\n commandMode: ComputerCommandMode.Custom,\n customCommand: 'sleep infinity',\n autoResume: false,\n idleTimeoutSeconds: BUILDER_IDLE_TIMEOUT_SECONDS,\n tags: ['final-agent-sandbox-build'],\n };\n if (config.regionSlug != null) body.regionSlug = config.regionSlug;\n // One builder per attempt: a retry after a failed build starts clean.\n const builder = await client.createComputer(\n body,\n `agent-guide-build-${(await sha256Hex(`${key}:${randomUuid()}`)).slice(0, 32)}`,\n );\n ctx.log?.(`building computer base ${key} on ${builder.name}`);\n try {\n await awaitComputerRunning(client, builder.id, runningWaitMs);\n const sandbox = setupSession({ client, info: builder, env: async () => ({}) }).sandbox;\n const prepared = await sandbox.run({\n command: '/bin/sh',\n args: ['-c', `mkdir -p ${BUILD_ROOT}\\n${homeBaselineScript()}`],\n cwd: '/',\n });\n if (prepared.exitCode !== 0) {\n throw computerSandboxError('build_failed', 'failed to record the pre-build home baseline');\n }\n const steps = [\n ...spec.template.build.steps.map((step) => ({ step, label: 'build step' })),\n ...spec.template.build.verify.map((step) => ({ step, label: 'verify step' })),\n ];\n for (const [index, { step, label }] of steps.entries()) {\n ctx.log?.(`${label} ${index + 1}/${steps.length}`);\n const result = await sandbox.run({\n command: `set -eu\\n${step.run}`,\n shell: true,\n cwd: BUILD_ROOT,\n timeoutMs: step.timeoutMinutes * 60_000,\n });\n if (result.exitCode !== 0) {\n throw computerSandboxError(\n 'build_failed',\n `${label} ${index + 1} failed (exit ${result.exitCode}): ${result.stderr.trim().slice(-2000)}`,\n );\n }\n }\n const homeContent = await sandbox.run({\n command: '/bin/sh',\n args: ['-c', homeContentScript({ excludedPaths: CAPTURE_SCRUBBED_PATHS })],\n cwd: '/',\n });\n if (homeContent.exitCode === HOME_BASELINE_MISSING_EXIT_CODE) {\n throw computerSandboxError(\n 'build_failed',\n `build steps removed ${HOME_BASELINE_ROOT}, which the home content check needs; leave /var/tmp/final-template-build in place.`,\n );\n }\n if (homeContent.exitCode !== 0) {\n const offending = homeContent.stdout\n .trim()\n .split('\\n')\n .filter((line) => line !== '');\n throw computerSandboxError(\n 'build_failed',\n `build steps left content under /home or /workspaces, which each computer's own volume hides: ${offending.join(', ')}. Install tools and configuration to system paths such as /usr/local, or point the tool's home there (for example CARGO_HOME=/usr/local/cargo, RUSTUP_HOME=/usr/local/rustup, NVM_DIR=/usr/local/nvm), put home files in /usr/share/final-vm/home-skel, and use /etc/gitconfig instead of git config --global.`,\n );\n }\n const captured = await client.captureComputer(builder.id, { retained: true });\n if (!captured.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the built base',\n );\n ctx.log?.(`capturing computer base ${key} as ${captured.id}`);\n const base = await awaitBase(client, captured.id, key);\n return {\n version: 1,\n key,\n image: spec.image,\n diskGb: diskGb ?? base.diskGb,\n seedFiles: {},\n base: { kind: 'captured', baseId: base.id },\n };\n } finally {\n // The capture stopped the builder; it is not part of the base.\n try {\n await client.action(builder.id, 'delete');\n } catch (error) {\n log('computer_sandbox.builder_delete_failed', {\n computerId: builder.id,\n error: error instanceof Error ? error.message : String(error),\n });\n }\n }\n };\n\n const environment = (\n rawOptions?: JsonValue,\n ): SandboxProviderImplementationIface<\n JsonValue,\n ComputerSandboxArtifact,\n ComputerSandboxState,\n ComputerSandboxSessionIface\n > => {\n const parsed = computerEnvironmentSchema.safeParse(rawOptions ?? {});\n if (!parsed.success) {\n throw computerSandboxError(\n 'invalid_environment',\n `invalid computer environment: ${parsed.error.message}`,\n );\n }\n const options = parsed.data;\n const resolve = (guides: SandboxGuidesIface): Promise<ResolvedComputerSpecIface> =>\n resolveComputerSpec({ options, guides, defaultImage });\n const keyFor = async (\n spec: ResolvedComputerSpecIface,\n files: Record<string, string>,\n ): Promise<string> => {\n const baseKey = await computeComputerArtifactKey({\n image: spec.image,\n template: spec.template,\n diskGb: config.machine?.diskGb ?? null,\n });\n return Object.keys(files).length === 0\n ? baseKey\n : `${baseKey}-s${await sha256Hex(sandboxSeedIdentity(files))}`;\n };\n\n const startServicesFor = async (args: {\n setup: SetupSessionIface;\n spec: ResolvedComputerSpecIface;\n env: () => Promise<Record<string, string>>;\n }): Promise<void> => {\n await startServices({\n sandbox: args.setup.sandbox,\n transport: args.setup.transport,\n template: args.spec.template,\n // Services run for the computer's life, with the platform's values as they are now.\n env: await args.env(),\n randomUuid,\n log,\n });\n };\n\n const awaitRunning = (\n ctx: SandboxStartContextIface,\n rawState: Pick<ComputerSandboxState, 'computerId'>,\n options: { timeoutMs: number },\n ): Promise<ComputerInfoIface> =>\n awaitComputerRunning(\n clientFor(ctx.session.organizationId),\n computerStateSchema.pick({ computerId: true }).parse(rawState).computerId,\n options.timeoutMs,\n );\n\n return {\n processes: async (ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n if (\n request.operation === ProcessInspectionOperation.Stop &&\n state.access === SandboxAccess.Read\n )\n throw new Error('stopping processes requires execute access');\n const result = await clientFor(ctx.organizationId).inspectProcesses(\n state.computerId,\n request,\n );\n return request.operation === ProcessInspectionOperation.Available && 'available' in result\n ? { ...result, canStop: state.access !== SandboxAccess.Read }\n : result;\n },\n editor: async (_ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n if (state.access !== SandboxAccess.Write) {\n if (request.operation === 'available') return { available: false };\n throw new Error('editor requires write access');\n }\n return computerEditor({\n client: clientFor(_ctx.organizationId),\n computerId: state.computerId,\n request,\n randomUuid,\n });\n },\n readSnapshot: async (ctx, rawState, request) => {\n const state = computerStateSchema.parse(rawState);\n return readComputerSnapshot({\n client: clientFor(ctx.organizationId),\n computerId: state.computerId,\n request,\n });\n },\n // The merged parameters' workspace: the binding's, else the saved version's default.\n workspace: async (ctx) =>\n sandboxWorkspaceOf[(await resolve(ctx.guides)).parameters.workspace],\n artifactKey: async (ctx) => keyFor(await resolve(ctx.guides), seedsFor(ctx)),\n // Registers an image reference so its version builds ahead of the first start;\n // a lineage needs nothing until then.\n prepare: async (ctx) => {\n const spec = await resolve(ctx.guides);\n const seedFiles = seedsFor(ctx);\n const key = await keyFor(spec, seedFiles);\n const seedArtifact = await sandboxSeedArtifact(ctx, seedFiles);\n if (computerNeedsBuild(spec)) {\n const baseKey = await keyFor(spec, {});\n const prepared = spec.guide?.preparedArtifact;\n if (\n prepared?.key === baseKey &&\n prepared.providerRef === formatProviderRef(packageRef(COMPUTER_SANDBOX_SPECIFIER))\n ) {\n const cached = computerArtifactSchema.safeParse(prepared.artifact);\n if (\n cached.success &&\n cached.data.key === baseKey &&\n cached.data.base.kind === 'captured'\n ) {\n const base = await clientFor(ctx.organizationId).getBase(cached.data.base.baseId);\n if (base?.state === ComputerBaseState.Ready) {\n if (!base.retained) {\n const retained = await clientFor(ctx.organizationId).setBaseRetention(\n base.id,\n true,\n );\n if (!retained.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the prepared base',\n );\n }\n return { ...cached.data, key, ...seedArtifact };\n }\n }\n }\n const cached = computerArtifactSchema.safeParse(await ctx.artifacts?.get(baseKey));\n if (\n cached.success &&\n cached.data.key === baseKey &&\n cached.data.base.kind === 'captured'\n ) {\n const base = await clientFor(ctx.organizationId).getBase(cached.data.base.baseId);\n if (base?.state === ComputerBaseState.Ready) {\n if (!base.retained) {\n const retained = await clientFor(ctx.organizationId).setBaseRetention(\n base.id,\n true,\n );\n if (!retained.retained)\n throw computerSandboxError(\n 'build_failed',\n 'the Computers API did not retain the prepared base',\n );\n }\n return { ...cached.data, key, ...seedArtifact };\n }\n }\n const built = await build(ctx, spec, baseKey);\n await ctx.artifacts?.put(baseKey, built);\n return { ...built, key, ...seedArtifact };\n }\n const imageVersionId = spec.image.startsWith(LINEAGE_PREFIX)\n ? null\n : (await registerImage(clientFor(ctx.organizationId), spec.image)).id;\n ctx.log?.(`computer base ${key} is image ${spec.image}`);\n return {\n version: 1,\n key,\n image: spec.image,\n diskGb: config.machine?.diskGb ?? null,\n ...seedArtifact,\n base: { kind: 'image', image: spec.image, imageVersionId },\n };\n },\n awaitRunning: async (ctx, state, options) => {\n await awaitRunning(ctx, state, options);\n },\n start: async (ctx, openOptions, rawArtifact) => {\n const access = computerOpenOptionsSchema.parse(openOptions ?? {}).access;\n const spec = await resolve(ctx.guides);\n const policy = withPlatformEgressHosts(ctx, spec.parameters.networkPolicy);\n const egress = computerEgressOf(policy);\n const artifact = computerArtifactSchema.safeParse(rawArtifact);\n if (!artifact.success) {\n throw computerSandboxError(\n 'artifact_unavailable',\n 'this computer base predates the public Computers API provider; prepare it again',\n );\n }\n const base = artifact.data.base;\n if (computerNeedsBuild(spec) && base.kind !== 'captured') {\n throw computerSandboxError(\n 'artifact_unavailable',\n `computer base ${artifact.data.key} was prepared without its build steps; prepare it again`,\n );\n }\n // Variables resolve before anything is created, so a missing one costs nothing.\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n const client = clientFor(ctx.session.organizationId);\n const workspace = spec.parameters.workspace;\n const name =\n workspace === ComputerWorkspacePolicy.Conversation && ctx.session.conversationId != null\n ? `ac-${(await sha256Hex(`${ctx.session.conversationId}:${ctx.session.target}`)).slice(0, 24)}`\n : `ab-${compactId(ctx.session.bindingId)}`;\n const existing = await client.getComputer(name);\n if (existing?.state === ComputerState.Error)\n throw computerSandboxError(\n 'computer_gone',\n `Computer ${existing.id} (${name}) is in the Error state. Recover it through the Computers API before retrying; its workspace is preserved.`,\n );\n let info: ComputerInfoIface;\n let fresh = true;\n if (existing != null && existing.state !== ComputerState.Deleted) {\n info = existing;\n fresh = !isRunningState(existing.state);\n if (existing.state === ComputerState.Paused) await client.action(existing.id, 'resume');\n else if (fresh) await client.action(existing.id, 'start');\n } else {\n const source: Pick<CreateComputerBodyIface, 'baseId' | 'imageVersionId'> =\n base.kind === 'captured'\n ? { baseId: (await awaitBase(client, base.baseId, artifact.data.key)).id }\n : { imageVersionId: await readyImageVersion(client, base) };\n const body: CreateComputerBodyIface = {\n name,\n ...source,\n ...config.machine,\n env: {},\n autoResume: true,\n idleTimeoutSeconds: config.idleTimeoutSeconds ?? 15 * 60,\n // Provider teardown owns deletion; VM-level ephemeral disks cannot be paused.\n ephemeral: false,\n network: egress,\n tags: [\n 'final-agent-sandbox',\n `agent-binding:${ctx.session.bindingId}`,\n 'agent-runtime-attachment:v1',\n 'agent-runtime-role:sandbox',\n ],\n };\n // Session teardown owns deletion, including ephemeral computers. Idle must preserve files.\n body.idlePolicy = ComputerIdlePolicy.Pause;\n if (config.regionSlug != null) body.regionSlug = config.regionSlug;\n // Keyed by the source too: a retry after re-registering is a different request.\n const idempotencyKey = `agent-sandbox-${(await sha256Hex(`${ctx.session.bindingId}:${name}:${source.baseId ?? source.imageVersionId}`)).slice(0, 32)}`;\n info = await client.createComputer(body, idempotencyKey);\n }\n const reused = existing != null && existing.id === info.id;\n log('computer_sandbox.started', { computerId: info.id, reused });\n try {\n info = await awaitRunning(ctx, { computerId: info.id }, { timeoutMs: runningWaitMs });\n // A reused computer keeps whatever policy it last ran under; it gets the spec's again.\n if (reused) await client.setNetworkPolicy(info.id, egress);\n await reportPlatformNetworkPolicy(ctx, policy);\n const setup = setupSession({ client, info, env });\n await writePlatformFiles(ctx, setup.sandbox);\n await mountRepositories({\n sandbox: setup.sandbox,\n repositories: spec.parameters.repositories,\n resolver: ctx.repositories,\n log,\n });\n await materializeSandboxSeeds({\n sandbox: setup.sandbox,\n root: WORKSPACE_ROOT,\n files: await sandboxSeedFilesForStart(ctx, artifact.data),\n });\n await installGuideCommands({ sandbox: setup.sandbox, template: spec.template });\n const setupHash = await runWorkspaceSetup({\n sandbox: setup.sandbox,\n template: spec.template,\n repositories: spec.parameters.repositories,\n log,\n });\n if (fresh) await startServicesFor({ setup, spec, env });\n const { handle } = await buildHandle({ ctx, client, info, spec, access, env });\n return {\n handle,\n region: info.regionSlug ?? config.regionSlug ?? null,\n state: {\n version: 1,\n computerId: info.id,\n computerName: info.name,\n workspace,\n access,\n guideVersionId: spec.guide?.versionId ?? null,\n setupHash,\n },\n };\n } catch (error) {\n // No state reaches the caller on failure; clean up only this start's new computer.\n if (!reused) {\n try {\n await client.action(info.id, 'delete');\n } catch (cleanupError) {\n throw new AggregateError(\n [error, cleanupError],\n `computer ${info.name} setup and cleanup failed`,\n );\n }\n }\n throw error;\n }\n },\n resumePassive: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n const info = await client.getComputer(state.computerId);\n if (info == null || info.state !== ComputerState.Running)\n throw computerSandboxError(\n 'computer_not_running',\n 'computer is not running for passive access',\n );\n await awaitRunning(ctx, state, { timeoutMs: runningWaitMs });\n const spec = await resolve(ctx.guides);\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n return (await buildHandle({ ctx, client, info, spec, access: state.access, env })).handle;\n },\n resume: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n const info = await client.getComputer(state.computerId);\n if (\n info == null ||\n info.state === ComputerState.Deleted ||\n info.state === ComputerState.Error\n ) {\n throw computerSandboxError('computer_gone', `computer ${state.computerName} is gone`);\n }\n // Computers pause when idle, so a resume usually continues in place; one the\n // platform stopped or shelved meanwhile boots again.\n const rebooted = !isRunningState(info.state);\n if (info.state === ComputerState.Paused) await client.action(info.id, 'resume');\n else if (rebooted) await client.action(info.id, 'start');\n const running = await awaitRunning(ctx, state, { timeoutMs: runningWaitMs });\n const spec = await resolve(ctx.guides);\n const env = platformProcessEnvironment(ctx, await loadVariables(ctx, spec));\n // The spec's policy again, whatever the computer last ran under.\n const policy = withPlatformEgressHosts(ctx, spec.parameters.networkPolicy);\n await client.setNetworkPolicy(running.id, computerEgressOf(policy));\n await reportPlatformNetworkPolicy(ctx, policy);\n const setup = setupSession({ client, info: running, env });\n await writePlatformFiles(ctx, setup.sandbox);\n await installGuideCommands({ sandbox: setup.sandbox, template: spec.template });\n // Processes survive a pause; a stopped or shelved computer booted again.\n if (rebooted) await startServicesFor({ setup, spec, env });\n const { handle } = await buildHandle({\n ctx,\n client,\n info: running,\n spec,\n access: state.access,\n env,\n });\n return handle;\n },\n park: async (ctx, _artifact, rawState) => {\n const state = computerStateSchema.parse(rawState);\n await closeComputerMcp(state.computerId);\n const client = clientFor(ctx.session.organizationId);\n // Park reads the computer's state rather than trusting a pause's status\n // alone: a pause that cannot land would otherwise fail on every retry.\n const current = await client.getComputer(state.computerId);\n if (current == null || hasNothingToPause(current.state)) {\n log('computer_sandbox.park_at_rest', {\n computerId: state.computerId,\n state: current?.state ?? null,\n });\n return state;\n }\n // A paused computer is paused again: a resume may be in flight.\n try {\n await client.action(state.computerId, 'pause');\n } catch (error) {\n if (!pauseMayHaveSettled(error)) throw error;\n // Parked if it came to rest meanwhile (an idle pause or stop, a delete);\n // otherwise the pause did not happen and park is retried.\n const settled = await client.getComputer(state.computerId);\n if (\n settled != null &&\n settled.state !== ComputerState.Paused &&\n !hasNothingToPause(settled.state)\n )\n throw error;\n log('computer_sandbox.park_at_rest', {\n computerId: state.computerId,\n state: settled?.state ?? null,\n });\n }\n return state;\n },\n onSessionEnd: async (ctx, _artifact, rawState, { reason }) => {\n const state = computerStateSchema.parse(rawState);\n const client = clientFor(ctx.session.organizationId);\n // A conversation workspace outlives its binding (the conversation was\n // archived, or its workspace replaced): it is shelved, its disk backed up\n // to storage with no host held, and the next binding for the\n // conversation starts it again by name. Session and ephemeral disks end\n // with their binding.\n const action = state.workspace === ComputerWorkspacePolicy.Conversation ? 'stop' : 'delete';\n log('computer_sandbox.session_end', { computerId: state.computerId, reason, action });\n try {\n await client.action(state.computerId, action);\n } catch (error) {\n if (isComputersApiStatus(error, 404)) return;\n if (!isComputersApiStatus(error, 409)) throw error;\n // A conflict is done only when the computer is already where the action\n // takes it; one mid-transition (an idle pause committing) is retried.\n const current = await client.getComputer(state.computerId);\n const settled =\n current == null ||\n current.state === ComputerState.Deleted ||\n (action === 'stop' && current.state === ComputerState.Shelved);\n if (!settled) throw error;\n return;\n }\n // `stop` returns once the shelve is scheduled: the cleanup (and the\n // session service's fence on reusing the workspace) lasts until it is.\n if (action === 'stop') await awaitShelved(client, state.computerId);\n },\n };\n };\n\n return defineSandboxProvider({\n name: 'computer',\n stateProtocolVersion: 1,\n environment,\n });\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,kCAAkC;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;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,OASK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,YAAY,OAAO;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,SAAS,cAAc,iBAAiB;AACjD,SAAS,sBAAsB;AAC/B,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,iCAAiC;AAC1C,SAAS,mCAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,wBAAwB,wBAAwB;AAEzD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE,8BAAAA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAAAC,mCAAkC;AAyD3C,MAAM,yBAAyB,0BAA0B,OAAO;AAAA,EAC9D,SAAS,EAAE,QAAQ,CAAC;AAAA,EACpB,KAAK,EAAE,OAAO;AAAA,EACd,OAAO,EAAE,OA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OAAO;AACd,cAAI,qBAAqB,OAAO,GAAG,EAAG;AACtC,cAAI,CAAC,qBAAqB,OAAO,GAAG,EAAG,OAAM;AAG7C,gBAAM,UAAU,MAAM,OAAO,YAAY,MAAM,UAAU;AACzD,gBAAM,UACJ,WAAW,QACX,QAAQ,UAAU,cAAc,WAC/B,WAAW,UAAU,QAAQ,UAAU,cAAc;AACxD,cAAI,CAAC,QAAS,OAAM;AACpB;AAAA,QACF;AAGA,YAAI,WAAW,OAAQ,OAAM,aAAa,QAAQ,MAAM,UAAU;AAAA,MACpE;AAAA,IACF;AAAA,EACF;AAEA,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN,sBAAsB;AAAA,IACtB;AAAA,EACF,CAAC;AACH;",
|
|
6
6
|
"names": ["COMPUTER_SANDBOX_SPECIFIER", "computeComputerArtifactKey", "options", "cached"]
|
|
7
7
|
}
|
|
@@ -13,6 +13,7 @@ const STATE = {
|
|
|
13
13
|
Paused: 4,
|
|
14
14
|
Stopped: 5,
|
|
15
15
|
Resuming: 6,
|
|
16
|
+
Error: 8,
|
|
16
17
|
Deleted: 9,
|
|
17
18
|
Shelved: 10
|
|
18
19
|
};
|
|
@@ -65,6 +66,7 @@ const createFakeComputersApi = (args = {}) => {
|
|
|
65
66
|
const requests = [];
|
|
66
67
|
const actions = [];
|
|
67
68
|
const actionConflicts = /* @__PURE__ */ new Set();
|
|
69
|
+
const actionFailures = /* @__PURE__ */ new Map();
|
|
68
70
|
const shelveReads = { count: 0 };
|
|
69
71
|
const shelving = /* @__PURE__ */ new Map();
|
|
70
72
|
const imageBuildReads = { count: 1 };
|
|
@@ -295,6 +297,14 @@ const createFakeComputersApi = (args = {}) => {
|
|
|
295
297
|
actions.push({ computerId: computer.id, action: name });
|
|
296
298
|
if (actionConflicts.has(name))
|
|
297
299
|
return json({ error: "a lifecycle transition is committing" }, 409);
|
|
300
|
+
const failure = actionFailures.get(name);
|
|
301
|
+
if (failure != null) return json({ error: `${name} failed` }, failure);
|
|
302
|
+
if (name === "pause" && computer.state === STATE.Shelved)
|
|
303
|
+
return json({ error: "VM is shelved; wake it before pausing" }, 409);
|
|
304
|
+
if (name === "pause" && computer.state === STATE.Stopped)
|
|
305
|
+
return json({ error: "VM is stopped; nothing to pause" }, 409);
|
|
306
|
+
if (name === "pause" && computer.state === STATE.Error)
|
|
307
|
+
return json({ error: "pause failed: cannot pause vm in state Error" }, 502);
|
|
298
308
|
if (name !== "resume" && name !== "start") booting.delete(computer.id);
|
|
299
309
|
if (name === "pause") computer.state = STATE.Paused;
|
|
300
310
|
if (name === "resume") boot(computer, STATE.Resuming);
|
|
@@ -394,6 +404,7 @@ const createFakeComputersApi = (args = {}) => {
|
|
|
394
404
|
requests,
|
|
395
405
|
actions,
|
|
396
406
|
actionConflicts,
|
|
407
|
+
actionFailures,
|
|
397
408
|
shelveReads,
|
|
398
409
|
imageBuildReads,
|
|
399
410
|
bootReads,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../src/sandboxes/testing/fake-backends.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n jsonObjectSchema,\n jsonValueSchema,\n type JsonObject,\n type JsonValue,\n} from '@finalai/agent-provider';\nimport { ComputerEgressPolicy } from '@finalai/computers';\nimport { posix } from 'node:path';\nimport * as z from 'zod';\nimport { concatBytes, decodeBase64, encodeBase64 } from \"../bytes.mjs\";\nimport { createFakeMachine, readFakeOutput, type FakeMachineIface } from \"./fake-machine.mjs\";\n\n// A fake public Computers API (vm-service `/v1` over fetch, API-key bearer),\n// backed by in-memory machines. The `device` provider's fakes live with the\n// Device API (device-api-service/src/testing), which it is tested against.\n\nexport interface FakeComputerIface {\n id: string;\n name: string;\n state: number;\n body: JsonObject;\n machine: FakeMachineIface;\n}\n\nexport interface FakeImageIface {\n id: string;\n source: 'platform' | 'customer';\n reference: string;\n lineage: string;\n state: 'pending' | 'building' | 'ready' | 'failed' | 'expired';\n error: string | null;\n}\n\nexport interface FakeBaseIface {\n id: string;\n computerId: string;\n state: 'capturing' | 'ready' | 'failed' | 'expired';\n error: string | null;\n retained: boolean;\n}\n\nexport interface FakeComputersApiIface {\n fetch: typeof fetch;\n computers: Map<string, FakeComputerIface>;\n images: Map<string, FakeImageIface>;\n bases: Map<string, FakeBaseIface>;\n // Base reads a fresh capture answers `capturing` before it settles.\n baseCaptureReads: { count: number };\n // Set: the next captures settle `failed` with this error instead of `ready`.\n captureFailure: { error: string | null };\n requests: { method: string; path: string; body: JsonValue; headers: Headers }[];\n actions: { computerId: string; action: string }[];\n // Actions answered 409 (a conflicting transition) without changing the computer.\n actionConflicts: Set<string>;\n // Computer reads a stopped computer answers `stopped` before it is shelved.\n shelveReads: { count: number };\n // Image reads a fresh registration answers `building` before it is ready.\n imageBuildReads: { count: number };\n // Computer reads a created or started computer answers `pending` (a resumed\n // one `resuming`) before it runs; until then commands and files answer 409.\n bootReads: { count: number };\n computerByName(name: string): FakeComputerIface | undefined;\n}\n\nconst STATE = {\n Pending: 1,\n Running: 3,\n Paused: 4,\n Stopped: 5,\n Resuming: 6,\n Deleted: 9,\n Shelved: 10,\n} as const;\nconst NOT_RUNNING = 'Computer is not running; resume it explicitly before this operation';\nexport const FAKE_COMPUTERS_API_KEY = 'fk_org_api_key';\nexport const FAKE_PLATFORM_SANDBOX_IMAGE = 'cimv_0190e0000000700080000000000001';\n\nconst json = (body: JsonValue, status = 200): Response =>\n new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });\n\n// What POST /v1/computers accepts (vm-service/src/routes/v1.ts); anything else,\n// such as the internal surface's image, lineage, projectArtifact or the\n// platform-only policies, is refused so a test fails when the provider asks for it.\nconst createComputerSchema = z.strictObject({\n name: z.string().optional(),\n regionSlug: z.string().optional(),\n imageVersionId: z.string().startsWith('cimv_').optional(),\n baseId: z.string().startsWith('part_').optional(),\n idlePolicy: z.enum(['shelve', 'pause', 'delete']).optional(),\n network: z\n .strictObject({\n egress: z.nativeEnum(ComputerEgressPolicy),\n allow: z.array(z.string()).optional(),\n })\n .optional(),\n teamId: z.string().startsWith('team_').optional(),\n vcpu: z.number().optional(),\n memoryMb: z.number().optional(),\n diskGb: z.number().optional(),\n userVolumeGb: z.number().nullable().optional(),\n env: z.record(z.string(), z.string()).optional(),\n setupScript: z.string().optional(),\n commandMode: z.number().optional(),\n customCommand: z.string().optional(),\n httpPort: z.number().optional(),\n httpPublic: z.boolean().optional(),\n ephemeral: z.boolean().optional(),\n idleTimeoutSeconds: z.number().optional(),\n autoResume: z.boolean().optional(),\n tags: z.array(z.string()).optional(),\n comment: z.string().optional(),\n});\n\nexport const createFakeComputersApi = (\n args: {\n machineFor?: (computer: { id: string; name: string }) => FakeMachineIface;\n computerUseAvailable?: boolean;\n screenAvailable?: boolean;\n } = {},\n): FakeComputersApiIface => {\n const computers = new Map<string, FakeComputerIface>();\n const images = new Map<string, FakeImageIface>([\n [\n FAKE_PLATFORM_SANDBOX_IMAGE,\n {\n id: FAKE_PLATFORM_SANDBOX_IMAGE,\n source: 'platform',\n reference: 'ghcr.io/final/sandbox:release',\n lineage: 'sandbox',\n state: 'ready',\n error: null,\n },\n ],\n ]);\n const requests: FakeComputersApiIface['requests'] = [];\n const actions: FakeComputersApiIface['actions'] = [];\n const actionConflicts = new Set<string>();\n const shelveReads = { count: 0 };\n const shelving = new Map<string, number>();\n const imageBuildReads = { count: 1 };\n const bootReads = { count: 1 };\n const booting = new Map<string, number>();\n const boot = (computer: FakeComputerIface, state: number) => {\n if (bootReads.count <= 0) {\n computer.state = STATE.Running;\n return;\n }\n computer.state = state;\n booting.set(computer.id, bootReads.count);\n };\n const imageReads = new Map<string, number>();\n const bases = new Map<string, FakeBaseIface>();\n const baseCaptureReads = { count: 1 };\n const captureFailure: FakeComputersApiIface['captureFailure'] = { error: null };\n const captureErrors = new Map<string, string>();\n const baseReads = new Map<string, number>();\n let computerCount = 0;\n const byIdempotency = new Map<string, string>();\n\n const wire = (computer: FakeComputerIface) => ({\n id: computer.id,\n name: computer.name,\n state: computer.state,\n imageVersionId: z\n .string()\n .nullable()\n .catch(null)\n .parse(computer.body.imageVersionId ?? null),\n teamId: z\n .string()\n .nullable()\n .catch(null)\n .parse(computer.body.teamId ?? null),\n hostname: `${computer.name}-k3p9x7qd.virtual-machine.lax-2.example`,\n tags: [],\n });\n const imageWire = (image: FakeImageIface) => ({\n ...image,\n digest: `sha256:${image.id}`,\n sizes: ['standard'],\n registryCredentialId: null,\n createdAt: null,\n readyAt: null,\n lastUsedAt: null,\n });\n const baseWire = (base: FakeBaseIface) => ({\n ...base,\n image: 'ghcr.io/final/sandbox:release',\n digest: `sha256:${'b'.repeat(64)}`,\n diskGb: 20,\n createdAt: null,\n readyAt: null,\n lastUsedAt: null,\n });\n const find = (idOrName: string): FakeComputerIface | undefined =>\n computers.get(idOrName) ??\n [...computers.values()].find(\n (computer) => computer.name === idOrName && computer.state !== STATE.Deleted,\n );\n\n const handle = async (request: Request): Promise<Response> => {\n const url = new URL(request.url);\n const text = request.method === 'GET' ? '' : await request.text();\n const body = text === '' ? null : jsonValueSchema.parse(JSON.parse(text));\n requests.push({ method: request.method, path: url.pathname, body, headers: request.headers });\n if (!url.pathname.startsWith('/v1/')) return json({ error: 'not found' }, 404);\n if (request.headers.get('authorization') !== `Bearer ${FAKE_COMPUTERS_API_KEY}`) {\n return json({ error: 'unauthorized' }, 401);\n }\n const path = url.pathname.slice('/v1'.length);\n if (request.method === 'POST' && path === '/computers') {\n const parsed = createComputerSchema.safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n if ((parsed.data.imageVersionId == null) === (parsed.data.baseId == null)) {\n return json({ error: 'pass exactly one of imageVersionId and baseId' }, 400);\n }\n if (parsed.data.imageVersionId != null) {\n const image = images.get(parsed.data.imageVersionId);\n if (image == null) return json({ error: 'image version not found' }, 404);\n if (image.state !== 'ready') return json({ error: `image version is ${image.state}` }, 409);\n }\n if (parsed.data.baseId != null) {\n const base = bases.get(parsed.data.baseId);\n if (base == null) return json({ error: 'base not found' }, 404);\n if (base.state !== 'ready') return json({ error: `base is ${base.state}` }, 409);\n }\n const key = request.headers.get('idempotency-key');\n if (parsed.data.ephemeral === true && parsed.data.idlePolicy === 'pause')\n return json({ error: 'ephemeral VMs are always deleted when idle' }, 400);\n const existing = key == null ? undefined : computers.get(byIdempotency.get(key) ?? '');\n if (existing != null) return json({ computer: wire(existing) });\n computerCount += 1;\n const id = `comp_0190a0000000700080000000${String(computerCount).padStart(4, '0')}`;\n const name = parsed.data.name ?? `computer-${computerCount}`;\n const computer: FakeComputerIface = {\n id,\n name,\n state: STATE.Pending,\n body: jsonObjectSchema.parse(body),\n machine: args.machineFor?.({ id, name }) ?? createFakeMachine(),\n };\n boot(computer, STATE.Pending);\n computers.set(id, computer);\n if (key != null) byIdempotency.set(key, id);\n return json({ computer: wire(computer) });\n }\n if (request.method === 'GET' && path === '/images') {\n const lineage = url.searchParams.get('lineage');\n const state = url.searchParams.get('state');\n const matching = [...images.values()]\n .filter((image) => lineage == null || image.lineage === lineage)\n .filter((image) => state == null || image.state === state)\n .reverse();\n return json({ images: matching.map(imageWire) });\n }\n if (request.method === 'POST' && path === '/images') {\n const parsed = z\n .strictObject({\n reference: z.string(),\n registryCredentialId: z.string().optional(),\n sizes: z.array(z.string()).optional(),\n })\n .safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n const known = [...images.values()].find(\n (image) =>\n image.reference === parsed.data.reference &&\n (image.state === 'pending' || image.state === 'building' || image.state === 'ready'),\n );\n if (known != null) return json({ image: imageWire(known) });\n const id = `cimv_0190f0000000700080000000${String(images.size + 1).padStart(4, '0')}`;\n const image: FakeImageIface = {\n id,\n source: 'customer',\n reference: parsed.data.reference,\n lineage: parsed.data.reference,\n state: 'building',\n error: null,\n };\n images.set(id, image);\n return json({ image: imageWire(image) }, 201);\n }\n const imageMatch = /^\\/images\\/([^/]+)$/.exec(path);\n if (request.method === 'GET' && imageMatch != null) {\n const image = images.get(decodeURIComponent(imageMatch[1] ?? ''));\n if (image == null) return json({ error: 'image not found' }, 404);\n const reads = (imageReads.get(image.id) ?? 0) + 1;\n imageReads.set(image.id, reads);\n if (image.state === 'building' && reads > imageBuildReads.count) image.state = 'ready';\n return json({ image: imageWire(image) });\n }\n if (request.method === 'POST' && path === '/tokens') {\n const parsed = z\n .strictObject({\n name: z.string(),\n computerId: z.string().startsWith('comp_').optional(),\n scopes: z.array(z.string()).optional(),\n expiresAt: z.string().optional(),\n })\n .safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n return json({ id: 'ctok_1', token: 'fvm1.http-token' });\n }\n const baseMatch = /^\\/bases\\/([^/]+)$/.exec(path);\n if (request.method === 'PATCH' && baseMatch != null) {\n const base = bases.get(decodeURIComponent(baseMatch[1] ?? ''));\n if (base == null) return json({ error: 'base not found' }, 404);\n const retained = z.object({ retained: z.boolean() }).parse(body);\n base.retained = retained.retained;\n return json({ base: baseWire(base) });\n }\n if (request.method === 'GET' && baseMatch != null) {\n const base = bases.get(decodeURIComponent(baseMatch[1] ?? ''));\n if (base == null) return json({ error: 'base not found' }, 404);\n const reads = (baseReads.get(base.id) ?? 0) + 1;\n baseReads.set(base.id, reads);\n if (base.state === 'capturing' && reads > baseCaptureReads.count) {\n const error = captureErrors.get(base.id) ?? null;\n base.state = error == null ? 'ready' : 'failed';\n base.error = error;\n }\n return json({ base: baseWire(base) });\n }\n const computerMatch = /^\\/computers\\/([^/]+)(\\/.*)?$/.exec(path);\n if (computerMatch == null) return json({ error: `no route ${path}` }, 404);\n const computer = find(decodeURIComponent(computerMatch[1] ?? ''));\n if (computer == null || computer.state === STATE.Deleted)\n return json({ error: 'computer not found' }, 404);\n const rest = computerMatch[2] ?? '';\n const machine = computer.machine;\n if (request.method === 'GET' && rest === '/screen')\n return json({ available: args.screenAvailable ?? false });\n if (request.method === 'POST' && rest === '/screen')\n return json({\n url: `https://computer-api.example/v1/computers/${computer.id}/screen/view#screen-token`,\n token: 'screen-token',\n expiresAt: new Date(Date.now() + 900_000).toISOString(),\n });\n if (request.method === 'PATCH' && rest === '') {\n const patch = createComputerSchema.pick({ network: true }).parse(body);\n if (patch.network != null) computer.body.network = patch.network;\n return json({ computer: wire(computer) });\n }\n if (request.method === 'GET' && rest === '/computer-use')\n return json({\n available: args.computerUseAvailable ?? false,\n installed: args.computerUseAvailable ?? false,\n });\n if (request.method === 'GET' && rest === '') {\n const starting = booting.get(computer.id);\n if (starting != null) {\n if (starting <= 0) {\n booting.delete(computer.id);\n computer.state = STATE.Running;\n } else booting.set(computer.id, starting - 1);\n }\n const left = shelving.get(computer.id);\n if (left != null) {\n if (left <= 0) {\n shelving.delete(computer.id);\n computer.state = STATE.Shelved;\n } else shelving.set(computer.id, left - 1);\n }\n return json({ computer: wire(computer) });\n }\n if (request.method === 'POST' && rest === '/capture') {\n if (computer.state !== STATE.Running) return json({ error: 'not running' }, 409);\n if (computer.body.userVolumeGb !== null) return json({ error: 'has a user volume' }, 409);\n const id = `part_0190b0000000700080000000${String(bases.size + 1).padStart(4, '0')}`;\n const capture = z.object({ retained: z.boolean().default(false) }).parse(body ?? {});\n const base: FakeBaseIface = {\n id,\n computerId: computer.id,\n state: 'capturing',\n error: null,\n retained: capture.retained,\n };\n bases.set(id, base);\n if (captureFailure.error != null) captureErrors.set(id, captureFailure.error);\n computer.state = STATE.Stopped;\n return json({ base: baseWire(base) }, 202);\n }\n const action = /^\\/actions\\/(.+)$/.exec(rest);\n if (request.method === 'POST' && action != null) {\n const name = action[1] ?? '';\n actions.push({ computerId: computer.id, action: name });\n if (actionConflicts.has(name))\n return json({ error: 'a lifecycle transition is committing' }, 409);\n if (name !== 'resume' && name !== 'start') booting.delete(computer.id);\n if (name === 'pause') computer.state = STATE.Paused;\n if (name === 'resume') boot(computer, STATE.Resuming);\n if (name === 'start') boot(computer, STATE.Pending);\n // A computer that is not ephemeral shelves on stop (vm-service vm-ops).\n if (name === 'stop') {\n computer.state = shelveReads.count > 0 ? STATE.Stopped : STATE.Shelved;\n if (shelveReads.count > 0) shelving.set(computer.id, shelveReads.count);\n }\n if (name === 'delete') computer.state = STATE.Deleted;\n return json({ computer: wire(computer) });\n }\n if (\n computer.state !== STATE.Running &&\n (rest === '/exec' || rest === '/run' || rest === '/files' || rest.startsWith('/processes/'))\n )\n return json({ error: NOT_RUNNING }, 409);\n if (request.method === 'POST' && (rest === '/exec' || rest === '/run')) {\n const parsed = z\n .object({\n command: z.string(),\n cwd: z.string().optional(),\n env: z.record(z.string(), z.string()).optional(),\n })\n .parse(body);\n const process = machine.exec({\n id: `proc-${machine.execs.length + 1}`,\n command: parsed.command,\n cwd: parsed.cwd ?? '/',\n env: parsed.env ?? {},\n });\n if (rest === '/exec')\n return json({ id: process.id, bootId: process.bootId, pid: 1, state: 'running' });\n const output = await readFakeOutput(process, { stdout: 0, stderr: 0, waitMs: 50 });\n return json({\n id: process.id,\n bootId: process.bootId,\n pid: 1,\n timedOut: false,\n elapsedMs: 1,\n ...outputBody(output, process, 0, 0),\n });\n }\n const processMatch = /^\\/processes\\/([^/]+)\\/(output|input|terminate)$/.exec(rest);\n if (processMatch != null) {\n const process = machine.processes.get(processMatch[1] ?? '');\n if (process == null) return json({ error: 'process not found' }, 404);\n if (processMatch[2] === 'output') {\n const stdoutOffset = Number(url.searchParams.get('stdoutOffset') ?? 0);\n const stderrOffset = Number(url.searchParams.get('stderrOffset') ?? 0);\n const output = await readFakeOutput(process, {\n stdout: stdoutOffset,\n stderr: stderrOffset,\n waitMs: Number(url.searchParams.get('waitMs') ?? 0),\n });\n return json(outputBody(output, process, stdoutOffset, stderrOffset));\n }\n if (processMatch[2] === 'terminate') {\n process.terminate();\n return json({ ok: true });\n }\n const input = z\n .object({\n dataB64: z.string().optional(),\n eof: z.boolean().optional(),\n signal: z.string().optional(),\n })\n .parse(body);\n if (input.dataB64 != null) process.write(decodeBase64(input.dataB64));\n if (input.eof === true) process.eof();\n if (input.signal != null) process.terminate(input.signal);\n return json({ ok: true });\n }\n if (rest === '/files' && request.method === 'GET') {\n const path = url.searchParams.get('path') ?? '';\n // Reads follow symlinks.\n const content = machine.files.get(machine.links.get(path) ?? path);\n if (content == null) return json({ error: `${path}: No such file or directory` }, 502);\n const offset = Number(url.searchParams.get('offset') ?? 0);\n const length = Number(url.searchParams.get('length') ?? content.byteLength);\n const slice = content.subarray(offset, offset + length);\n return json({\n dataB64: encodeBase64(slice),\n eof: offset + slice.byteLength >= content.byteLength,\n offset,\n });\n }\n if (rest === '/files' && request.method === 'PUT') {\n const parsed = z\n .object({ path: z.string(), dataB64: z.string(), append: z.boolean().optional() })\n .parse(body);\n if (!machine.dirs.has(posix.dirname(parsed.path)))\n return json({ error: 'No such file or directory' }, 502);\n const data = decodeBase64(parsed.dataB64);\n const previous =\n parsed.append === true\n ? (machine.files.get(parsed.path) ?? new Uint8Array())\n : new Uint8Array();\n machine.files.set(parsed.path, concatBytes([previous, data]));\n return json({ bytesWritten: data.byteLength });\n }\n return json({ error: `no route ${request.method} ${path}` }, 404);\n };\n\n return {\n fetch: async (input, init) => handle(new Request(input, init)),\n computers,\n images,\n bases,\n baseCaptureReads,\n captureFailure,\n requests,\n actions,\n actionConflicts,\n shelveReads,\n imageBuildReads,\n bootReads,\n computerByName: (name) => [...computers.values()].find((computer) => computer.name === name),\n };\n};\n\nconst outputBody = (\n output: { stdout: Uint8Array; stderr: Uint8Array; exited: boolean },\n process: {\n exitCode: number | null;\n signal: string | null;\n stdout: Uint8Array;\n stderr: Uint8Array;\n },\n stdoutOffset: number,\n stderrOffset: number,\n) => ({\n stdout: {\n dataB64: encodeBase64(output.stdout),\n offset: stdoutOffset,\n nextOffset: stdoutOffset + output.stdout.byteLength,\n eof: output.exited && stdoutOffset + output.stdout.byteLength >= process.stdout.byteLength,\n },\n stderr: {\n dataB64: encodeBase64(output.stderr),\n offset: stderrOffset,\n nextOffset: stderrOffset + output.stderr.byteLength,\n eof: output.exited && stderrOffset + output.stderr.byteLength >= process.stderr.byteLength,\n },\n state: output.exited ? 'exited' : 'running',\n result: output.exited ? { exitCode: process.exitCode, signal: process.signal } : null,\n});\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP,SAAS,4BAA4B;AACrC,SAAS,aAAa;AACtB,YAAY,OAAO;AACnB,SAAS,aAAa,cAAc,oBAAoB;AACxD,SAAS,mBAAmB,sBAA6C;AAsDzE,MAAM,QAAQ;AAAA,EACZ,SAAS;AAAA,EACT,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,UAAU;AAAA,EACV,SAAS;AAAA,EACT,SAAS;AACX;AACA,MAAM,cAAc;AACb,MAAM,yBAAyB;AAC/B,MAAM,8BAA8B;AAE3C,MAAM,OAAO,CAAC,MAAiB,SAAS,QACtC,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG,EAAE,QAAQ,SAAS,EAAE,gBAAgB,mBAAmB,EAAE,CAAC;AAKhG,MAAM,uBAAuB,EAAE,aAAa;AAAA,EAC1C,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,gBAAgB,EAAE,OAAO,EAAE,WAAW,OAAO,EAAE,SAAS;AAAA,EACxD,QAAQ,EAAE,OAAO,EAAE,WAAW,OAAO,EAAE,SAAS;AAAA,EAChD,YAAY,EAAE,KAAK,CAAC,UAAU,SAAS,QAAQ,CAAC,EAAE,SAAS;AAAA,EAC3D,SAAS,EACN,aAAa;AAAA,IACZ,QAAQ,EAAE,WAAW,oBAAoB;AAAA,IACzC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,SAAS;AAAA,EACtC,CAAC,EACA,SAAS;AAAA,EACZ,QAAQ,EAAE,OAAO,EAAE,WAAW,OAAO,EAAE,SAAS;AAAA,EAChD,MAAM,EAAE,OAAO,EAAE,SAAS;AAAA,EAC1B,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,QAAQ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,QAAQ;AAAA,IACR,YAAY,eAAe,OAAO,OAAO;AAAA,IACzC,KAAK,OAAO,UAAU,eAAe,OAAO,OAAO,cAAc,QAAQ,OAAO;AAAA,EAClF;AAAA,EACA,OAAO,OAAO,SAAS,WAAW;AAAA,EAClC,QAAQ,OAAO,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ,QAAQ,OAAO,IAAI;AACnF;",
|
|
4
|
+
"sourcesContent": ["import {\n jsonObjectSchema,\n jsonValueSchema,\n type JsonObject,\n type JsonValue,\n} from '@finalai/agent-provider';\nimport { ComputerEgressPolicy } from '@finalai/computers';\nimport { posix } from 'node:path';\nimport * as z from 'zod';\nimport { concatBytes, decodeBase64, encodeBase64 } from \"../bytes.mjs\";\nimport { createFakeMachine, readFakeOutput, type FakeMachineIface } from \"./fake-machine.mjs\";\n\n// A fake public Computers API (vm-service `/v1` over fetch, API-key bearer),\n// backed by in-memory machines. The `device` provider's fakes live with the\n// Device API (device-api-service/src/testing), which it is tested against.\n\nexport interface FakeComputerIface {\n id: string;\n name: string;\n state: number;\n body: JsonObject;\n machine: FakeMachineIface;\n}\n\nexport interface FakeImageIface {\n id: string;\n source: 'platform' | 'customer';\n reference: string;\n lineage: string;\n state: 'pending' | 'building' | 'ready' | 'failed' | 'expired';\n error: string | null;\n}\n\nexport interface FakeBaseIface {\n id: string;\n computerId: string;\n state: 'capturing' | 'ready' | 'failed' | 'expired';\n error: string | null;\n retained: boolean;\n}\n\nexport interface FakeComputersApiIface {\n fetch: typeof fetch;\n computers: Map<string, FakeComputerIface>;\n images: Map<string, FakeImageIface>;\n bases: Map<string, FakeBaseIface>;\n // Base reads a fresh capture answers `capturing` before it settles.\n baseCaptureReads: { count: number };\n // Set: the next captures settle `failed` with this error instead of `ready`.\n captureFailure: { error: string | null };\n requests: { method: string; path: string; body: JsonValue; headers: Headers }[];\n actions: { computerId: string; action: string }[];\n // Actions answered 409 (a conflicting transition) without changing the computer.\n actionConflicts: Set<string>;\n // Actions answered with this status (a failed host command) without changing the computer.\n actionFailures: Map<string, number>;\n // Computer reads a stopped computer answers `stopped` before it is shelved.\n shelveReads: { count: number };\n // Image reads a fresh registration answers `building` before it is ready.\n imageBuildReads: { count: number };\n // Computer reads a created or started computer answers `pending` (a resumed\n // one `resuming`) before it runs; until then commands and files answer 409.\n bootReads: { count: number };\n computerByName(name: string): FakeComputerIface | undefined;\n}\n\nconst STATE = {\n Pending: 1,\n Running: 3,\n Paused: 4,\n Stopped: 5,\n Resuming: 6,\n Error: 8,\n Deleted: 9,\n Shelved: 10,\n} as const;\nconst NOT_RUNNING = 'Computer is not running; resume it explicitly before this operation';\nexport const FAKE_COMPUTERS_API_KEY = 'fk_org_api_key';\nexport const FAKE_PLATFORM_SANDBOX_IMAGE = 'cimv_0190e0000000700080000000000001';\n\nconst json = (body: JsonValue, status = 200): Response =>\n new Response(JSON.stringify(body), { status, headers: { 'content-type': 'application/json' } });\n\n// What POST /v1/computers accepts (vm-service/src/routes/v1.ts); anything else,\n// such as the internal surface's image, lineage, projectArtifact or the\n// platform-only policies, is refused so a test fails when the provider asks for it.\nconst createComputerSchema = z.strictObject({\n name: z.string().optional(),\n regionSlug: z.string().optional(),\n imageVersionId: z.string().startsWith('cimv_').optional(),\n baseId: z.string().startsWith('part_').optional(),\n idlePolicy: z.enum(['shelve', 'pause', 'delete']).optional(),\n network: z\n .strictObject({\n egress: z.nativeEnum(ComputerEgressPolicy),\n allow: z.array(z.string()).optional(),\n })\n .optional(),\n teamId: z.string().startsWith('team_').optional(),\n vcpu: z.number().optional(),\n memoryMb: z.number().optional(),\n diskGb: z.number().optional(),\n userVolumeGb: z.number().nullable().optional(),\n env: z.record(z.string(), z.string()).optional(),\n setupScript: z.string().optional(),\n commandMode: z.number().optional(),\n customCommand: z.string().optional(),\n httpPort: z.number().optional(),\n httpPublic: z.boolean().optional(),\n ephemeral: z.boolean().optional(),\n idleTimeoutSeconds: z.number().optional(),\n autoResume: z.boolean().optional(),\n tags: z.array(z.string()).optional(),\n comment: z.string().optional(),\n});\n\nexport const createFakeComputersApi = (\n args: {\n machineFor?: (computer: { id: string; name: string }) => FakeMachineIface;\n computerUseAvailable?: boolean;\n screenAvailable?: boolean;\n } = {},\n): FakeComputersApiIface => {\n const computers = new Map<string, FakeComputerIface>();\n const images = new Map<string, FakeImageIface>([\n [\n FAKE_PLATFORM_SANDBOX_IMAGE,\n {\n id: FAKE_PLATFORM_SANDBOX_IMAGE,\n source: 'platform',\n reference: 'ghcr.io/final/sandbox:release',\n lineage: 'sandbox',\n state: 'ready',\n error: null,\n },\n ],\n ]);\n const requests: FakeComputersApiIface['requests'] = [];\n const actions: FakeComputersApiIface['actions'] = [];\n const actionConflicts = new Set<string>();\n const actionFailures = new Map<string, number>();\n const shelveReads = { count: 0 };\n const shelving = new Map<string, number>();\n const imageBuildReads = { count: 1 };\n const bootReads = { count: 1 };\n const booting = new Map<string, number>();\n const boot = (computer: FakeComputerIface, state: number) => {\n if (bootReads.count <= 0) {\n computer.state = STATE.Running;\n return;\n }\n computer.state = state;\n booting.set(computer.id, bootReads.count);\n };\n const imageReads = new Map<string, number>();\n const bases = new Map<string, FakeBaseIface>();\n const baseCaptureReads = { count: 1 };\n const captureFailure: FakeComputersApiIface['captureFailure'] = { error: null };\n const captureErrors = new Map<string, string>();\n const baseReads = new Map<string, number>();\n let computerCount = 0;\n const byIdempotency = new Map<string, string>();\n\n const wire = (computer: FakeComputerIface) => ({\n id: computer.id,\n name: computer.name,\n state: computer.state,\n imageVersionId: z\n .string()\n .nullable()\n .catch(null)\n .parse(computer.body.imageVersionId ?? null),\n teamId: z\n .string()\n .nullable()\n .catch(null)\n .parse(computer.body.teamId ?? null),\n hostname: `${computer.name}-k3p9x7qd.virtual-machine.lax-2.example`,\n tags: [],\n });\n const imageWire = (image: FakeImageIface) => ({\n ...image,\n digest: `sha256:${image.id}`,\n sizes: ['standard'],\n registryCredentialId: null,\n createdAt: null,\n readyAt: null,\n lastUsedAt: null,\n });\n const baseWire = (base: FakeBaseIface) => ({\n ...base,\n image: 'ghcr.io/final/sandbox:release',\n digest: `sha256:${'b'.repeat(64)}`,\n diskGb: 20,\n createdAt: null,\n readyAt: null,\n lastUsedAt: null,\n });\n const find = (idOrName: string): FakeComputerIface | undefined =>\n computers.get(idOrName) ??\n [...computers.values()].find(\n (computer) => computer.name === idOrName && computer.state !== STATE.Deleted,\n );\n\n const handle = async (request: Request): Promise<Response> => {\n const url = new URL(request.url);\n const text = request.method === 'GET' ? '' : await request.text();\n const body = text === '' ? null : jsonValueSchema.parse(JSON.parse(text));\n requests.push({ method: request.method, path: url.pathname, body, headers: request.headers });\n if (!url.pathname.startsWith('/v1/')) return json({ error: 'not found' }, 404);\n if (request.headers.get('authorization') !== `Bearer ${FAKE_COMPUTERS_API_KEY}`) {\n return json({ error: 'unauthorized' }, 401);\n }\n const path = url.pathname.slice('/v1'.length);\n if (request.method === 'POST' && path === '/computers') {\n const parsed = createComputerSchema.safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n if ((parsed.data.imageVersionId == null) === (parsed.data.baseId == null)) {\n return json({ error: 'pass exactly one of imageVersionId and baseId' }, 400);\n }\n if (parsed.data.imageVersionId != null) {\n const image = images.get(parsed.data.imageVersionId);\n if (image == null) return json({ error: 'image version not found' }, 404);\n if (image.state !== 'ready') return json({ error: `image version is ${image.state}` }, 409);\n }\n if (parsed.data.baseId != null) {\n const base = bases.get(parsed.data.baseId);\n if (base == null) return json({ error: 'base not found' }, 404);\n if (base.state !== 'ready') return json({ error: `base is ${base.state}` }, 409);\n }\n const key = request.headers.get('idempotency-key');\n if (parsed.data.ephemeral === true && parsed.data.idlePolicy === 'pause')\n return json({ error: 'ephemeral VMs are always deleted when idle' }, 400);\n const existing = key == null ? undefined : computers.get(byIdempotency.get(key) ?? '');\n if (existing != null) return json({ computer: wire(existing) });\n computerCount += 1;\n const id = `comp_0190a0000000700080000000${String(computerCount).padStart(4, '0')}`;\n const name = parsed.data.name ?? `computer-${computerCount}`;\n const computer: FakeComputerIface = {\n id,\n name,\n state: STATE.Pending,\n body: jsonObjectSchema.parse(body),\n machine: args.machineFor?.({ id, name }) ?? createFakeMachine(),\n };\n boot(computer, STATE.Pending);\n computers.set(id, computer);\n if (key != null) byIdempotency.set(key, id);\n return json({ computer: wire(computer) });\n }\n if (request.method === 'GET' && path === '/images') {\n const lineage = url.searchParams.get('lineage');\n const state = url.searchParams.get('state');\n const matching = [...images.values()]\n .filter((image) => lineage == null || image.lineage === lineage)\n .filter((image) => state == null || image.state === state)\n .reverse();\n return json({ images: matching.map(imageWire) });\n }\n if (request.method === 'POST' && path === '/images') {\n const parsed = z\n .strictObject({\n reference: z.string(),\n registryCredentialId: z.string().optional(),\n sizes: z.array(z.string()).optional(),\n })\n .safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n const known = [...images.values()].find(\n (image) =>\n image.reference === parsed.data.reference &&\n (image.state === 'pending' || image.state === 'building' || image.state === 'ready'),\n );\n if (known != null) return json({ image: imageWire(known) });\n const id = `cimv_0190f0000000700080000000${String(images.size + 1).padStart(4, '0')}`;\n const image: FakeImageIface = {\n id,\n source: 'customer',\n reference: parsed.data.reference,\n lineage: parsed.data.reference,\n state: 'building',\n error: null,\n };\n images.set(id, image);\n return json({ image: imageWire(image) }, 201);\n }\n const imageMatch = /^\\/images\\/([^/]+)$/.exec(path);\n if (request.method === 'GET' && imageMatch != null) {\n const image = images.get(decodeURIComponent(imageMatch[1] ?? ''));\n if (image == null) return json({ error: 'image not found' }, 404);\n const reads = (imageReads.get(image.id) ?? 0) + 1;\n imageReads.set(image.id, reads);\n if (image.state === 'building' && reads > imageBuildReads.count) image.state = 'ready';\n return json({ image: imageWire(image) });\n }\n if (request.method === 'POST' && path === '/tokens') {\n const parsed = z\n .strictObject({\n name: z.string(),\n computerId: z.string().startsWith('comp_').optional(),\n scopes: z.array(z.string()).optional(),\n expiresAt: z.string().optional(),\n })\n .safeParse(body);\n if (!parsed.success) return json({ error: 'invalid body' }, 400);\n return json({ id: 'ctok_1', token: 'fvm1.http-token' });\n }\n const baseMatch = /^\\/bases\\/([^/]+)$/.exec(path);\n if (request.method === 'PATCH' && baseMatch != null) {\n const base = bases.get(decodeURIComponent(baseMatch[1] ?? ''));\n if (base == null) return json({ error: 'base not found' }, 404);\n const retained = z.object({ retained: z.boolean() }).parse(body);\n base.retained = retained.retained;\n return json({ base: baseWire(base) });\n }\n if (request.method === 'GET' && baseMatch != null) {\n const base = bases.get(decodeURIComponent(baseMatch[1] ?? ''));\n if (base == null) return json({ error: 'base not found' }, 404);\n const reads = (baseReads.get(base.id) ?? 0) + 1;\n baseReads.set(base.id, reads);\n if (base.state === 'capturing' && reads > baseCaptureReads.count) {\n const error = captureErrors.get(base.id) ?? null;\n base.state = error == null ? 'ready' : 'failed';\n base.error = error;\n }\n return json({ base: baseWire(base) });\n }\n const computerMatch = /^\\/computers\\/([^/]+)(\\/.*)?$/.exec(path);\n if (computerMatch == null) return json({ error: `no route ${path}` }, 404);\n const computer = find(decodeURIComponent(computerMatch[1] ?? ''));\n if (computer == null || computer.state === STATE.Deleted)\n return json({ error: 'computer not found' }, 404);\n const rest = computerMatch[2] ?? '';\n const machine = computer.machine;\n if (request.method === 'GET' && rest === '/screen')\n return json({ available: args.screenAvailable ?? false });\n if (request.method === 'POST' && rest === '/screen')\n return json({\n url: `https://computer-api.example/v1/computers/${computer.id}/screen/view#screen-token`,\n token: 'screen-token',\n expiresAt: new Date(Date.now() + 900_000).toISOString(),\n });\n if (request.method === 'PATCH' && rest === '') {\n const patch = createComputerSchema.pick({ network: true }).parse(body);\n if (patch.network != null) computer.body.network = patch.network;\n return json({ computer: wire(computer) });\n }\n if (request.method === 'GET' && rest === '/computer-use')\n return json({\n available: args.computerUseAvailable ?? false,\n installed: args.computerUseAvailable ?? false,\n });\n if (request.method === 'GET' && rest === '') {\n const starting = booting.get(computer.id);\n if (starting != null) {\n if (starting <= 0) {\n booting.delete(computer.id);\n computer.state = STATE.Running;\n } else booting.set(computer.id, starting - 1);\n }\n const left = shelving.get(computer.id);\n if (left != null) {\n if (left <= 0) {\n shelving.delete(computer.id);\n computer.state = STATE.Shelved;\n } else shelving.set(computer.id, left - 1);\n }\n return json({ computer: wire(computer) });\n }\n if (request.method === 'POST' && rest === '/capture') {\n if (computer.state !== STATE.Running) return json({ error: 'not running' }, 409);\n if (computer.body.userVolumeGb !== null) return json({ error: 'has a user volume' }, 409);\n const id = `part_0190b0000000700080000000${String(bases.size + 1).padStart(4, '0')}`;\n const capture = z.object({ retained: z.boolean().default(false) }).parse(body ?? {});\n const base: FakeBaseIface = {\n id,\n computerId: computer.id,\n state: 'capturing',\n error: null,\n retained: capture.retained,\n };\n bases.set(id, base);\n if (captureFailure.error != null) captureErrors.set(id, captureFailure.error);\n computer.state = STATE.Stopped;\n return json({ base: baseWire(base) }, 202);\n }\n const action = /^\\/actions\\/(.+)$/.exec(rest);\n if (request.method === 'POST' && action != null) {\n const name = action[1] ?? '';\n actions.push({ computerId: computer.id, action: name });\n if (actionConflicts.has(name))\n return json({ error: 'a lifecycle transition is committing' }, 409);\n const failure = actionFailures.get(name);\n if (failure != null) return json({ error: `${name} failed` }, failure);\n // vm-service pauses only a computer that runs (vm-ops applyVmLifecycleAction).\n if (name === 'pause' && computer.state === STATE.Shelved)\n return json({ error: 'VM is shelved; wake it before pausing' }, 409);\n if (name === 'pause' && computer.state === STATE.Stopped)\n return json({ error: 'VM is stopped; nothing to pause' }, 409);\n if (name === 'pause' && computer.state === STATE.Error)\n return json({ error: 'pause failed: cannot pause vm in state Error' }, 502);\n if (name !== 'resume' && name !== 'start') booting.delete(computer.id);\n if (name === 'pause') computer.state = STATE.Paused;\n if (name === 'resume') boot(computer, STATE.Resuming);\n if (name === 'start') boot(computer, STATE.Pending);\n // A computer that is not ephemeral shelves on stop (vm-service vm-ops).\n if (name === 'stop') {\n computer.state = shelveReads.count > 0 ? STATE.Stopped : STATE.Shelved;\n if (shelveReads.count > 0) shelving.set(computer.id, shelveReads.count);\n }\n if (name === 'delete') computer.state = STATE.Deleted;\n return json({ computer: wire(computer) });\n }\n if (\n computer.state !== STATE.Running &&\n (rest === '/exec' || rest === '/run' || rest === '/files' || rest.startsWith('/processes/'))\n )\n return json({ error: NOT_RUNNING }, 409);\n if (request.method === 'POST' && (rest === '/exec' || rest === '/run')) {\n const parsed = z\n .object({\n command: z.string(),\n cwd: z.string().optional(),\n env: z.record(z.string(), z.string()).optional(),\n })\n .parse(body);\n const process = machine.exec({\n id: `proc-${machine.execs.length + 1}`,\n command: parsed.command,\n cwd: parsed.cwd ?? '/',\n env: parsed.env ?? {},\n });\n if (rest === '/exec')\n return json({ id: process.id, bootId: process.bootId, pid: 1, state: 'running' });\n const output = await readFakeOutput(process, { stdout: 0, stderr: 0, waitMs: 50 });\n return json({\n id: process.id,\n bootId: process.bootId,\n pid: 1,\n timedOut: false,\n elapsedMs: 1,\n ...outputBody(output, process, 0, 0),\n });\n }\n const processMatch = /^\\/processes\\/([^/]+)\\/(output|input|terminate)$/.exec(rest);\n if (processMatch != null) {\n const process = machine.processes.get(processMatch[1] ?? '');\n if (process == null) return json({ error: 'process not found' }, 404);\n if (processMatch[2] === 'output') {\n const stdoutOffset = Number(url.searchParams.get('stdoutOffset') ?? 0);\n const stderrOffset = Number(url.searchParams.get('stderrOffset') ?? 0);\n const output = await readFakeOutput(process, {\n stdout: stdoutOffset,\n stderr: stderrOffset,\n waitMs: Number(url.searchParams.get('waitMs') ?? 0),\n });\n return json(outputBody(output, process, stdoutOffset, stderrOffset));\n }\n if (processMatch[2] === 'terminate') {\n process.terminate();\n return json({ ok: true });\n }\n const input = z\n .object({\n dataB64: z.string().optional(),\n eof: z.boolean().optional(),\n signal: z.string().optional(),\n })\n .parse(body);\n if (input.dataB64 != null) process.write(decodeBase64(input.dataB64));\n if (input.eof === true) process.eof();\n if (input.signal != null) process.terminate(input.signal);\n return json({ ok: true });\n }\n if (rest === '/files' && request.method === 'GET') {\n const path = url.searchParams.get('path') ?? '';\n // Reads follow symlinks.\n const content = machine.files.get(machine.links.get(path) ?? path);\n if (content == null) return json({ error: `${path}: No such file or directory` }, 502);\n const offset = Number(url.searchParams.get('offset') ?? 0);\n const length = Number(url.searchParams.get('length') ?? content.byteLength);\n const slice = content.subarray(offset, offset + length);\n return json({\n dataB64: encodeBase64(slice),\n eof: offset + slice.byteLength >= content.byteLength,\n offset,\n });\n }\n if (rest === '/files' && request.method === 'PUT') {\n const parsed = z\n .object({ path: z.string(), dataB64: z.string(), append: z.boolean().optional() })\n .parse(body);\n if (!machine.dirs.has(posix.dirname(parsed.path)))\n return json({ error: 'No such file or directory' }, 502);\n const data = decodeBase64(parsed.dataB64);\n const previous =\n parsed.append === true\n ? (machine.files.get(parsed.path) ?? new Uint8Array())\n : new Uint8Array();\n machine.files.set(parsed.path, concatBytes([previous, data]));\n return json({ bytesWritten: data.byteLength });\n }\n return json({ error: `no route ${request.method} ${path}` }, 404);\n };\n\n return {\n fetch: async (input, init) => handle(new Request(input, init)),\n computers,\n images,\n bases,\n baseCaptureReads,\n captureFailure,\n requests,\n actions,\n actionConflicts,\n actionFailures,\n shelveReads,\n imageBuildReads,\n bootReads,\n computerByName: (name) => [...computers.values()].find((computer) => computer.name === name),\n };\n};\n\nconst outputBody = (\n output: { stdout: Uint8Array; stderr: Uint8Array; exited: boolean },\n process: {\n exitCode: number | null;\n signal: string | null;\n stdout: Uint8Array;\n stderr: Uint8Array;\n },\n stdoutOffset: number,\n stderrOffset: number,\n) => ({\n stdout: {\n dataB64: encodeBase64(output.stdout),\n offset: stdoutOffset,\n nextOffset: stdoutOffset + output.stdout.byteLength,\n eof: output.exited && stdoutOffset + output.stdout.byteLength >= process.stdout.byteLength,\n },\n stderr: {\n dataB64: encodeBase64(output.stderr),\n offset: stderrOffset,\n nextOffset: stderrOffset + output.stderr.byteLength,\n eof: output.exited && stderrOffset + output.stderr.byteLength >= process.stderr.byteLength,\n },\n state: output.exited ? 'exited' : 'running',\n result: output.exited ? { exitCode: process.exitCode, signal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BAAgB,CAAC,SAAS,CAAC,GAAG,UAAU,OAAO,CAAC,EAAE,KAAK,CAAC,aAAa,SAAS,SAAS,IAAI;AAAA,EAC7F;AACF;AAEA,MAAM,aAAa,CACjB,QACA,SAMA,cACA,kBACI;AAAA,EACJ,QAAQ;AAAA,IACN,SAAS,aAAa,OAAO,MAAM;AAAA,IACnC,QAAQ;AAAA,IACR,YAAY,eAAe,OAAO,OAAO;AAAA,IACzC,KAAK,OAAO,UAAU,eAAe,OAAO,OAAO,cAAc,QAAQ,OAAO;AAAA,EAClF;AAAA,EACA,QAAQ;AAAA,IACN,SAAS,aAAa,OAAO,MAAM;AAAA,IACnC,QAAQ;AAAA,IACR,YAAY,eAAe,OAAO,OAAO;AAAA,IACzC,KAAK,OAAO,UAAU,eAAe,OAAO,OAAO,cAAc,QAAQ,OAAO;AAAA,EAClF;AAAA,EACA,OAAO,OAAO,SAAS,WAAW;AAAA,EAClC,QAAQ,OAAO,SAAS,EAAE,UAAU,QAAQ,UAAU,QAAQ,QAAQ,OAAO,IAAI;AACnF;",
|
|
6
6
|
"names": ["computer", "image", "path"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finalai/final-agent-provider",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Final's provider package: serverless, remote and local harnesses; the computer and device sandboxes; the messaging, schedule and event channels.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
"@finalai/agent-protocol": "0.2.1",
|
|
213
213
|
"@finalai/agent-provider": "0.2.2",
|
|
214
214
|
"@finalai/computers": "0.1.4",
|
|
215
|
-
"@finalai/websockets": "0.1.
|
|
215
|
+
"@finalai/websockets": "0.1.5",
|
|
216
216
|
"ws": "^8.21.3",
|
|
217
217
|
"zod": "4.6.5",
|
|
218
218
|
"@finalai/agent-definition": "0.1.9"
|