@computesdk/agent37 0.1.4 → 0.1.5
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/README.md +1 -1
- package/dist/index.js +30 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,7 +85,7 @@ interface Agent37Config {
|
|
|
85
85
|
- Output is returned when the command finishes; there is no streaming.
|
|
86
86
|
- `runCommand`'s `timeout` stops waiting for the result. The command itself keeps running in the sandbox.
|
|
87
87
|
- Filesystem content is UTF-8 text, not arbitrary binary. Writes use bounded exec requests and a unique mode-0600 staging file in the remote shell's writable `TMPDIR` (default `/tmp`), then overwrite in place. Staging does not require destination-directory write permission. Existing permissions and hard links are preserved, and symlinks are followed. When `flock` is available (as in the base template), an inode lock prevents concurrent SDK writes to the same inode from interleaving; lock errors are propagated. Custom images without `flock` fall back to ordinary redirection, so concurrent writes to the same inode can interleave. Readers can observe the final copy in progress in either case. Failed uploads leave the destination unchanged; a failure during final publication can leave an empty or partial file.
|
|
88
|
-
- Reads use
|
|
88
|
+
- Reads use GNU `stat`, `dd` and `base64` to transfer at most 256 KiB per exec, below the 512 KB output cap, then decode UTF-8 across chunk boundaries. Empty files and symlink targets are supported. Truncation, malformed chunks, read errors, short reads and detected file changes throw instead of returning partial content. Reads are not snapshots: avoid modifying the file during a transfer. The complete string is still held in client memory.
|
|
89
89
|
- Sandboxes have no lifetime limit, so always call `destroy()` when you are done.
|
|
90
90
|
|
|
91
91
|
## Links
|
package/dist/index.js
CHANGED
|
@@ -26,8 +26,10 @@ __export(index_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
var import_node_crypto = require("crypto");
|
|
28
28
|
var import_node_path = require("path");
|
|
29
|
+
var import_node_string_decoder = require("string_decoder");
|
|
29
30
|
var import_provider = require("@computesdk/provider");
|
|
30
31
|
var WRITE_CHUNK_BYTES = 48 * 1024;
|
|
32
|
+
var READ_CHUNK_BYTES = 256 * 1024;
|
|
31
33
|
function resolveConfig(config) {
|
|
32
34
|
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
33
35
|
const apiKey = config.apiKey || env?.AGENT37_API_KEY || "";
|
|
@@ -198,10 +200,34 @@ var agent37 = (0, import_provider.defineProvider)({
|
|
|
198
200
|
getInstance: (sandbox) => sandbox,
|
|
199
201
|
filesystem: {
|
|
200
202
|
readFile: async (sandbox, path) => {
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
203
|
+
const target = shellPath(path);
|
|
204
|
+
const read = async (command) => {
|
|
205
|
+
const result = await exec(sandbox, command);
|
|
206
|
+
if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);
|
|
207
|
+
if (result.truncated) throw new Error(`Failed to read ${path}: truncated exec output`);
|
|
208
|
+
return result;
|
|
209
|
+
};
|
|
210
|
+
const metadataCommand = `test -f ${target} && stat -Lc '%s:%d:%i:%y:%z' -- ${target}`;
|
|
211
|
+
const metadata = (await read(metadataCommand)).stdout;
|
|
212
|
+
const size = Number(metadata.split(":", 1)[0]);
|
|
213
|
+
if (!/^\d+:/.test(metadata) || !Number.isSafeInteger(size)) throw new Error(`Failed to read ${path}: invalid file size`);
|
|
214
|
+
const decoder = new import_node_string_decoder.StringDecoder("utf8");
|
|
215
|
+
const parts = [];
|
|
216
|
+
for (let index = 0; index < Math.max(1, Math.ceil(size / READ_CHUNK_BYTES)); index++) {
|
|
217
|
+
const result = await read(`{ dd if=${target} bs=${READ_CHUNK_BYTES} skip=${index} count=1 iflag=fullblock status=none; printf '\\n%03d' "$?"; } | base64 -w0`);
|
|
218
|
+
if (result.stdout.length > 4 * Math.ceil((READ_CHUNK_BYTES + 4) / 3)) throw new Error(`Failed to read ${path}: oversized read chunk`);
|
|
219
|
+
const bytes = Buffer.from(result.stdout, "base64");
|
|
220
|
+
if (bytes.toString("base64") !== result.stdout || !/^\n\d{3}$/.test(bytes.subarray(-4).toString("utf8"))) {
|
|
221
|
+
throw new Error(`Failed to read ${path}: invalid read chunk`);
|
|
222
|
+
}
|
|
223
|
+
const status = bytes.subarray(-3).toString("utf8");
|
|
224
|
+
if (status !== "000") throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${Number(status)}`}`);
|
|
225
|
+
const expected = Math.min(READ_CHUNK_BYTES, size - index * READ_CHUNK_BYTES);
|
|
226
|
+
if (bytes.length !== expected + 4) throw new Error(`Failed to read ${path}: unexpected read length (expected ${expected}, received ${bytes.length - 4})`);
|
|
227
|
+
parts.push(decoder.write(bytes.subarray(0, -4)));
|
|
228
|
+
}
|
|
229
|
+
if ((await read(metadataCommand)).stdout !== metadata) throw new Error(`Failed to read ${path}: file changed during read`);
|
|
230
|
+
return parts.join("") + decoder.end();
|
|
205
231
|
},
|
|
206
232
|
writeFile: async (sandbox, path, content, run) => {
|
|
207
233
|
const bytes = Buffer.from(content, "utf8");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Agent37 Provider - Factory-based Implementation\n *\n * Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small\n * JSON surface, so this package talks to it with `fetch` and has no SDK dependency.\n *\n * Commands run as root by default, since Agent37 images ship no sudo. Pass\n * `runAsRoot: false` to run as the image's own user instead.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { posix } from 'node:path';\nimport { defineProvider, escapeShellArg, InstanceSizeError } from '@computesdk/provider';\n\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nexport interface Agent37Config {\n /** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */\n apiKey?: string;\n /** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */\n baseUrl?: string;\n /** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */\n execUrl?: string;\n /** Run commands as root (default true). Set false to run as the image's default user. */\n runAsRoot?: boolean;\n}\n\n/** An instance as the Agent37 API returns it. */\nexport interface Agent37InstanceData {\n id: string;\n status: string;\n template: string;\n type: string;\n region: string;\n resources: { cpu: number; memory: number; disk: number };\n url: string;\n created: number;\n [key: string]: unknown;\n}\n\nexport interface Agent37Sandbox {\n id: string;\n data: Agent37InstanceData;\n apiKey: string;\n baseUrl: string;\n execUrl: string;\n runAsRoot: boolean;\n}\n\ninterface ExecResponse {\n exit_code: number;\n stdout: string;\n stderr: string;\n truncated?: boolean;\n}\n\ntype FsRunCommand = (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions) => Promise<CommandResult>;\n\n// 48 KiB becomes 64 KiB of base64, leaving room for JSON and paths under exec's 128 KB request cap.\nconst WRITE_CHUNK_BYTES = 48 * 1024;\n\nfunction resolveConfig(config: Agent37Config) {\n const env = typeof process !== 'undefined' ? process.env : undefined;\n const apiKey = config.apiKey || env?.AGENT37_API_KEY || '';\n if (!apiKey) {\n throw new Error(\n `Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. ` +\n `Create one at https://www.agent37.com/dashboard/cloud/api-keys`,\n );\n }\n const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || 'https://api.agent37.com').replace(/\\/+$/, '');\n const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || 'https://sandbox.agent37.app').replace(/\\/+$/, '');\n return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };\n}\n\nasync function request<T>(\n auth: { apiKey: string; baseUrl: string },\n method: string,\n path: string,\n body?: unknown,\n timeoutMs?: number,\n keyHeader = false,\n): Promise<{ status: number; data: T | null }> {\n const res = await fetch(`${auth.baseUrl}${path}`, {\n method,\n headers: {\n ...(keyHeader ? { 'X-Agent37-Key': auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` }),\n 'Content-Type': 'application/json',\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined,\n });\n if (res.status === 404) return { status: 404, data: null };\n const text = await res.text();\n if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);\n return { status: res.status, data: (text ? JSON.parse(text) : null) as T };\n}\n\nfunction toSandbox(auth: { apiKey: string; baseUrl: string; execUrl: string; runAsRoot: boolean }, data: Agent37InstanceData): Agent37Sandbox {\n return { id: data.id, data, ...auth };\n}\n\nfunction megabytesToGb(mb: unknown): number | undefined {\n return typeof mb === 'number' && mb > 0 ? Math.ceil(mb / 1024) : undefined;\n}\n\n/** Maps ComputeSDK's create options onto the body of POST /v1/instances. */\nfunction createBody(options: CreateInstanceOptions = {}): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n if (options.templateId) body.template = options.templateId;\n if (typeof options.type === 'string') body.type = options.type;\n if (typeof options.region === 'string') body.region = options.region;\n if (options.name) body.name = options.name;\n if (options.metadata) body.metadata = options.metadata;\n if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;\n\n const cpu = options.cpu ?? options.vcpus ?? options.cpus;\n const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);\n const disk = megabytesToGb(options.diskMb ?? options.diskMiB);\n const resources = {\n ...(typeof cpu === 'number' ? { cpu } : {}),\n ...(memory ? { memory } : {}),\n ...(disk ? { disk } : {}),\n };\n if (Object.keys(resources).length > 0) body.resources = resources;\n return body;\n}\n\nfunction wrapCommand(command: string, options?: RunCommandOptions): string {\n let cmd = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const exports = Object.entries(options.env).map(([key, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);\n return `export ${key}=\"${escapeShellArg(value)}\"`;\n });\n cmd = `${exports.join(' && ')} && ${cmd}`;\n }\n if (options?.cwd) cmd = `cd \"${escapeShellArg(options.cwd)}\" && ${cmd}`;\n if (options?.background) cmd = `nohup sh -c \"${escapeShellArg(cmd)}\" >/dev/null 2>&1 &`;\n return cmd;\n}\n\n// A leading dash would be read as an option by base64, find, mkdir and rm.\nfunction shellPath(path: string): string {\n return `\"${escapeShellArg(path.startsWith('-') ? `./${path}` : path)}\"`;\n}\n\n// Exec is answered by the machine the instance runs on, at execUrl, which takes the key as X-Agent37-Key.\nasync function exec(sandbox: Agent37Sandbox, command: string, timeoutMs?: number): Promise<ExecResponse> {\n const { data } = await request<ExecResponse>(\n { apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,\n { command, ...(sandbox.runAsRoot ? { user: 'root' } : {}) },\n timeoutMs,\n true,\n );\n if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n return data;\n}\n\nfunction infoStatus(status: string): InstanceInfo['status'] {\n if (status === 'failed') return 'error';\n if (status === 'stopped' || status === 'stopping' || status === 'deleting' || status === 'deleted') return 'stopped';\n return 'running';\n}\n\nasync function mustSucceed(run: FsRunCommand, sandbox: Agent37Sandbox, command: string, what: string): Promise<CommandResult> {\n const result = await run(sandbox, command);\n if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);\n return result;\n}\n\n// Agent37 offers four create shapes (vCPU / GB RAM): 2/4, 4/8, 4/16 and 4/32. 4 vCPU is the ceiling on\n// every type, and a request for more cores is quietly capped, so only exact shapes are claimed.\n// https://www.agent37.com/docs/agents-api/instance-sizing\nconst SHAPES = new Set(['2/4096', '4/8192', '4/16384', '4/32768']);\nconst NATIVE_SIZE_FIELDS = ['cpu', 'vcpus', 'cpus', 'memory', 'memoryMiB', 'memoryMb', 'memMiB'] as const;\n\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\n sizes: (_config, profile, options) => {\n if (NATIVE_SIZE_FIELDS.some((field) => options?.[field] !== undefined)) {\n throw new InstanceSizeError('conflict', 'cannot combine sizeClass with native Agent37 cpu/memory fields');\n }\n const type = options?.type ?? 'default';\n if (type !== 'default' && type !== 'performance' && type !== 'vm') {\n return { status: 'unknown', reason: `Agent37 shapes are published for the default, performance and vm types, not ${JSON.stringify(type)}.` };\n }\n if (!SHAPES.has(`${profile.vcpus}/${profile.memoryMiB}`)) {\n return {\n status: 'unsupported',\n reason: `Agent37 has no ${profile.vcpus} vCPU / ${profile.memoryMiB / 1024} GB shape; it offers 2/4, 4/8, 4/16 and 4/32 (4 vCPU ceiling).`,\n };\n }\n return { status: 'supported', nativeOptions: { cpu: profile.vcpus, memoryMiB: profile.memoryMiB } };\n },\n methods: {\n instances: {\n create: async (config: Agent37Config, options?: CreateInstanceOptions) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'POST', '/v1/instances', createBody(options));\n if (!data) throw new Error('Agent37 API returned no instance on create');\n return { instance: toSandbox(auth, data), instanceId: data.id };\n },\n\n getById: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'GET', `/v1/instances/${encodeURIComponent(instanceId)}`);\n return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;\n },\n\n list: async (config: Agent37Config) => {\n const auth = resolveConfig(config);\n const { data } = await request<{ data: Agent37InstanceData[] }>(auth, 'GET', '/v1/instances');\n return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));\n },\n\n destroy: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n await request(auth, 'DELETE', `/v1/instances/${encodeURIComponent(instanceId)}`);\n },\n\n runCommand: async (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const start = Date.now();\n const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);\n return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox: Agent37Sandbox): Promise<InstanceInfo> => {\n const { data } = await request<Agent37InstanceData>(sandbox, 'GET', `/v1/instances/${encodeURIComponent(sandbox.id)}`);\n const current = data ?? { ...sandbox.data, status: 'deleted' };\n return {\n id: sandbox.id,\n provider: 'agent37',\n status: infoStatus(current.status),\n createdAt: new Date(current.created * 1000),\n timeout: 0,\n metadata: {\n status: current.status,\n template: current.template,\n type: current.type,\n region: current.region,\n resources: current.resources,\n url: current.url,\n },\n };\n },\n\n // A signed URL that reaches the port without an API key, valid for one hour.\n getUrl: async (sandbox: Agent37Sandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const { data } = await request<{ url: string }>(\n sandbox,\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,\n { port: options.port },\n );\n if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n // The URL carries its own access token, so it is only ever handed out encrypted.\n return options.protocol === 'ws' || options.protocol === 'wss' ? data.url.replace(/^https/, 'wss') : data.url;\n },\n\n getInstance: (sandbox: Agent37Sandbox): Agent37Sandbox => sandbox,\n\n filesystem: {\n readFile: async (sandbox: Agent37Sandbox, path: string): Promise<string> => {\n const result = await exec(sandbox, `base64 -w0 ${shellPath(path)}`);\n if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);\n if (result.truncated) throw new Error(`Failed to read ${path}: the file is larger than one command's output limit`);\n return Buffer.from(result.stdout, 'base64').toString('utf8');\n },\n writeFile: async (sandbox: Agent37Sandbox, path: string, content: string, run: FsRunCommand): Promise<void> => {\n const bytes = Buffer.from(content, 'utf8');\n const target = shellPath(path);\n const directory = shellPath(posix.dirname(path));\n const temporary = `\"\\${TMPDIR:-/tmp}/.computesdk-write-${randomUUID()}\"`;\n try {\n await mustSucceed(run, sandbox, `mkdir -p -- ${directory} && (umask 077; set -C; : > ${temporary})`, `write ${path}`);\n for (let offset = 0; offset < bytes.length; offset += WRITE_CHUNK_BYTES) {\n const encoded = bytes.subarray(offset, offset + WRITE_CHUNK_BYTES).toString('base64');\n await mustSucceed(run, sandbox, `printf '%s' '${encoded}' | base64 -d >> ${temporary}`, `write ${path}`);\n }\n // Custom images may omit flock; only that case falls back to ordinary redirection.\n const copy = `cat ${temporary} > ${target}`;\n await mustSucceed(run, sandbox, `if command -v flock >/dev/null 2>&1; then (flock -x 9 && ${copy}) 9>> ${target}; else ${copy}; fi`, `write ${path}`);\n } finally {\n await run(sandbox, `rm -f -- ${temporary}`).catch(() => {});\n }\n },\n mkdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);\n },\n readdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<FileEntry[]> => {\n const result = await mustSucceed(\n run,\n sandbox,\n `find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n'`,\n `list ${path}`,\n );\n return result.stdout\n .split('\\n')\n .filter(Boolean)\n .map((line) => {\n const [kind, size, modified, ...name] = line.split('\\t');\n return {\n name: name.join('\\t'),\n type: kind === 'd' ? ('directory' as const) : ('file' as const),\n size: Number(size),\n modified: new Date(Number(modified) * 1000),\n };\n });\n },\n exists: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<boolean> => {\n const result = await run(sandbox, `test -e ${shellPath(path)}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);\n },\n },\n },\n },\n});\n\nexport default agent37;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,yBAA2B;AAC3B,uBAAsB;AACtB,sBAAkE;AA+ClE,IAAM,oBAAoB,KAAK;AAE/B,SAAS,cAA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AA,QACA,QAAQ,OAAO,SAAyB,MAAc,QAAqC;AACzF,gBAAM,YAAY,KAAK,SAAS,UAAU,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,EAAE;AAAA,QAC/E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,IAAO,gBAAQ;","names":["exports"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Agent37 Provider - Factory-based Implementation\n *\n * Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small\n * JSON surface, so this package talks to it with `fetch` and has no SDK dependency.\n *\n * Commands run as root by default, since Agent37 images ship no sudo. Pass\n * `runAsRoot: false` to run as the image's own user instead.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { posix } from 'node:path';\nimport { StringDecoder } from 'node:string_decoder';\nimport { defineProvider, escapeShellArg, InstanceSizeError } from '@computesdk/provider';\n\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nexport interface Agent37Config {\n /** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */\n apiKey?: string;\n /** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */\n baseUrl?: string;\n /** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */\n execUrl?: string;\n /** Run commands as root (default true). Set false to run as the image's default user. */\n runAsRoot?: boolean;\n}\n\n/** An instance as the Agent37 API returns it. */\nexport interface Agent37InstanceData {\n id: string;\n status: string;\n template: string;\n type: string;\n region: string;\n resources: { cpu: number; memory: number; disk: number };\n url: string;\n created: number;\n [key: string]: unknown;\n}\n\nexport interface Agent37Sandbox {\n id: string;\n data: Agent37InstanceData;\n apiKey: string;\n baseUrl: string;\n execUrl: string;\n runAsRoot: boolean;\n}\n\ninterface ExecResponse {\n exit_code: number;\n stdout: string;\n stderr: string;\n truncated?: boolean;\n}\n\ntype FsRunCommand = (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions) => Promise<CommandResult>;\n\n// 48 KiB becomes 64 KiB of base64, leaving room for JSON and paths under exec's 128 KB request cap.\nconst WRITE_CHUNK_BYTES = 48 * 1024;\n// Base64 plus the read-status trailer stays below exec's 512 KB output cap.\nconst READ_CHUNK_BYTES = 256 * 1024;\n\nfunction resolveConfig(config: Agent37Config) {\n const env = typeof process !== 'undefined' ? process.env : undefined;\n const apiKey = config.apiKey || env?.AGENT37_API_KEY || '';\n if (!apiKey) {\n throw new Error(\n `Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. ` +\n `Create one at https://www.agent37.com/dashboard/cloud/api-keys`,\n );\n }\n const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || 'https://api.agent37.com').replace(/\\/+$/, '');\n const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || 'https://sandbox.agent37.app').replace(/\\/+$/, '');\n return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };\n}\n\nasync function request<T>(\n auth: { apiKey: string; baseUrl: string },\n method: string,\n path: string,\n body?: unknown,\n timeoutMs?: number,\n keyHeader = false,\n): Promise<{ status: number; data: T | null }> {\n const res = await fetch(`${auth.baseUrl}${path}`, {\n method,\n headers: {\n ...(keyHeader ? { 'X-Agent37-Key': auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` }),\n 'Content-Type': 'application/json',\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined,\n });\n if (res.status === 404) return { status: 404, data: null };\n const text = await res.text();\n if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);\n return { status: res.status, data: (text ? JSON.parse(text) : null) as T };\n}\n\nfunction toSandbox(auth: { apiKey: string; baseUrl: string; execUrl: string; runAsRoot: boolean }, data: Agent37InstanceData): Agent37Sandbox {\n return { id: data.id, data, ...auth };\n}\n\nfunction megabytesToGb(mb: unknown): number | undefined {\n return typeof mb === 'number' && mb > 0 ? Math.ceil(mb / 1024) : undefined;\n}\n\n/** Maps ComputeSDK's create options onto the body of POST /v1/instances. */\nfunction createBody(options: CreateInstanceOptions = {}): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n if (options.templateId) body.template = options.templateId;\n if (typeof options.type === 'string') body.type = options.type;\n if (typeof options.region === 'string') body.region = options.region;\n if (options.name) body.name = options.name;\n if (options.metadata) body.metadata = options.metadata;\n if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;\n\n const cpu = options.cpu ?? options.vcpus ?? options.cpus;\n const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);\n const disk = megabytesToGb(options.diskMb ?? options.diskMiB);\n const resources = {\n ...(typeof cpu === 'number' ? { cpu } : {}),\n ...(memory ? { memory } : {}),\n ...(disk ? { disk } : {}),\n };\n if (Object.keys(resources).length > 0) body.resources = resources;\n return body;\n}\n\nfunction wrapCommand(command: string, options?: RunCommandOptions): string {\n let cmd = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const exports = Object.entries(options.env).map(([key, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);\n return `export ${key}=\"${escapeShellArg(value)}\"`;\n });\n cmd = `${exports.join(' && ')} && ${cmd}`;\n }\n if (options?.cwd) cmd = `cd \"${escapeShellArg(options.cwd)}\" && ${cmd}`;\n if (options?.background) cmd = `nohup sh -c \"${escapeShellArg(cmd)}\" >/dev/null 2>&1 &`;\n return cmd;\n}\n\n// A leading dash would be read as an option by base64, find, mkdir and rm.\nfunction shellPath(path: string): string {\n return `\"${escapeShellArg(path.startsWith('-') ? `./${path}` : path)}\"`;\n}\n\n// Exec is answered by the machine the instance runs on, at execUrl, which takes the key as X-Agent37-Key.\nasync function exec(sandbox: Agent37Sandbox, command: string, timeoutMs?: number): Promise<ExecResponse> {\n const { data } = await request<ExecResponse>(\n { apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,\n { command, ...(sandbox.runAsRoot ? { user: 'root' } : {}) },\n timeoutMs,\n true,\n );\n if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n return data;\n}\n\nfunction infoStatus(status: string): InstanceInfo['status'] {\n if (status === 'failed') return 'error';\n if (status === 'stopped' || status === 'stopping' || status === 'deleting' || status === 'deleted') return 'stopped';\n return 'running';\n}\n\nasync function mustSucceed(run: FsRunCommand, sandbox: Agent37Sandbox, command: string, what: string): Promise<CommandResult> {\n const result = await run(sandbox, command);\n if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);\n return result;\n}\n\n// Agent37 offers four create shapes (vCPU / GB RAM): 2/4, 4/8, 4/16 and 4/32. 4 vCPU is the ceiling on\n// every type, and a request for more cores is quietly capped, so only exact shapes are claimed.\n// https://www.agent37.com/docs/agents-api/instance-sizing\nconst SHAPES = new Set(['2/4096', '4/8192', '4/16384', '4/32768']);\nconst NATIVE_SIZE_FIELDS = ['cpu', 'vcpus', 'cpus', 'memory', 'memoryMiB', 'memoryMb', 'memMiB'] as const;\n\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\n sizes: (_config, profile, options) => {\n if (NATIVE_SIZE_FIELDS.some((field) => options?.[field] !== undefined)) {\n throw new InstanceSizeError('conflict', 'cannot combine sizeClass with native Agent37 cpu/memory fields');\n }\n const type = options?.type ?? 'default';\n if (type !== 'default' && type !== 'performance' && type !== 'vm') {\n return { status: 'unknown', reason: `Agent37 shapes are published for the default, performance and vm types, not ${JSON.stringify(type)}.` };\n }\n if (!SHAPES.has(`${profile.vcpus}/${profile.memoryMiB}`)) {\n return {\n status: 'unsupported',\n reason: `Agent37 has no ${profile.vcpus} vCPU / ${profile.memoryMiB / 1024} GB shape; it offers 2/4, 4/8, 4/16 and 4/32 (4 vCPU ceiling).`,\n };\n }\n return { status: 'supported', nativeOptions: { cpu: profile.vcpus, memoryMiB: profile.memoryMiB } };\n },\n methods: {\n instances: {\n create: async (config: Agent37Config, options?: CreateInstanceOptions) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'POST', '/v1/instances', createBody(options));\n if (!data) throw new Error('Agent37 API returned no instance on create');\n return { instance: toSandbox(auth, data), instanceId: data.id };\n },\n\n getById: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'GET', `/v1/instances/${encodeURIComponent(instanceId)}`);\n return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;\n },\n\n list: async (config: Agent37Config) => {\n const auth = resolveConfig(config);\n const { data } = await request<{ data: Agent37InstanceData[] }>(auth, 'GET', '/v1/instances');\n return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));\n },\n\n destroy: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n await request(auth, 'DELETE', `/v1/instances/${encodeURIComponent(instanceId)}`);\n },\n\n runCommand: async (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const start = Date.now();\n const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);\n return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox: Agent37Sandbox): Promise<InstanceInfo> => {\n const { data } = await request<Agent37InstanceData>(sandbox, 'GET', `/v1/instances/${encodeURIComponent(sandbox.id)}`);\n const current = data ?? { ...sandbox.data, status: 'deleted' };\n return {\n id: sandbox.id,\n provider: 'agent37',\n status: infoStatus(current.status),\n createdAt: new Date(current.created * 1000),\n timeout: 0,\n metadata: {\n status: current.status,\n template: current.template,\n type: current.type,\n region: current.region,\n resources: current.resources,\n url: current.url,\n },\n };\n },\n\n // A signed URL that reaches the port without an API key, valid for one hour.\n getUrl: async (sandbox: Agent37Sandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const { data } = await request<{ url: string }>(\n sandbox,\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,\n { port: options.port },\n );\n if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n // The URL carries its own access token, so it is only ever handed out encrypted.\n return options.protocol === 'ws' || options.protocol === 'wss' ? data.url.replace(/^https/, 'wss') : data.url;\n },\n\n getInstance: (sandbox: Agent37Sandbox): Agent37Sandbox => sandbox,\n\n filesystem: {\n readFile: async (sandbox: Agent37Sandbox, path: string): Promise<string> => {\n const target = shellPath(path);\n const read = async (command: string) => {\n const result = await exec(sandbox, command);\n if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);\n if (result.truncated) throw new Error(`Failed to read ${path}: truncated exec output`);\n return result;\n };\n const metadataCommand = `test -f ${target} && stat -Lc '%s:%d:%i:%y:%z' -- ${target}`;\n const metadata = (await read(metadataCommand)).stdout;\n const size = Number(metadata.split(':', 1)[0]);\n if (!/^\\d+:/.test(metadata) || !Number.isSafeInteger(size)) throw new Error(`Failed to read ${path}: invalid file size`);\n const decoder = new StringDecoder('utf8');\n const parts: string[] = [];\n for (let index = 0; index < Math.max(1, Math.ceil(size / READ_CHUNK_BYTES)); index++) {\n // Carry dd's exit status through base64: sh pipelines otherwise hide producer failures.\n const result = await read(`{ dd if=${target} bs=${READ_CHUNK_BYTES} skip=${index} count=1 iflag=fullblock status=none; printf '\\\\n%03d' \"$?\"; } | base64 -w0`);\n if (result.stdout.length > 4 * Math.ceil((READ_CHUNK_BYTES + 4) / 3)) throw new Error(`Failed to read ${path}: oversized read chunk`);\n const bytes = Buffer.from(result.stdout, 'base64');\n if (bytes.toString('base64') !== result.stdout || !/^\\n\\d{3}$/.test(bytes.subarray(-4).toString('utf8'))) {\n throw new Error(`Failed to read ${path}: invalid read chunk`);\n }\n const status = bytes.subarray(-3).toString('utf8');\n if (status !== '000') throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${Number(status)}`}`);\n const expected = Math.min(READ_CHUNK_BYTES, size - index * READ_CHUNK_BYTES);\n if (bytes.length !== expected + 4) throw new Error(`Failed to read ${path}: unexpected read length (expected ${expected}, received ${bytes.length - 4})`);\n parts.push(decoder.write(bytes.subarray(0, -4)));\n }\n if ((await read(metadataCommand)).stdout !== metadata) throw new Error(`Failed to read ${path}: file changed during read`);\n return parts.join('') + decoder.end();\n },\n writeFile: async (sandbox: Agent37Sandbox, path: string, content: string, run: FsRunCommand): Promise<void> => {\n const bytes = Buffer.from(content, 'utf8');\n const target = shellPath(path);\n const directory = shellPath(posix.dirname(path));\n const temporary = `\"\\${TMPDIR:-/tmp}/.computesdk-write-${randomUUID()}\"`;\n try {\n await mustSucceed(run, sandbox, `mkdir -p -- ${directory} && (umask 077; set -C; : > ${temporary})`, `write ${path}`);\n for (let offset = 0; offset < bytes.length; offset += WRITE_CHUNK_BYTES) {\n const encoded = bytes.subarray(offset, offset + WRITE_CHUNK_BYTES).toString('base64');\n await mustSucceed(run, sandbox, `printf '%s' '${encoded}' | base64 -d >> ${temporary}`, `write ${path}`);\n }\n // Custom images may omit flock; only that case falls back to ordinary redirection.\n const copy = `cat ${temporary} > ${target}`;\n await mustSucceed(run, sandbox, `if command -v flock >/dev/null 2>&1; then (flock -x 9 && ${copy}) 9>> ${target}; else ${copy}; fi`, `write ${path}`);\n } finally {\n await run(sandbox, `rm -f -- ${temporary}`).catch(() => {});\n }\n },\n mkdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);\n },\n readdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<FileEntry[]> => {\n const result = await mustSucceed(\n run,\n sandbox,\n `find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n'`,\n `list ${path}`,\n );\n return result.stdout\n .split('\\n')\n .filter(Boolean)\n .map((line) => {\n const [kind, size, modified, ...name] = line.split('\\t');\n return {\n name: name.join('\\t'),\n type: kind === 'd' ? ('directory' as const) : ('file' as const),\n size: Number(size),\n modified: new Date(Number(modified) * 1000),\n };\n });\n },\n exists: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<boolean> => {\n const result = await run(sandbox, `test -e ${shellPath(path)}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);\n },\n },\n },\n },\n});\n\nexport default agent37;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,yBAA2B;AAC3B,uBAAsB;AACtB,iCAA8B;AAC9B,sBAAkE;AA+ClE,IAAM,oBAAoB,KAAK;AAE/B,IAAM,mBAAmB,MAAM;AAE/B,SAAS,cAAc,QAAuB;AAC5C,QAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM;AAC3D,QAAM,SAAS,OAAO,UAAU,KAAK,mBAAmB;AACxD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,QAAM,WAAW,OAAO,WAAW,KAAK,oBAAoB,2BAA2B,QAAQ,QAAQ,EAAE;AACzG,QAAM,WAAW,OAAO,WAAW,KAAK,oBAAoB,+BAA+B,QAAQ,QAAQ,EAAE;AAC7G,SAAO,EAAE,QAAQ,SAAS,SAAS,WAAW,OAAO,cAAc,MAAM;AAC3E;AAEA,eAAe,QACb,MACA,QACA,MACA,MACA,WACA,YAAY,OACiC;AAC7C,QAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,IAChD;AAAA,IACA,SAAS;AAAA,MACP,GAAI,YAAY,EAAE,iBAAiB,KAAK,OAAO,IAAI,EAAE,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AAAA,UAC5D;AAAA,QACF;AAAA,QACA,OAAO,OAAO,SAAyB,MAAc,QAAqC;AACxF,gBAAM,YAAY,KAAK,SAAS,YAAY,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,EAAE;AAAA,QACjF;AAAA,QACA,SAAS,OAAO,SAAyB,MAAc,QAA4C;AACjG,gBAAM,SAAS,MAAM;AAAA,YACnB;AAAA,YACA;AAAA,YACA,QAAQ,UAAU,IAAI,CAAC;AAAA,YACvB,QAAQ,IAAI;AAAA,UACd;AACA,iBAAO,OAAO,OACX,MAAM,IAAI,EACV,OAAO,OAAO,EACd,IAAI,CAAC,SAAS;AACb,kBAAM,CAAC,MAAM,MAAM,UAAU,GAAG,IAAI,IAAI,KAAK,MAAM,GAAI;AACvD,mBAAO;AAAA,cACL,MAAM,KAAK,KAAK,GAAI;AAAA,cACpB,MAAM,SAAS,MAAO,cAAyB;AAAA,cAC/C,MAAM,OAAO,IAAI;AAAA,cACjB,UAAU,IAAI,KAAK,OAAO,QAAQ,IAAI,GAAI;AAAA,YAC5C;AAAA,UACF,CAAC;AAAA,QACL;AAAA,QACA,QAAQ,OAAO,SAAyB,MAAc,QAAwC;AAC5F,gBAAM,SAAS,MAAM,IAAI,SAAS,WAAW,UAAU,IAAI,CAAC,EAAE;AAC9D,iBAAO,OAAO,aAAa;AAAA,QAC7B;AAAA,QACA,QAAQ,OAAO,SAAyB,MAAc,QAAqC;AACzF,gBAAM,YAAY,KAAK,SAAS,UAAU,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,EAAE;AAAA,QAC/E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,IAAO,gBAAQ;","names":["exports"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { randomUUID } from "crypto";
|
|
3
3
|
import { posix } from "path";
|
|
4
|
+
import { StringDecoder } from "string_decoder";
|
|
4
5
|
import { defineProvider, escapeShellArg, InstanceSizeError } from "@computesdk/provider";
|
|
5
6
|
var WRITE_CHUNK_BYTES = 48 * 1024;
|
|
7
|
+
var READ_CHUNK_BYTES = 256 * 1024;
|
|
6
8
|
function resolveConfig(config) {
|
|
7
9
|
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
8
10
|
const apiKey = config.apiKey || env?.AGENT37_API_KEY || "";
|
|
@@ -173,10 +175,34 @@ var agent37 = defineProvider({
|
|
|
173
175
|
getInstance: (sandbox) => sandbox,
|
|
174
176
|
filesystem: {
|
|
175
177
|
readFile: async (sandbox, path) => {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
const target = shellPath(path);
|
|
179
|
+
const read = async (command) => {
|
|
180
|
+
const result = await exec(sandbox, command);
|
|
181
|
+
if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);
|
|
182
|
+
if (result.truncated) throw new Error(`Failed to read ${path}: truncated exec output`);
|
|
183
|
+
return result;
|
|
184
|
+
};
|
|
185
|
+
const metadataCommand = `test -f ${target} && stat -Lc '%s:%d:%i:%y:%z' -- ${target}`;
|
|
186
|
+
const metadata = (await read(metadataCommand)).stdout;
|
|
187
|
+
const size = Number(metadata.split(":", 1)[0]);
|
|
188
|
+
if (!/^\d+:/.test(metadata) || !Number.isSafeInteger(size)) throw new Error(`Failed to read ${path}: invalid file size`);
|
|
189
|
+
const decoder = new StringDecoder("utf8");
|
|
190
|
+
const parts = [];
|
|
191
|
+
for (let index = 0; index < Math.max(1, Math.ceil(size / READ_CHUNK_BYTES)); index++) {
|
|
192
|
+
const result = await read(`{ dd if=${target} bs=${READ_CHUNK_BYTES} skip=${index} count=1 iflag=fullblock status=none; printf '\\n%03d' "$?"; } | base64 -w0`);
|
|
193
|
+
if (result.stdout.length > 4 * Math.ceil((READ_CHUNK_BYTES + 4) / 3)) throw new Error(`Failed to read ${path}: oversized read chunk`);
|
|
194
|
+
const bytes = Buffer.from(result.stdout, "base64");
|
|
195
|
+
if (bytes.toString("base64") !== result.stdout || !/^\n\d{3}$/.test(bytes.subarray(-4).toString("utf8"))) {
|
|
196
|
+
throw new Error(`Failed to read ${path}: invalid read chunk`);
|
|
197
|
+
}
|
|
198
|
+
const status = bytes.subarray(-3).toString("utf8");
|
|
199
|
+
if (status !== "000") throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${Number(status)}`}`);
|
|
200
|
+
const expected = Math.min(READ_CHUNK_BYTES, size - index * READ_CHUNK_BYTES);
|
|
201
|
+
if (bytes.length !== expected + 4) throw new Error(`Failed to read ${path}: unexpected read length (expected ${expected}, received ${bytes.length - 4})`);
|
|
202
|
+
parts.push(decoder.write(bytes.subarray(0, -4)));
|
|
203
|
+
}
|
|
204
|
+
if ((await read(metadataCommand)).stdout !== metadata) throw new Error(`Failed to read ${path}: file changed during read`);
|
|
205
|
+
return parts.join("") + decoder.end();
|
|
180
206
|
},
|
|
181
207
|
writeFile: async (sandbox, path, content, run) => {
|
|
182
208
|
const bytes = Buffer.from(content, "utf8");
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Agent37 Provider - Factory-based Implementation\n *\n * Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small\n * JSON surface, so this package talks to it with `fetch` and has no SDK dependency.\n *\n * Commands run as root by default, since Agent37 images ship no sudo. Pass\n * `runAsRoot: false` to run as the image's own user instead.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { posix } from 'node:path';\nimport { defineProvider, escapeShellArg, InstanceSizeError } from '@computesdk/provider';\n\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nexport interface Agent37Config {\n /** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */\n apiKey?: string;\n /** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */\n baseUrl?: string;\n /** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */\n execUrl?: string;\n /** Run commands as root (default true). Set false to run as the image's default user. */\n runAsRoot?: boolean;\n}\n\n/** An instance as the Agent37 API returns it. */\nexport interface Agent37InstanceData {\n id: string;\n status: string;\n template: string;\n type: string;\n region: string;\n resources: { cpu: number; memory: number; disk: number };\n url: string;\n created: number;\n [key: string]: unknown;\n}\n\nexport interface Agent37Sandbox {\n id: string;\n data: Agent37InstanceData;\n apiKey: string;\n baseUrl: string;\n execUrl: string;\n runAsRoot: boolean;\n}\n\ninterface ExecResponse {\n exit_code: number;\n stdout: string;\n stderr: string;\n truncated?: boolean;\n}\n\ntype FsRunCommand = (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions) => Promise<CommandResult>;\n\n// 48 KiB becomes 64 KiB of base64, leaving room for JSON and paths under exec's 128 KB request cap.\nconst WRITE_CHUNK_BYTES = 48 * 1024;\n\nfunction resolveConfig(config: Agent37Config) {\n const env = typeof process !== 'undefined' ? process.env : undefined;\n const apiKey = config.apiKey || env?.AGENT37_API_KEY || '';\n if (!apiKey) {\n throw new Error(\n `Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. ` +\n `Create one at https://www.agent37.com/dashboard/cloud/api-keys`,\n );\n }\n const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || 'https://api.agent37.com').replace(/\\/+$/, '');\n const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || 'https://sandbox.agent37.app').replace(/\\/+$/, '');\n return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };\n}\n\nasync function request<T>(\n auth: { apiKey: string; baseUrl: string },\n method: string,\n path: string,\n body?: unknown,\n timeoutMs?: number,\n keyHeader = false,\n): Promise<{ status: number; data: T | null }> {\n const res = await fetch(`${auth.baseUrl}${path}`, {\n method,\n headers: {\n ...(keyHeader ? { 'X-Agent37-Key': auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` }),\n 'Content-Type': 'application/json',\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined,\n });\n if (res.status === 404) return { status: 404, data: null };\n const text = await res.text();\n if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);\n return { status: res.status, data: (text ? JSON.parse(text) : null) as T };\n}\n\nfunction toSandbox(auth: { apiKey: string; baseUrl: string; execUrl: string; runAsRoot: boolean }, data: Agent37InstanceData): Agent37Sandbox {\n return { id: data.id, data, ...auth };\n}\n\nfunction megabytesToGb(mb: unknown): number | undefined {\n return typeof mb === 'number' && mb > 0 ? Math.ceil(mb / 1024) : undefined;\n}\n\n/** Maps ComputeSDK's create options onto the body of POST /v1/instances. */\nfunction createBody(options: CreateInstanceOptions = {}): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n if (options.templateId) body.template = options.templateId;\n if (typeof options.type === 'string') body.type = options.type;\n if (typeof options.region === 'string') body.region = options.region;\n if (options.name) body.name = options.name;\n if (options.metadata) body.metadata = options.metadata;\n if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;\n\n const cpu = options.cpu ?? options.vcpus ?? options.cpus;\n const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);\n const disk = megabytesToGb(options.diskMb ?? options.diskMiB);\n const resources = {\n ...(typeof cpu === 'number' ? { cpu } : {}),\n ...(memory ? { memory } : {}),\n ...(disk ? { disk } : {}),\n };\n if (Object.keys(resources).length > 0) body.resources = resources;\n return body;\n}\n\nfunction wrapCommand(command: string, options?: RunCommandOptions): string {\n let cmd = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const exports = Object.entries(options.env).map(([key, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);\n return `export ${key}=\"${escapeShellArg(value)}\"`;\n });\n cmd = `${exports.join(' && ')} && ${cmd}`;\n }\n if (options?.cwd) cmd = `cd \"${escapeShellArg(options.cwd)}\" && ${cmd}`;\n if (options?.background) cmd = `nohup sh -c \"${escapeShellArg(cmd)}\" >/dev/null 2>&1 &`;\n return cmd;\n}\n\n// A leading dash would be read as an option by base64, find, mkdir and rm.\nfunction shellPath(path: string): string {\n return `\"${escapeShellArg(path.startsWith('-') ? `./${path}` : path)}\"`;\n}\n\n// Exec is answered by the machine the instance runs on, at execUrl, which takes the key as X-Agent37-Key.\nasync function exec(sandbox: Agent37Sandbox, command: string, timeoutMs?: number): Promise<ExecResponse> {\n const { data } = await request<ExecResponse>(\n { apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,\n { command, ...(sandbox.runAsRoot ? { user: 'root' } : {}) },\n timeoutMs,\n true,\n );\n if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n return data;\n}\n\nfunction infoStatus(status: string): InstanceInfo['status'] {\n if (status === 'failed') return 'error';\n if (status === 'stopped' || status === 'stopping' || status === 'deleting' || status === 'deleted') return 'stopped';\n return 'running';\n}\n\nasync function mustSucceed(run: FsRunCommand, sandbox: Agent37Sandbox, command: string, what: string): Promise<CommandResult> {\n const result = await run(sandbox, command);\n if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);\n return result;\n}\n\n// Agent37 offers four create shapes (vCPU / GB RAM): 2/4, 4/8, 4/16 and 4/32. 4 vCPU is the ceiling on\n// every type, and a request for more cores is quietly capped, so only exact shapes are claimed.\n// https://www.agent37.com/docs/agents-api/instance-sizing\nconst SHAPES = new Set(['2/4096', '4/8192', '4/16384', '4/32768']);\nconst NATIVE_SIZE_FIELDS = ['cpu', 'vcpus', 'cpus', 'memory', 'memoryMiB', 'memoryMb', 'memMiB'] as const;\n\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\n sizes: (_config, profile, options) => {\n if (NATIVE_SIZE_FIELDS.some((field) => options?.[field] !== undefined)) {\n throw new InstanceSizeError('conflict', 'cannot combine sizeClass with native Agent37 cpu/memory fields');\n }\n const type = options?.type ?? 'default';\n if (type !== 'default' && type !== 'performance' && type !== 'vm') {\n return { status: 'unknown', reason: `Agent37 shapes are published for the default, performance and vm types, not ${JSON.stringify(type)}.` };\n }\n if (!SHAPES.has(`${profile.vcpus}/${profile.memoryMiB}`)) {\n return {\n status: 'unsupported',\n reason: `Agent37 has no ${profile.vcpus} vCPU / ${profile.memoryMiB / 1024} GB shape; it offers 2/4, 4/8, 4/16 and 4/32 (4 vCPU ceiling).`,\n };\n }\n return { status: 'supported', nativeOptions: { cpu: profile.vcpus, memoryMiB: profile.memoryMiB } };\n },\n methods: {\n instances: {\n create: async (config: Agent37Config, options?: CreateInstanceOptions) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'POST', '/v1/instances', createBody(options));\n if (!data) throw new Error('Agent37 API returned no instance on create');\n return { instance: toSandbox(auth, data), instanceId: data.id };\n },\n\n getById: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'GET', `/v1/instances/${encodeURIComponent(instanceId)}`);\n return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;\n },\n\n list: async (config: Agent37Config) => {\n const auth = resolveConfig(config);\n const { data } = await request<{ data: Agent37InstanceData[] }>(auth, 'GET', '/v1/instances');\n return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));\n },\n\n destroy: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n await request(auth, 'DELETE', `/v1/instances/${encodeURIComponent(instanceId)}`);\n },\n\n runCommand: async (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const start = Date.now();\n const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);\n return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox: Agent37Sandbox): Promise<InstanceInfo> => {\n const { data } = await request<Agent37InstanceData>(sandbox, 'GET', `/v1/instances/${encodeURIComponent(sandbox.id)}`);\n const current = data ?? { ...sandbox.data, status: 'deleted' };\n return {\n id: sandbox.id,\n provider: 'agent37',\n status: infoStatus(current.status),\n createdAt: new Date(current.created * 1000),\n timeout: 0,\n metadata: {\n status: current.status,\n template: current.template,\n type: current.type,\n region: current.region,\n resources: current.resources,\n url: current.url,\n },\n };\n },\n\n // A signed URL that reaches the port without an API key, valid for one hour.\n getUrl: async (sandbox: Agent37Sandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const { data } = await request<{ url: string }>(\n sandbox,\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,\n { port: options.port },\n );\n if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n // The URL carries its own access token, so it is only ever handed out encrypted.\n return options.protocol === 'ws' || options.protocol === 'wss' ? data.url.replace(/^https/, 'wss') : data.url;\n },\n\n getInstance: (sandbox: Agent37Sandbox): Agent37Sandbox => sandbox,\n\n filesystem: {\n readFile: async (sandbox: Agent37Sandbox, path: string): Promise<string> => {\n const result = await exec(sandbox, `base64 -w0 ${shellPath(path)}`);\n if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);\n if (result.truncated) throw new Error(`Failed to read ${path}: the file is larger than one command's output limit`);\n return Buffer.from(result.stdout, 'base64').toString('utf8');\n },\n writeFile: async (sandbox: Agent37Sandbox, path: string, content: string, run: FsRunCommand): Promise<void> => {\n const bytes = Buffer.from(content, 'utf8');\n const target = shellPath(path);\n const directory = shellPath(posix.dirname(path));\n const temporary = `\"\\${TMPDIR:-/tmp}/.computesdk-write-${randomUUID()}\"`;\n try {\n await mustSucceed(run, sandbox, `mkdir -p -- ${directory} && (umask 077; set -C; : > ${temporary})`, `write ${path}`);\n for (let offset = 0; offset < bytes.length; offset += WRITE_CHUNK_BYTES) {\n const encoded = bytes.subarray(offset, offset + WRITE_CHUNK_BYTES).toString('base64');\n await mustSucceed(run, sandbox, `printf '%s' '${encoded}' | base64 -d >> ${temporary}`, `write ${path}`);\n }\n // Custom images may omit flock; only that case falls back to ordinary redirection.\n const copy = `cat ${temporary} > ${target}`;\n await mustSucceed(run, sandbox, `if command -v flock >/dev/null 2>&1; then (flock -x 9 && ${copy}) 9>> ${target}; else ${copy}; fi`, `write ${path}`);\n } finally {\n await run(sandbox, `rm -f -- ${temporary}`).catch(() => {});\n }\n },\n mkdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);\n },\n readdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<FileEntry[]> => {\n const result = await mustSucceed(\n run,\n sandbox,\n `find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n'`,\n `list ${path}`,\n );\n return result.stdout\n .split('\\n')\n .filter(Boolean)\n .map((line) => {\n const [kind, size, modified, ...name] = line.split('\\t');\n return {\n name: name.join('\\t'),\n type: kind === 'd' ? ('directory' as const) : ('file' as const),\n size: Number(size),\n modified: new Date(Number(modified) * 1000),\n };\n });\n },\n exists: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<boolean> => {\n const result = await run(sandbox, `test -e ${shellPath(path)}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);\n },\n },\n },\n },\n});\n\nexport default agent37;\n"],"mappings":";AAUA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,gBAAgB,gBAAgB,yBAAyB;AA+ClE,IAAM,oBAAoB,KAAK;AAE/B,SAAS,cA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AAQ,OAAO,SAAyB,MAAc,QAAqC;AACzF,gBAAM,YAAY,KAAK,SAAS,UAAU,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,EAAE;AAAA,QAC/E;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;AAED,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Agent37 Provider - Factory-based Implementation\n *\n * Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small\n * JSON surface, so this package talks to it with `fetch` and has no SDK dependency.\n *\n * Commands run as root by default, since Agent37 images ship no sudo. Pass\n * `runAsRoot: false` to run as the image's own user instead.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { posix } from 'node:path';\nimport { StringDecoder } from 'node:string_decoder';\nimport { defineProvider, escapeShellArg, InstanceSizeError } from '@computesdk/provider';\n\nimport type { CommandResult, CreateInstanceOptions, FileEntry, InstanceInfo, RunCommandOptions } from '@computesdk/provider';\n\nexport interface Agent37Config {\n /** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */\n apiKey?: string;\n /** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */\n baseUrl?: string;\n /** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */\n execUrl?: string;\n /** Run commands as root (default true). Set false to run as the image's default user. */\n runAsRoot?: boolean;\n}\n\n/** An instance as the Agent37 API returns it. */\nexport interface Agent37InstanceData {\n id: string;\n status: string;\n template: string;\n type: string;\n region: string;\n resources: { cpu: number; memory: number; disk: number };\n url: string;\n created: number;\n [key: string]: unknown;\n}\n\nexport interface Agent37Sandbox {\n id: string;\n data: Agent37InstanceData;\n apiKey: string;\n baseUrl: string;\n execUrl: string;\n runAsRoot: boolean;\n}\n\ninterface ExecResponse {\n exit_code: number;\n stdout: string;\n stderr: string;\n truncated?: boolean;\n}\n\ntype FsRunCommand = (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions) => Promise<CommandResult>;\n\n// 48 KiB becomes 64 KiB of base64, leaving room for JSON and paths under exec's 128 KB request cap.\nconst WRITE_CHUNK_BYTES = 48 * 1024;\n// Base64 plus the read-status trailer stays below exec's 512 KB output cap.\nconst READ_CHUNK_BYTES = 256 * 1024;\n\nfunction resolveConfig(config: Agent37Config) {\n const env = typeof process !== 'undefined' ? process.env : undefined;\n const apiKey = config.apiKey || env?.AGENT37_API_KEY || '';\n if (!apiKey) {\n throw new Error(\n `Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. ` +\n `Create one at https://www.agent37.com/dashboard/cloud/api-keys`,\n );\n }\n const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || 'https://api.agent37.com').replace(/\\/+$/, '');\n const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || 'https://sandbox.agent37.app').replace(/\\/+$/, '');\n return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };\n}\n\nasync function request<T>(\n auth: { apiKey: string; baseUrl: string },\n method: string,\n path: string,\n body?: unknown,\n timeoutMs?: number,\n keyHeader = false,\n): Promise<{ status: number; data: T | null }> {\n const res = await fetch(`${auth.baseUrl}${path}`, {\n method,\n headers: {\n ...(keyHeader ? { 'X-Agent37-Key': auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` }),\n 'Content-Type': 'application/json',\n },\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined,\n });\n if (res.status === 404) return { status: 404, data: null };\n const text = await res.text();\n if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);\n return { status: res.status, data: (text ? JSON.parse(text) : null) as T };\n}\n\nfunction toSandbox(auth: { apiKey: string; baseUrl: string; execUrl: string; runAsRoot: boolean }, data: Agent37InstanceData): Agent37Sandbox {\n return { id: data.id, data, ...auth };\n}\n\nfunction megabytesToGb(mb: unknown): number | undefined {\n return typeof mb === 'number' && mb > 0 ? Math.ceil(mb / 1024) : undefined;\n}\n\n/** Maps ComputeSDK's create options onto the body of POST /v1/instances. */\nfunction createBody(options: CreateInstanceOptions = {}): Record<string, unknown> {\n const body: Record<string, unknown> = {};\n if (options.templateId) body.template = options.templateId;\n if (typeof options.type === 'string') body.type = options.type;\n if (typeof options.region === 'string') body.region = options.region;\n if (options.name) body.name = options.name;\n if (options.metadata) body.metadata = options.metadata;\n if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;\n\n const cpu = options.cpu ?? options.vcpus ?? options.cpus;\n const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);\n const disk = megabytesToGb(options.diskMb ?? options.diskMiB);\n const resources = {\n ...(typeof cpu === 'number' ? { cpu } : {}),\n ...(memory ? { memory } : {}),\n ...(disk ? { disk } : {}),\n };\n if (Object.keys(resources).length > 0) body.resources = resources;\n return body;\n}\n\nfunction wrapCommand(command: string, options?: RunCommandOptions): string {\n let cmd = command;\n if (options?.env && Object.keys(options.env).length > 0) {\n const exports = Object.entries(options.env).map(([key, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);\n return `export ${key}=\"${escapeShellArg(value)}\"`;\n });\n cmd = `${exports.join(' && ')} && ${cmd}`;\n }\n if (options?.cwd) cmd = `cd \"${escapeShellArg(options.cwd)}\" && ${cmd}`;\n if (options?.background) cmd = `nohup sh -c \"${escapeShellArg(cmd)}\" >/dev/null 2>&1 &`;\n return cmd;\n}\n\n// A leading dash would be read as an option by base64, find, mkdir and rm.\nfunction shellPath(path: string): string {\n return `\"${escapeShellArg(path.startsWith('-') ? `./${path}` : path)}\"`;\n}\n\n// Exec is answered by the machine the instance runs on, at execUrl, which takes the key as X-Agent37-Key.\nasync function exec(sandbox: Agent37Sandbox, command: string, timeoutMs?: number): Promise<ExecResponse> {\n const { data } = await request<ExecResponse>(\n { apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,\n { command, ...(sandbox.runAsRoot ? { user: 'root' } : {}) },\n timeoutMs,\n true,\n );\n if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n return data;\n}\n\nfunction infoStatus(status: string): InstanceInfo['status'] {\n if (status === 'failed') return 'error';\n if (status === 'stopped' || status === 'stopping' || status === 'deleting' || status === 'deleted') return 'stopped';\n return 'running';\n}\n\nasync function mustSucceed(run: FsRunCommand, sandbox: Agent37Sandbox, command: string, what: string): Promise<CommandResult> {\n const result = await run(sandbox, command);\n if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);\n return result;\n}\n\n// Agent37 offers four create shapes (vCPU / GB RAM): 2/4, 4/8, 4/16 and 4/32. 4 vCPU is the ceiling on\n// every type, and a request for more cores is quietly capped, so only exact shapes are claimed.\n// https://www.agent37.com/docs/agents-api/instance-sizing\nconst SHAPES = new Set(['2/4096', '4/8192', '4/16384', '4/32768']);\nconst NATIVE_SIZE_FIELDS = ['cpu', 'vcpus', 'cpus', 'memory', 'memoryMiB', 'memoryMb', 'memMiB'] as const;\n\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\n sizes: (_config, profile, options) => {\n if (NATIVE_SIZE_FIELDS.some((field) => options?.[field] !== undefined)) {\n throw new InstanceSizeError('conflict', 'cannot combine sizeClass with native Agent37 cpu/memory fields');\n }\n const type = options?.type ?? 'default';\n if (type !== 'default' && type !== 'performance' && type !== 'vm') {\n return { status: 'unknown', reason: `Agent37 shapes are published for the default, performance and vm types, not ${JSON.stringify(type)}.` };\n }\n if (!SHAPES.has(`${profile.vcpus}/${profile.memoryMiB}`)) {\n return {\n status: 'unsupported',\n reason: `Agent37 has no ${profile.vcpus} vCPU / ${profile.memoryMiB / 1024} GB shape; it offers 2/4, 4/8, 4/16 and 4/32 (4 vCPU ceiling).`,\n };\n }\n return { status: 'supported', nativeOptions: { cpu: profile.vcpus, memoryMiB: profile.memoryMiB } };\n },\n methods: {\n instances: {\n create: async (config: Agent37Config, options?: CreateInstanceOptions) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'POST', '/v1/instances', createBody(options));\n if (!data) throw new Error('Agent37 API returned no instance on create');\n return { instance: toSandbox(auth, data), instanceId: data.id };\n },\n\n getById: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n const { data } = await request<Agent37InstanceData>(auth, 'GET', `/v1/instances/${encodeURIComponent(instanceId)}`);\n return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;\n },\n\n list: async (config: Agent37Config) => {\n const auth = resolveConfig(config);\n const { data } = await request<{ data: Agent37InstanceData[] }>(auth, 'GET', '/v1/instances');\n return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));\n },\n\n destroy: async (config: Agent37Config, instanceId: string) => {\n const auth = resolveConfig(config);\n await request(auth, 'DELETE', `/v1/instances/${encodeURIComponent(instanceId)}`);\n },\n\n runCommand: async (sandbox: Agent37Sandbox, command: string, options?: RunCommandOptions): Promise<CommandResult> => {\n const start = Date.now();\n const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);\n return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };\n },\n\n getInfo: async (sandbox: Agent37Sandbox): Promise<InstanceInfo> => {\n const { data } = await request<Agent37InstanceData>(sandbox, 'GET', `/v1/instances/${encodeURIComponent(sandbox.id)}`);\n const current = data ?? { ...sandbox.data, status: 'deleted' };\n return {\n id: sandbox.id,\n provider: 'agent37',\n status: infoStatus(current.status),\n createdAt: new Date(current.created * 1000),\n timeout: 0,\n metadata: {\n status: current.status,\n template: current.template,\n type: current.type,\n region: current.region,\n resources: current.resources,\n url: current.url,\n },\n };\n },\n\n // A signed URL that reaches the port without an API key, valid for one hour.\n getUrl: async (sandbox: Agent37Sandbox, options: { port: number; protocol?: string }): Promise<string> => {\n const { data } = await request<{ url: string }>(\n sandbox,\n 'POST',\n `/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,\n { port: options.port },\n );\n if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);\n // The URL carries its own access token, so it is only ever handed out encrypted.\n return options.protocol === 'ws' || options.protocol === 'wss' ? data.url.replace(/^https/, 'wss') : data.url;\n },\n\n getInstance: (sandbox: Agent37Sandbox): Agent37Sandbox => sandbox,\n\n filesystem: {\n readFile: async (sandbox: Agent37Sandbox, path: string): Promise<string> => {\n const target = shellPath(path);\n const read = async (command: string) => {\n const result = await exec(sandbox, command);\n if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);\n if (result.truncated) throw new Error(`Failed to read ${path}: truncated exec output`);\n return result;\n };\n const metadataCommand = `test -f ${target} && stat -Lc '%s:%d:%i:%y:%z' -- ${target}`;\n const metadata = (await read(metadataCommand)).stdout;\n const size = Number(metadata.split(':', 1)[0]);\n if (!/^\\d+:/.test(metadata) || !Number.isSafeInteger(size)) throw new Error(`Failed to read ${path}: invalid file size`);\n const decoder = new StringDecoder('utf8');\n const parts: string[] = [];\n for (let index = 0; index < Math.max(1, Math.ceil(size / READ_CHUNK_BYTES)); index++) {\n // Carry dd's exit status through base64: sh pipelines otherwise hide producer failures.\n const result = await read(`{ dd if=${target} bs=${READ_CHUNK_BYTES} skip=${index} count=1 iflag=fullblock status=none; printf '\\\\n%03d' \"$?\"; } | base64 -w0`);\n if (result.stdout.length > 4 * Math.ceil((READ_CHUNK_BYTES + 4) / 3)) throw new Error(`Failed to read ${path}: oversized read chunk`);\n const bytes = Buffer.from(result.stdout, 'base64');\n if (bytes.toString('base64') !== result.stdout || !/^\\n\\d{3}$/.test(bytes.subarray(-4).toString('utf8'))) {\n throw new Error(`Failed to read ${path}: invalid read chunk`);\n }\n const status = bytes.subarray(-3).toString('utf8');\n if (status !== '000') throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${Number(status)}`}`);\n const expected = Math.min(READ_CHUNK_BYTES, size - index * READ_CHUNK_BYTES);\n if (bytes.length !== expected + 4) throw new Error(`Failed to read ${path}: unexpected read length (expected ${expected}, received ${bytes.length - 4})`);\n parts.push(decoder.write(bytes.subarray(0, -4)));\n }\n if ((await read(metadataCommand)).stdout !== metadata) throw new Error(`Failed to read ${path}: file changed during read`);\n return parts.join('') + decoder.end();\n },\n writeFile: async (sandbox: Agent37Sandbox, path: string, content: string, run: FsRunCommand): Promise<void> => {\n const bytes = Buffer.from(content, 'utf8');\n const target = shellPath(path);\n const directory = shellPath(posix.dirname(path));\n const temporary = `\"\\${TMPDIR:-/tmp}/.computesdk-write-${randomUUID()}\"`;\n try {\n await mustSucceed(run, sandbox, `mkdir -p -- ${directory} && (umask 077; set -C; : > ${temporary})`, `write ${path}`);\n for (let offset = 0; offset < bytes.length; offset += WRITE_CHUNK_BYTES) {\n const encoded = bytes.subarray(offset, offset + WRITE_CHUNK_BYTES).toString('base64');\n await mustSucceed(run, sandbox, `printf '%s' '${encoded}' | base64 -d >> ${temporary}`, `write ${path}`);\n }\n // Custom images may omit flock; only that case falls back to ordinary redirection.\n const copy = `cat ${temporary} > ${target}`;\n await mustSucceed(run, sandbox, `if command -v flock >/dev/null 2>&1; then (flock -x 9 && ${copy}) 9>> ${target}; else ${copy}; fi`, `write ${path}`);\n } finally {\n await run(sandbox, `rm -f -- ${temporary}`).catch(() => {});\n }\n },\n mkdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);\n },\n readdir: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<FileEntry[]> => {\n const result = await mustSucceed(\n run,\n sandbox,\n `find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\\\t%s\\\\t%T@\\\\t%f\\\\n'`,\n `list ${path}`,\n );\n return result.stdout\n .split('\\n')\n .filter(Boolean)\n .map((line) => {\n const [kind, size, modified, ...name] = line.split('\\t');\n return {\n name: name.join('\\t'),\n type: kind === 'd' ? ('directory' as const) : ('file' as const),\n size: Number(size),\n modified: new Date(Number(modified) * 1000),\n };\n });\n },\n exists: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<boolean> => {\n const result = await run(sandbox, `test -e ${shellPath(path)}`);\n return result.exitCode === 0;\n },\n remove: async (sandbox: Agent37Sandbox, path: string, run: FsRunCommand): Promise<void> => {\n await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);\n },\n },\n },\n },\n});\n\nexport default agent37;\n"],"mappings":";AAUA,SAAS,kBAAkB;AAC3B,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB,gBAAgB,yBAAyB;AA+ClE,IAAM,oBAAoB,KAAK;AAE/B,IAAM,mBAAmB,MAAM;AAE/B,SAAS,cAAc,QAAuB;AAC5C,QAAM,MAAM,OAAO,YAAY,cAAc,QAAQ,MAAM;AAC3D,QAAM,SAAS,OAAO,UAAU,KAAK,mBAAmB;AACxD,MAAI,CAAC,QAAQ;AACX,UAAM,IAAI;AAAA,MACR;AAAA,IAEF;AAAA,EACF;AACA,QAAM,WAAW,OAAO,WAAW,KAAK,oBAAoB,2BAA2B,QAAQ,QAAQ,EAAE;AACzG,QAAM,WAAW,OAAO,WAAW,KAAK,oBAAoB,+BAA+B,QAAQ,QAAQ,EAAE;AAC7G,SAAO,EAAE,QAAQ,SAAS,SAAS,WAAW,OAAO,cAAc,MAAM;AAC3E;AAEA,eAAe,QACb,MACA,QACA,MACA,MACA,WACA,YAAY,OACiC;AAC7C,QAAM,MAAM,MAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI,IAAI;AAAA,IAChD;AAAA,IACA,SAAS;AAAA,MACP,GAAI,YAAY,EAAE,iBAAiB,KAAK,OAAO,IAAI,EAAE,eAAe,UAAU,KAAK,MAAM,GAAG;AAA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