@hallohuman/hightea 0.1.17 → 0.1.30
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/bin.js +171 -64
- package/dist/chunk-0r70ekxd.js +8 -0
- package/dist/chunk-13tpn1g6.js +465 -0
- package/dist/chunk-3rgfnt23.js +16 -0
- package/dist/{chunk-rs0vvh3x.js → chunk-9e325ntw.js} +15 -4
- package/dist/{chunk-3ah56pdt.js → chunk-cx3yvvkz.js} +174 -207
- package/dist/{chunk-h5s3wwdz.js → chunk-dvnzt54t.js} +1126 -2001
- package/dist/chunk-dvt4hb8z.js +1491 -0
- package/dist/chunk-gk8tyqac.js +184 -0
- package/dist/chunk-h8pdqn31.js +157 -0
- package/dist/{chunk-1xykqbdm.js → chunk-ph04jess.js} +5 -2
- package/dist/chunk-w0ebwtch.js +161 -0
- package/dist/{chunk-6ae0ftqh.js → chunk-y5r2yxx1.js} +1 -1
- package/dist/plugin/plugin.json +8 -1
- package/dist/plugin/plugin.mjs +2179 -627
- package/package.json +8 -5
- package/dist/chunk-hxs6jv2m.js +0 -91
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sourceOf,
|
|
3
|
+
preview,
|
|
4
|
+
applyPreview,
|
|
5
|
+
describe,
|
|
6
|
+
connectAhp
|
|
7
|
+
} from "./chunk-13tpn1g6.js";
|
|
8
|
+
import"./chunk-0ab6h39c.js";
|
|
9
|
+
import {
|
|
10
|
+
ownerIo,
|
|
11
|
+
sendOwner
|
|
12
|
+
} from "./chunk-sbqmqp8e.js";
|
|
1
13
|
import { createRequire } from "node:module";
|
|
2
14
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
3
15
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
@@ -6910,165 +6922,6 @@ import { readFile } from "node:fs/promises";
|
|
|
6910
6922
|
import { basename, dirname, extname, resolve } from "node:path";
|
|
6911
6923
|
import { pathToFileURL } from "node:url";
|
|
6912
6924
|
|
|
6913
|
-
// ../client/src/index.ts
|
|
6914
|
-
var sourceOf = (kind, id) => ({ kind, id });
|
|
6915
|
-
var sameSource = (a, b) => a !== undefined && b !== undefined && a.kind === b.kind && a.id === b.id;
|
|
6916
|
-
var sourceText = (source) => `${source.kind}:${source.id}`;
|
|
6917
|
-
var neutralFields = ["command", "cwd", "env", "schedule", "restart", "dependsOn", "healthCheck"];
|
|
6918
|
-
var fieldsOf = (service) => ({
|
|
6919
|
-
command: service.command,
|
|
6920
|
-
cwd: service.cwd,
|
|
6921
|
-
env: service.env,
|
|
6922
|
-
schedule: service.schedule,
|
|
6923
|
-
restart: service.restart,
|
|
6924
|
-
dependsOn: service.dependsOn,
|
|
6925
|
-
healthCheck: service.healthCheck
|
|
6926
|
-
});
|
|
6927
|
-
var canonical = (value) => {
|
|
6928
|
-
if (value === undefined)
|
|
6929
|
-
return "undefined";
|
|
6930
|
-
if (Array.isArray(value))
|
|
6931
|
-
return `[${value.map(canonical).join(",")}]`;
|
|
6932
|
-
if (value !== null && typeof value === "object") {
|
|
6933
|
-
const keys = Object.keys(value).sort();
|
|
6934
|
-
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(value[k])}`).join(",")}}`;
|
|
6935
|
-
}
|
|
6936
|
-
return JSON.stringify(value);
|
|
6937
|
-
};
|
|
6938
|
-
var changedFields = (before, after) => {
|
|
6939
|
-
const a = fieldsOf(before);
|
|
6940
|
-
const b = fieldsOf(after);
|
|
6941
|
-
return neutralFields.filter((field) => canonical(a[field]) !== canonical(b[field]));
|
|
6942
|
-
};
|
|
6943
|
-
var SERVICES_CHANNEL = "x-hh-services://";
|
|
6944
|
-
var operate = (host, operationId, rest) => host.call("x-ahpd/invokeOperation", { channel: SERVICES_CHANNEL, operationId, ...rest });
|
|
6945
|
-
var listOf = async (host) => {
|
|
6946
|
-
const answer = await host.call("subscribe", { channel: SERVICES_CHANNEL });
|
|
6947
|
-
await host.call("unsubscribe", { channel: SERVICES_CHANNEL });
|
|
6948
|
-
const state = answer?.snapshot?.state;
|
|
6949
|
-
if (typeof state?.error === "string")
|
|
6950
|
-
throw new Error(`the machine's services could not be read: ${state.error}`);
|
|
6951
|
-
if (state === undefined || !Array.isArray(state.rows))
|
|
6952
|
-
throw new Error("the services channel answered no rows");
|
|
6953
|
-
const rows = state.rows;
|
|
6954
|
-
return {
|
|
6955
|
-
services: rows.flatMap((row) => row.record === undefined ? [] : [row.record]),
|
|
6956
|
-
readOnly: rows.flatMap((row) => row.readOnly === undefined ? [] : [{ name: row.name, reason: row.readOnly }]),
|
|
6957
|
-
capabilities: state.capabilities,
|
|
6958
|
-
ifVersion: state.ifVersion,
|
|
6959
|
-
...typeof state.file === "string" ? { file: state.file } : {}
|
|
6960
|
-
};
|
|
6961
|
-
};
|
|
6962
|
-
async function preview(plan, host, options) {
|
|
6963
|
-
refuseUncarried(plan);
|
|
6964
|
-
const current = await listOf(host);
|
|
6965
|
-
const byName = new Map(current.services.map((service) => [service.name, service]));
|
|
6966
|
-
const readOnly = new Map(current.readOnly.map((entry) => [entry.name, entry.reason]));
|
|
6967
|
-
const create = [];
|
|
6968
|
-
const change = [];
|
|
6969
|
-
const unchanged = [];
|
|
6970
|
-
const planned = new Set;
|
|
6971
|
-
for (const service of plan.services ?? []) {
|
|
6972
|
-
planned.add(service.name);
|
|
6973
|
-
const before = byName.get(service.name);
|
|
6974
|
-
if (readOnly.has(service.name)) {
|
|
6975
|
-
throw new Error(`${service.name} is read-only on this machine: ${readOnly.get(service.name) ?? ""}`);
|
|
6976
|
-
}
|
|
6977
|
-
if (before === undefined) {
|
|
6978
|
-
create.push(service);
|
|
6979
|
-
} else {
|
|
6980
|
-
const changed = changedFields(before, service);
|
|
6981
|
-
if (changed.length === 0)
|
|
6982
|
-
unchanged.push(service.name);
|
|
6983
|
-
else
|
|
6984
|
-
change.push({ name: service.name, before, after: service, changed });
|
|
6985
|
-
}
|
|
6986
|
-
}
|
|
6987
|
-
const remove = options.prune === true ? current.services.filter((service) => sameSource(service.source, options.source) && !planned.has(service.name)) : [];
|
|
6988
|
-
return { ifVersion: current.ifVersion, create, change, unchanged, readOnly: current.readOnly, remove };
|
|
6989
|
-
}
|
|
6990
|
-
function refuseUncarried(plan) {
|
|
6991
|
-
if ((plan.hosts?.length ?? 0) > 0) {
|
|
6992
|
-
throw new Error("this client does not carry host entries yet; host writes are not part of the services methods");
|
|
6993
|
-
}
|
|
6994
|
-
if ((plan.agents?.length ?? 0) > 0) {
|
|
6995
|
-
throw new Error("this client does not carry agent entries yet; agent records are edited by their own client");
|
|
6996
|
-
}
|
|
6997
|
-
}
|
|
6998
|
-
async function applyPreview(shown, host) {
|
|
6999
|
-
let ifVersion = shown.ifVersion;
|
|
7000
|
-
const written = [];
|
|
7001
|
-
for (const service of shown.create) {
|
|
7002
|
-
const answer = await operate(host, "put", { input: { service, ifVersion: "absent" } });
|
|
7003
|
-
ifVersion = answer.ifVersion ?? ifVersion;
|
|
7004
|
-
written.push(service.name);
|
|
7005
|
-
}
|
|
7006
|
-
for (const entry of shown.change) {
|
|
7007
|
-
const answer = await operate(host, "put", { input: { service: entry.after, ifVersion } });
|
|
7008
|
-
ifVersion = answer.ifVersion ?? ifVersion;
|
|
7009
|
-
written.push(entry.name);
|
|
7010
|
-
}
|
|
7011
|
-
const removed = [];
|
|
7012
|
-
for (const entry of shown.remove) {
|
|
7013
|
-
const answer = await operate(host, "remove", { target: { id: entry.name }, input: { ifVersion } });
|
|
7014
|
-
ifVersion = answer.ifVersion ?? ifVersion;
|
|
7015
|
-
removed.push(entry.name);
|
|
7016
|
-
}
|
|
7017
|
-
return { preview: shown, written, removed };
|
|
7018
|
-
}
|
|
7019
|
-
function describe(preview) {
|
|
7020
|
-
const lines = [];
|
|
7021
|
-
for (const service of preview.create)
|
|
7022
|
-
lines.push(`+ ${service.name}`);
|
|
7023
|
-
for (const change of preview.change)
|
|
7024
|
-
lines.push(`~ ${change.name} (${change.changed.join(", ")})`);
|
|
7025
|
-
for (const service of preview.remove)
|
|
7026
|
-
lines.push(`- ${service.name} (source ${sourceText(service.source)})`);
|
|
7027
|
-
for (const name of preview.unchanged)
|
|
7028
|
-
lines.push(`= ${name}`);
|
|
7029
|
-
for (const entry of preview.readOnly)
|
|
7030
|
-
lines.push(`! ${entry.name} read-only: ${entry.reason}`);
|
|
7031
|
-
return lines;
|
|
7032
|
-
}
|
|
7033
|
-
|
|
7034
|
-
// ../client/src/ahp.ts
|
|
7035
|
-
import WebSocket from "ws";
|
|
7036
|
-
async function connectAhp(url, options) {
|
|
7037
|
-
const endpoint = options.token === undefined ? url : `${url}${url.includes("?") ? "&" : "?"}tkn=${encodeURIComponent(options.token)}`;
|
|
7038
|
-
const ws = new WebSocket(endpoint);
|
|
7039
|
-
const waiting = new Map;
|
|
7040
|
-
let closed;
|
|
7041
|
-
let nextId = 0;
|
|
7042
|
-
ws.on("message", (data) => {
|
|
7043
|
-
const frame = JSON.parse(String(data));
|
|
7044
|
-
if (frame.id !== undefined && frame.method === undefined)
|
|
7045
|
-
waiting.get(frame.id)?.(frame);
|
|
7046
|
-
});
|
|
7047
|
-
ws.on("close", (code, reason) => {
|
|
7048
|
-
closed = `${String(code)} ${reason.toString()}`;
|
|
7049
|
-
for (const resolve of waiting.values())
|
|
7050
|
-
resolve({ error: { code: 0, message: `closed: ${closed}` } });
|
|
7051
|
-
});
|
|
7052
|
-
await new Promise((resolve, reject) => {
|
|
7053
|
-
ws.once("open", () => resolve());
|
|
7054
|
-
ws.once("error", (error) => reject(error));
|
|
7055
|
-
});
|
|
7056
|
-
const call = (method, params) => new Promise((resolve, reject) => {
|
|
7057
|
-
if (closed !== undefined)
|
|
7058
|
-
return reject(new Error(`the machine's connection closed: ${closed}`));
|
|
7059
|
-
const id = ++nextId;
|
|
7060
|
-
waiting.set(id, (frame) => {
|
|
7061
|
-
if (frame.error !== undefined)
|
|
7062
|
-
reject(new Error(frame.error.message));
|
|
7063
|
-
else
|
|
7064
|
-
resolve(frame.result);
|
|
7065
|
-
});
|
|
7066
|
-
ws.send(JSON.stringify({ jsonrpc: "2.0", id, method, params }));
|
|
7067
|
-
});
|
|
7068
|
-
await call("initialize", { channel: "ahp-root://", protocolVersions: ["1.1.0"], clientId: options.clientId });
|
|
7069
|
-
return { call, close: () => ws.close() };
|
|
7070
|
-
}
|
|
7071
|
-
|
|
7072
6925
|
// ../../node_modules/.bun/yaml@2.8.1/node_modules/yaml/dist/index.js
|
|
7073
6926
|
var composer = require_composer();
|
|
7074
6927
|
var Document = require_Document();
|
|
@@ -7116,18 +6969,20 @@ var $visit = visit.visit;
|
|
|
7116
6969
|
var $visitAsync = visit.visitAsync;
|
|
7117
6970
|
|
|
7118
6971
|
// ../client/src/native.ts
|
|
7119
|
-
var
|
|
7120
|
-
|
|
6972
|
+
var DEPENDENCY_CONDITIONS = [
|
|
6973
|
+
"process_started",
|
|
6974
|
+
"process_healthy",
|
|
6975
|
+
"process_completed",
|
|
6976
|
+
"process_completed_successfully",
|
|
6977
|
+
"process_log_ready"
|
|
6978
|
+
];
|
|
6979
|
+
var RESTART_POLICIES = ["always", "on_failure", "exit_on_failure", "no"];
|
|
6980
|
+
var shellWord = (word) => /^[A-Za-z0-9_@%+=:,./-]+$/u.test(word) ? word : `'${word.replaceAll("'", "'\\''")}'`;
|
|
6981
|
+
var commandOf = (name, command) => {
|
|
6982
|
+
if (typeof command === "string" && command.trim() !== "")
|
|
7121
6983
|
return command;
|
|
7122
|
-
if (
|
|
7123
|
-
|
|
7124
|
-
throw new Error(`${name}: the command quotes arguments; write it as a list so no shell parsing is guessed`);
|
|
7125
|
-
}
|
|
7126
|
-
const parts = command.trim().split(/\s+/);
|
|
7127
|
-
if (parts.some((part) => /[$`|&;<>()*?~\\]/.test(part))) {
|
|
7128
|
-
throw new Error(`${name}: the command uses shell syntax; write it as a list, or keep it in a shell script`);
|
|
7129
|
-
}
|
|
7130
|
-
return parts;
|
|
6984
|
+
if (Array.isArray(command) && command.length > 0 && command.every((part) => typeof part === "string")) {
|
|
6985
|
+
return command.map(shellWord).join(" ");
|
|
7131
6986
|
}
|
|
7132
6987
|
throw new Error(`${name}: no command`);
|
|
7133
6988
|
};
|
|
@@ -7163,7 +7018,7 @@ var scheduleOf = (entry) => {
|
|
|
7163
7018
|
...cron !== undefined ? { cron } : {},
|
|
7164
7019
|
...interval !== undefined ? { interval } : {},
|
|
7165
7020
|
...timezone !== undefined ? { timezone } : {},
|
|
7166
|
-
...runOnStart !== undefined ? { runOnStart } : {}
|
|
7021
|
+
...runOnStart !== undefined ? { run_on_start: runOnStart } : {}
|
|
7167
7022
|
};
|
|
7168
7023
|
};
|
|
7169
7024
|
var restartOf = (name, entry) => {
|
|
@@ -7172,26 +7027,43 @@ var restartOf = (name, entry) => {
|
|
|
7172
7027
|
return;
|
|
7173
7028
|
const map = raw !== null && typeof raw === "object" ? raw : undefined;
|
|
7174
7029
|
const policy = map === undefined ? raw : map.policy;
|
|
7175
|
-
if (
|
|
7176
|
-
throw new Error(`${name}: restart policy ${JSON.stringify(policy)} is not one of
|
|
7030
|
+
if (typeof policy !== "string" || !RESTART_POLICIES.includes(policy)) {
|
|
7031
|
+
throw new Error(`${name}: restart policy ${JSON.stringify(policy)} is not one of ${RESTART_POLICIES.join(", ")}`);
|
|
7177
7032
|
}
|
|
7178
7033
|
const backoff = map !== undefined && typeof map.backoff_seconds === "number" ? map.backoff_seconds : undefined;
|
|
7179
7034
|
const maxRestarts = map !== undefined && typeof map.max_restarts === "number" ? map.max_restarts : undefined;
|
|
7180
7035
|
return {
|
|
7181
7036
|
policy,
|
|
7182
|
-
...backoff !== undefined ? { backoff } : {},
|
|
7183
|
-
...maxRestarts !== undefined ? { maxRestarts } : {}
|
|
7037
|
+
...backoff !== undefined ? { backoff_seconds: backoff } : {},
|
|
7038
|
+
...maxRestarts !== undefined ? { max_restarts: maxRestarts } : {}
|
|
7184
7039
|
};
|
|
7185
7040
|
};
|
|
7186
|
-
var dependsOf = (entry) => {
|
|
7041
|
+
var dependsOf = (name, entry) => {
|
|
7187
7042
|
const raw = entry.depends_on;
|
|
7188
7043
|
if (raw === undefined)
|
|
7189
7044
|
return;
|
|
7190
|
-
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7045
|
+
const dependency = (service, condition) => {
|
|
7046
|
+
if (condition === undefined)
|
|
7047
|
+
return { name: service, condition: "process_started" };
|
|
7048
|
+
if (typeof condition !== "string" || !DEPENDENCY_CONDITIONS.includes(condition)) {
|
|
7049
|
+
throw new Error(`${name}: depends_on ${service} condition ${JSON.stringify(condition)} is not one of ${DEPENDENCY_CONDITIONS.join(", ")}`);
|
|
7050
|
+
}
|
|
7051
|
+
return { name: service, condition };
|
|
7052
|
+
};
|
|
7053
|
+
if (Array.isArray(raw)) {
|
|
7054
|
+
return raw.map((service) => {
|
|
7055
|
+
if (typeof service !== "string")
|
|
7056
|
+
throw new Error(`${name}: depends_on must name services`);
|
|
7057
|
+
return dependency(service, undefined);
|
|
7058
|
+
});
|
|
7059
|
+
}
|
|
7060
|
+
if (raw !== null && typeof raw === "object") {
|
|
7061
|
+
return Object.entries(raw).map(([service, value]) => {
|
|
7062
|
+
const condition = value !== null && typeof value === "object" ? value.condition : undefined;
|
|
7063
|
+
return dependency(service, condition);
|
|
7064
|
+
});
|
|
7065
|
+
}
|
|
7066
|
+
throw new Error(`${name}: depends_on must be a list or a map`);
|
|
7195
7067
|
};
|
|
7196
7068
|
var healthOf = (name, entry) => {
|
|
7197
7069
|
const probe = entry.readiness_probe ?? entry.liveness_probe;
|
|
@@ -7201,14 +7073,72 @@ var healthOf = (name, entry) => {
|
|
|
7201
7073
|
throw new Error(`${name}: the health probe must be a map`);
|
|
7202
7074
|
const map = probe;
|
|
7203
7075
|
if (map.exec?.command !== undefined)
|
|
7204
|
-
return { exec:
|
|
7076
|
+
return { exec: commandOf(`${name} health`, map.exec.command) };
|
|
7205
7077
|
const http = map.http_get;
|
|
7206
7078
|
if (http !== undefined && typeof http.path === "string" && typeof http.port === "number") {
|
|
7207
|
-
const host = typeof http.host === "string" ? http.host :
|
|
7208
|
-
|
|
7079
|
+
const host = typeof http.host === "string" ? http.host : undefined;
|
|
7080
|
+
const scheme = http.scheme === "https" || http.scheme === "http" ? http.scheme : undefined;
|
|
7081
|
+
return { http: { port: http.port, ...host !== undefined ? { host } : {}, path: http.path, ...scheme !== undefined ? { scheme } : {} } };
|
|
7209
7082
|
}
|
|
7210
7083
|
throw new Error(`${name}: the health probe is neither exec.command nor http_get with path and port`);
|
|
7211
7084
|
};
|
|
7085
|
+
var NATIVE_MAP = [
|
|
7086
|
+
{ keys: ["command"], to: ["command"], read: (name, entry) => ({ command: commandOf(name, entry.command) }) },
|
|
7087
|
+
{
|
|
7088
|
+
keys: ["working_dir"],
|
|
7089
|
+
to: ["cwd"],
|
|
7090
|
+
read: (_name, entry) => typeof entry.working_dir === "string" ? { cwd: entry.working_dir } : {}
|
|
7091
|
+
},
|
|
7092
|
+
{
|
|
7093
|
+
keys: ["environment"],
|
|
7094
|
+
to: ["env"],
|
|
7095
|
+
read: (name, entry) => {
|
|
7096
|
+
const env = envOf(name, entry.environment);
|
|
7097
|
+
return env === undefined ? {} : { env };
|
|
7098
|
+
}
|
|
7099
|
+
},
|
|
7100
|
+
{
|
|
7101
|
+
keys: ["schedule", "cron", "interval", "timezone", "run_on_start"],
|
|
7102
|
+
to: ["schedule"],
|
|
7103
|
+
read: (_name, entry) => {
|
|
7104
|
+
const schedule = scheduleOf(entry);
|
|
7105
|
+
return schedule === undefined ? {} : { schedule };
|
|
7106
|
+
}
|
|
7107
|
+
},
|
|
7108
|
+
{
|
|
7109
|
+
keys: ["restart", "restart_policy"],
|
|
7110
|
+
to: ["restart"],
|
|
7111
|
+
read: (name, entry) => {
|
|
7112
|
+
const restart = restartOf(name, entry);
|
|
7113
|
+
return restart === undefined ? {} : { restart };
|
|
7114
|
+
}
|
|
7115
|
+
},
|
|
7116
|
+
{
|
|
7117
|
+
keys: ["depends_on"],
|
|
7118
|
+
to: ["depends_on"],
|
|
7119
|
+
read: (name, entry) => {
|
|
7120
|
+
const depends_on = dependsOf(name, entry);
|
|
7121
|
+
return depends_on === undefined ? {} : { depends_on };
|
|
7122
|
+
}
|
|
7123
|
+
},
|
|
7124
|
+
{
|
|
7125
|
+
keys: ["readiness_probe", "liveness_probe"],
|
|
7126
|
+
to: ["health"],
|
|
7127
|
+
read: (name, entry) => {
|
|
7128
|
+
const health = healthOf(name, entry);
|
|
7129
|
+
return health === undefined ? {} : { health };
|
|
7130
|
+
}
|
|
7131
|
+
}
|
|
7132
|
+
];
|
|
7133
|
+
var NATIVE_KEYS = new Set(NATIVE_MAP.flatMap((row) => row.keys));
|
|
7134
|
+
function neutralOf(name, entry) {
|
|
7135
|
+
for (const key of Object.keys(entry)) {
|
|
7136
|
+
if (!NATIVE_KEYS.has(key)) {
|
|
7137
|
+
throw new Error(`${name}: ${key} is not a field this client carries, and the driver's record cannot hold it (carried: ${[...NATIVE_KEYS].join(", ")})`);
|
|
7138
|
+
}
|
|
7139
|
+
}
|
|
7140
|
+
return Object.assign({}, ...NATIVE_MAP.map((row) => row.read(name, entry)));
|
|
7141
|
+
}
|
|
7212
7142
|
function readNativeFile(file, source) {
|
|
7213
7143
|
let document;
|
|
7214
7144
|
try {
|
|
@@ -7231,22 +7161,7 @@ function readNativeFile(file, source) {
|
|
|
7231
7161
|
if (entry.extends !== undefined) {
|
|
7232
7162
|
throw new Error(`${name}: extends is not representable; the machine lists it read-only`);
|
|
7233
7163
|
}
|
|
7234
|
-
|
|
7235
|
-
const schedule = scheduleOf(entry);
|
|
7236
|
-
const restart = restartOf(name, entry);
|
|
7237
|
-
const dependsOn = dependsOf(entry);
|
|
7238
|
-
const healthCheck = healthOf(name, entry);
|
|
7239
|
-
services.push({
|
|
7240
|
-
name,
|
|
7241
|
-
command: argvOf(name, entry.command),
|
|
7242
|
-
source,
|
|
7243
|
-
...typeof entry.working_dir === "string" ? { cwd: entry.working_dir } : {},
|
|
7244
|
-
...env !== undefined ? { env } : {},
|
|
7245
|
-
...schedule !== undefined ? { schedule } : {},
|
|
7246
|
-
...restart !== undefined ? { restart } : {},
|
|
7247
|
-
...dependsOn !== undefined ? { dependsOn } : {},
|
|
7248
|
-
...healthCheck !== undefined ? { healthCheck } : {}
|
|
7249
|
-
});
|
|
7164
|
+
services.push({ name, source, ...neutralOf(name, entry) });
|
|
7250
7165
|
}
|
|
7251
7166
|
if (services.length === 0)
|
|
7252
7167
|
throw new Error(`${file.path}: processes is empty; nothing to apply`);
|
|
@@ -7280,6 +7195,40 @@ async function sourceAt(path) {
|
|
|
7280
7195
|
}
|
|
7281
7196
|
return sourceOf("file", `${path}@${commit}`);
|
|
7282
7197
|
}
|
|
7198
|
+
function hostJoinSurface(flags) {
|
|
7199
|
+
if (flags.origin.trim().length === 0 || flags.workspace.trim().length === 0)
|
|
7200
|
+
return;
|
|
7201
|
+
const target = {
|
|
7202
|
+
origin: flags.origin.trim(),
|
|
7203
|
+
workspace: flags.workspace.trim(),
|
|
7204
|
+
sessionFile: flags.sessionFile,
|
|
7205
|
+
json: flags.json
|
|
7206
|
+
};
|
|
7207
|
+
const io = ownerIo();
|
|
7208
|
+
return {
|
|
7209
|
+
async mintHostJoin(agentMemberIds) {
|
|
7210
|
+
const sent = await sendOwner(target, io, {
|
|
7211
|
+
method: "POST",
|
|
7212
|
+
path: "/join-links",
|
|
7213
|
+
body: { purpose: "host", agentMemberIds: [...agentMemberIds] },
|
|
7214
|
+
what: "mint a host join link",
|
|
7215
|
+
label: "HOST_JOIN"
|
|
7216
|
+
});
|
|
7217
|
+
if ("error" in sent)
|
|
7218
|
+
throw new Error(sent.error);
|
|
7219
|
+
const made = sent.answer;
|
|
7220
|
+
if (typeof made.id !== "string" || typeof made.code !== "string" || typeof made.expiresAt !== "string") {
|
|
7221
|
+
throw new Error(`HOST_JOIN_ANSWER_INVALID: the workspace minted a link without id, code and expiresAt (${JSON.stringify(sent.answer).slice(0, 300)})`);
|
|
7222
|
+
}
|
|
7223
|
+
return {
|
|
7224
|
+
id: made.id,
|
|
7225
|
+
code: made.code,
|
|
7226
|
+
url: typeof made.url === "string" ? made.url : "",
|
|
7227
|
+
expiresAt: made.expiresAt
|
|
7228
|
+
};
|
|
7229
|
+
}
|
|
7230
|
+
};
|
|
7231
|
+
}
|
|
7283
7232
|
var print = (flags, shown, source) => {
|
|
7284
7233
|
if (flags.json) {
|
|
7285
7234
|
console.log(JSON.stringify(shown, null, 2));
|
|
@@ -7288,32 +7237,50 @@ var print = (flags, shown, source) => {
|
|
|
7288
7237
|
console.log(`machine ${flags.machine}; source ${source.kind}:${source.id}`);
|
|
7289
7238
|
for (const line of describe(shown))
|
|
7290
7239
|
console.log(line);
|
|
7291
|
-
|
|
7240
|
+
const agents = shown.agents;
|
|
7241
|
+
const changes = shown.create.length + shown.change.length + shown.remove.length + (agents === undefined ? 0 : agents.create.length + agents.change.length + agents.remove.length) + (shown.hosts?.pending.length ?? 0);
|
|
7242
|
+
if (changes === 0)
|
|
7292
7243
|
console.log("nothing to do");
|
|
7293
7244
|
};
|
|
7294
7245
|
async function applyFile(fileArgument, flags) {
|
|
7295
7246
|
let host;
|
|
7296
7247
|
try {
|
|
7297
|
-
if (flags.
|
|
7298
|
-
throw new Error("--
|
|
7248
|
+
if (flags.stop && flags.keep)
|
|
7249
|
+
throw new Error("--stop and --keep answer the same question differently; pass one");
|
|
7299
7250
|
const path = resolve(fileArgument);
|
|
7300
7251
|
const source = await sourceAt(path);
|
|
7301
7252
|
const plan = await planAt(path, source);
|
|
7302
|
-
|
|
7303
|
-
|
|
7253
|
+
const namedMachineEntries = plan.services !== undefined || plan.agents !== undefined;
|
|
7254
|
+
if (namedMachineEntries && flags.machine.length === 0)
|
|
7255
|
+
throw new Error("--machine <url> is required: the machine's ahpd WebSocket endpoint");
|
|
7256
|
+
if (flags.machine.length > 0)
|
|
7257
|
+
host = await connectAhp(flags.machine, { token: flags.token, clientId: "hightea-apply" });
|
|
7258
|
+
const machine = host ?? { call: async () => {
|
|
7259
|
+
throw new Error("this plan names no services or agents, so no ahpd channel is read");
|
|
7260
|
+
} };
|
|
7261
|
+
const removal = flags.stop ? "stop" : flags.keep ? "keep" : undefined;
|
|
7262
|
+
const hostJoin = hostJoinSurface(flags);
|
|
7263
|
+
const shown = await preview(plan, machine, { source, prune: flags.prune, ...removal === undefined ? {} : { removal }, ...hostJoin === undefined ? {} : { hostJoin } });
|
|
7304
7264
|
print(flags, shown, source);
|
|
7305
7265
|
if (!flags.yes) {
|
|
7306
7266
|
if (!flags.json)
|
|
7307
7267
|
console.log("nothing sent; run again with --yes to apply");
|
|
7308
7268
|
return 0;
|
|
7309
7269
|
}
|
|
7310
|
-
const result = await applyPreview(shown,
|
|
7270
|
+
const result = await applyPreview(shown, machine, hostJoin);
|
|
7311
7271
|
if (flags.json) {
|
|
7312
7272
|
console.log(JSON.stringify(result, null, 2));
|
|
7313
7273
|
} else {
|
|
7314
7274
|
const wrote = result.written.length === 0 ? "nothing" : result.written.join(", ");
|
|
7315
7275
|
const removed = result.removed.length === 0 ? "nothing" : result.removed.join(", ");
|
|
7316
|
-
|
|
7276
|
+
const kept = result.kept.length === 0 ? "" : `; kept ${result.kept.join(", ")}`;
|
|
7277
|
+
const links = result.hostLinks === undefined || result.hostLinks.length === 0 ? "" : `; minted ${result.hostLinks.length} host ${result.hostLinks.length === 1 ? "link" : "links"}`;
|
|
7278
|
+
console.log(`wrote ${wrote}; removed ${removed}${kept}${links}`);
|
|
7279
|
+
if (result.hostNote !== undefined)
|
|
7280
|
+
console.log(`note: ${result.hostNote}`);
|
|
7281
|
+
for (const entry of result.hostLinks ?? []) {
|
|
7282
|
+
console.log(`host ${entry.name}: join with ${entry.link.url || entry.link.code} (single use; expires ${entry.link.expiresAt})`);
|
|
7283
|
+
}
|
|
7317
7284
|
}
|
|
7318
7285
|
return 0;
|
|
7319
7286
|
} catch (error) {
|