@tealbrick/avm 0.1.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/LICENSE +21 -0
- package/PROVENANCE.md +38 -0
- package/README.md +165 -0
- package/dist/_chunks/extension-CS1otfhf.mjs +232 -0
- package/dist/_chunks/src-BhUiVsTW.mjs +522 -0
- package/dist/client/administration.d.ts +3 -0
- package/dist/client/administration.js +145 -0
- package/dist/client/config.d.ts +1125 -0
- package/dist/client/config.js +257 -0
- package/dist/client/index.d.ts +126 -0
- package/dist/client/index.js +364 -0
- package/dist/extension/_manifest.json +11 -0
- package/dist/extension/extension.d.ts +626 -0
- package/dist/extension/extension.mjs +8 -0
- package/dist/extension/tools/action.d.ts +24 -0
- package/dist/extension/tools/action.mjs +46 -0
- package/dist/extension/tools/inspect.d.ts +50 -0
- package/dist/extension/tools/inspect.mjs +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +8 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.mjs +9 -0
- package/package.json +70 -0
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { n as administrationSchema } from "./extension-CS1otfhf.mjs";
|
|
8
|
+
import { spawn } from "node:child_process";
|
|
9
|
+
function administrationArgv(value) {
|
|
10
|
+
const r = administrationSchema.parse(value);
|
|
11
|
+
const flags = (pairs) => pairs.flatMap(([k, v]) => v === void 0 ? [] : [k, String(v)]);
|
|
12
|
+
switch (r.operation) {
|
|
13
|
+
case "tenantSync": return [
|
|
14
|
+
"tenant",
|
|
15
|
+
"sync",
|
|
16
|
+
r.workspace,
|
|
17
|
+
...flags([
|
|
18
|
+
["--display-name", r.displayName],
|
|
19
|
+
["--principal-id", r.principalId],
|
|
20
|
+
["--issuer", r.issuer],
|
|
21
|
+
["--subject", r.subject],
|
|
22
|
+
["--role", r.role],
|
|
23
|
+
["--weight", r.weight],
|
|
24
|
+
["--concurrent-heavy-work", r.concurrentHeavyWork],
|
|
25
|
+
["--queue-policy", r.queuePolicy]
|
|
26
|
+
])
|
|
27
|
+
];
|
|
28
|
+
case "ingressPut": return [
|
|
29
|
+
"ingress",
|
|
30
|
+
"put",
|
|
31
|
+
r.provider,
|
|
32
|
+
r.externalIdentity,
|
|
33
|
+
"--agent",
|
|
34
|
+
r.worker,
|
|
35
|
+
...flags([["--channel-scope", r.channelScope], ["--metadata-file", r.metadataFile]])
|
|
36
|
+
];
|
|
37
|
+
case "ingressRevoke": return [
|
|
38
|
+
"ingress",
|
|
39
|
+
"revoke",
|
|
40
|
+
r.identityId
|
|
41
|
+
];
|
|
42
|
+
case "ingressWake": return [
|
|
43
|
+
"ingress",
|
|
44
|
+
"wake",
|
|
45
|
+
r.provider,
|
|
46
|
+
r.externalIdentity,
|
|
47
|
+
"--event-id",
|
|
48
|
+
r.eventId,
|
|
49
|
+
...flags([
|
|
50
|
+
["--channel-scope", r.channelScope],
|
|
51
|
+
["--payload-file", r.payloadFile],
|
|
52
|
+
["--correlation-id", r.correlationId]
|
|
53
|
+
])
|
|
54
|
+
];
|
|
55
|
+
case "ingressComplete": return [
|
|
56
|
+
"ingress",
|
|
57
|
+
"complete",
|
|
58
|
+
r.wakeId,
|
|
59
|
+
...flags([["--error", r.error]])
|
|
60
|
+
];
|
|
61
|
+
case "resize": return [
|
|
62
|
+
"worker",
|
|
63
|
+
"resize",
|
|
64
|
+
r.worker,
|
|
65
|
+
"--memory-target",
|
|
66
|
+
String(r.memoryTargetMiB)
|
|
67
|
+
];
|
|
68
|
+
case "workspacePut": return [
|
|
69
|
+
"workspace",
|
|
70
|
+
"put",
|
|
71
|
+
r.workspace,
|
|
72
|
+
...flags([
|
|
73
|
+
["--display-name", r.displayName],
|
|
74
|
+
["--weight", r.weight],
|
|
75
|
+
["--concurrent-heavy-work", r.concurrentHeavyWork],
|
|
76
|
+
["--queue-policy", r.queuePolicy]
|
|
77
|
+
])
|
|
78
|
+
];
|
|
79
|
+
case "workspaceDisable": return [
|
|
80
|
+
"workspace",
|
|
81
|
+
"disable",
|
|
82
|
+
r.workspace
|
|
83
|
+
];
|
|
84
|
+
case "userPut": return [
|
|
85
|
+
"user",
|
|
86
|
+
"put",
|
|
87
|
+
r.user,
|
|
88
|
+
"--workspace",
|
|
89
|
+
r.workspace,
|
|
90
|
+
"--role",
|
|
91
|
+
r.role
|
|
92
|
+
];
|
|
93
|
+
case "ownerSet": return [
|
|
94
|
+
"agent",
|
|
95
|
+
"owner",
|
|
96
|
+
"set",
|
|
97
|
+
r.worker,
|
|
98
|
+
"--workspace",
|
|
99
|
+
r.workspace,
|
|
100
|
+
...flags([["--user", r.user]])
|
|
101
|
+
];
|
|
102
|
+
case "shareGrant": return [
|
|
103
|
+
"agent",
|
|
104
|
+
"share",
|
|
105
|
+
"grant",
|
|
106
|
+
r.worker,
|
|
107
|
+
r.grantee.kind === "workspace" ? "--tenant" : "--principal",
|
|
108
|
+
r.grantee.id,
|
|
109
|
+
...r.allow.flatMap((a) => ["--allow", a])
|
|
110
|
+
];
|
|
111
|
+
case "shareRevoke": return [
|
|
112
|
+
"agent",
|
|
113
|
+
"share",
|
|
114
|
+
"revoke",
|
|
115
|
+
r.worker,
|
|
116
|
+
r.shareId
|
|
117
|
+
];
|
|
118
|
+
case "residentSet": return [
|
|
119
|
+
"agent",
|
|
120
|
+
"resident",
|
|
121
|
+
"set",
|
|
122
|
+
r.worker
|
|
123
|
+
];
|
|
124
|
+
case "wake": return [
|
|
125
|
+
"agent",
|
|
126
|
+
"wake",
|
|
127
|
+
r.worker,
|
|
128
|
+
"--source",
|
|
129
|
+
r.source,
|
|
130
|
+
"--idempotency-key",
|
|
131
|
+
r.idempotencyKey,
|
|
132
|
+
...flags([["--reason", r.reason], ["--external-event-id", r.externalEventId]])
|
|
133
|
+
];
|
|
134
|
+
case "cool": return [
|
|
135
|
+
"agent",
|
|
136
|
+
"cool",
|
|
137
|
+
r.worker
|
|
138
|
+
];
|
|
139
|
+
case "poolPolicySet": return [
|
|
140
|
+
"pool",
|
|
141
|
+
"policy",
|
|
142
|
+
"set",
|
|
143
|
+
...flags([
|
|
144
|
+
["--cpu-percent", r.cpuPercent],
|
|
145
|
+
["--memory-max-bytes", r.memoryMaxBytes],
|
|
146
|
+
["--memory-high-bytes", r.memoryHighBytes],
|
|
147
|
+
["--host-memory-reserve-bytes", r.hostMemoryReserveBytes],
|
|
148
|
+
["--launch-reserve-bytes", r.launchReserveBytes]
|
|
149
|
+
])
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
var AvmError = class extends Error {
|
|
154
|
+
code;
|
|
155
|
+
exitCode;
|
|
156
|
+
constructor(code, exitCode) {
|
|
157
|
+
super(`AgentVM ${code.toLowerCase().replaceAll("_", " ")}`);
|
|
158
|
+
this.code = code;
|
|
159
|
+
this.exitCode = exitCode;
|
|
160
|
+
this.name = "AvmError";
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const identifier = (value) => {
|
|
164
|
+
if (typeof value !== "string" || !/^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$/.test(value)) throw new AvmError("INVALID_REQUEST");
|
|
165
|
+
return value;
|
|
166
|
+
};
|
|
167
|
+
const limit = (value = 50) => {
|
|
168
|
+
if (!Number.isInteger(value) || value < 1 || value > 200) throw new AvmError("INVALID_REQUEST");
|
|
169
|
+
return String(value);
|
|
170
|
+
};
|
|
171
|
+
function commandArgv(request, policy = {}) {
|
|
172
|
+
const prefix = ["--json"];
|
|
173
|
+
switch (request.operation) {
|
|
174
|
+
case "configured": {
|
|
175
|
+
const grant = policy.administration?.find((g) => g.name === identifier(request.action));
|
|
176
|
+
if (!grant) throw new AvmError("DENIED");
|
|
177
|
+
try {
|
|
178
|
+
return [...prefix, ...administrationArgv(grant.request)];
|
|
179
|
+
} catch {
|
|
180
|
+
throw new AvmError("INVALID_REQUEST");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
case "poolStatus":
|
|
184
|
+
case "poolPressure":
|
|
185
|
+
case "poolQueue": return [
|
|
186
|
+
...prefix,
|
|
187
|
+
"pool",
|
|
188
|
+
request.operation.slice(4).toLowerCase()
|
|
189
|
+
];
|
|
190
|
+
case "poolPolicy": return [
|
|
191
|
+
...prefix,
|
|
192
|
+
"pool",
|
|
193
|
+
"policy",
|
|
194
|
+
"show"
|
|
195
|
+
];
|
|
196
|
+
case "workspaces": return [
|
|
197
|
+
...prefix,
|
|
198
|
+
"workspace",
|
|
199
|
+
"ls"
|
|
200
|
+
];
|
|
201
|
+
case "users": return [
|
|
202
|
+
...prefix,
|
|
203
|
+
"user",
|
|
204
|
+
"ls"
|
|
205
|
+
];
|
|
206
|
+
case "workspace":
|
|
207
|
+
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(request.id)) throw new AvmError("INVALID_REQUEST");
|
|
208
|
+
return [
|
|
209
|
+
...prefix,
|
|
210
|
+
"workspace",
|
|
211
|
+
"show",
|
|
212
|
+
request.id
|
|
213
|
+
];
|
|
214
|
+
case "user": return [
|
|
215
|
+
...prefix,
|
|
216
|
+
"user",
|
|
217
|
+
"show",
|
|
218
|
+
identifier(request.id)
|
|
219
|
+
];
|
|
220
|
+
case "owner": return [
|
|
221
|
+
...prefix,
|
|
222
|
+
"agent",
|
|
223
|
+
"owner",
|
|
224
|
+
"get",
|
|
225
|
+
identifier(request.worker)
|
|
226
|
+
];
|
|
227
|
+
case "shares": return [
|
|
228
|
+
...prefix,
|
|
229
|
+
"agent",
|
|
230
|
+
"share",
|
|
231
|
+
"ls",
|
|
232
|
+
identifier(request.worker)
|
|
233
|
+
];
|
|
234
|
+
case "resident": return [
|
|
235
|
+
...prefix,
|
|
236
|
+
"agent",
|
|
237
|
+
"resident",
|
|
238
|
+
"get"
|
|
239
|
+
];
|
|
240
|
+
case "ingress": return [
|
|
241
|
+
...prefix,
|
|
242
|
+
"ingress",
|
|
243
|
+
"ls",
|
|
244
|
+
...request.worker ? ["--agent", identifier(request.worker)] : []
|
|
245
|
+
];
|
|
246
|
+
case "doctor":
|
|
247
|
+
case "inventory": return [...prefix, request.operation];
|
|
248
|
+
case "workers": return [
|
|
249
|
+
...prefix,
|
|
250
|
+
"worker",
|
|
251
|
+
"ls"
|
|
252
|
+
];
|
|
253
|
+
case "bundles": return [
|
|
254
|
+
...prefix,
|
|
255
|
+
"bundle",
|
|
256
|
+
"ls"
|
|
257
|
+
];
|
|
258
|
+
case "monitor": return [
|
|
259
|
+
...prefix,
|
|
260
|
+
"monitor",
|
|
261
|
+
"status"
|
|
262
|
+
];
|
|
263
|
+
case "workerStatus": return [
|
|
264
|
+
...prefix,
|
|
265
|
+
"worker",
|
|
266
|
+
"status",
|
|
267
|
+
identifier(request.worker)
|
|
268
|
+
];
|
|
269
|
+
case "capabilities": return [
|
|
270
|
+
...prefix,
|
|
271
|
+
"capability",
|
|
272
|
+
"manifest",
|
|
273
|
+
identifier(request.worker)
|
|
274
|
+
];
|
|
275
|
+
case "runs": return [
|
|
276
|
+
...prefix,
|
|
277
|
+
"runs",
|
|
278
|
+
"ls",
|
|
279
|
+
"--limit",
|
|
280
|
+
limit(request.limit)
|
|
281
|
+
];
|
|
282
|
+
case "events": return [
|
|
283
|
+
...prefix,
|
|
284
|
+
"events",
|
|
285
|
+
"--limit",
|
|
286
|
+
limit(request.limit),
|
|
287
|
+
...[
|
|
288
|
+
["--vm", request.worker],
|
|
289
|
+
["--event", request.event],
|
|
290
|
+
["--run-id", request.runId]
|
|
291
|
+
].flatMap(([flag, value]) => value === void 0 ? [] : [flag, identifier(value)])
|
|
292
|
+
];
|
|
293
|
+
case "runStatus": return [
|
|
294
|
+
...prefix,
|
|
295
|
+
"runs",
|
|
296
|
+
"status",
|
|
297
|
+
identifier(request.runId)
|
|
298
|
+
];
|
|
299
|
+
case "start":
|
|
300
|
+
case "stop":
|
|
301
|
+
case "promote":
|
|
302
|
+
case "destroy": {
|
|
303
|
+
const worker = identifier(request.worker);
|
|
304
|
+
if (!policy.lifecycle?.some((g) => g.worker === worker && g.operations.includes(request.operation))) throw new AvmError("DENIED");
|
|
305
|
+
return [
|
|
306
|
+
...prefix,
|
|
307
|
+
"worker",
|
|
308
|
+
request.operation,
|
|
309
|
+
worker
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
case "spawn": {
|
|
313
|
+
const worker = identifier(request.worker);
|
|
314
|
+
const grant = policy.spawns?.find((g) => g.worker === worker);
|
|
315
|
+
if (!grant) throw new AvmError("DENIED");
|
|
316
|
+
if (![
|
|
317
|
+
"light",
|
|
318
|
+
"small",
|
|
319
|
+
"standard",
|
|
320
|
+
"browser"
|
|
321
|
+
].includes(grant.profile) || !["ephemeral", "durable"].includes(grant.mode)) throw new AvmError("INVALID_REQUEST");
|
|
322
|
+
const argv = [
|
|
323
|
+
...prefix,
|
|
324
|
+
"worker",
|
|
325
|
+
"create",
|
|
326
|
+
worker,
|
|
327
|
+
"--profile",
|
|
328
|
+
grant.profile,
|
|
329
|
+
"--mode",
|
|
330
|
+
grant.mode
|
|
331
|
+
];
|
|
332
|
+
for (const [flag, values] of [
|
|
333
|
+
["--harness", grant.harnesses],
|
|
334
|
+
["--mcp", grant.mcps],
|
|
335
|
+
["--plugin", grant.plugins],
|
|
336
|
+
["--bundle", grant.bundles],
|
|
337
|
+
["--cap", grant.capabilities]
|
|
338
|
+
]) for (const value of values ?? []) {
|
|
339
|
+
if (!/^[A-Za-z0-9@][A-Za-z0-9@_./:+-]{0,255}$/.test(value)) throw new AvmError("INVALID_REQUEST");
|
|
340
|
+
argv.push(flag, value);
|
|
341
|
+
}
|
|
342
|
+
for (const value of grant.auth ?? []) {
|
|
343
|
+
if (!/^[a-z][a-z0-9_-]*=(none|local)$|^codex=shared$/.test(value)) throw new AvmError("INVALID_REQUEST");
|
|
344
|
+
argv.push("--auth", value);
|
|
345
|
+
}
|
|
346
|
+
return argv;
|
|
347
|
+
}
|
|
348
|
+
case "exec": {
|
|
349
|
+
const worker = identifier(request.worker);
|
|
350
|
+
const grant = policy.commands?.find((g) => g.worker === worker && g.command === request.command);
|
|
351
|
+
if (!grant) throw new AvmError("DENIED");
|
|
352
|
+
if (!grant.argv.length || grant.argv.some((a) => typeof a !== "string" || a.includes("\0") || a.length > 8192)) throw new AvmError("INVALID_REQUEST");
|
|
353
|
+
return [
|
|
354
|
+
...prefix,
|
|
355
|
+
"worker",
|
|
356
|
+
"exec",
|
|
357
|
+
worker,
|
|
358
|
+
"--",
|
|
359
|
+
...grant.argv
|
|
360
|
+
];
|
|
361
|
+
}
|
|
362
|
+
default: throw new AvmError("INVALID_REQUEST");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
var AvmClient = class {
|
|
366
|
+
transport;
|
|
367
|
+
policy;
|
|
368
|
+
constructor(transport, options = {}) {
|
|
369
|
+
this.transport = transport;
|
|
370
|
+
this.policy = structuredClone(options.policy ?? {});
|
|
371
|
+
this.timeoutMs = options.timeoutMs ?? 3e4;
|
|
372
|
+
if (!Number.isInteger(this.timeoutMs) || this.timeoutMs < 1 || this.timeoutMs > 3e5) throw new AvmError("INVALID_REQUEST");
|
|
373
|
+
}
|
|
374
|
+
timeoutMs;
|
|
375
|
+
async request(request, options = {}) {
|
|
376
|
+
const argv = commandArgv(request, this.policy);
|
|
377
|
+
if (options.signal?.aborted) throw new AvmError("CANCELLED");
|
|
378
|
+
const controller = new AbortController();
|
|
379
|
+
let rejectAbort = () => {};
|
|
380
|
+
const aborted = new Promise((_, reject) => {
|
|
381
|
+
rejectAbort = reject;
|
|
382
|
+
});
|
|
383
|
+
const abort = (code) => {
|
|
384
|
+
controller.abort();
|
|
385
|
+
rejectAbort(new AvmError(code));
|
|
386
|
+
};
|
|
387
|
+
const onAbort = () => abort("CANCELLED");
|
|
388
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
389
|
+
const timer = setTimeout(() => abort("TIMEOUT"), this.timeoutMs);
|
|
390
|
+
try {
|
|
391
|
+
const raw = await Promise.race([this.transport.run(argv, { signal: controller.signal }), aborted]);
|
|
392
|
+
let envelope;
|
|
393
|
+
try {
|
|
394
|
+
envelope = JSON.parse(raw.stdout);
|
|
395
|
+
} catch {
|
|
396
|
+
throw new AvmError(raw.exitCode ? "TRANSPORT" : "PROTOCOL", raw.exitCode);
|
|
397
|
+
}
|
|
398
|
+
if (!envelope || typeof envelope !== "object" || Array.isArray(envelope) || envelope.api_version !== "agentvm/v1") throw new AvmError("PROTOCOL");
|
|
399
|
+
const response = envelope;
|
|
400
|
+
if ("error" in response) throw new AvmError("REMOTE", raw.exitCode);
|
|
401
|
+
if (!("result" in response)) throw new AvmError("PROTOCOL");
|
|
402
|
+
if (request.operation === "exec") {
|
|
403
|
+
const result = response.result;
|
|
404
|
+
if (!result || typeof result !== "object" || Array.isArray(result) || !Number.isInteger(result.returncode) || typeof result.stdout !== "string" || typeof result.stderr !== "string") throw new AvmError("PROTOCOL");
|
|
405
|
+
if (result.returncode !== 0) throw new AvmError("GUEST_FAILED", result.returncode);
|
|
406
|
+
}
|
|
407
|
+
if (raw.exitCode !== 0) throw new AvmError("TRANSPORT", raw.exitCode);
|
|
408
|
+
return response.result;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (error instanceof AvmError) throw error;
|
|
411
|
+
throw new AvmError("TRANSPORT");
|
|
412
|
+
} finally {
|
|
413
|
+
clearTimeout(timer);
|
|
414
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
var SshTransport = class {
|
|
419
|
+
target;
|
|
420
|
+
mode;
|
|
421
|
+
identityFile;
|
|
422
|
+
identityTokenFile;
|
|
423
|
+
command;
|
|
424
|
+
maxOutputBytes;
|
|
425
|
+
constructor(options) {
|
|
426
|
+
if (!/^(?:[A-Za-z0-9_][A-Za-z0-9_.-]*@)?[A-Za-z0-9][A-Za-z0-9.-]*$/.test(options.target)) throw new AvmError("INVALID_REQUEST");
|
|
427
|
+
this.mode = options.mode ?? "operator";
|
|
428
|
+
if (!["operator", "paired"].includes(this.mode)) throw new AvmError("INVALID_REQUEST");
|
|
429
|
+
for (const path of [options.identityFile, options.identityTokenFile]) if (path !== void 0 && (!/^\/[A-Za-z0-9_./ -]+$/.test(path) || path.length > 4096)) throw new AvmError("INVALID_REQUEST");
|
|
430
|
+
if (this.mode === "paired" && (!options.target.startsWith("agentvm-client@") || !options.identityFile || options.sudo || options.identityTokenFile)) throw new AvmError("INVALID_REQUEST");
|
|
431
|
+
this.identityFile = options.identityFile;
|
|
432
|
+
this.identityTokenFile = options.identityTokenFile;
|
|
433
|
+
this.target = options.target;
|
|
434
|
+
this.maxOutputBytes = options.maxOutputBytes ?? 1048576;
|
|
435
|
+
if (!Number.isInteger(this.maxOutputBytes) || this.maxOutputBytes < 1024 || this.maxOutputBytes > 16777216) throw new AvmError("INVALID_REQUEST");
|
|
436
|
+
this.command = options.sudo ? `/usr/bin/python3 -c 'import json,subprocess,sys;sys.exit(subprocess.call(["sudo","-n","/usr/local/bin/avm"]+json.load(sys.stdin)))'` : `/usr/bin/python3 -c 'import json,subprocess,sys;sys.exit(subprocess.call(["/usr/local/bin/avm"]+json.load(sys.stdin)))'`;
|
|
437
|
+
}
|
|
438
|
+
run(argv, { signal }) {
|
|
439
|
+
if (signal.aborted) return Promise.reject(new AvmError("CANCELLED"));
|
|
440
|
+
if (argv.some((a) => typeof a !== "string" || a.includes("\0") || a.length > 8192)) return Promise.reject(new AvmError("INVALID_REQUEST"));
|
|
441
|
+
const remoteArgv = this.identityTokenFile ? [
|
|
442
|
+
"--identity-token-file",
|
|
443
|
+
this.identityTokenFile,
|
|
444
|
+
...argv
|
|
445
|
+
] : [...argv];
|
|
446
|
+
const quote = (value) => "'" + value.replaceAll("'", "'\"'\"'") + "'";
|
|
447
|
+
const command = this.mode === "paired" ? "exec /usr/local/bin/avm " + remoteArgv.map(quote).join(" ") : this.command;
|
|
448
|
+
return new Promise((resolve, reject) => {
|
|
449
|
+
const child = spawn("/usr/bin/ssh", [
|
|
450
|
+
...this.mode === "paired" ? ["-F", "/dev/null"] : [],
|
|
451
|
+
"-T",
|
|
452
|
+
"-o",
|
|
453
|
+
"ForwardAgent=no",
|
|
454
|
+
"-o",
|
|
455
|
+
"ClearAllForwardings=yes",
|
|
456
|
+
"-o",
|
|
457
|
+
"PermitLocalCommand=no",
|
|
458
|
+
"-o",
|
|
459
|
+
"BatchMode=yes",
|
|
460
|
+
"-o",
|
|
461
|
+
"ConnectTimeout=10",
|
|
462
|
+
"-o",
|
|
463
|
+
"StrictHostKeyChecking=yes",
|
|
464
|
+
...this.identityFile ? [
|
|
465
|
+
"-o",
|
|
466
|
+
"IdentitiesOnly=yes",
|
|
467
|
+
"-o",
|
|
468
|
+
"IdentityAgent=none",
|
|
469
|
+
"-i",
|
|
470
|
+
this.identityFile
|
|
471
|
+
] : [],
|
|
472
|
+
"--",
|
|
473
|
+
this.target,
|
|
474
|
+
command
|
|
475
|
+
], {
|
|
476
|
+
shell: false,
|
|
477
|
+
stdio: [
|
|
478
|
+
"pipe",
|
|
479
|
+
"pipe",
|
|
480
|
+
"pipe"
|
|
481
|
+
],
|
|
482
|
+
env: {
|
|
483
|
+
PATH: "/usr/bin:/bin",
|
|
484
|
+
HOME: process.env.HOME
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
const chunks = [];
|
|
488
|
+
let bytes = 0;
|
|
489
|
+
let failure;
|
|
490
|
+
const stop = () => {
|
|
491
|
+
failure ??= new AvmError("CANCELLED");
|
|
492
|
+
child.kill("SIGKILL");
|
|
493
|
+
};
|
|
494
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
495
|
+
const collect = (data, keep) => {
|
|
496
|
+
bytes += data.length;
|
|
497
|
+
if (bytes > this.maxOutputBytes) {
|
|
498
|
+
failure = new AvmError("OUTPUT_LIMIT");
|
|
499
|
+
child.kill("SIGKILL");
|
|
500
|
+
} else if (keep) chunks.push(data);
|
|
501
|
+
};
|
|
502
|
+
child.stdout.on("data", (data) => collect(data, true));
|
|
503
|
+
child.stderr.on("data", (data) => collect(data, false));
|
|
504
|
+
child.stdin.on("error", () => {});
|
|
505
|
+
child.on("error", () => {
|
|
506
|
+
signal.removeEventListener("abort", stop);
|
|
507
|
+
reject(new AvmError("TRANSPORT"));
|
|
508
|
+
});
|
|
509
|
+
child.on("close", (code) => {
|
|
510
|
+
signal.removeEventListener("abort", stop);
|
|
511
|
+
if (failure) reject(failure);
|
|
512
|
+
else resolve({
|
|
513
|
+
stdout: Buffer.concat(chunks).toString("utf8"),
|
|
514
|
+
exitCode: code ?? 255
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
child.stdin.end(this.mode === "paired" ? void 0 : JSON.stringify(remoteArgv));
|
|
518
|
+
if (signal.aborted) stop();
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
export { SshTransport as n, AvmClient as t };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { administrationSchema } from "./config.js";
|
|
2
|
+
/** Only called for an exact named operator grant, never for model-supplied flags. */
|
|
3
|
+
export function administrationArgv(value) {
|
|
4
|
+
const r = administrationSchema.parse(value);
|
|
5
|
+
const flags = (pairs) => pairs.flatMap(([k, v]) => (v === undefined ? [] : [k, String(v)]));
|
|
6
|
+
switch (r.operation) {
|
|
7
|
+
case "tenantSync":
|
|
8
|
+
return [
|
|
9
|
+
"tenant",
|
|
10
|
+
"sync",
|
|
11
|
+
r.workspace,
|
|
12
|
+
...flags([
|
|
13
|
+
["--display-name", r.displayName],
|
|
14
|
+
["--principal-id", r.principalId],
|
|
15
|
+
["--issuer", r.issuer],
|
|
16
|
+
["--subject", r.subject],
|
|
17
|
+
["--role", r.role],
|
|
18
|
+
["--weight", r.weight],
|
|
19
|
+
["--concurrent-heavy-work", r.concurrentHeavyWork],
|
|
20
|
+
["--queue-policy", r.queuePolicy],
|
|
21
|
+
]),
|
|
22
|
+
];
|
|
23
|
+
case "ingressPut":
|
|
24
|
+
return [
|
|
25
|
+
"ingress",
|
|
26
|
+
"put",
|
|
27
|
+
r.provider,
|
|
28
|
+
r.externalIdentity,
|
|
29
|
+
"--agent",
|
|
30
|
+
r.worker,
|
|
31
|
+
...flags([
|
|
32
|
+
["--channel-scope", r.channelScope],
|
|
33
|
+
["--metadata-file", r.metadataFile],
|
|
34
|
+
]),
|
|
35
|
+
];
|
|
36
|
+
case "ingressRevoke":
|
|
37
|
+
return ["ingress", "revoke", r.identityId];
|
|
38
|
+
case "ingressWake":
|
|
39
|
+
return [
|
|
40
|
+
"ingress",
|
|
41
|
+
"wake",
|
|
42
|
+
r.provider,
|
|
43
|
+
r.externalIdentity,
|
|
44
|
+
"--event-id",
|
|
45
|
+
r.eventId,
|
|
46
|
+
...flags([
|
|
47
|
+
["--channel-scope", r.channelScope],
|
|
48
|
+
["--payload-file", r.payloadFile],
|
|
49
|
+
["--correlation-id", r.correlationId],
|
|
50
|
+
]),
|
|
51
|
+
];
|
|
52
|
+
case "ingressComplete":
|
|
53
|
+
return [
|
|
54
|
+
"ingress",
|
|
55
|
+
"complete",
|
|
56
|
+
r.wakeId,
|
|
57
|
+
...flags([["--error", r.error]]),
|
|
58
|
+
];
|
|
59
|
+
case "resize":
|
|
60
|
+
return [
|
|
61
|
+
"worker",
|
|
62
|
+
"resize",
|
|
63
|
+
r.worker,
|
|
64
|
+
"--memory-target",
|
|
65
|
+
String(r.memoryTargetMiB),
|
|
66
|
+
];
|
|
67
|
+
case "workspacePut":
|
|
68
|
+
return [
|
|
69
|
+
"workspace",
|
|
70
|
+
"put",
|
|
71
|
+
r.workspace,
|
|
72
|
+
...flags([
|
|
73
|
+
["--display-name", r.displayName],
|
|
74
|
+
["--weight", r.weight],
|
|
75
|
+
["--concurrent-heavy-work", r.concurrentHeavyWork],
|
|
76
|
+
["--queue-policy", r.queuePolicy],
|
|
77
|
+
]),
|
|
78
|
+
];
|
|
79
|
+
case "workspaceDisable":
|
|
80
|
+
return ["workspace", "disable", r.workspace];
|
|
81
|
+
case "userPut":
|
|
82
|
+
return [
|
|
83
|
+
"user",
|
|
84
|
+
"put",
|
|
85
|
+
r.user,
|
|
86
|
+
"--workspace",
|
|
87
|
+
r.workspace,
|
|
88
|
+
"--role",
|
|
89
|
+
r.role,
|
|
90
|
+
];
|
|
91
|
+
case "ownerSet":
|
|
92
|
+
return [
|
|
93
|
+
"agent",
|
|
94
|
+
"owner",
|
|
95
|
+
"set",
|
|
96
|
+
r.worker,
|
|
97
|
+
"--workspace",
|
|
98
|
+
r.workspace,
|
|
99
|
+
...flags([["--user", r.user]]),
|
|
100
|
+
];
|
|
101
|
+
case "shareGrant":
|
|
102
|
+
return [
|
|
103
|
+
"agent",
|
|
104
|
+
"share",
|
|
105
|
+
"grant",
|
|
106
|
+
r.worker,
|
|
107
|
+
r.grantee.kind === "workspace" ? "--tenant" : "--principal",
|
|
108
|
+
r.grantee.id,
|
|
109
|
+
...r.allow.flatMap((a) => ["--allow", a]),
|
|
110
|
+
];
|
|
111
|
+
case "shareRevoke":
|
|
112
|
+
return ["agent", "share", "revoke", r.worker, r.shareId];
|
|
113
|
+
case "residentSet":
|
|
114
|
+
return ["agent", "resident", "set", r.worker];
|
|
115
|
+
case "wake":
|
|
116
|
+
return [
|
|
117
|
+
"agent",
|
|
118
|
+
"wake",
|
|
119
|
+
r.worker,
|
|
120
|
+
"--source",
|
|
121
|
+
r.source,
|
|
122
|
+
"--idempotency-key",
|
|
123
|
+
r.idempotencyKey,
|
|
124
|
+
...flags([
|
|
125
|
+
["--reason", r.reason],
|
|
126
|
+
["--external-event-id", r.externalEventId],
|
|
127
|
+
]),
|
|
128
|
+
];
|
|
129
|
+
case "cool":
|
|
130
|
+
return ["agent", "cool", r.worker];
|
|
131
|
+
case "poolPolicySet":
|
|
132
|
+
return [
|
|
133
|
+
"pool",
|
|
134
|
+
"policy",
|
|
135
|
+
"set",
|
|
136
|
+
...flags([
|
|
137
|
+
["--cpu-percent", r.cpuPercent],
|
|
138
|
+
["--memory-max-bytes", r.memoryMaxBytes],
|
|
139
|
+
["--memory-high-bytes", r.memoryHighBytes],
|
|
140
|
+
["--host-memory-reserve-bytes", r.hostMemoryReserveBytes],
|
|
141
|
+
["--launch-reserve-bytes", r.launchReserveBytes],
|
|
142
|
+
]),
|
|
143
|
+
];
|
|
144
|
+
}
|
|
145
|
+
}
|