aicomputer 0.1.22 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -136
- package/dist/index.d.ts +381 -1
- package/dist/index.js +1657 -4977
- package/package.json +24 -31
- package/dist/chunk-3ZF7JRBW.js +0 -270
- package/dist/chunk-5Y2NWK5I.js +0 -14
- package/dist/chunk-E7QD4MHI.js +0 -279
- package/dist/chunk-G7UQLVUZ.js +0 -75
- package/dist/chunk-GD42GHW3.js +0 -183
- package/dist/chunk-GGBVVRLL.js +0 -32
- package/dist/chunk-HDZTFK4U.js +0 -544
- package/dist/chunk-JMRAYXUO.js +0 -62
- package/dist/chunk-KXLTHWW3.js +0 -184
- package/dist/chunk-LGJN26BQ.js +0 -242
- package/dist/chunk-TPFE3CC6.js +0 -367
- package/dist/lib/autossh-runtime.d.ts +0 -21
- package/dist/lib/autossh-runtime.js +0 -23
- package/dist/lib/mount-config.d.ts +0 -79
- package/dist/lib/mount-config.js +0 -40
- package/dist/lib/mount-host.d.ts +0 -13
- package/dist/lib/mount-host.js +0 -10
- package/dist/lib/mount-mutagen.d.ts +0 -39
- package/dist/lib/mount-mutagen.js +0 -25
- package/dist/lib/mount-reconcile.d.ts +0 -30
- package/dist/lib/mount-reconcile.js +0 -17
- package/dist/lib/mutagen-runtime.d.ts +0 -20
- package/dist/lib/mutagen-runtime.js +0 -19
- package/dist/lib/ssh-access.d.ts +0 -74
- package/dist/lib/ssh-access.js +0 -25
- package/dist/lib/ssh-config.d.ts +0 -14
- package/dist/lib/ssh-config.js +0 -10
- package/dist/lib/upgrade-version.d.ts +0 -10
- package/dist/lib/upgrade-version.js +0 -8
- package/scripts/postinstall.mjs +0 -48
package/package.json
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aicomputer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "High-level TypeScript SDK for AgentComputer computers and execution workflows.",
|
|
6
|
+
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/getcompanion-ai/
|
|
9
|
+
"url": "git+https://github.com/getcompanion-ai/microagentcomputer.git",
|
|
10
|
+
"directory": "packages/agentcomputer"
|
|
9
11
|
},
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
12
|
+
"homepage": "https://agentcomputer.ai",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
14
18
|
},
|
|
15
|
-
"
|
|
19
|
+
"files": [
|
|
20
|
+
"dist",
|
|
21
|
+
"README.md"
|
|
22
|
+
],
|
|
16
23
|
"publishConfig": {
|
|
17
24
|
"access": "public",
|
|
18
25
|
"registry": "https://registry.npmjs.org/"
|
|
19
26
|
},
|
|
20
27
|
"scripts": {
|
|
21
|
-
"build": "
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"sync:nix": "../../scripts/cli/sync-nix-package.sh",
|
|
26
|
-
"test": "npm run build && node --test test/**/*.test.mjs",
|
|
27
|
-
"typecheck": "tsc --noEmit"
|
|
28
|
-
},
|
|
29
|
-
"files": [
|
|
30
|
-
"dist",
|
|
31
|
-
"scripts",
|
|
32
|
-
"package.json",
|
|
33
|
-
"README.md"
|
|
34
|
-
],
|
|
35
|
-
"dependencies": {
|
|
36
|
-
"@inquirer/prompts": "^8.3.2",
|
|
37
|
-
"chalk": "^5.3.0",
|
|
38
|
-
"commander": "^12.1.0",
|
|
39
|
-
"open": "^10.1.0",
|
|
40
|
-
"ora": "^8.0.1"
|
|
28
|
+
"build": "pnpm --filter @microagentcomputer/public-api-client build && tsup",
|
|
29
|
+
"typecheck": "pnpm --filter @microagentcomputer/public-api-client build && tsc --noEmit",
|
|
30
|
+
"typecheck:examples": "pnpm --filter @microagentcomputer/public-api-client build && tsc -p tsconfig.examples.json --noEmit",
|
|
31
|
+
"docs:generate": "pnpm --filter @microagentcomputer/public-api-client build && node ./scripts/generate-docs.mjs"
|
|
41
32
|
},
|
|
33
|
+
"dependencies": {},
|
|
42
34
|
"devDependencies": {
|
|
43
|
-
"@
|
|
35
|
+
"@microagentcomputer/public-api-client": "workspace:*",
|
|
44
36
|
"tsup": "^8.0.0",
|
|
45
|
-
"
|
|
37
|
+
"typedoc": "^0.28.14",
|
|
38
|
+
"typescript": "5.9.3"
|
|
46
39
|
}
|
|
47
40
|
}
|
package/dist/chunk-3ZF7JRBW.js
DELETED
|
@@ -1,270 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveSystemCommandPath
|
|
3
|
-
} from "./chunk-5Y2NWK5I.js";
|
|
4
|
-
|
|
5
|
-
// src/lib/autossh-runtime.ts
|
|
6
|
-
import { spawnSync } from "child_process";
|
|
7
|
-
import { createHash } from "crypto";
|
|
8
|
-
import {
|
|
9
|
-
chmodSync,
|
|
10
|
-
existsSync,
|
|
11
|
-
mkdirSync,
|
|
12
|
-
readdirSync,
|
|
13
|
-
renameSync,
|
|
14
|
-
rmSync
|
|
15
|
-
} from "fs";
|
|
16
|
-
import { writeFile } from "fs/promises";
|
|
17
|
-
import { homedir } from "os";
|
|
18
|
-
import { dirname, join } from "path";
|
|
19
|
-
var BUNDLED_AUTOSSH_VERSION = "1.4f";
|
|
20
|
-
var BUNDLED_AUTOSSH_DOWNLOAD_BASE = `https://github.com/Autossh/autossh/archive/refs/tags/v${BUNDLED_AUTOSSH_VERSION}.tar.gz`;
|
|
21
|
-
var BUNDLED_AUTOSSH_ARCHIVE_SHA256 = "fce67ee6e8e032eb41eca984f7e16a6ea74f85c513d94f78e56656815c473604";
|
|
22
|
-
var AGENTCOMPUTER_AUTOSSH_PATH_ENV = "AGENTCOMPUTER_AUTOSSH_PATH";
|
|
23
|
-
var AUTOSSH_SSH_PATH_ENV = "AUTOSSH_PATH";
|
|
24
|
-
function getBundledAutosshAsset(platform = process.platform, homeDirectory = homedir()) {
|
|
25
|
-
if (!isSupportedPlatform(platform)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const installDir = join(
|
|
29
|
-
homeDirectory,
|
|
30
|
-
".agentcomputer",
|
|
31
|
-
"tools",
|
|
32
|
-
"autossh",
|
|
33
|
-
`v${BUNDLED_AUTOSSH_VERSION}`,
|
|
34
|
-
platform
|
|
35
|
-
);
|
|
36
|
-
return {
|
|
37
|
-
platform,
|
|
38
|
-
version: BUNDLED_AUTOSSH_VERSION,
|
|
39
|
-
archiveName: `autossh-v${BUNDLED_AUTOSSH_VERSION}.tar.gz`,
|
|
40
|
-
downloadUrl: BUNDLED_AUTOSSH_DOWNLOAD_BASE,
|
|
41
|
-
archiveSha256: BUNDLED_AUTOSSH_ARCHIVE_SHA256,
|
|
42
|
-
installDir,
|
|
43
|
-
executablePath: join(installDir, "bin", "autossh")
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
function hasBundledAutossh() {
|
|
47
|
-
const asset = getBundledAutosshAsset();
|
|
48
|
-
return asset ? existsSync(asset.executablePath) : false;
|
|
49
|
-
}
|
|
50
|
-
async function ensureAutosshCommandPath(env = process.env) {
|
|
51
|
-
const resolution = lookupAutosshCommandPath(env);
|
|
52
|
-
if (resolution.commandPath) {
|
|
53
|
-
return resolution.commandPath;
|
|
54
|
-
}
|
|
55
|
-
if (!resolution.asset) {
|
|
56
|
-
throw new Error(
|
|
57
|
-
`Agent Computer does not ship bundled autossh for ${process.platform}. Install autossh manually and rerun \`computer ssh\`.`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
return await installBundledAutossh(resolution.asset);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
const reason = error instanceof Error ? error.message : "unknown autossh install failure";
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Failed to install Agent Computer's bundled autossh (${reason}). Check your network connection and local build tools, then rerun \`computer ssh\`.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async function ensureBundledAutosshInstalled() {
|
|
70
|
-
const asset = getBundledAutosshAsset();
|
|
71
|
-
if (!asset) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Agent Computer does not ship bundled autossh for ${process.platform}.`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
return installBundledAutossh(asset);
|
|
77
|
-
}
|
|
78
|
-
function resolveAutosshCommandPath(env = process.env) {
|
|
79
|
-
const resolution = lookupAutosshCommandPath(env);
|
|
80
|
-
if (resolution.commandPath) {
|
|
81
|
-
return resolution.commandPath;
|
|
82
|
-
}
|
|
83
|
-
if (!resolution.asset) {
|
|
84
|
-
throw new Error(
|
|
85
|
-
`Agent Computer does not ship bundled autossh for ${process.platform}. Install autossh manually and rerun \`computer ssh\`.`
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
throw new Error(
|
|
89
|
-
"autossh is not installed yet. Re-run `computer ssh` and Agent Computer will install its bundled copy."
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
function resolveAutosshSSHCommandPath(env = process.env) {
|
|
93
|
-
const overridden = env[AUTOSSH_SSH_PATH_ENV]?.trim();
|
|
94
|
-
if (overridden) {
|
|
95
|
-
return overridden;
|
|
96
|
-
}
|
|
97
|
-
const systemPath = resolveSystemCommandPath("ssh", env);
|
|
98
|
-
if (systemPath) {
|
|
99
|
-
return systemPath;
|
|
100
|
-
}
|
|
101
|
-
throw new Error(getMissingOpenSSHClientMessage());
|
|
102
|
-
}
|
|
103
|
-
function getMissingOpenSSHClientMessage(platform = process.platform) {
|
|
104
|
-
switch (platform) {
|
|
105
|
-
case "darwin":
|
|
106
|
-
return "OpenSSH client tools are required for `computer ssh`. Install the macOS command line tools or make sure `ssh` is available on PATH, then rerun the command.";
|
|
107
|
-
case "linux":
|
|
108
|
-
return "OpenSSH client tools are required for `computer ssh`. Install `ssh` and `scp` with your package manager, then rerun the command.";
|
|
109
|
-
default:
|
|
110
|
-
return "OpenSSH client tools are required for `computer ssh`. Install `ssh` and `scp`, then rerun the command.";
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function installBundledAutossh(asset) {
|
|
114
|
-
if (existsSync(asset.executablePath)) {
|
|
115
|
-
return asset.executablePath;
|
|
116
|
-
}
|
|
117
|
-
const sshPath = resolveSystemCommandPath("ssh");
|
|
118
|
-
if (!sshPath) {
|
|
119
|
-
throw new Error("OpenSSH client (`ssh`) is required before autossh can be provisioned");
|
|
120
|
-
}
|
|
121
|
-
if (!resolveSystemCommandPath("make")) {
|
|
122
|
-
throw new Error("`make` is required to build bundled autossh");
|
|
123
|
-
}
|
|
124
|
-
const ccPath = resolveSystemCommandPath("cc") ?? resolveSystemCommandPath("clang");
|
|
125
|
-
if (!ccPath) {
|
|
126
|
-
throw new Error("a C compiler is required to build bundled autossh");
|
|
127
|
-
}
|
|
128
|
-
if (!resolveSystemCommandPath("tar")) {
|
|
129
|
-
throw new Error("`tar` is required to extract bundled autossh");
|
|
130
|
-
}
|
|
131
|
-
mkdirSync(dirname(asset.installDir), { recursive: true });
|
|
132
|
-
const stagingDir = `${asset.installDir}.staging-${process.pid}-${Date.now()}`;
|
|
133
|
-
const archivePath = join(stagingDir, asset.archiveName);
|
|
134
|
-
const prefixDir = join(stagingDir, "prefix");
|
|
135
|
-
rmSync(stagingDir, { recursive: true, force: true });
|
|
136
|
-
if (existsSync(asset.installDir) && !existsSync(asset.executablePath)) {
|
|
137
|
-
rmSync(asset.installDir, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
mkdirSync(stagingDir, { recursive: true });
|
|
140
|
-
try {
|
|
141
|
-
const response = await fetch(asset.downloadUrl, {
|
|
142
|
-
headers: {
|
|
143
|
-
"User-Agent": "aicomputer-cli"
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
if (!response.ok || !response.body) {
|
|
147
|
-
throw new Error(`download failed with status ${response.status}`);
|
|
148
|
-
}
|
|
149
|
-
const archiveBuffer = Buffer.from(await response.arrayBuffer());
|
|
150
|
-
verifyAutosshArchiveChecksum(asset, archiveBuffer);
|
|
151
|
-
await writeFile(archivePath, archiveBuffer, {
|
|
152
|
-
mode: 384
|
|
153
|
-
});
|
|
154
|
-
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", stagingDir], {
|
|
155
|
-
encoding: "utf8"
|
|
156
|
-
});
|
|
157
|
-
if (extract.status !== 0) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
extract.stderr.trim() || extract.stdout.trim() || `failed to extract ${asset.archiveName}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
const sourceDir = findExtractedSourceDir(stagingDir);
|
|
163
|
-
if (!sourceDir) {
|
|
164
|
-
throw new Error("downloaded autossh archive did not contain source files");
|
|
165
|
-
}
|
|
166
|
-
const configure = spawnSync(
|
|
167
|
-
"./configure",
|
|
168
|
-
[`--prefix=${prefixDir}`, `--with-ssh=${sshPath}`],
|
|
169
|
-
{
|
|
170
|
-
cwd: sourceDir,
|
|
171
|
-
encoding: "utf8",
|
|
172
|
-
env: {
|
|
173
|
-
...process.env,
|
|
174
|
-
CC: ccPath
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
if (configure.status !== 0) {
|
|
179
|
-
throw new Error(
|
|
180
|
-
configure.stderr.trim() || configure.stdout.trim() || "autossh configure failed"
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
const make = spawnSync("make", [], {
|
|
184
|
-
cwd: sourceDir,
|
|
185
|
-
encoding: "utf8",
|
|
186
|
-
env: {
|
|
187
|
-
...process.env,
|
|
188
|
-
CC: ccPath
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
if (make.status !== 0) {
|
|
192
|
-
throw new Error(make.stderr.trim() || make.stdout.trim() || "autossh build failed");
|
|
193
|
-
}
|
|
194
|
-
const install = spawnSync("make", ["install"], {
|
|
195
|
-
cwd: sourceDir,
|
|
196
|
-
encoding: "utf8",
|
|
197
|
-
env: {
|
|
198
|
-
...process.env,
|
|
199
|
-
CC: ccPath
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
if (install.status !== 0) {
|
|
203
|
-
throw new Error(
|
|
204
|
-
install.stderr.trim() || install.stdout.trim() || "autossh install failed"
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (!existsSync(join(prefixDir, "bin", "autossh"))) {
|
|
208
|
-
throw new Error("autossh install did not produce the executable");
|
|
209
|
-
}
|
|
210
|
-
chmodSync(join(prefixDir, "bin", "autossh"), 493);
|
|
211
|
-
rmSync(archivePath, { force: true });
|
|
212
|
-
try {
|
|
213
|
-
renameSync(prefixDir, asset.installDir);
|
|
214
|
-
} catch (error) {
|
|
215
|
-
if (!existsSync(asset.executablePath)) {
|
|
216
|
-
throw error;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
rmSync(stagingDir, { recursive: true, force: true });
|
|
220
|
-
return asset.executablePath;
|
|
221
|
-
} catch (error) {
|
|
222
|
-
rmSync(stagingDir, { recursive: true, force: true });
|
|
223
|
-
throw error;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
function lookupAutosshCommandPath(env) {
|
|
227
|
-
const overridden = env[AGENTCOMPUTER_AUTOSSH_PATH_ENV]?.trim();
|
|
228
|
-
const asset = getBundledAutosshAsset();
|
|
229
|
-
if (overridden) {
|
|
230
|
-
return { asset, commandPath: overridden };
|
|
231
|
-
}
|
|
232
|
-
if (asset && existsSync(asset.executablePath)) {
|
|
233
|
-
return { asset, commandPath: asset.executablePath };
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
asset,
|
|
237
|
-
commandPath: resolveSystemCommandPath("autossh", env)
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
function verifyAutosshArchiveChecksum(asset, archiveBuffer) {
|
|
241
|
-
const digest = createHash("sha256").update(archiveBuffer).digest("hex");
|
|
242
|
-
if (digest !== asset.archiveSha256) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
`autossh archive checksum mismatch (expected ${asset.archiveSha256}, got ${digest})`
|
|
245
|
-
);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function findExtractedSourceDir(stagingDir) {
|
|
249
|
-
for (const entry of readdirSync(stagingDir, { withFileTypes: true })) {
|
|
250
|
-
if (entry.isDirectory() && entry.name !== "prefix") {
|
|
251
|
-
return join(stagingDir, entry.name);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
function isSupportedPlatform(platform) {
|
|
257
|
-
return platform === "darwin" || platform === "linux";
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export {
|
|
261
|
-
AGENTCOMPUTER_AUTOSSH_PATH_ENV,
|
|
262
|
-
AUTOSSH_SSH_PATH_ENV,
|
|
263
|
-
getBundledAutosshAsset,
|
|
264
|
-
hasBundledAutossh,
|
|
265
|
-
ensureAutosshCommandPath,
|
|
266
|
-
ensureBundledAutosshInstalled,
|
|
267
|
-
resolveAutosshCommandPath,
|
|
268
|
-
resolveAutosshSSHCommandPath,
|
|
269
|
-
getMissingOpenSSHClientMessage
|
|
270
|
-
};
|
package/dist/chunk-5Y2NWK5I.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// src/lib/system-tools.ts
|
|
2
|
-
import { spawnSync } from "child_process";
|
|
3
|
-
function resolveSystemCommandPath(command, env = process.env) {
|
|
4
|
-
const result = spawnSync("which", [command], { encoding: "utf8", env });
|
|
5
|
-
if (result.status !== 0) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
const resolved = result.stdout.trim();
|
|
9
|
-
return resolved.length > 0 ? resolved : null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
resolveSystemCommandPath
|
|
14
|
-
};
|
package/dist/chunk-E7QD4MHI.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
// src/lib/config.ts
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "fs";
|
|
3
|
-
import { homedir } from "os";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
var CONFIG_DIR = join(homedir(), ".computer");
|
|
6
|
-
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
7
|
-
function ensureConfigDir() {
|
|
8
|
-
if (!existsSync(CONFIG_DIR)) {
|
|
9
|
-
mkdirSync(CONFIG_DIR, { recursive: true, mode: 448 });
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function readConfig() {
|
|
13
|
-
ensureConfigDir();
|
|
14
|
-
if (!existsSync(CONFIG_FILE)) {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
try {
|
|
18
|
-
return JSON.parse(readFileSync(CONFIG_FILE, "utf8"));
|
|
19
|
-
} catch {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function writeConfig(config) {
|
|
24
|
-
ensureConfigDir();
|
|
25
|
-
const tempFile = `${CONFIG_FILE}.${process.pid}.tmp`;
|
|
26
|
-
writeFileSync(tempFile, JSON.stringify(config, null, 2), { mode: 384 });
|
|
27
|
-
renameSync(tempFile, CONFIG_FILE);
|
|
28
|
-
}
|
|
29
|
-
function getAPIKey() {
|
|
30
|
-
const envValue = process.env.COMPUTER_API_KEY ?? process.env.AGENTCOMPUTER_API_KEY;
|
|
31
|
-
if (envValue) {
|
|
32
|
-
return envValue.trim();
|
|
33
|
-
}
|
|
34
|
-
return getStoredAPIKey();
|
|
35
|
-
}
|
|
36
|
-
function getStoredAPIKey() {
|
|
37
|
-
return readConfig().auth?.apiKey?.trim() || null;
|
|
38
|
-
}
|
|
39
|
-
function hasEnvAPIKey() {
|
|
40
|
-
return Boolean(process.env.COMPUTER_API_KEY ?? process.env.AGENTCOMPUTER_API_KEY);
|
|
41
|
-
}
|
|
42
|
-
function setAPIKey(apiKey) {
|
|
43
|
-
const config = readConfig();
|
|
44
|
-
config.auth = { apiKey: apiKey.trim() };
|
|
45
|
-
writeConfig(config);
|
|
46
|
-
}
|
|
47
|
-
function clearAPIKey() {
|
|
48
|
-
const config = readConfig();
|
|
49
|
-
delete config.auth;
|
|
50
|
-
writeConfig(config);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/lib/api.ts
|
|
54
|
-
var BASE_URL = process.env.COMPUTER_API_URL ?? process.env.AGENTCOMPUTER_API_URL ?? "https://api.computer.agentcomputer.ai";
|
|
55
|
-
var WEB_URL = process.env.COMPUTER_WEB_URL ?? process.env.AGENTCOMPUTER_WEB_URL ?? resolveDefaultWebURL(BASE_URL);
|
|
56
|
-
var ApiError = class extends Error {
|
|
57
|
-
constructor(status, message) {
|
|
58
|
-
super(message);
|
|
59
|
-
this.status = status;
|
|
60
|
-
this.name = "ApiError";
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
function getBaseURL() {
|
|
64
|
-
return BASE_URL;
|
|
65
|
-
}
|
|
66
|
-
function getWebURL() {
|
|
67
|
-
return WEB_URL;
|
|
68
|
-
}
|
|
69
|
-
async function api(path, options = {}) {
|
|
70
|
-
const apiKey = getAPIKey();
|
|
71
|
-
if (!apiKey) {
|
|
72
|
-
throw new ApiError(401, "not logged in; run 'computer login' first");
|
|
73
|
-
}
|
|
74
|
-
return requestWithKey(apiKey, path, options);
|
|
75
|
-
}
|
|
76
|
-
function resolveDefaultWebURL(apiURL) {
|
|
77
|
-
try {
|
|
78
|
-
const parsed = new URL(apiURL);
|
|
79
|
-
if (parsed.hostname === "api.computer.agentcomputer.ai") {
|
|
80
|
-
return "https://agentcomputer.ai";
|
|
81
|
-
}
|
|
82
|
-
if (parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1") {
|
|
83
|
-
return `${parsed.protocol}//${parsed.hostname}:3000`;
|
|
84
|
-
}
|
|
85
|
-
} catch {
|
|
86
|
-
return "https://agentcomputer.ai";
|
|
87
|
-
}
|
|
88
|
-
return "https://agentcomputer.ai";
|
|
89
|
-
}
|
|
90
|
-
async function apiWithKey(apiKey, path, options = {}) {
|
|
91
|
-
return requestWithKey(apiKey, path, options);
|
|
92
|
-
}
|
|
93
|
-
async function requestWithKey(apiKey, path, options) {
|
|
94
|
-
const headers = {
|
|
95
|
-
Accept: "application/json",
|
|
96
|
-
...options.headers ?? {}
|
|
97
|
-
};
|
|
98
|
-
if (options.body !== void 0) {
|
|
99
|
-
headers["Content-Type"] = "application/json";
|
|
100
|
-
}
|
|
101
|
-
if (apiKey) {
|
|
102
|
-
headers.Authorization = `Bearer ${apiKey}`;
|
|
103
|
-
}
|
|
104
|
-
const response = await fetch(`${BASE_URL}${path}`, {
|
|
105
|
-
...options,
|
|
106
|
-
headers
|
|
107
|
-
});
|
|
108
|
-
if (!response.ok) {
|
|
109
|
-
throw new ApiError(response.status, await readErrorMessage(response));
|
|
110
|
-
}
|
|
111
|
-
if (response.status === 204) {
|
|
112
|
-
return void 0;
|
|
113
|
-
}
|
|
114
|
-
return await response.json();
|
|
115
|
-
}
|
|
116
|
-
async function readErrorMessage(response) {
|
|
117
|
-
const contentType = response.headers.get("content-type") ?? "";
|
|
118
|
-
if (contentType.includes("application/json")) {
|
|
119
|
-
try {
|
|
120
|
-
const payload = await response.json();
|
|
121
|
-
if (payload.error) {
|
|
122
|
-
return payload.error;
|
|
123
|
-
}
|
|
124
|
-
return JSON.stringify(payload);
|
|
125
|
-
} catch {
|
|
126
|
-
return response.statusText || "request failed";
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const body = await response.text();
|
|
130
|
-
return body || response.statusText || "request failed";
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/lib/computers.ts
|
|
134
|
-
async function listComputers(signal) {
|
|
135
|
-
const [ownedResponse, sharedResponse] = await Promise.all([
|
|
136
|
-
api("/v1/computers", { signal }),
|
|
137
|
-
api("/v1/computers/shared", { signal }).catch((error) => {
|
|
138
|
-
if (!(error instanceof Error) || !("status" in error)) {
|
|
139
|
-
throw error;
|
|
140
|
-
}
|
|
141
|
-
const status = Reflect.get(error, "status");
|
|
142
|
-
if (status === 404 || status === 405) {
|
|
143
|
-
return { computers: [] };
|
|
144
|
-
}
|
|
145
|
-
throw error;
|
|
146
|
-
})
|
|
147
|
-
]);
|
|
148
|
-
return mergeComputerLists(ownedResponse.computers, sharedResponse.computers);
|
|
149
|
-
}
|
|
150
|
-
async function getComputerByID(id) {
|
|
151
|
-
return api(`/v1/computers/${id}`);
|
|
152
|
-
}
|
|
153
|
-
async function createComputer(input) {
|
|
154
|
-
return api("/v1/computers", {
|
|
155
|
-
method: "POST",
|
|
156
|
-
body: JSON.stringify(input)
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
async function deleteComputer(computerID) {
|
|
160
|
-
return api(`/v1/computers/${computerID}`, {
|
|
161
|
-
method: "DELETE"
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
async function powerOnComputer(computerID) {
|
|
165
|
-
return api(`/v1/computers/${computerID}/power-on`, {
|
|
166
|
-
method: "POST"
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
async function powerOffComputer(computerID) {
|
|
170
|
-
return api(`/v1/computers/${computerID}/power-off`, {
|
|
171
|
-
method: "POST"
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
async function getFilesystemSettings() {
|
|
175
|
-
return api("/v1/me/filesystem");
|
|
176
|
-
}
|
|
177
|
-
async function getConnectionInfo(computerID, signal) {
|
|
178
|
-
return api(`/v1/computers/${computerID}/connection`, {
|
|
179
|
-
signal
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
async function createBrowserAccess(computerID) {
|
|
183
|
-
return api(`/v1/computers/${computerID}/access/browser`, {
|
|
184
|
-
method: "POST"
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
async function listPublishedPorts(computerID) {
|
|
188
|
-
const response = await api(`/v1/computers/${computerID}/ports`);
|
|
189
|
-
return response.ports;
|
|
190
|
-
}
|
|
191
|
-
async function publishPort(computerID, input) {
|
|
192
|
-
return api(`/v1/computers/${computerID}/ports`, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
body: JSON.stringify(input)
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
async function deletePublishedPort(computerID, targetPort) {
|
|
198
|
-
return api(`/v1/computers/${computerID}/ports/${targetPort}`, {
|
|
199
|
-
method: "DELETE"
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
async function resolveComputer(identifier) {
|
|
203
|
-
try {
|
|
204
|
-
return await getComputerByID(identifier);
|
|
205
|
-
} catch (error) {
|
|
206
|
-
if (!(error instanceof Error) || !("status" in error)) {
|
|
207
|
-
throw error;
|
|
208
|
-
}
|
|
209
|
-
const status = Reflect.get(error, "status");
|
|
210
|
-
if (status !== 404) {
|
|
211
|
-
throw error;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
const computers = await listComputers();
|
|
215
|
-
const exact = computers.find(
|
|
216
|
-
(computer) => computer.handle === identifier || computer.id === identifier
|
|
217
|
-
);
|
|
218
|
-
if (exact) {
|
|
219
|
-
return exact;
|
|
220
|
-
}
|
|
221
|
-
throw new Error(`computer '${identifier}' not found`);
|
|
222
|
-
}
|
|
223
|
-
function mergeComputerLists(owned, shared) {
|
|
224
|
-
const merged = [];
|
|
225
|
-
const seen = /* @__PURE__ */ new Set();
|
|
226
|
-
for (const computer of [...owned, ...shared]) {
|
|
227
|
-
if (seen.has(computer.id)) {
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
seen.add(computer.id);
|
|
231
|
-
merged.push(computer);
|
|
232
|
-
}
|
|
233
|
-
return merged;
|
|
234
|
-
}
|
|
235
|
-
function webURL(computer) {
|
|
236
|
-
return `https://${computer.primary_web_host}${normalizePrimaryPath(computer.primary_path)}`;
|
|
237
|
-
}
|
|
238
|
-
function vncURL(computer) {
|
|
239
|
-
if (!computer.vnc_enabled) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
const domain = computer.primary_web_host.replace(/^[^.]+\./, "");
|
|
243
|
-
return `https://6080--${computer.handle}.${domain}`;
|
|
244
|
-
}
|
|
245
|
-
function normalizePrimaryPath(primaryPath) {
|
|
246
|
-
const trimmed = primaryPath?.trim();
|
|
247
|
-
if (!trimmed) {
|
|
248
|
-
return "/";
|
|
249
|
-
}
|
|
250
|
-
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export {
|
|
254
|
-
getAPIKey,
|
|
255
|
-
getStoredAPIKey,
|
|
256
|
-
hasEnvAPIKey,
|
|
257
|
-
setAPIKey,
|
|
258
|
-
clearAPIKey,
|
|
259
|
-
ApiError,
|
|
260
|
-
getBaseURL,
|
|
261
|
-
getWebURL,
|
|
262
|
-
api,
|
|
263
|
-
apiWithKey,
|
|
264
|
-
listComputers,
|
|
265
|
-
getComputerByID,
|
|
266
|
-
createComputer,
|
|
267
|
-
deleteComputer,
|
|
268
|
-
powerOnComputer,
|
|
269
|
-
powerOffComputer,
|
|
270
|
-
getFilesystemSettings,
|
|
271
|
-
getConnectionInfo,
|
|
272
|
-
createBrowserAccess,
|
|
273
|
-
listPublishedPorts,
|
|
274
|
-
publishPort,
|
|
275
|
-
deletePublishedPort,
|
|
276
|
-
resolveComputer,
|
|
277
|
-
webURL,
|
|
278
|
-
vncURL
|
|
279
|
-
};
|