@andorra-labs/code 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/acp-agent.d.ts +6 -0
- package/dist/src/acp-agent.js +15 -4
- package/dist/src/agent-execution.js +11 -8
- package/dist/src/agent-mcp-catalog.js +1 -0
- package/dist/src/agent-mcp.d.ts +3 -0
- package/dist/src/agent-mcp.js +33 -1
- package/dist/src/andorra/entry.d.ts +10 -0
- package/dist/src/andorra/entry.js +18 -4
- package/dist/src/andorra/hosted.d.ts +2 -1
- package/dist/src/andorra/hosted.js +2 -1
- package/dist/src/andorra/notices.d.ts +5 -0
- package/dist/src/andorra/notices.js +7 -0
- package/dist/src/andorra/state.d.ts +3 -2
- package/dist/src/andorra/state.js +4 -4
- package/dist/src/andorra/terminal.js +7 -2
- package/dist/src/anthropic-credentials.js +2 -0
- package/dist/src/app-server/error.d.ts +5 -0
- package/dist/src/app-server/error.js +7 -0
- package/dist/src/app-server/protocol.d.ts +19 -44
- package/dist/src/app-server/protocol.js +5 -1
- package/dist/src/app-server/workspace.d.ts +89 -0
- package/dist/src/app-server/workspace.js +457 -11
- package/dist/src/app-server.d.ts +358 -32
- package/dist/src/app-server.js +2429 -509
- package/dist/src/bridge/cloud.d.ts +27 -0
- package/dist/src/bridge/cloud.js +187 -0
- package/dist/src/bridge/command.d.ts +30 -0
- package/dist/src/bridge/command.js +347 -0
- package/dist/src/bridge/control.d.ts +68 -0
- package/dist/src/bridge/control.js +233 -0
- package/dist/src/bridge/engines.d.ts +90 -0
- package/dist/src/bridge/engines.js +601 -0
- package/dist/src/bridge/host-ops.d.ts +9 -0
- package/dist/src/bridge/host-ops.js +129 -0
- package/dist/src/bridge/host.d.ts +47 -0
- package/dist/src/bridge/host.js +540 -0
- package/dist/src/bridge/link.d.ts +38 -0
- package/dist/src/bridge/link.js +508 -0
- package/dist/src/bridge/login-link.d.ts +29 -0
- package/dist/src/bridge/login-link.js +54 -0
- package/dist/src/bridge/protocol.d.ts +136 -0
- package/dist/src/bridge/protocol.js +11 -0
- package/dist/src/bridge/store.d.ts +12 -0
- package/dist/src/bridge/store.js +61 -0
- package/dist/src/bridge/wording.d.ts +6 -0
- package/dist/src/bridge/wording.js +10 -0
- package/dist/src/browser-server.js +7 -1
- package/dist/src/browser-ui/tokens.css +1 -1
- package/dist/src/change-authors.d.ts +41 -0
- package/dist/src/change-authors.js +146 -0
- package/dist/src/cli.js +182 -32
- package/dist/src/coding-tools.js +15 -15
- package/dist/src/command-screens.d.ts +6 -0
- package/dist/src/command-screens.js +14 -11
- package/dist/src/commands.d.ts +14 -2
- package/dist/src/compaction-phrases.js +1 -1
- package/dist/src/completion.js +82 -5
- package/dist/src/config.d.ts +71 -3
- package/dist/src/config.js +202 -77
- package/dist/src/deadline.js +13 -1
- package/dist/src/decision/checks.js +1 -1
- package/dist/src/decision/requestPhrases.js +0 -1
- package/dist/src/default-graph.js +1 -1
- package/dist/src/file-diff.d.ts +4 -0
- package/dist/src/file-diff.js +2 -1
- package/dist/src/github-app/agent-writes.d.ts +102 -0
- package/dist/src/github-app/agent-writes.js +320 -0
- package/dist/src/github-app/client.d.ts +349 -0
- package/dist/src/github-app/client.js +810 -0
- package/dist/src/github-app/event-source.d.ts +208 -0
- package/dist/src/github-app/event-source.js +684 -0
- package/dist/src/github-app/metrics.d.ts +32 -0
- package/dist/src/github-app/metrics.js +49 -0
- package/dist/src/github-app/review-loop.d.ts +274 -0
- package/dist/src/github-app/review-loop.js +1177 -0
- package/dist/src/github-app/review-node.d.ts +81 -0
- package/dist/src/github-app/review-node.js +205 -0
- package/dist/src/github-app/review-post.d.ts +73 -0
- package/dist/src/github-app/review-post.js +139 -0
- package/dist/src/github-app/review-text.d.ts +107 -0
- package/dist/src/github-app/review-text.js +1133 -0
- package/dist/src/github-app/review-threads.d.ts +47 -0
- package/dist/src/github-app/review-threads.js +107 -0
- package/dist/src/github-app/reviewer.d.ts +121 -0
- package/dist/src/github-app/reviewer.js +598 -0
- package/dist/src/github-app/store.d.ts +59 -0
- package/dist/src/github-app/store.js +148 -0
- package/dist/src/github-app/triggers.d.ts +141 -0
- package/dist/src/github-app/triggers.js +441 -0
- package/dist/src/github-names.d.ts +8 -0
- package/dist/src/github-names.js +8 -0
- package/dist/src/glob-search.d.ts +61 -0
- package/dist/src/glob-search.js +180 -0
- package/dist/src/graph-health.js +6 -1
- package/dist/src/graph-manager-chat.js +1 -1
- package/dist/src/graph-preview.d.ts +46 -0
- package/dist/src/graph-preview.js +55 -0
- package/dist/src/graph-provider-portability.js +2 -1
- package/dist/src/graph-runner.js +64 -3
- package/dist/src/graph-server.js +3 -3
- package/dist/src/graph-sync.js +3 -3
- package/dist/src/graph-ui/app.js +91 -7
- package/dist/src/graph-ui/icons.js +2 -1
- package/dist/src/graph-ui/studio.js +15 -1
- package/dist/src/graph-ui/tokens.css +1 -1
- package/dist/src/graphs.d.ts +34 -1
- package/dist/src/graphs.js +158 -14
- package/dist/src/image-input.d.ts +16 -0
- package/dist/src/image-input.js +41 -0
- package/dist/src/membership.d.ts +10 -0
- package/dist/src/membership.js +19 -4
- package/dist/src/model-health-cache.js +1 -1
- package/dist/src/model-metadata.d.ts +6 -0
- package/dist/src/model-metadata.js +35 -15
- package/dist/src/model-relay/local.d.ts +116 -0
- package/dist/src/model-relay/local.js +468 -0
- package/dist/src/model-relay/remote.d.ts +129 -0
- package/dist/src/model-relay/remote.js +252 -0
- package/dist/src/model-relay/runs.d.ts +34 -0
- package/dist/src/model-relay/runs.js +146 -0
- package/dist/src/model-relay/wire.d.ts +5 -0
- package/dist/src/model-relay/wire.js +5 -0
- package/dist/src/project-registry.d.ts +21 -0
- package/dist/src/project-registry.js +74 -0
- package/dist/src/provider-import.d.ts +0 -12
- package/dist/src/provider-import.js +7 -195
- package/dist/src/providers.d.ts +23 -2
- package/dist/src/providers.js +25 -4
- package/dist/src/pull-request-logs.d.ts +12 -1
- package/dist/src/pull-request-logs.js +14 -3
- package/dist/src/pull-requests.d.ts +327 -7
- package/dist/src/pull-requests.js +429 -51
- package/dist/src/react-runtime.js +1 -1
- package/dist/src/remote/engine-pool.d.ts +88 -4
- package/dist/src/remote/engine-pool.js +366 -89
- package/dist/src/remote/roots.d.ts +19 -0
- package/dist/src/remote/roots.js +45 -7
- package/dist/src/remote/types.d.ts +0 -44
- package/dist/src/run-control.d.ts +7 -0
- package/dist/src/run-control.js +23 -0
- package/dist/src/run-records.d.ts +7 -2
- package/dist/src/run-records.js +71 -6
- package/dist/src/runtime.d.ts +5 -1
- package/dist/src/runtime.js +10 -2
- package/dist/src/session-changes.d.ts +35 -0
- package/dist/src/session-changes.js +194 -6
- package/dist/src/session-monitor.js +2 -1
- package/dist/src/session-reaper.d.ts +1 -1
- package/dist/src/session-reaper.js +6 -1
- package/dist/src/session-summary.d.ts +2 -1
- package/dist/src/session-summary.js +2 -1
- package/dist/src/sessions.d.ts +11 -1
- package/dist/src/sessions.js +17 -4
- package/dist/src/skills/bundled/diagram/SKILL.md +5 -3
- package/dist/src/skills/bundled/graph-manager/SKILL.md +7 -4
- package/dist/src/skills/bundled/provenance.json +2 -2
- package/dist/src/skills/runtime-skills.js +1 -1
- package/dist/src/telemetry/emitter.d.ts +15 -0
- package/dist/src/telemetry/emitter.js +35 -1
- package/dist/src/telemetry/schema.d.ts +25 -2
- package/dist/src/telemetry/schema.js +52 -4
- package/dist/src/telemetry/surface.d.ts +2 -1
- package/dist/src/telemetry/surface.js +4 -1
- package/dist/src/terminal-ui.d.ts +1 -0
- package/dist/src/terminal-ui.js +10 -3
- package/dist/src/test-edit-guard.d.ts +7 -0
- package/dist/src/test-edit-guard.js +49 -1
- package/dist/src/timers.d.ts +2 -0
- package/dist/src/tools.js +59 -9
- package/package.json +6 -1
- package/dist/src/remote/cert.d.ts +0 -11
- package/dist/src/remote/cert.js +0 -87
- package/dist/src/remote/client.d.ts +0 -119
- package/dist/src/remote/client.js +0 -544
- package/dist/src/remote/command.d.ts +0 -4
- package/dist/src/remote/command.js +0 -194
- package/dist/src/remote/errors.d.ts +0 -11
- package/dist/src/remote/errors.js +0 -14
- package/dist/src/remote/network.d.ts +0 -22
- package/dist/src/remote/network.js +0 -102
- package/dist/src/remote/pairing.d.ts +0 -63
- package/dist/src/remote/pairing.js +0 -299
- package/dist/src/remote/pem.d.ts +0 -2
- package/dist/src/remote/pem.js +0 -7
- package/dist/src/remote/serve.d.ts +0 -68
- package/dist/src/remote/serve.js +0 -244
- package/dist/src/remote/server.d.ts +0 -21
- package/dist/src/remote/server.js +0 -406
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
export class ControlError extends Error {
|
|
2
|
+
code;
|
|
3
|
+
constructor(code, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.code = code;
|
|
6
|
+
this.name = 'ControlError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const CONTROL_TIMEOUT_MS = 15_000;
|
|
10
|
+
const HEARTBEAT_TIMEOUT_MS = 10_000;
|
|
11
|
+
const MAX_CONTROL_BODY_CHARS = 64 * 1024;
|
|
12
|
+
const STOP_REASONS = ['idle', 'user', 'boot_timeout'];
|
|
13
|
+
async function call(base, method, path, options = {}) {
|
|
14
|
+
let response;
|
|
15
|
+
let text;
|
|
16
|
+
const headers = {};
|
|
17
|
+
if (options.body !== undefined)
|
|
18
|
+
headers['Content-Type'] = 'application/json';
|
|
19
|
+
if (options.accessToken !== undefined)
|
|
20
|
+
headers.Authorization = `Bearer ${options.accessToken}`;
|
|
21
|
+
try {
|
|
22
|
+
response = await globalThis.fetch(`${base.replace(/\/+$/, '')}/environments${path ? `/${path}` : ''}`, {
|
|
23
|
+
method,
|
|
24
|
+
headers,
|
|
25
|
+
...(options.body !== undefined ? { body: JSON.stringify(options.body) } : {}),
|
|
26
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? CONTROL_TIMEOUT_MS),
|
|
27
|
+
redirect: 'error',
|
|
28
|
+
});
|
|
29
|
+
text = (await response.text()).slice(0, MAX_CONTROL_BODY_CHARS);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw new ControlError('network', `The Andorra service could not be reached: ${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
}
|
|
34
|
+
let value = {};
|
|
35
|
+
try {
|
|
36
|
+
const parsed = JSON.parse(text);
|
|
37
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed))
|
|
38
|
+
value = parsed;
|
|
39
|
+
}
|
|
40
|
+
catch { }
|
|
41
|
+
return { status: response.status, value };
|
|
42
|
+
}
|
|
43
|
+
const post = (base, path, body) => call(base, 'POST', path, { body });
|
|
44
|
+
function serverError(status, value) {
|
|
45
|
+
const detail = typeof value.error === 'string' ? value.error : `HTTP ${status}`;
|
|
46
|
+
return new ControlError('server', `The Andorra service refused the request (${detail}).`);
|
|
47
|
+
}
|
|
48
|
+
function text(value, key) {
|
|
49
|
+
const found = value[key];
|
|
50
|
+
if (typeof found !== 'string' || !found)
|
|
51
|
+
throw new ControlError('server', `The Andorra service answered without ${key}.`);
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
/** Starts a link for a machine whose secret hashes to `secretHash` (SHA-256, hex). */
|
|
55
|
+
export async function linkStart(base, secretHash) {
|
|
56
|
+
const { status, value } = await post(base, 'link/start', { secretHash });
|
|
57
|
+
if (status !== 200)
|
|
58
|
+
throw serverError(status, value);
|
|
59
|
+
return { code: text(value, 'code'), pollToken: text(value, 'pollToken'), expiresAt: text(value, 'expiresAt') };
|
|
60
|
+
}
|
|
61
|
+
export async function linkPoll(base, pollToken) {
|
|
62
|
+
const { status, value } = await post(base, 'link/poll', { pollToken });
|
|
63
|
+
if (status === 410)
|
|
64
|
+
throw new ControlError('code_expired', 'The link code expired before it was used.');
|
|
65
|
+
if (status !== 200)
|
|
66
|
+
throw serverError(status, value);
|
|
67
|
+
if (value.status === 'pending')
|
|
68
|
+
return { status: 'pending' };
|
|
69
|
+
if (value.status === 'linked') {
|
|
70
|
+
return {
|
|
71
|
+
status: 'linked', environmentId: text(value, 'environmentId'), name: text(value, 'name'),
|
|
72
|
+
// Printed on the machine's terminal, so nothing in it may move the cursor or change the colours.
|
|
73
|
+
account: typeof value.account === 'string' ? value.account.replace(/[\u0000-\u001f\u007f-\u009f]/g, '').slice(0, 320) : '',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
throw new ControlError('server', 'The Andorra service answered the link poll with an unknown status.');
|
|
77
|
+
}
|
|
78
|
+
export async function environmentToken(base, id, secret) {
|
|
79
|
+
const { status, value } = await post(base, 'token', { environmentId: id, secret });
|
|
80
|
+
if (status === 401)
|
|
81
|
+
throw new ControlError('unlinked', 'This machine is no longer linked to an Andorra account.');
|
|
82
|
+
if (status !== 200)
|
|
83
|
+
throw serverError(status, value);
|
|
84
|
+
return { token: text(value, 'token'), expiresAt: text(value, 'expiresAt') };
|
|
85
|
+
}
|
|
86
|
+
const BOOT_REFUSALS = {
|
|
87
|
+
404: { code: 'boot_unknown', message: 'The start code was not recognised.' },
|
|
88
|
+
409: { code: 'boot_used', message: 'The start code was already used.' },
|
|
89
|
+
410: { code: 'boot_expired', message: 'The start code expired.' },
|
|
90
|
+
};
|
|
91
|
+
/** Links a Cloud instance: the boot code proves the caller, and only the hash of the instance's own secret is sent. */
|
|
92
|
+
export async function cloudBoot(base, bootCode, secretHash) {
|
|
93
|
+
const { status, value } = await post(base, 'cloud/boot', { bootCode, secretHash });
|
|
94
|
+
const refusal = BOOT_REFUSALS[status];
|
|
95
|
+
if (refusal !== undefined)
|
|
96
|
+
throw new ControlError(refusal.code, refusal.message);
|
|
97
|
+
if (status !== 200)
|
|
98
|
+
throw serverError(status, value);
|
|
99
|
+
return { environmentId: text(value, 'environmentId'), name: text(value, 'name') };
|
|
100
|
+
}
|
|
101
|
+
export async function heartbeat(base, environmentId, secret, activity) {
|
|
102
|
+
const { status, value } = await call(base, 'POST', 'cloud/heartbeat', { body: { environmentId, secret, running: activity.running, attached: activity.attached }, timeoutMs: HEARTBEAT_TIMEOUT_MS });
|
|
103
|
+
if (status === 401)
|
|
104
|
+
throw new ControlError('unlinked', 'This machine is no longer linked to an Andorra account.');
|
|
105
|
+
if (status !== 200)
|
|
106
|
+
throw serverError(status, value);
|
|
107
|
+
}
|
|
108
|
+
// The calls below act for the signed-in account and carry its access token.
|
|
109
|
+
const REFUSALS = {
|
|
110
|
+
code_unknown: { status: 404, code: 'code_unknown', message: 'That code was not recognised.' },
|
|
111
|
+
code_expired: { status: 410, code: 'code_expired', message: 'That code expired.' },
|
|
112
|
+
code_used: { status: 409, code: 'code_used', message: 'That code was already used.' },
|
|
113
|
+
environment_limit: { status: 409, code: 'environment_limit', message: 'The account has linked the most machines allowed.' },
|
|
114
|
+
invalid_name: { status: 400, code: 'invalid_name', message: 'The machine name was refused.' },
|
|
115
|
+
cloud_environment: { status: 409, code: 'cloud_environment', message: 'Delete Cloud from Settings \u2192 Environments.' },
|
|
116
|
+
};
|
|
117
|
+
function accountError(status, value, notFound = false) {
|
|
118
|
+
if (status === 401)
|
|
119
|
+
return new ControlError('unauthorized', 'The Andorra service did not accept this sign-in.');
|
|
120
|
+
const refusal = typeof value.error === 'string' ? REFUSALS[value.error] : undefined;
|
|
121
|
+
if (refusal !== undefined && refusal.status === status)
|
|
122
|
+
return new ControlError(refusal.code, refusal.message);
|
|
123
|
+
if (notFound && status === 404)
|
|
124
|
+
return new ControlError('not_found', 'That machine is not linked to this account.');
|
|
125
|
+
return serverError(status, value);
|
|
126
|
+
}
|
|
127
|
+
function environmentRecord(value) {
|
|
128
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
129
|
+
return undefined;
|
|
130
|
+
const { id, name, kind, createdAt } = value;
|
|
131
|
+
if (typeof id !== 'string' || !id || typeof name !== 'string' || (kind !== 'machine' && kind !== 'cloud') || typeof createdAt !== 'string')
|
|
132
|
+
return undefined;
|
|
133
|
+
return { id, name, kind, createdAt };
|
|
134
|
+
}
|
|
135
|
+
function environmentOf(value) {
|
|
136
|
+
const found = environmentRecord(value.environment);
|
|
137
|
+
if (!found)
|
|
138
|
+
throw new ControlError('server', 'The Andorra service answered without an environment.');
|
|
139
|
+
return found;
|
|
140
|
+
}
|
|
141
|
+
export async function listEnvironments(base, accessToken) {
|
|
142
|
+
const { status, value } = await call(base, 'GET', '', { accessToken });
|
|
143
|
+
if (status !== 200)
|
|
144
|
+
throw accountError(status, value);
|
|
145
|
+
if (!Array.isArray(value.environments))
|
|
146
|
+
throw new ControlError('server', 'The Andorra service answered without environments.');
|
|
147
|
+
return value.environments.flatMap(entry => environmentRecord(entry) ?? []);
|
|
148
|
+
}
|
|
149
|
+
export async function claimEnvironment(base, accessToken, code, name) {
|
|
150
|
+
const { status, value } = await call(base, 'POST', 'link/claim', { accessToken, body: { code, name } });
|
|
151
|
+
if (status !== 200)
|
|
152
|
+
throw accountError(status, value);
|
|
153
|
+
return environmentOf(value);
|
|
154
|
+
}
|
|
155
|
+
export async function renameEnvironment(base, accessToken, id, name) {
|
|
156
|
+
const { status, value } = await call(base, 'PATCH', encodeURIComponent(id), { accessToken, body: { name } });
|
|
157
|
+
if (status !== 200)
|
|
158
|
+
throw accountError(status, value, true);
|
|
159
|
+
return environmentOf(value);
|
|
160
|
+
}
|
|
161
|
+
export async function removeEnvironment(base, accessToken, id) {
|
|
162
|
+
const { status, value } = await call(base, 'DELETE', encodeURIComponent(id), { accessToken });
|
|
163
|
+
if (status !== 200)
|
|
164
|
+
throw accountError(status, value, true);
|
|
165
|
+
}
|
|
166
|
+
const CLOUD_REFUSALS = {
|
|
167
|
+
cloud_not_enabled: { status: 403, code: 'cloud_not_enabled', message: 'Cloud is not available for this account.' },
|
|
168
|
+
stopping: { status: 409, code: 'stopping', message: 'Cloud is still stopping.' },
|
|
169
|
+
no_capacity: { status: 503, code: 'no_capacity', message: 'Cloud has no capacity right now.' },
|
|
170
|
+
invalid_version: { status: 400, code: 'invalid_version', message: 'This version of Andorra Code cannot start Cloud. Update Andorra Code and try again.' },
|
|
171
|
+
};
|
|
172
|
+
const CLOUD_STATES = ['none', 'starting', 'running', 'stopping', 'stopped'];
|
|
173
|
+
const CLOUD_LABEL = /^Andorra-Code-Cloud-[1-9][0-9]{9}$/;
|
|
174
|
+
const CLOUD_ENVIRONMENT_ID = /^env_[A-Za-z0-9_-]{22}$/;
|
|
175
|
+
const CLOUD_VERSION = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
|
|
176
|
+
const ISO_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,9})?(Z|[+-]\d{2}:\d{2})$/;
|
|
177
|
+
/** Keeps only the fields of a Cloud answer that have the expected shape; an unknown state is an error. */
|
|
178
|
+
function cloudStatus(value) {
|
|
179
|
+
const { state, enabled, environmentId, label, version, step, deleteAt, error, stopReason } = value;
|
|
180
|
+
if (typeof state !== 'string' || !CLOUD_STATES.includes(state))
|
|
181
|
+
throw new ControlError('server', 'The Andorra service answered with an unknown Cloud state.');
|
|
182
|
+
const status = { state: state, enabled: enabled === true };
|
|
183
|
+
if (typeof environmentId === 'string' && CLOUD_ENVIRONMENT_ID.test(environmentId))
|
|
184
|
+
status.environmentId = environmentId;
|
|
185
|
+
if (typeof label === 'string' && CLOUD_LABEL.test(label))
|
|
186
|
+
status.label = label;
|
|
187
|
+
if (typeof version === 'string' && CLOUD_VERSION.test(version))
|
|
188
|
+
status.version = version;
|
|
189
|
+
if (step === 'machine' || step === 'bridge')
|
|
190
|
+
status.step = step;
|
|
191
|
+
if (typeof deleteAt === 'string' && ISO_TIME.test(deleteAt) && !Number.isNaN(Date.parse(deleteAt)))
|
|
192
|
+
status.deleteAt = deleteAt;
|
|
193
|
+
if (error === 'boot_timeout' || error === 'no_capacity')
|
|
194
|
+
status.error = error;
|
|
195
|
+
if ((state === 'stopping' || state === 'stopped') && typeof stopReason === 'string' && STOP_REASONS.includes(stopReason))
|
|
196
|
+
status.stopReason = stopReason;
|
|
197
|
+
return status;
|
|
198
|
+
}
|
|
199
|
+
function cloudError(status, value) {
|
|
200
|
+
const refusal = typeof value.error === 'string' ? CLOUD_REFUSALS[value.error] : undefined;
|
|
201
|
+
if (refusal !== undefined && refusal.status === status)
|
|
202
|
+
return new ControlError(refusal.code, refusal.message);
|
|
203
|
+
if (status === 401)
|
|
204
|
+
return accountError(status, value);
|
|
205
|
+
return new ControlError('cloud_unavailable', 'Cloud is not available right now. Try again in a moment.');
|
|
206
|
+
}
|
|
207
|
+
export async function cloudGet(base, accessToken) {
|
|
208
|
+
const { status, value } = await call(base, 'GET', 'cloud', { accessToken });
|
|
209
|
+
if (status !== 200)
|
|
210
|
+
throw cloudError(status, value);
|
|
211
|
+
return cloudStatus(value);
|
|
212
|
+
}
|
|
213
|
+
export async function cloudStart(base, accessToken, version) {
|
|
214
|
+
const { status, value } = await call(base, 'POST', 'cloud/start', { accessToken, body: { version } });
|
|
215
|
+
if (status !== 200)
|
|
216
|
+
throw cloudError(status, value);
|
|
217
|
+
return cloudStatus(value);
|
|
218
|
+
}
|
|
219
|
+
export async function cloudStop(base, accessToken) {
|
|
220
|
+
const { status, value } = await call(base, 'POST', 'cloud/stop', { accessToken });
|
|
221
|
+
if (status !== 200)
|
|
222
|
+
throw cloudError(status, value);
|
|
223
|
+
return cloudStatus(value);
|
|
224
|
+
}
|
|
225
|
+
/** Deletes the account's Cloud; with `environmentId`, only while that is still the account's Cloud (another answers none). */
|
|
226
|
+
export async function cloudDelete(base, accessToken, environmentId) {
|
|
227
|
+
const path = environmentId === undefined ? 'cloud' : `cloud?environmentId=${encodeURIComponent(environmentId)}`;
|
|
228
|
+
const { status, value } = await call(base, 'DELETE', path, { accessToken });
|
|
229
|
+
if (status !== 200)
|
|
230
|
+
throw cloudError(status, value);
|
|
231
|
+
// The service answers none, or the environment a start put in place of the deleted one while the delete ran.
|
|
232
|
+
return cloudStatus({ state: 'none', enabled: true, ...value });
|
|
233
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { type RelayEngines } from '../remote/engine-pool.js';
|
|
2
|
+
export declare const PACKAGE_NAME = "@andorra-labs/code";
|
|
3
|
+
/** The first release that starts engines matching the desktop's version; it is fixed when the feature ships and never follows later releases. */
|
|
4
|
+
export declare const MIN_ENGINE_VERSION = "0.1.16";
|
|
5
|
+
export declare const MAX_ENGINE_VERSIONS = 3;
|
|
6
|
+
export declare const ENGINE_INSTALL_TIMEOUT_MS = 300000;
|
|
7
|
+
/** The exit code with which a host asks the launcher to start it again as the version in next-host-version. */
|
|
8
|
+
export declare const HOST_RESTART_EXIT_CODE = 75;
|
|
9
|
+
export declare const MAX_CONCURRENT_INSTALLS = 2;
|
|
10
|
+
/** Installs that may wait for a slot; a version asked for past that is answered busy, so made-up versions cannot pile up. */
|
|
11
|
+
export declare const MAX_QUEUED_INSTALLS = 8;
|
|
12
|
+
/** How long a failed version is not installed again: connections that open meanwhile are told the failure. */
|
|
13
|
+
export declare const INSTALL_RETRY_COOLDOWN_MS = 60000;
|
|
14
|
+
/** How long close() waits for installs to settle before returning anyway. */
|
|
15
|
+
export declare const STORE_CLOSE_BOUND_MS = 5000;
|
|
16
|
+
/** Why an install failed, as the desktop is told it: never npm's own output. */
|
|
17
|
+
export declare const INSTALL_FAILURES: {
|
|
18
|
+
readonly npm: "npm did not answer.";
|
|
19
|
+
readonly timeout: "the installation took too long.";
|
|
20
|
+
readonly mismatch: "npm installed a different version than asked for.";
|
|
21
|
+
readonly disk: "the disk is full.";
|
|
22
|
+
};
|
|
23
|
+
export type InstallFailure = typeof INSTALL_FAILURES[keyof typeof INSTALL_FAILURES];
|
|
24
|
+
export type EngineStoreErrorCode = 'invalid-params' | 'busy' | 'remote';
|
|
25
|
+
export declare class EngineStoreError extends Error {
|
|
26
|
+
readonly code: EngineStoreErrorCode;
|
|
27
|
+
constructor(code: EngineStoreErrorCode, message: string);
|
|
28
|
+
}
|
|
29
|
+
export type EngineInstallEvent = {
|
|
30
|
+
version: string;
|
|
31
|
+
state: 'installing';
|
|
32
|
+
} | {
|
|
33
|
+
version: string;
|
|
34
|
+
state: 'ready';
|
|
35
|
+
} | {
|
|
36
|
+
version: string;
|
|
37
|
+
state: 'failed';
|
|
38
|
+
reason: InstallFailure;
|
|
39
|
+
};
|
|
40
|
+
export interface EngineStore extends RelayEngines {
|
|
41
|
+
prepare(version: string | undefined): Promise<'started' | 'underway' | 'none' | 'failed'>;
|
|
42
|
+
watch(listener: (event: EngineInstallEvent) => void): () => void;
|
|
43
|
+
installState(version: string): {
|
|
44
|
+
state: 'installing';
|
|
45
|
+
} | {
|
|
46
|
+
state: 'failed';
|
|
47
|
+
reason: InstallFailure;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/** Whether that version is installed and ready to start. */
|
|
50
|
+
installed(version: string): Promise<boolean>;
|
|
51
|
+
/** Installs under way or waiting for a slot in this process. */
|
|
52
|
+
installing(): number;
|
|
53
|
+
/** Names the version the launcher should start as the next host, and records when it was asked for in last-host-request. */
|
|
54
|
+
requestHostVersion(version: string, at: number): Promise<void>;
|
|
55
|
+
/** Takes back a request that was not acted on: removes next-host-version and last-host-request. */
|
|
56
|
+
withdrawHostVersion(): Promise<void>;
|
|
57
|
+
/** The last version a host asked to be restarted as, and when; it survives the restart, which in-memory state does not. */
|
|
58
|
+
lastHostRequest(): Promise<{
|
|
59
|
+
version: string;
|
|
60
|
+
at: number;
|
|
61
|
+
} | undefined>;
|
|
62
|
+
close(): Promise<void>;
|
|
63
|
+
}
|
|
64
|
+
/** Schedules `run` after `ms` and returns what cancels it; tests replace the clock with their own. */
|
|
65
|
+
export type Schedule = (run: () => void, ms: number) => () => void;
|
|
66
|
+
export interface EngineStoreOptions {
|
|
67
|
+
/** <Andorra home>/bridge/engines */
|
|
68
|
+
root: string;
|
|
69
|
+
hostVersion: string;
|
|
70
|
+
/** The command that starts this host's own engine. */
|
|
71
|
+
hostCommand?: () => string[];
|
|
72
|
+
/** An npm to run instead of the one beside this Node: a script (.mjs, .cjs, .js) is run with this Node. */
|
|
73
|
+
npm?: string;
|
|
74
|
+
installTimeoutMs?: number;
|
|
75
|
+
schedule?: Schedule;
|
|
76
|
+
/** The clock of the retry cool-down. */
|
|
77
|
+
now?: () => number;
|
|
78
|
+
/** How long an install waits on another process's live lock before giving up as taking too long. */
|
|
79
|
+
lockWaitMs?: number;
|
|
80
|
+
log?: (line: string) => void;
|
|
81
|
+
}
|
|
82
|
+
export declare const validVersion: (text: unknown) => text is string;
|
|
83
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
84
|
+
export declare function engineEntry(root: string, version: string): string;
|
|
85
|
+
export declare function installedVersions(root: string): Promise<string[]>;
|
|
86
|
+
/** Removes the least recently used versions beyond MAX_ENGINE_VERSIONS, never one in `keep`. */
|
|
87
|
+
export declare function pruneEngines(root: string, keep: readonly string[]): Promise<string[]>;
|
|
88
|
+
export declare function createEngineStore(options: EngineStoreOptions): EngineStore;
|
|
89
|
+
/** The store a host uses under the bridge launcher, which names it with ANDORRA_BRIDGE_ENGINES; none otherwise, or when the engine command is overridden. */
|
|
90
|
+
export declare function engineStoreFromEnvironment(env: NodeJS.ProcessEnv, deps: Omit<EngineStoreOptions, 'root' | 'npm'>): EngineStore | undefined;
|