@computesdk/agent37 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +90 -2
- package/dist/index.d.mts +51 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +226 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +201 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +59 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 computesdk
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @computesdk/agent37
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Agent37 provider for ComputeSDK - persistent Linux sandboxes for AI agents, with signed URLs for any port and an optional Performance type whose cores are held for it.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @computesdk/agent37
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
1. Create an API key at [agent37.com/dashboard/cloud/api-keys](https://www.agent37.com/dashboard/cloud/api-keys)
|
|
14
|
+
2. Set the environment variable:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
export AGENT37_API_KEY=sk_live_your_api_key
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { compute } from 'computesdk';
|
|
24
|
+
import { agent37 } from '@computesdk/agent37';
|
|
25
|
+
|
|
26
|
+
compute.setConfig({
|
|
27
|
+
provider: agent37({ apiKey: process.env.AGENT37_API_KEY }),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const sandbox = await compute.instances.create();
|
|
31
|
+
|
|
32
|
+
const result = await sandbox.runCommand('node -v && python3 --version');
|
|
33
|
+
console.log(result.stdout);
|
|
34
|
+
|
|
35
|
+
await sandbox.destroy();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Or call the provider factory directly:
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { agent37 } from '@computesdk/agent37';
|
|
42
|
+
|
|
43
|
+
const sdk = agent37({ apiKey: process.env.AGENT37_API_KEY });
|
|
44
|
+
const sandbox = await sdk.sandbox.create({ type: 'performance', cpu: 4, memory: 16384 });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
interface Agent37Config {
|
|
51
|
+
/** Agent37 API key - if not provided, will use AGENT37_API_KEY env var */
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
/** API base URL - defaults to AGENT37_BASE_URL, then https://api.agent37.com */
|
|
54
|
+
baseUrl?: string;
|
|
55
|
+
/** Exec base URL - defaults to AGENT37_EXEC_URL, then https://sandbox.agent37.app */
|
|
56
|
+
execUrl?: string;
|
|
57
|
+
/** Run commands as root (default true). Set false to run as the image's own user. */
|
|
58
|
+
runAsRoot?: boolean;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Create Options
|
|
63
|
+
|
|
64
|
+
| Option | Maps to | Notes |
|
|
65
|
+
|---|---|---|
|
|
66
|
+
| `templateId` | `template` | Template name. Default `agent37-base` (Debian with Node, Python, git and build tools). |
|
|
67
|
+
| `type` | `type` | `default`, `performance` (a whole machine whose cores are held for it) or `vm`. |
|
|
68
|
+
| `cpu` (or `vcpus`, `cpus`) | `resources.cpu` | vCPUs. Sizes are 2 vCPU / 4 GB, 4 / 8, 4 / 16 and 4 / 32. |
|
|
69
|
+
| `memory` (MB, or `memoryMiB`, `memoryMb`) | `resources.memory` | Rounded up to whole GB. |
|
|
70
|
+
| `diskMb` (or `diskMiB`) | `resources.disk` | Rounded up to whole GB. |
|
|
71
|
+
| `region` | `region` | `us` (default), `eu` or `ap-south`. |
|
|
72
|
+
| `envs` | `env` | Environment variables for the sandbox. |
|
|
73
|
+
| `name`, `metadata` | `name`, `metadata` | Labels returned on the instance. |
|
|
74
|
+
|
|
75
|
+
## Features
|
|
76
|
+
|
|
77
|
+
- **Command execution** with `cwd`, `env` and background commands
|
|
78
|
+
- **Filesystem** read, write, list, mkdir, exists and remove
|
|
79
|
+
- **Port URLs**: `getUrl({ port })` returns a signed URL that reaches the port without an API key for one hour
|
|
80
|
+
- **Persistence**: a sandbox keeps its files and installed packages until you destroy it
|
|
81
|
+
|
|
82
|
+
## Limitations
|
|
83
|
+
|
|
84
|
+
- Output is returned when the command finishes; there is no streaming.
|
|
85
|
+
- `runCommand`'s `timeout` stops waiting for the result. The command itself keeps running in the sandbox.
|
|
86
|
+
- Sandboxes have no lifetime limit, so always call `destroy()` when you are done.
|
|
87
|
+
|
|
88
|
+
## Links
|
|
89
|
+
|
|
90
|
+
- [Agent37 API docs](https://www.agent37.com/docs)
|
|
91
|
+
- [Pricing](https://www.agent37.com/pricing)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _computesdk_provider from '@computesdk/provider';
|
|
2
|
+
import * as computesdk from 'computesdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Agent37 Provider - Factory-based Implementation
|
|
6
|
+
*
|
|
7
|
+
* Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small
|
|
8
|
+
* JSON surface, so this package talks to it with `fetch` and has no SDK dependency.
|
|
9
|
+
*
|
|
10
|
+
* Commands run as root by default, since Agent37 images ship no sudo. Pass
|
|
11
|
+
* `runAsRoot: false` to run as the image's own user instead.
|
|
12
|
+
*/
|
|
13
|
+
interface Agent37Config {
|
|
14
|
+
/** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */
|
|
19
|
+
execUrl?: string;
|
|
20
|
+
/** Run commands as root (default true). Set false to run as the image's default user. */
|
|
21
|
+
runAsRoot?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** An instance as the Agent37 API returns it. */
|
|
24
|
+
interface Agent37InstanceData {
|
|
25
|
+
id: string;
|
|
26
|
+
status: string;
|
|
27
|
+
template: string;
|
|
28
|
+
type: string;
|
|
29
|
+
region: string;
|
|
30
|
+
resources: {
|
|
31
|
+
cpu: number;
|
|
32
|
+
memory: number;
|
|
33
|
+
disk: number;
|
|
34
|
+
};
|
|
35
|
+
url: string;
|
|
36
|
+
created: number;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface Agent37Sandbox {
|
|
40
|
+
id: string;
|
|
41
|
+
data: Agent37InstanceData;
|
|
42
|
+
apiKey: string;
|
|
43
|
+
baseUrl: string;
|
|
44
|
+
execUrl: string;
|
|
45
|
+
runAsRoot: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare const agent37: (config: Agent37Config) => _computesdk_provider.Provider<Agent37Sandbox, any, any, computesdk.Volume> & {
|
|
48
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { type Agent37Config, type Agent37InstanceData, type Agent37Sandbox, agent37, agent37 as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as _computesdk_provider from '@computesdk/provider';
|
|
2
|
+
import * as computesdk from 'computesdk';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Agent37 Provider - Factory-based Implementation
|
|
6
|
+
*
|
|
7
|
+
* Linux sandboxes on the Agent37 API (https://www.agent37.com/docs). The API is a small
|
|
8
|
+
* JSON surface, so this package talks to it with `fetch` and has no SDK dependency.
|
|
9
|
+
*
|
|
10
|
+
* Commands run as root by default, since Agent37 images ship no sudo. Pass
|
|
11
|
+
* `runAsRoot: false` to run as the image's own user instead.
|
|
12
|
+
*/
|
|
13
|
+
interface Agent37Config {
|
|
14
|
+
/** Agent37 API key - if not provided, will fallback to AGENT37_API_KEY environment variable */
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
/** API base URL - if not provided, will fallback to AGENT37_BASE_URL, then https://api.agent37.com */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Exec base URL - if not provided, will fallback to AGENT37_EXEC_URL, then https://sandbox.agent37.app */
|
|
19
|
+
execUrl?: string;
|
|
20
|
+
/** Run commands as root (default true). Set false to run as the image's default user. */
|
|
21
|
+
runAsRoot?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/** An instance as the Agent37 API returns it. */
|
|
24
|
+
interface Agent37InstanceData {
|
|
25
|
+
id: string;
|
|
26
|
+
status: string;
|
|
27
|
+
template: string;
|
|
28
|
+
type: string;
|
|
29
|
+
region: string;
|
|
30
|
+
resources: {
|
|
31
|
+
cpu: number;
|
|
32
|
+
memory: number;
|
|
33
|
+
disk: number;
|
|
34
|
+
};
|
|
35
|
+
url: string;
|
|
36
|
+
created: number;
|
|
37
|
+
[key: string]: unknown;
|
|
38
|
+
}
|
|
39
|
+
interface Agent37Sandbox {
|
|
40
|
+
id: string;
|
|
41
|
+
data: Agent37InstanceData;
|
|
42
|
+
apiKey: string;
|
|
43
|
+
baseUrl: string;
|
|
44
|
+
execUrl: string;
|
|
45
|
+
runAsRoot: boolean;
|
|
46
|
+
}
|
|
47
|
+
declare const agent37: (config: Agent37Config) => _computesdk_provider.Provider<Agent37Sandbox, any, any, computesdk.Volume> & {
|
|
48
|
+
readonly sizes: computesdk.InstanceSizeManager;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export { type Agent37Config, type Agent37InstanceData, type Agent37Sandbox, agent37, agent37 as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
agent37: () => agent37,
|
|
24
|
+
default: () => index_default
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(index_exports);
|
|
27
|
+
var import_provider = require("@computesdk/provider");
|
|
28
|
+
function resolveConfig(config) {
|
|
29
|
+
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
30
|
+
const apiKey = config.apiKey || env?.AGENT37_API_KEY || "";
|
|
31
|
+
if (!apiKey) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. Create one at https://www.agent37.com/dashboard/cloud/api-keys`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || "https://api.agent37.com").replace(/\/+$/, "");
|
|
37
|
+
const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || "https://sandbox.agent37.app").replace(/\/+$/, "");
|
|
38
|
+
return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };
|
|
39
|
+
}
|
|
40
|
+
async function request(auth, method, path, body, timeoutMs, keyHeader = false) {
|
|
41
|
+
const res = await fetch(`${auth.baseUrl}${path}`, {
|
|
42
|
+
method,
|
|
43
|
+
headers: {
|
|
44
|
+
...keyHeader ? { "X-Agent37-Key": auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` },
|
|
45
|
+
"Content-Type": "application/json"
|
|
46
|
+
},
|
|
47
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
48
|
+
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : void 0
|
|
49
|
+
});
|
|
50
|
+
if (res.status === 404) return { status: 404, data: null };
|
|
51
|
+
const text = await res.text();
|
|
52
|
+
if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);
|
|
53
|
+
return { status: res.status, data: text ? JSON.parse(text) : null };
|
|
54
|
+
}
|
|
55
|
+
function toSandbox(auth, data) {
|
|
56
|
+
return { id: data.id, data, ...auth };
|
|
57
|
+
}
|
|
58
|
+
function megabytesToGb(mb) {
|
|
59
|
+
return typeof mb === "number" && mb > 0 ? Math.ceil(mb / 1024) : void 0;
|
|
60
|
+
}
|
|
61
|
+
function createBody(options = {}) {
|
|
62
|
+
const body = {};
|
|
63
|
+
if (options.templateId) body.template = options.templateId;
|
|
64
|
+
if (typeof options.type === "string") body.type = options.type;
|
|
65
|
+
if (typeof options.region === "string") body.region = options.region;
|
|
66
|
+
if (options.name) body.name = options.name;
|
|
67
|
+
if (options.metadata) body.metadata = options.metadata;
|
|
68
|
+
if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;
|
|
69
|
+
const cpu = options.cpu ?? options.vcpus ?? options.cpus;
|
|
70
|
+
const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);
|
|
71
|
+
const disk = megabytesToGb(options.diskMb ?? options.diskMiB);
|
|
72
|
+
const resources = {
|
|
73
|
+
...typeof cpu === "number" ? { cpu } : {},
|
|
74
|
+
...memory ? { memory } : {},
|
|
75
|
+
...disk ? { disk } : {}
|
|
76
|
+
};
|
|
77
|
+
if (Object.keys(resources).length > 0) body.resources = resources;
|
|
78
|
+
return body;
|
|
79
|
+
}
|
|
80
|
+
function wrapCommand(command, options) {
|
|
81
|
+
let cmd = command;
|
|
82
|
+
if (options?.env && Object.keys(options.env).length > 0) {
|
|
83
|
+
const exports2 = Object.entries(options.env).map(([key, value]) => {
|
|
84
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);
|
|
85
|
+
return `export ${key}="${(0, import_provider.escapeShellArg)(value)}"`;
|
|
86
|
+
});
|
|
87
|
+
cmd = `${exports2.join(" && ")} && ${cmd}`;
|
|
88
|
+
}
|
|
89
|
+
if (options?.cwd) cmd = `cd "${(0, import_provider.escapeShellArg)(options.cwd)}" && ${cmd}`;
|
|
90
|
+
if (options?.background) cmd = `nohup sh -c "${(0, import_provider.escapeShellArg)(cmd)}" >/dev/null 2>&1 &`;
|
|
91
|
+
return cmd;
|
|
92
|
+
}
|
|
93
|
+
function shellPath(path) {
|
|
94
|
+
return `"${(0, import_provider.escapeShellArg)(path.startsWith("-") ? `./${path}` : path)}"`;
|
|
95
|
+
}
|
|
96
|
+
async function exec(sandbox, command, timeoutMs) {
|
|
97
|
+
const { data } = await request(
|
|
98
|
+
{ apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },
|
|
99
|
+
"POST",
|
|
100
|
+
`/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,
|
|
101
|
+
{ command, ...sandbox.runAsRoot ? { user: "root" } : {} },
|
|
102
|
+
timeoutMs,
|
|
103
|
+
true
|
|
104
|
+
);
|
|
105
|
+
if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);
|
|
106
|
+
return data;
|
|
107
|
+
}
|
|
108
|
+
function infoStatus(status) {
|
|
109
|
+
if (status === "failed") return "error";
|
|
110
|
+
if (status === "stopped" || status === "stopping" || status === "deleting" || status === "deleted") return "stopped";
|
|
111
|
+
return "running";
|
|
112
|
+
}
|
|
113
|
+
async function mustSucceed(run, sandbox, command, what) {
|
|
114
|
+
const result = await run(sandbox, command);
|
|
115
|
+
if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
var agent37 = (0, import_provider.defineProvider)({
|
|
119
|
+
name: "agent37",
|
|
120
|
+
methods: {
|
|
121
|
+
instances: {
|
|
122
|
+
create: async (config, options) => {
|
|
123
|
+
const auth = resolveConfig(config);
|
|
124
|
+
const { data } = await request(auth, "POST", "/v1/instances", createBody(options));
|
|
125
|
+
if (!data) throw new Error("Agent37 API returned no instance on create");
|
|
126
|
+
return { instance: toSandbox(auth, data), instanceId: data.id };
|
|
127
|
+
},
|
|
128
|
+
getById: async (config, instanceId) => {
|
|
129
|
+
const auth = resolveConfig(config);
|
|
130
|
+
const { data } = await request(auth, "GET", `/v1/instances/${encodeURIComponent(instanceId)}`);
|
|
131
|
+
return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;
|
|
132
|
+
},
|
|
133
|
+
list: async (config) => {
|
|
134
|
+
const auth = resolveConfig(config);
|
|
135
|
+
const { data } = await request(auth, "GET", "/v1/instances");
|
|
136
|
+
return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));
|
|
137
|
+
},
|
|
138
|
+
destroy: async (config, instanceId) => {
|
|
139
|
+
const auth = resolveConfig(config);
|
|
140
|
+
await request(auth, "DELETE", `/v1/instances/${encodeURIComponent(instanceId)}`);
|
|
141
|
+
},
|
|
142
|
+
runCommand: async (sandbox, command, options) => {
|
|
143
|
+
const start = Date.now();
|
|
144
|
+
const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);
|
|
145
|
+
return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };
|
|
146
|
+
},
|
|
147
|
+
getInfo: async (sandbox) => {
|
|
148
|
+
const { data } = await request(sandbox, "GET", `/v1/instances/${encodeURIComponent(sandbox.id)}`);
|
|
149
|
+
const current = data ?? { ...sandbox.data, status: "deleted" };
|
|
150
|
+
return {
|
|
151
|
+
id: sandbox.id,
|
|
152
|
+
provider: "agent37",
|
|
153
|
+
status: infoStatus(current.status),
|
|
154
|
+
createdAt: new Date(current.created * 1e3),
|
|
155
|
+
timeout: 0,
|
|
156
|
+
metadata: {
|
|
157
|
+
status: current.status,
|
|
158
|
+
template: current.template,
|
|
159
|
+
type: current.type,
|
|
160
|
+
region: current.region,
|
|
161
|
+
resources: current.resources,
|
|
162
|
+
url: current.url
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
// A signed URL that reaches the port without an API key, valid for one hour.
|
|
167
|
+
getUrl: async (sandbox, options) => {
|
|
168
|
+
const { data } = await request(
|
|
169
|
+
sandbox,
|
|
170
|
+
"POST",
|
|
171
|
+
`/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,
|
|
172
|
+
{ port: options.port }
|
|
173
|
+
);
|
|
174
|
+
if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);
|
|
175
|
+
return options.protocol === "ws" || options.protocol === "wss" ? data.url.replace(/^https/, "wss") : data.url;
|
|
176
|
+
},
|
|
177
|
+
getInstance: (sandbox) => sandbox,
|
|
178
|
+
filesystem: {
|
|
179
|
+
readFile: async (sandbox, path) => {
|
|
180
|
+
const result = await exec(sandbox, `base64 -w0 ${shellPath(path)}`);
|
|
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}: the file is larger than one command's output limit`);
|
|
183
|
+
return Buffer.from(result.stdout, "base64").toString("utf8");
|
|
184
|
+
},
|
|
185
|
+
writeFile: async (sandbox, path, content, run) => {
|
|
186
|
+
const encoded = Buffer.from(content, "utf8").toString("base64");
|
|
187
|
+
const target = shellPath(path);
|
|
188
|
+
await mustSucceed(run, sandbox, `mkdir -p "$(dirname ${target})" && printf '%s' '${encoded}' | base64 -d > ${target}`, `write ${path}`);
|
|
189
|
+
},
|
|
190
|
+
mkdir: async (sandbox, path, run) => {
|
|
191
|
+
await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);
|
|
192
|
+
},
|
|
193
|
+
readdir: async (sandbox, path, run) => {
|
|
194
|
+
const result = await mustSucceed(
|
|
195
|
+
run,
|
|
196
|
+
sandbox,
|
|
197
|
+
`find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\t%s\\t%T@\\t%f\\n'`,
|
|
198
|
+
`list ${path}`
|
|
199
|
+
);
|
|
200
|
+
return result.stdout.split("\n").filter(Boolean).map((line) => {
|
|
201
|
+
const [kind, size, modified, ...name] = line.split(" ");
|
|
202
|
+
return {
|
|
203
|
+
name: name.join(" "),
|
|
204
|
+
type: kind === "d" ? "directory" : "file",
|
|
205
|
+
size: Number(size),
|
|
206
|
+
modified: new Date(Number(modified) * 1e3)
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
},
|
|
210
|
+
exists: async (sandbox, path, run) => {
|
|
211
|
+
const result = await run(sandbox, `test -e ${shellPath(path)}`);
|
|
212
|
+
return result.exitCode === 0;
|
|
213
|
+
},
|
|
214
|
+
remove: async (sandbox, path, run) => {
|
|
215
|
+
await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
var index_default = agent37;
|
|
222
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
223
|
+
0 && (module.exports = {
|
|
224
|
+
agent37
|
|
225
|
+
});
|
|
226
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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 { defineProvider, escapeShellArg } 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\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\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\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 encoded = Buffer.from(content, 'utf8').toString('base64');\n const target = shellPath(path);\n await mustSucceed(run, sandbox, `mkdir -p \"$(dirname ${target})\" && printf '%s' '${encoded}' | base64 -d > ${target}`, `write ${path}`);\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,sBAA+C;AA8C/C,SAAS,cAA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U,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
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { defineProvider, escapeShellArg } from "@computesdk/provider";
|
|
3
|
+
function resolveConfig(config) {
|
|
4
|
+
const env = typeof process !== "undefined" ? process.env : void 0;
|
|
5
|
+
const apiKey = config.apiKey || env?.AGENT37_API_KEY || "";
|
|
6
|
+
if (!apiKey) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
`Missing Agent37 API key. Provide 'apiKey' in config or set AGENT37_API_KEY environment variable. Create one at https://www.agent37.com/dashboard/cloud/api-keys`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const baseUrl = (config.baseUrl || env?.AGENT37_BASE_URL || "https://api.agent37.com").replace(/\/+$/, "");
|
|
12
|
+
const execUrl = (config.execUrl || env?.AGENT37_EXEC_URL || "https://sandbox.agent37.app").replace(/\/+$/, "");
|
|
13
|
+
return { apiKey, baseUrl, execUrl, runAsRoot: config.runAsRoot !== false };
|
|
14
|
+
}
|
|
15
|
+
async function request(auth, method, path, body, timeoutMs, keyHeader = false) {
|
|
16
|
+
const res = await fetch(`${auth.baseUrl}${path}`, {
|
|
17
|
+
method,
|
|
18
|
+
headers: {
|
|
19
|
+
...keyHeader ? { "X-Agent37-Key": auth.apiKey } : { Authorization: `Bearer ${auth.apiKey}` },
|
|
20
|
+
"Content-Type": "application/json"
|
|
21
|
+
},
|
|
22
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
23
|
+
signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : void 0
|
|
24
|
+
});
|
|
25
|
+
if (res.status === 404) return { status: 404, data: null };
|
|
26
|
+
const text = await res.text();
|
|
27
|
+
if (!res.ok) throw new Error(`Agent37 API error (${res.status}) on ${method} ${path}: ${text}`);
|
|
28
|
+
return { status: res.status, data: text ? JSON.parse(text) : null };
|
|
29
|
+
}
|
|
30
|
+
function toSandbox(auth, data) {
|
|
31
|
+
return { id: data.id, data, ...auth };
|
|
32
|
+
}
|
|
33
|
+
function megabytesToGb(mb) {
|
|
34
|
+
return typeof mb === "number" && mb > 0 ? Math.ceil(mb / 1024) : void 0;
|
|
35
|
+
}
|
|
36
|
+
function createBody(options = {}) {
|
|
37
|
+
const body = {};
|
|
38
|
+
if (options.templateId) body.template = options.templateId;
|
|
39
|
+
if (typeof options.type === "string") body.type = options.type;
|
|
40
|
+
if (typeof options.region === "string") body.region = options.region;
|
|
41
|
+
if (options.name) body.name = options.name;
|
|
42
|
+
if (options.metadata) body.metadata = options.metadata;
|
|
43
|
+
if (options.envs && Object.keys(options.envs).length > 0) body.env = options.envs;
|
|
44
|
+
const cpu = options.cpu ?? options.vcpus ?? options.cpus;
|
|
45
|
+
const memory = megabytesToGb(options.memory ?? options.memoryMiB ?? options.memoryMb ?? options.memMiB);
|
|
46
|
+
const disk = megabytesToGb(options.diskMb ?? options.diskMiB);
|
|
47
|
+
const resources = {
|
|
48
|
+
...typeof cpu === "number" ? { cpu } : {},
|
|
49
|
+
...memory ? { memory } : {},
|
|
50
|
+
...disk ? { disk } : {}
|
|
51
|
+
};
|
|
52
|
+
if (Object.keys(resources).length > 0) body.resources = resources;
|
|
53
|
+
return body;
|
|
54
|
+
}
|
|
55
|
+
function wrapCommand(command, options) {
|
|
56
|
+
let cmd = command;
|
|
57
|
+
if (options?.env && Object.keys(options.env).length > 0) {
|
|
58
|
+
const exports = Object.entries(options.env).map(([key, value]) => {
|
|
59
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) throw new Error(`Invalid environment variable name: ${key}`);
|
|
60
|
+
return `export ${key}="${escapeShellArg(value)}"`;
|
|
61
|
+
});
|
|
62
|
+
cmd = `${exports.join(" && ")} && ${cmd}`;
|
|
63
|
+
}
|
|
64
|
+
if (options?.cwd) cmd = `cd "${escapeShellArg(options.cwd)}" && ${cmd}`;
|
|
65
|
+
if (options?.background) cmd = `nohup sh -c "${escapeShellArg(cmd)}" >/dev/null 2>&1 &`;
|
|
66
|
+
return cmd;
|
|
67
|
+
}
|
|
68
|
+
function shellPath(path) {
|
|
69
|
+
return `"${escapeShellArg(path.startsWith("-") ? `./${path}` : path)}"`;
|
|
70
|
+
}
|
|
71
|
+
async function exec(sandbox, command, timeoutMs) {
|
|
72
|
+
const { data } = await request(
|
|
73
|
+
{ apiKey: sandbox.apiKey, baseUrl: sandbox.execUrl },
|
|
74
|
+
"POST",
|
|
75
|
+
`/v1/instances/${encodeURIComponent(sandbox.id)}/exec`,
|
|
76
|
+
{ command, ...sandbox.runAsRoot ? { user: "root" } : {} },
|
|
77
|
+
timeoutMs,
|
|
78
|
+
true
|
|
79
|
+
);
|
|
80
|
+
if (!data) throw new Error(`Agent37 instance ${sandbox.id} not found`);
|
|
81
|
+
return data;
|
|
82
|
+
}
|
|
83
|
+
function infoStatus(status) {
|
|
84
|
+
if (status === "failed") return "error";
|
|
85
|
+
if (status === "stopped" || status === "stopping" || status === "deleting" || status === "deleted") return "stopped";
|
|
86
|
+
return "running";
|
|
87
|
+
}
|
|
88
|
+
async function mustSucceed(run, sandbox, command, what) {
|
|
89
|
+
const result = await run(sandbox, command);
|
|
90
|
+
if (result.exitCode !== 0) throw new Error(`Failed to ${what}: ${result.stderr.trim() || `exit code ${result.exitCode}`}`);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
var agent37 = defineProvider({
|
|
94
|
+
name: "agent37",
|
|
95
|
+
methods: {
|
|
96
|
+
instances: {
|
|
97
|
+
create: async (config, options) => {
|
|
98
|
+
const auth = resolveConfig(config);
|
|
99
|
+
const { data } = await request(auth, "POST", "/v1/instances", createBody(options));
|
|
100
|
+
if (!data) throw new Error("Agent37 API returned no instance on create");
|
|
101
|
+
return { instance: toSandbox(auth, data), instanceId: data.id };
|
|
102
|
+
},
|
|
103
|
+
getById: async (config, instanceId) => {
|
|
104
|
+
const auth = resolveConfig(config);
|
|
105
|
+
const { data } = await request(auth, "GET", `/v1/instances/${encodeURIComponent(instanceId)}`);
|
|
106
|
+
return data ? { instance: toSandbox(auth, data), instanceId: data.id } : null;
|
|
107
|
+
},
|
|
108
|
+
list: async (config) => {
|
|
109
|
+
const auth = resolveConfig(config);
|
|
110
|
+
const { data } = await request(auth, "GET", "/v1/instances");
|
|
111
|
+
return (data?.data ?? []).map((row) => ({ instance: toSandbox(auth, row), instanceId: row.id }));
|
|
112
|
+
},
|
|
113
|
+
destroy: async (config, instanceId) => {
|
|
114
|
+
const auth = resolveConfig(config);
|
|
115
|
+
await request(auth, "DELETE", `/v1/instances/${encodeURIComponent(instanceId)}`);
|
|
116
|
+
},
|
|
117
|
+
runCommand: async (sandbox, command, options) => {
|
|
118
|
+
const start = Date.now();
|
|
119
|
+
const data = await exec(sandbox, wrapCommand(command, options), options?.timeout);
|
|
120
|
+
return { stdout: data.stdout, stderr: data.stderr, exitCode: data.exit_code, durationMs: Date.now() - start };
|
|
121
|
+
},
|
|
122
|
+
getInfo: async (sandbox) => {
|
|
123
|
+
const { data } = await request(sandbox, "GET", `/v1/instances/${encodeURIComponent(sandbox.id)}`);
|
|
124
|
+
const current = data ?? { ...sandbox.data, status: "deleted" };
|
|
125
|
+
return {
|
|
126
|
+
id: sandbox.id,
|
|
127
|
+
provider: "agent37",
|
|
128
|
+
status: infoStatus(current.status),
|
|
129
|
+
createdAt: new Date(current.created * 1e3),
|
|
130
|
+
timeout: 0,
|
|
131
|
+
metadata: {
|
|
132
|
+
status: current.status,
|
|
133
|
+
template: current.template,
|
|
134
|
+
type: current.type,
|
|
135
|
+
region: current.region,
|
|
136
|
+
resources: current.resources,
|
|
137
|
+
url: current.url
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
// A signed URL that reaches the port without an API key, valid for one hour.
|
|
142
|
+
getUrl: async (sandbox, options) => {
|
|
143
|
+
const { data } = await request(
|
|
144
|
+
sandbox,
|
|
145
|
+
"POST",
|
|
146
|
+
`/v1/instances/${encodeURIComponent(sandbox.id)}/signed-url`,
|
|
147
|
+
{ port: options.port }
|
|
148
|
+
);
|
|
149
|
+
if (!data?.url) throw new Error(`Agent37 instance ${sandbox.id} not found`);
|
|
150
|
+
return options.protocol === "ws" || options.protocol === "wss" ? data.url.replace(/^https/, "wss") : data.url;
|
|
151
|
+
},
|
|
152
|
+
getInstance: (sandbox) => sandbox,
|
|
153
|
+
filesystem: {
|
|
154
|
+
readFile: async (sandbox, path) => {
|
|
155
|
+
const result = await exec(sandbox, `base64 -w0 ${shellPath(path)}`);
|
|
156
|
+
if (result.exit_code !== 0) throw new Error(`Failed to read ${path}: ${result.stderr.trim() || `exit code ${result.exit_code}`}`);
|
|
157
|
+
if (result.truncated) throw new Error(`Failed to read ${path}: the file is larger than one command's output limit`);
|
|
158
|
+
return Buffer.from(result.stdout, "base64").toString("utf8");
|
|
159
|
+
},
|
|
160
|
+
writeFile: async (sandbox, path, content, run) => {
|
|
161
|
+
const encoded = Buffer.from(content, "utf8").toString("base64");
|
|
162
|
+
const target = shellPath(path);
|
|
163
|
+
await mustSucceed(run, sandbox, `mkdir -p "$(dirname ${target})" && printf '%s' '${encoded}' | base64 -d > ${target}`, `write ${path}`);
|
|
164
|
+
},
|
|
165
|
+
mkdir: async (sandbox, path, run) => {
|
|
166
|
+
await mustSucceed(run, sandbox, `mkdir -p ${shellPath(path)}`, `create ${path}`);
|
|
167
|
+
},
|
|
168
|
+
readdir: async (sandbox, path, run) => {
|
|
169
|
+
const result = await mustSucceed(
|
|
170
|
+
run,
|
|
171
|
+
sandbox,
|
|
172
|
+
`find ${shellPath(path)} -mindepth 1 -maxdepth 1 -printf '%y\\t%s\\t%T@\\t%f\\n'`,
|
|
173
|
+
`list ${path}`
|
|
174
|
+
);
|
|
175
|
+
return result.stdout.split("\n").filter(Boolean).map((line) => {
|
|
176
|
+
const [kind, size, modified, ...name] = line.split(" ");
|
|
177
|
+
return {
|
|
178
|
+
name: name.join(" "),
|
|
179
|
+
type: kind === "d" ? "directory" : "file",
|
|
180
|
+
size: Number(size),
|
|
181
|
+
modified: new Date(Number(modified) * 1e3)
|
|
182
|
+
};
|
|
183
|
+
});
|
|
184
|
+
},
|
|
185
|
+
exists: async (sandbox, path, run) => {
|
|
186
|
+
const result = await run(sandbox, `test -e ${shellPath(path)}`);
|
|
187
|
+
return result.exitCode === 0;
|
|
188
|
+
},
|
|
189
|
+
remove: async (sandbox, path, run) => {
|
|
190
|
+
await mustSucceed(run, sandbox, `rm -rf ${shellPath(path)}`, `remove ${path}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
var index_default = agent37;
|
|
197
|
+
export {
|
|
198
|
+
agent37,
|
|
199
|
+
index_default as default
|
|
200
|
+
};
|
|
201
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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 { defineProvider, escapeShellArg } 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\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\nexport const agent37 = defineProvider<Agent37Sandbox, Agent37Config>({\n name: 'agent37',\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 encoded = Buffer.from(content, 'utf8').toString('base64');\n const target = shellPath(path);\n await mustSucceed(run, sandbox, `mkdir -p \"$(dirname ${target})\" && printf '%s' '${encoded}' | base64 -d > ${target}`, `write ${path}`);\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,gBAAgB,sBAAsB;AA8C/C,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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
+
"description": "Agent37 provider for ComputeSDK - Linux sandboxes and dedicated-core VMs for AI agents, with public URLs for any port",
|
|
5
|
+
"author": "Agent37",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"module": "./dist/index.mjs",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.mjs",
|
|
14
|
+
"require": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"computesdk",
|
|
22
|
+
"provider",
|
|
23
|
+
"sandbox",
|
|
24
|
+
"code-execution",
|
|
25
|
+
"cloud",
|
|
26
|
+
"compute",
|
|
27
|
+
"agent37"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@computesdk/provider": "2.1.21",
|
|
31
|
+
"computesdk": "4.1.15"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^20.0.0",
|
|
35
|
+
"@vitest/coverage-v8": "^1.0.0",
|
|
36
|
+
"eslint": "^8.37.0",
|
|
37
|
+
"rimraf": "^5.0.0",
|
|
38
|
+
"tsup": "^8.0.0",
|
|
39
|
+
"typescript": "^5.0.0",
|
|
40
|
+
"vitest": "^1.0.0",
|
|
41
|
+
"@computesdk/test-utils": "2.0.5"
|
|
42
|
+
},
|
|
43
|
+
"repository": {
|
|
44
|
+
"type": "git",
|
|
45
|
+
"url": "https://github.com/computesdk/computesdk.git",
|
|
46
|
+
"directory": "packages/agent37"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://www.agent37.com",
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/computesdk/computesdk/issues"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "tsup",
|
|
54
|
+
"clean": "rimraf dist",
|
|
55
|
+
"dev": "tsup --watch",
|
|
56
|
+
"test": "vitest run",
|
|
57
|
+
"test:watch": "vitest watch",
|
|
58
|
+
"test:coverage": "vitest run --coverage",
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"lint": "eslint"
|
|
61
|
+
}
|
|
6
62
|
}
|