aicomputer 0.1.18 → 0.1.20
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 +28 -0
- package/dist/{chunk-3ZUTAUUD.js → chunk-36BZXAAX.js} +129 -258
- package/dist/chunk-3ZF7JRBW.js +270 -0
- package/dist/chunk-4TE5XTYE.js +242 -0
- package/dist/chunk-5Y2NWK5I.js +14 -0
- package/dist/chunk-D3SAFNSI.js +75 -0
- package/dist/chunk-GD42GHW3.js +183 -0
- package/dist/chunk-GGBVVRLL.js +32 -0
- package/dist/chunk-LOGK7YYJ.js +255 -0
- package/dist/{chunk-F2U4SFJ4.js → chunk-TPFE3CC6.js} +24 -174
- package/dist/index.js +678 -430
- package/dist/lib/autossh-runtime.d.ts +21 -0
- package/dist/lib/autossh-runtime.js +23 -0
- package/dist/lib/mount-config.d.ts +5 -1
- package/dist/lib/mount-mutagen.d.ts +2 -0
- package/dist/lib/mount-mutagen.js +3 -1
- package/dist/lib/mount-reconcile.js +5 -2
- package/dist/lib/mutagen-runtime.d.ts +20 -0
- package/dist/lib/mutagen-runtime.js +19 -0
- package/dist/lib/ssh-access.d.ts +74 -0
- package/dist/lib/ssh-access.js +25 -0
- package/dist/lib/ssh-config.d.ts +14 -0
- package/dist/lib/ssh-config.js +10 -0
- package/dist/lib/upgrade-version.d.ts +10 -0
- package/dist/lib/upgrade-version.js +8 -0
- package/package.json +3 -3
- package/scripts/postinstall.mjs +36 -23
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveSystemCommandPath
|
|
3
|
+
} from "./chunk-5Y2NWK5I.js";
|
|
4
|
+
|
|
5
|
+
// src/lib/mutagen-runtime.ts
|
|
6
|
+
import { spawnSync } from "child_process";
|
|
7
|
+
import {
|
|
8
|
+
chmodSync,
|
|
9
|
+
existsSync,
|
|
10
|
+
mkdirSync,
|
|
11
|
+
renameSync,
|
|
12
|
+
rmSync
|
|
13
|
+
} from "fs";
|
|
14
|
+
import { writeFile } from "fs/promises";
|
|
15
|
+
import { homedir } from "os";
|
|
16
|
+
import { dirname, join } from "path";
|
|
17
|
+
var BUNDLED_MUTAGEN_VERSION = "0.18.1";
|
|
18
|
+
var BUNDLED_MUTAGEN_DOWNLOAD_BASE = `https://github.com/mutagen-io/mutagen/releases/download/v${BUNDLED_MUTAGEN_VERSION}`;
|
|
19
|
+
var AGENTCOMPUTER_MUTAGEN_PATH_ENV = "AGENTCOMPUTER_MUTAGEN_PATH";
|
|
20
|
+
function getBundledMutagenAsset(platform = process.platform, arch = process.arch, homeDirectory = homedir()) {
|
|
21
|
+
if (!isSupportedPlatform(platform)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const assetArch = resolveMutagenAssetArch(arch);
|
|
25
|
+
if (!assetArch) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const assetName = `mutagen_${platform}_${assetArch}_v${BUNDLED_MUTAGEN_VERSION}.tar.gz`;
|
|
29
|
+
const installDir = join(
|
|
30
|
+
homeDirectory,
|
|
31
|
+
".agentcomputer",
|
|
32
|
+
"tools",
|
|
33
|
+
"mutagen",
|
|
34
|
+
`v${BUNDLED_MUTAGEN_VERSION}`,
|
|
35
|
+
`${platform}-${assetArch}`
|
|
36
|
+
);
|
|
37
|
+
return {
|
|
38
|
+
platform,
|
|
39
|
+
arch: assetArch,
|
|
40
|
+
version: BUNDLED_MUTAGEN_VERSION,
|
|
41
|
+
assetName,
|
|
42
|
+
downloadUrl: `${BUNDLED_MUTAGEN_DOWNLOAD_BASE}/${assetName}`,
|
|
43
|
+
installDir,
|
|
44
|
+
executablePath: join(installDir, "mutagen")
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function hasBundledMutagen() {
|
|
48
|
+
const asset = getBundledMutagenAsset();
|
|
49
|
+
return asset ? existsSync(asset.executablePath) : false;
|
|
50
|
+
}
|
|
51
|
+
async function ensureMutagenCommandPath() {
|
|
52
|
+
const asset = getBundledMutagenAsset();
|
|
53
|
+
if (asset && existsSync(asset.executablePath)) {
|
|
54
|
+
return asset.executablePath;
|
|
55
|
+
}
|
|
56
|
+
const systemPath = resolveSystemCommandPath("mutagen");
|
|
57
|
+
if (!asset) {
|
|
58
|
+
if (systemPath) {
|
|
59
|
+
return systemPath;
|
|
60
|
+
}
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return await installBundledMutagen(asset);
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (systemPath) {
|
|
69
|
+
return systemPath;
|
|
70
|
+
}
|
|
71
|
+
const reason = error instanceof Error ? error.message : "unknown Mutagen install failure";
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Failed to install Agent Computer's bundled Mutagen (${reason}). Check your network connection and rerun \`computer mount\`.`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function ensureBundledMutagenInstalled() {
|
|
78
|
+
const asset = getBundledMutagenAsset();
|
|
79
|
+
if (!asset) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return installBundledMutagen(asset);
|
|
85
|
+
}
|
|
86
|
+
function resolveMutagenCommandPath() {
|
|
87
|
+
const overridden = process.env[AGENTCOMPUTER_MUTAGEN_PATH_ENV]?.trim();
|
|
88
|
+
if (overridden) {
|
|
89
|
+
return overridden;
|
|
90
|
+
}
|
|
91
|
+
const asset = getBundledMutagenAsset();
|
|
92
|
+
if (asset && existsSync(asset.executablePath)) {
|
|
93
|
+
return asset.executablePath;
|
|
94
|
+
}
|
|
95
|
+
const systemPath = resolveSystemCommandPath("mutagen");
|
|
96
|
+
if (systemPath) {
|
|
97
|
+
return systemPath;
|
|
98
|
+
}
|
|
99
|
+
if (!asset) {
|
|
100
|
+
throw new Error(
|
|
101
|
+
`Agent Computer does not ship bundled Mutagen for ${process.platform} ${process.arch}. Install Mutagen manually and rerun \`computer mount\`.`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
throw new Error(
|
|
105
|
+
"Mutagen is not installed yet. Re-run `computer mount` and Agent Computer will install its bundled copy."
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
async function installBundledMutagen(asset) {
|
|
109
|
+
if (existsSync(asset.executablePath)) {
|
|
110
|
+
return asset.executablePath;
|
|
111
|
+
}
|
|
112
|
+
mkdirSync(dirname(asset.installDir), { recursive: true });
|
|
113
|
+
const stagingDir = `${asset.installDir}.staging-${process.pid}-${Date.now()}`;
|
|
114
|
+
const archivePath = join(stagingDir, asset.assetName);
|
|
115
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
116
|
+
if (existsSync(asset.installDir) && !existsSync(asset.executablePath)) {
|
|
117
|
+
rmSync(asset.installDir, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
mkdirSync(stagingDir, { recursive: true });
|
|
120
|
+
try {
|
|
121
|
+
const response = await fetch(asset.downloadUrl, {
|
|
122
|
+
headers: {
|
|
123
|
+
"User-Agent": "aicomputer-cli"
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok || !response.body) {
|
|
127
|
+
throw new Error(`download failed with status ${response.status}`);
|
|
128
|
+
}
|
|
129
|
+
await writeFile(archivePath, Buffer.from(await response.arrayBuffer()), {
|
|
130
|
+
mode: 384
|
|
131
|
+
});
|
|
132
|
+
const extract = spawnSync("tar", ["-xzf", archivePath, "-C", stagingDir], {
|
|
133
|
+
encoding: "utf8"
|
|
134
|
+
});
|
|
135
|
+
if (extract.status !== 0) {
|
|
136
|
+
throw new Error(
|
|
137
|
+
extract.stderr.trim() || extract.stdout.trim() || `failed to extract ${asset.assetName}`
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if (!existsSync(join(stagingDir, "mutagen"))) {
|
|
141
|
+
throw new Error("archive did not contain the Mutagen executable");
|
|
142
|
+
}
|
|
143
|
+
chmodSync(join(stagingDir, "mutagen"), 493);
|
|
144
|
+
rmSync(archivePath, { force: true });
|
|
145
|
+
try {
|
|
146
|
+
renameSync(stagingDir, asset.installDir);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (!existsSync(asset.executablePath)) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
152
|
+
}
|
|
153
|
+
return asset.executablePath;
|
|
154
|
+
} catch (error) {
|
|
155
|
+
rmSync(stagingDir, { recursive: true, force: true });
|
|
156
|
+
throw error;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function isSupportedPlatform(platform) {
|
|
160
|
+
return platform === "darwin" || platform === "linux";
|
|
161
|
+
}
|
|
162
|
+
function resolveMutagenAssetArch(arch) {
|
|
163
|
+
if (!isSupportedNodeArch(arch)) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
if (arch === "x64") {
|
|
167
|
+
return "amd64";
|
|
168
|
+
}
|
|
169
|
+
return arch;
|
|
170
|
+
}
|
|
171
|
+
function isSupportedNodeArch(arch) {
|
|
172
|
+
return arch === "arm64" || arch === "x64";
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export {
|
|
176
|
+
AGENTCOMPUTER_MUTAGEN_PATH_ENV,
|
|
177
|
+
getBundledMutagenAsset,
|
|
178
|
+
hasBundledMutagen,
|
|
179
|
+
ensureMutagenCommandPath,
|
|
180
|
+
ensureBundledMutagenInstalled,
|
|
181
|
+
resolveMutagenCommandPath,
|
|
182
|
+
resolveMutagenAssetArch
|
|
183
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/lib/upgrade-version.ts
|
|
2
|
+
function normalizeVersion(version) {
|
|
3
|
+
return version.split("-")[0].split(".").map((part) => Number.parseInt(part, 10)).map((part) => Number.isNaN(part) ? 0 : part);
|
|
4
|
+
}
|
|
5
|
+
function compareVersions(a, b) {
|
|
6
|
+
const left = normalizeVersion(a);
|
|
7
|
+
const right = normalizeVersion(b);
|
|
8
|
+
const size = Math.max(left.length, right.length);
|
|
9
|
+
for (let index = 0; index < size; index += 1) {
|
|
10
|
+
const diff = (left[index] ?? 0) - (right[index] ?? 0);
|
|
11
|
+
if (diff !== 0) {
|
|
12
|
+
return diff;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return 0;
|
|
16
|
+
}
|
|
17
|
+
function resolveLatestPublishedVersion(packument) {
|
|
18
|
+
const versions = Object.keys(packument.versions ?? {});
|
|
19
|
+
if (versions.length === 0) {
|
|
20
|
+
throw new Error("Registry response missing published versions");
|
|
21
|
+
}
|
|
22
|
+
const taggedLatest = packument["dist-tags"]?.latest;
|
|
23
|
+
if (taggedLatest && versions.includes(taggedLatest)) {
|
|
24
|
+
return taggedLatest;
|
|
25
|
+
}
|
|
26
|
+
return versions.sort((left, right) => compareVersions(right, left))[0];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
compareVersions,
|
|
31
|
+
resolveLatestPublishedVersion
|
|
32
|
+
};
|
|
@@ -0,0 +1,255 @@
|
|
|
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 response = await api("/v1/computers", { signal });
|
|
136
|
+
return response.computers;
|
|
137
|
+
}
|
|
138
|
+
async function getComputerByID(id) {
|
|
139
|
+
return api(`/v1/computers/${id}`);
|
|
140
|
+
}
|
|
141
|
+
async function createComputer(input) {
|
|
142
|
+
return api("/v1/computers", {
|
|
143
|
+
method: "POST",
|
|
144
|
+
body: JSON.stringify(input)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
async function deleteComputer(computerID) {
|
|
148
|
+
return api(`/v1/computers/${computerID}`, {
|
|
149
|
+
method: "DELETE"
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
async function powerOnComputer(computerID) {
|
|
153
|
+
return api(`/v1/computers/${computerID}/power-on`, {
|
|
154
|
+
method: "POST"
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
async function powerOffComputer(computerID) {
|
|
158
|
+
return api(`/v1/computers/${computerID}/power-off`, {
|
|
159
|
+
method: "POST"
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
async function getFilesystemSettings() {
|
|
163
|
+
return api("/v1/me/filesystem");
|
|
164
|
+
}
|
|
165
|
+
async function getConnectionInfo(computerID, signal) {
|
|
166
|
+
return api(`/v1/computers/${computerID}/connection`, {
|
|
167
|
+
signal
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
async function createBrowserAccess(computerID) {
|
|
171
|
+
return api(`/v1/computers/${computerID}/access/browser`, {
|
|
172
|
+
method: "POST"
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
async function listPublishedPorts(computerID) {
|
|
176
|
+
const response = await api(`/v1/computers/${computerID}/ports`);
|
|
177
|
+
return response.ports;
|
|
178
|
+
}
|
|
179
|
+
async function publishPort(computerID, input) {
|
|
180
|
+
return api(`/v1/computers/${computerID}/ports`, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
body: JSON.stringify(input)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async function deletePublishedPort(computerID, targetPort) {
|
|
186
|
+
return api(`/v1/computers/${computerID}/ports/${targetPort}`, {
|
|
187
|
+
method: "DELETE"
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
async function resolveComputer(identifier) {
|
|
191
|
+
try {
|
|
192
|
+
return await getComputerByID(identifier);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (!(error instanceof Error) || !("status" in error)) {
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
const status = Reflect.get(error, "status");
|
|
198
|
+
if (status !== 404) {
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
const computers = await listComputers();
|
|
203
|
+
const exact = computers.find(
|
|
204
|
+
(computer) => computer.handle === identifier || computer.id === identifier
|
|
205
|
+
);
|
|
206
|
+
if (exact) {
|
|
207
|
+
return exact;
|
|
208
|
+
}
|
|
209
|
+
throw new Error(`computer '${identifier}' not found`);
|
|
210
|
+
}
|
|
211
|
+
function webURL(computer) {
|
|
212
|
+
return `https://${computer.primary_web_host}${normalizePrimaryPath(computer.primary_path)}`;
|
|
213
|
+
}
|
|
214
|
+
function vncURL(computer) {
|
|
215
|
+
if (!computer.vnc_enabled) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const domain = computer.primary_web_host.replace(/^[^.]+\./, "");
|
|
219
|
+
return `https://6080--${computer.handle}.${domain}`;
|
|
220
|
+
}
|
|
221
|
+
function normalizePrimaryPath(primaryPath) {
|
|
222
|
+
const trimmed = primaryPath?.trim();
|
|
223
|
+
if (!trimmed) {
|
|
224
|
+
return "/";
|
|
225
|
+
}
|
|
226
|
+
return trimmed.startsWith("/") ? trimmed : `/${trimmed}`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export {
|
|
230
|
+
getAPIKey,
|
|
231
|
+
getStoredAPIKey,
|
|
232
|
+
hasEnvAPIKey,
|
|
233
|
+
setAPIKey,
|
|
234
|
+
clearAPIKey,
|
|
235
|
+
ApiError,
|
|
236
|
+
getBaseURL,
|
|
237
|
+
getWebURL,
|
|
238
|
+
api,
|
|
239
|
+
apiWithKey,
|
|
240
|
+
listComputers,
|
|
241
|
+
getComputerByID,
|
|
242
|
+
createComputer,
|
|
243
|
+
deleteComputer,
|
|
244
|
+
powerOnComputer,
|
|
245
|
+
powerOffComputer,
|
|
246
|
+
getFilesystemSettings,
|
|
247
|
+
getConnectionInfo,
|
|
248
|
+
createBrowserAccess,
|
|
249
|
+
listPublishedPorts,
|
|
250
|
+
publishPort,
|
|
251
|
+
deletePublishedPort,
|
|
252
|
+
resolveComputer,
|
|
253
|
+
webURL,
|
|
254
|
+
vncURL
|
|
255
|
+
};
|