@hallohuman/hightea 0.1.13 → 0.1.15
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 +16 -16
- package/dist/{chunk-pk0ntfzc.js → chunk-1xykqbdm.js} +1 -1
- package/dist/{chunk-1kzh6qrv.js → chunk-3ah56pdt.js} +20 -5
- package/dist/{chunk-n6qgzk8y.js → chunk-6ae0ftqh.js} +2 -2
- package/dist/{chunk-hqjkbadp.js → chunk-h5s3wwdz.js} +16 -14
- package/dist/{chunk-f5kk24rj.js → chunk-hxs6jv2m.js} +1 -1
- package/dist/plugin/plugin.json +1 -1
- package/dist/plugin/plugin.mjs +128 -27
- package/package.json +7 -7
package/dist/bin.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from "node:url";
|
|
|
5
5
|
// package.json
|
|
6
6
|
var package_default = {
|
|
7
7
|
name: "@hallohuman/hightea",
|
|
8
|
-
version: "0.1.
|
|
8
|
+
version: "0.1.15",
|
|
9
9
|
description: "The Hightea command line: join this machine to a Hightea workspace as a host.",
|
|
10
10
|
publishConfig: {
|
|
11
11
|
access: "public"
|
|
@@ -25,10 +25,10 @@ var package_default = {
|
|
|
25
25
|
prepack: "bun run build"
|
|
26
26
|
},
|
|
27
27
|
dependencies: {
|
|
28
|
-
"@ahpd/deploy": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
29
|
-
"@ahpd/sdk": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
30
|
-
"@ahpd/server": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
31
|
-
"@
|
|
28
|
+
"@ahpd/deploy": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-deploy-0.15.0-beorn.3a159188.tgz",
|
|
29
|
+
"@ahpd/sdk": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-sdk-0.15.0-beorn.3a159188.tgz",
|
|
30
|
+
"@ahpd/server": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-server-0.15.0-beorn.3a159188.tgz",
|
|
31
|
+
"@hallohuman/hightea-services": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/hallohuman-hightea-services-0.16.0-beorn.3a159188.tgz",
|
|
32
32
|
"@silvery/commander": "0.29.3",
|
|
33
33
|
ws: "8.21.0"
|
|
34
34
|
},
|
|
@@ -45,7 +45,7 @@ async function runCli(argv, options) {
|
|
|
45
45
|
const program = new Command("hightea").description("Hightea: join this machine to a Hightea workspace as a host for your own agents.").version(options.version, "-v, --version").exitOverride();
|
|
46
46
|
program.command("apply <file>").description("Apply a native process-compose file, or a TypeScript program that returns a plan, to one machine's ahpd: preview first, write only with --yes.").option("--machine <url>", "The machine's ahpd WebSocket endpoint, e.g. ws://127.0.0.1:7777").option("--token <token>", "The machine's token for this client (default: AHP_TKN)").option("--yes", "Send the previewed changes; without it nothing is sent").option("--prune", "After the preview lists them, remove entries this same source created that the plan no longer carries").option("--json", "Print one JSON document").addHelpText("after", `
|
|
47
47
|
Exit status: 0 previewed or applied; 1 the machine refused the plan or could not be reached.`).exitOverride().action(async (file, flags) => {
|
|
48
|
-
const { applyFile } = await import("./chunk-
|
|
48
|
+
const { applyFile } = await import("./chunk-3ah56pdt.js");
|
|
49
49
|
code = await applyFile(file, {
|
|
50
50
|
machine: flags.machine ?? "",
|
|
51
51
|
token: flags.token ?? process.env.AHP_TKN,
|
|
@@ -58,7 +58,7 @@ Exit status: 0 previewed or applied; 1 the machine refused the plan or could not
|
|
|
58
58
|
host.command("join").description("Join this machine to a workspace with a one-use host join code from the workspace owner.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--code <code>", "The one-use join code").option("--owner-config <file>", "Your owner configuration: agents, provider plugins and their credentials").addHelpText("after", `
|
|
59
59
|
Exit status: 0 registered; 2 pending, rerun the same command; 3 not authorised for that workspace or agent;
|
|
60
60
|
4 an agent is already bound to another host; 1 any other failure.`).exitOverride().action(async (flags) => {
|
|
61
|
-
const { hostJoin } = await import("./chunk-
|
|
61
|
+
const { hostJoin } = await import("./chunk-1xykqbdm.js");
|
|
62
62
|
code = await hostJoin({ origin: flags.origin ?? "", workspace: flags.workspace ?? "", code: flags.code ?? "", ownerConfig: flags.ownerConfig ?? "" }, { directory: options.pluginDirectory, version: options.version });
|
|
63
63
|
});
|
|
64
64
|
host.command("list").description("List the workspace's registered hosts and which agents each runs; a workspace owner sees every host.").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--session-file <file>", "File holding your signed-in ht_session cookie (default: HIGHTEA_SESSION_FILE)").option("--json", "Print one JSON document").addHelpText("after", `
|
|
@@ -83,14 +83,14 @@ Exit status: 0 removed or already removed; 3 your account is not this workspace'
|
|
|
83
83
|
});
|
|
84
84
|
});
|
|
85
85
|
host.command("status").description("Show every joined host on this machine and whether its plugin bundle is intact. Changes nothing.").option("--json", "Print one JSON document").exitOverride().action(async (flags) => {
|
|
86
|
-
const { hostStatus } = await import("./chunk-
|
|
86
|
+
const { hostStatus } = await import("./chunk-1xykqbdm.js");
|
|
87
87
|
code = await hostStatus({ version: options.version, json: flags.json === true });
|
|
88
88
|
});
|
|
89
89
|
host.command("update").description("Move a joined host on this machine to this CLI's plugin bundle; same host id and credentials. Restart the host after.").option("--host <id>", "The joined host's id, when this machine holds more than one").addHelpText("after", `
|
|
90
90
|
The old bundle is kept until the host has connected once on the new one; a later update removes it.
|
|
91
91
|
` + `A bundle newer than this CLI's is refused (HOST_UPDATE_DOWNGRADE).
|
|
92
92
|
Exit status: 0 updated or already current; 1 any refusal, named on stderr.`).exitOverride().action(async (flags) => {
|
|
93
|
-
const { hostUpdate } = await import("./chunk-
|
|
93
|
+
const { hostUpdate } = await import("./chunk-1xykqbdm.js");
|
|
94
94
|
code = await hostUpdate({ host: flags.host }, { directory: options.pluginDirectory, version: options.version });
|
|
95
95
|
});
|
|
96
96
|
const trust = host.command("trust").description("The browser and host keys this machine trusts to ask its agents through a room.").addHelpText("after", `
|
|
@@ -99,16 +99,16 @@ What it protects against: an ask forged by a compromised Hightea server or datab
|
|
|
99
99
|
` + "running as this machine's user, which can edit trusted-keys.json as it can config.json.").exitOverride();
|
|
100
100
|
trust.command("add").description("Trust a browser's (or another host's) public key, under a name of your choosing.").argument("<name>", "A name for the key, e.g. the browser it came from").argument("<public-key>", "The raw Ed25519 public key, base64url, as the browser's Members page shows it").option("--host <id>", "Which of this machine's joined hosts, when it holds more than one").addHelpText("after", `
|
|
101
101
|
Exit status: 0 trusted or already trusted; 1 any failure, with the file left unchanged.`).exitOverride().action(async (name, publicKey, flags) => {
|
|
102
|
-
const { hostTrust } = await import("./chunk-
|
|
102
|
+
const { hostTrust } = await import("./chunk-hxs6jv2m.js");
|
|
103
103
|
code = await hostTrust({ action: "add", name, publicKey, ...flags.host === undefined ? {} : { host: flags.host } });
|
|
104
104
|
});
|
|
105
105
|
trust.command("remove").description("Stop trusting the key with this name; asks signed with it are refused from then on.").argument("<name>", "The key's name, as `hightea host trust list` shows it").option("--host <id>", "Which of this machine's joined hosts, when it holds more than one").addHelpText("after", `
|
|
106
106
|
Exit status: 0 removed; 1 any failure, including an unknown name, with the file left unchanged.`).exitOverride().action(async (name, flags) => {
|
|
107
|
-
const { hostTrust } = await import("./chunk-
|
|
107
|
+
const { hostTrust } = await import("./chunk-hxs6jv2m.js");
|
|
108
108
|
code = await hostTrust({ action: "remove", name, ...flags.host === undefined ? {} : { host: flags.host } });
|
|
109
109
|
});
|
|
110
110
|
trust.command("list").description("List the keys this machine trusts. Changes nothing.").option("--host <id>", "Which of this machine's joined hosts, when it holds more than one").option("--json", "Print one JSON document").exitOverride().action(async (flags) => {
|
|
111
|
-
const { hostTrust } = await import("./chunk-
|
|
111
|
+
const { hostTrust } = await import("./chunk-hxs6jv2m.js");
|
|
112
112
|
code = await hostTrust({ action: "list", json: flags.json === true, ...flags.host === undefined ? {} : { host: flags.host } });
|
|
113
113
|
});
|
|
114
114
|
const auth = program.command("auth").description("Sign this machine in to a Hightea deployment for the owner commands.").exitOverride();
|
|
@@ -189,7 +189,7 @@ Exit status: 0 set; 3 your account is not this workspace's owner; 1 any other fa
|
|
|
189
189
|
Exit status: 0 done; 3 your account may not manage this host's services; 1 any other failure, named on stderr.`).exitOverride().action(async (...args) => {
|
|
190
190
|
const name = options.named ? String(args[0]) : undefined;
|
|
191
191
|
const flags = options.named ? args[1] : args[0];
|
|
192
|
-
const { serviceCommand } = await import("./chunk-
|
|
192
|
+
const { serviceCommand } = await import("./chunk-6ae0ftqh.js");
|
|
193
193
|
const text = (key) => typeof flags[key] === "string" ? flags[key] : undefined;
|
|
194
194
|
code = await serviceCommand({
|
|
195
195
|
origin: text("origin") ?? "",
|
|
@@ -212,7 +212,7 @@ Exit status: 0 done; 3 your account may not manage this host's services; 1 any o
|
|
|
212
212
|
serviceAction("acknowledge", "Accept the process-compose files as they are now, so drift stops alerting on a hand edit.");
|
|
213
213
|
service.command("backup").description("Show Hightea's backup of a host's services and their change log, labelled with how far it reaches; works while the host is offline or revoked.").requiredOption("--host <id>", "The registered host's id").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--session-file <file>", "File holding your signed-in ht_session cookie (default: HIGHTEA_SESSION_FILE)").option("--json", "Print the backup as one JSON document").addHelpText("after", `
|
|
214
214
|
Exit status: 0 shown; 3 your account may not read this host's backup; 1 any other failure, named on stderr.`).exitOverride().action(async (flags) => {
|
|
215
|
-
const { serviceBackupCommand } = await import("./chunk-
|
|
215
|
+
const { serviceBackupCommand } = await import("./chunk-6ae0ftqh.js");
|
|
216
216
|
const text = (key) => typeof flags[key] === "string" ? flags[key] : undefined;
|
|
217
217
|
code = await serviceBackupCommand({
|
|
218
218
|
origin: text("origin") ?? "",
|
|
@@ -225,7 +225,7 @@ Exit status: 0 shown; 3 your account may not read this host's backup; 1 any othe
|
|
|
225
225
|
});
|
|
226
226
|
service.command("restore").description("Create a host's backed-up services on a new host, create-only: shows what it will create and asks first.").argument("[names...]", "Which services; every one in the backup when none is named").requiredOption("--from <id>", "The old host whose backup is read").option("--host <id>", "The new registered host's id; with --local, which of this machine's joined hosts").option("--local", "Create them on this machine, in-process, as you").option("--origin <url>", "The deployment, e.g. https://hightea.dev").option("--workspace <slug>", "The workspace slug").option("--session-file <file>", "File holding your signed-in ht_session cookie (default: HIGHTEA_SESSION_FILE)").option("--yes", "Do not ask; for scripts").option("--json", "Print each service's outcome as one JSON document").addHelpText("after", `
|
|
227
227
|
Exit status: 0 every service created; 3 your account may not read the old host's backup; 1 anything else, each named.`).exitOverride().action(async (names, flags) => {
|
|
228
|
-
const { serviceRestore } = await import("./chunk-
|
|
228
|
+
const { serviceRestore } = await import("./chunk-6ae0ftqh.js");
|
|
229
229
|
const text = (key) => typeof flags[key] === "string" ? flags[key] : undefined;
|
|
230
230
|
code = await serviceRestore({
|
|
231
231
|
origin: text("origin") ?? "",
|
|
@@ -239,7 +239,7 @@ Exit status: 0 every service created; 3 your account may not read the old host's
|
|
|
239
239
|
for (const [verb, enable] of [["enable", true], ["disable", false]]) {
|
|
240
240
|
service.command(verb).description(enable ? "On this machine: let Hightea list, read logs of, change, start and stop this machine's services (adds the services grants)." : "On this machine: stop Hightea managing this machine's services (removes the services grants).").option("--host <id>", "Which of this machine's joined hosts, when it holds more than one").addHelpText("after", `
|
|
241
241
|
Exit status: 0 changed or already so; 1 any failure, named on stderr.`).exitOverride().action(async (flags) => {
|
|
242
|
-
const { hostServicesGrants } = await import("./chunk-
|
|
242
|
+
const { hostServicesGrants } = await import("./chunk-1xykqbdm.js");
|
|
243
243
|
code = await hostServicesGrants({ enable, ...typeof flags.host === "string" ? { host: flags.host } : {} });
|
|
244
244
|
});
|
|
245
245
|
}
|
|
@@ -6940,9 +6940,24 @@ var changedFields = (before, after) => {
|
|
|
6940
6940
|
const b = fieldsOf(after);
|
|
6941
6941
|
return neutralFields.filter((field) => canonical(a[field]) !== canonical(b[field]));
|
|
6942
6942
|
};
|
|
6943
|
+
var SERVICES_CHANNEL = "x-hh-services://";
|
|
6944
|
+
var operate = (host, operationId, rest) => host.call("x-ahpd/invokeOperation", { channel: SERVICES_CHANNEL, operationId, ...rest });
|
|
6943
6945
|
var listOf = async (host) => {
|
|
6944
|
-
const answer = await host.call("
|
|
6945
|
-
|
|
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
|
+
};
|
|
6946
6961
|
};
|
|
6947
6962
|
async function preview(plan, host, options) {
|
|
6948
6963
|
refuseUncarried(plan);
|
|
@@ -6984,18 +6999,18 @@ async function applyPreview(shown, host) {
|
|
|
6984
6999
|
let ifVersion = shown.ifVersion;
|
|
6985
7000
|
const written = [];
|
|
6986
7001
|
for (const service of shown.create) {
|
|
6987
|
-
const answer = await host
|
|
7002
|
+
const answer = await operate(host, "put", { input: { service, ifVersion: "absent" } });
|
|
6988
7003
|
ifVersion = answer.ifVersion ?? ifVersion;
|
|
6989
7004
|
written.push(service.name);
|
|
6990
7005
|
}
|
|
6991
7006
|
for (const entry of shown.change) {
|
|
6992
|
-
const answer = await host
|
|
7007
|
+
const answer = await operate(host, "put", { input: { service: entry.after, ifVersion } });
|
|
6993
7008
|
ifVersion = answer.ifVersion ?? ifVersion;
|
|
6994
7009
|
written.push(entry.name);
|
|
6995
7010
|
}
|
|
6996
7011
|
const removed = [];
|
|
6997
7012
|
for (const entry of shown.remove) {
|
|
6998
|
-
const answer = await host
|
|
7013
|
+
const answer = await operate(host, "remove", { target: { id: entry.name }, input: { ifVersion } });
|
|
6999
7014
|
ifVersion = answer.ifVersion ?? ifVersion;
|
|
7000
7015
|
removed.push(entry.name);
|
|
7001
7016
|
}
|
|
@@ -45,11 +45,11 @@ function remoteDriver(target, io) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
async function localDriver(target) {
|
|
48
|
-
const { localHost } = await import("./chunk-
|
|
48
|
+
const { localHost } = await import("./chunk-1xykqbdm.js");
|
|
49
49
|
const found = await localHost(target.host);
|
|
50
50
|
if ("error" in found)
|
|
51
51
|
return found;
|
|
52
|
-
const { localServices, LOG_LINES_MAX } = await import("@
|
|
52
|
+
const { localServices, LOG_LINES_MAX } = await import("@hallohuman/hightea-services");
|
|
53
53
|
const local = localServices(found.configDir);
|
|
54
54
|
if (typeof local === "string")
|
|
55
55
|
return { error: `SERVICE_NOT_CONFIGURED: ${local}` };
|
|
@@ -6722,17 +6722,7 @@ var MissingRefusalSchema = object({
|
|
|
6722
6722
|
data: object({ staleRevision: literal(0) })
|
|
6723
6723
|
});
|
|
6724
6724
|
// ../ahp/src/host-requests.ts
|
|
6725
|
-
var HOST_SCOPED_METHODS = [
|
|
6726
|
-
"x-ahpd/services/list",
|
|
6727
|
-
"x-ahpd/services/put",
|
|
6728
|
-
"x-ahpd/services/remove",
|
|
6729
|
-
"x-ahpd/services/start",
|
|
6730
|
-
"x-ahpd/services/stop",
|
|
6731
|
-
"x-ahpd/services/restart",
|
|
6732
|
-
"x-ahpd/services/logs",
|
|
6733
|
-
"x-ahpd/services/acknowledge",
|
|
6734
|
-
"x-ahpd/services/backup"
|
|
6735
|
-
];
|
|
6725
|
+
var HOST_SCOPED_METHODS = ["subscribe", "x-ahpd/invokeOperation", "resourceRead"];
|
|
6736
6726
|
var HOST_REQUEST_METHODS = [
|
|
6737
6727
|
"x-ahpd/agents/list",
|
|
6738
6728
|
"x-ahpd/agents/put",
|
|
@@ -7773,7 +7763,17 @@ async function hostStatus2(options) {
|
|
|
7773
7763
|
}
|
|
7774
7764
|
return 0;
|
|
7775
7765
|
}
|
|
7776
|
-
var SERVICES_GRANTS = [
|
|
7766
|
+
var SERVICES_GRANTS = [
|
|
7767
|
+
"service:watch",
|
|
7768
|
+
"service:logs",
|
|
7769
|
+
"service:put",
|
|
7770
|
+
"service:remove",
|
|
7771
|
+
"service:start",
|
|
7772
|
+
"service:stop",
|
|
7773
|
+
"service:restart",
|
|
7774
|
+
"service:accept"
|
|
7775
|
+
];
|
|
7776
|
+
var RETIRED_SERVICES_GRANTS = ["services:list", "services:get", "services:put", "services:delete", "services:control"];
|
|
7777
7777
|
async function localHost2(host) {
|
|
7778
7778
|
let claims;
|
|
7779
7779
|
try {
|
|
@@ -7835,8 +7835,10 @@ async function hostServicesGrants2(options) {
|
|
|
7835
7835
|
return 1;
|
|
7836
7836
|
}
|
|
7837
7837
|
const held = ours.grants ?? [];
|
|
7838
|
-
const services = SERVICES_GRANTS;
|
|
7839
|
-
const
|
|
7838
|
+
const services = [...SERVICES_GRANTS, ...RETIRED_SERVICES_GRANTS];
|
|
7839
|
+
const retired = RETIRED_SERVICES_GRANTS;
|
|
7840
|
+
const kept = held.filter((grant) => !retired.includes(grant));
|
|
7841
|
+
const grants = options.enable ? [...kept, ...SERVICES_GRANTS.filter((grant) => !kept.includes(grant))] : held.filter((grant) => !services.includes(grant));
|
|
7840
7842
|
const what = `Hightea managing this machine's services (host ${found.hostId})`;
|
|
7841
7843
|
if (grants.length === held.length && grants.every((grant, index) => grant === held[index])) {
|
|
7842
7844
|
console.log(`${what} is already ${options.enable ? "enabled" : "disabled"}; ${found.config} was left unchanged.`);
|
package/dist/plugin/plugin.json
CHANGED
package/dist/plugin/plugin.mjs
CHANGED
|
@@ -9867,17 +9867,33 @@ var MissingRefusalSchema = object({
|
|
|
9867
9867
|
data: object({ staleRevision: literal(0) })
|
|
9868
9868
|
});
|
|
9869
9869
|
// ../ahp/src/host-requests.ts
|
|
9870
|
-
var HOST_SCOPED_METHODS = [
|
|
9871
|
-
|
|
9872
|
-
|
|
9873
|
-
|
|
9874
|
-
|
|
9875
|
-
|
|
9876
|
-
|
|
9877
|
-
"
|
|
9878
|
-
|
|
9879
|
-
|
|
9880
|
-
|
|
9870
|
+
var HOST_SCOPED_METHODS = ["subscribe", "x-ahpd/invokeOperation", "resourceRead"];
|
|
9871
|
+
var SERVICES_CHANNEL = "x-hh-services://";
|
|
9872
|
+
var SERVICE_OPERATIONS = ["put", "remove", "start", "stop", "restart", "accept"];
|
|
9873
|
+
var SERVICES_BACKUP_URI = "hh-services://backup";
|
|
9874
|
+
var SERVICES_CHANGES_URI = "hh-services://changes";
|
|
9875
|
+
var SERVICE_READ = /^(hh-service:\/\/[^/?#]+\/logs|hh-services:\/\/(backup|changes))(\?[^#]*)?$/u;
|
|
9876
|
+
function hostScopedRefusal(method, params) {
|
|
9877
|
+
const named = (key) => typeof params[key] === "string" ? JSON.stringify(params[key]) : `no ${key}`;
|
|
9878
|
+
switch (method) {
|
|
9879
|
+
case "subscribe":
|
|
9880
|
+
if (params.channel === SERVICES_CHANNEL && Object.keys(params).length === 1)
|
|
9881
|
+
return;
|
|
9882
|
+
return `subscribe to ${named("channel")}${Object.keys(params).length > 1 ? " with more than a channel" : ""} is not one Hightea sends; only ${SERVICES_CHANNEL}`;
|
|
9883
|
+
case "x-ahpd/invokeOperation":
|
|
9884
|
+
if (params.channel !== SERVICES_CHANNEL)
|
|
9885
|
+
return `x-ahpd/invokeOperation on ${named("channel")} is not one Hightea sends; only ${SERVICES_CHANNEL}`;
|
|
9886
|
+
if (typeof params.operationId === "string" && SERVICE_OPERATIONS.includes(params.operationId))
|
|
9887
|
+
return;
|
|
9888
|
+
return `x-ahpd/invokeOperation ${named("operationId")} on ${SERVICES_CHANNEL} is not one Hightea sends; only ${SERVICE_OPERATIONS.join(", ")}`;
|
|
9889
|
+
case "resourceRead":
|
|
9890
|
+
if (typeof params.uri === "string" && SERVICE_READ.test(params.uri))
|
|
9891
|
+
return;
|
|
9892
|
+
return `resourceRead of ${named("uri")} is not one Hightea sends; only hh-service://<name>/logs, ${SERVICES_BACKUP_URI} and ${SERVICES_CHANGES_URI}`;
|
|
9893
|
+
default:
|
|
9894
|
+
return `${JSON.stringify(method)} is not a host-scoped method; only ${HOST_SCOPED_METHODS.join(", ")}`;
|
|
9895
|
+
}
|
|
9896
|
+
}
|
|
9881
9897
|
var HOST_REQUEST_METHODS = [
|
|
9882
9898
|
"x-ahpd/agents/list",
|
|
9883
9899
|
"x-ahpd/agents/put",
|
|
@@ -9892,6 +9908,8 @@ function isHostScopedMethod(method) {
|
|
|
9892
9908
|
}
|
|
9893
9909
|
var HOST_REQUEST_TIMEOUT_MS = 1e4;
|
|
9894
9910
|
var HOST_LOCAL_TIMEOUT_MS = HOST_REQUEST_TIMEOUT_MS - 1000;
|
|
9911
|
+
var HOST_REQUEST_ID_PREFIX = "host-request:";
|
|
9912
|
+
var AHP_PROTOCOL_VERSION = "1.1.0";
|
|
9895
9913
|
var HostRequestMetaSchema = object({
|
|
9896
9914
|
workspaceId: string2().min(1),
|
|
9897
9915
|
hostId: string2().min(1),
|
|
@@ -10133,8 +10151,34 @@ var refusal = (error) => {
|
|
|
10133
10151
|
var isCreate = (params) => params.ifRevision === 0;
|
|
10134
10152
|
var timedOut = (error) => error instanceof Error && /timed? ?out|timeout/iu.test(error.message);
|
|
10135
10153
|
var AGENTS_CHANNEL = "x-ahpd-agents://";
|
|
10136
|
-
function
|
|
10137
|
-
|
|
10154
|
+
async function listHostServices(options) {
|
|
10155
|
+
let state;
|
|
10156
|
+
let subscribed = false;
|
|
10157
|
+
try {
|
|
10158
|
+
const answer = await options.peer.request("subscribe", { channel: SERVICES_CHANNEL }, HOST_LOCAL_TIMEOUT_MS);
|
|
10159
|
+
subscribed = true;
|
|
10160
|
+
const snapshot = typeof answer === "object" && answer !== null ? answer.snapshot : undefined;
|
|
10161
|
+
state = typeof snapshot === "object" && snapshot !== null ? snapshot.state : undefined;
|
|
10162
|
+
if (typeof state !== "object" || state === null)
|
|
10163
|
+
throw new Error("hightea-pipe: the services snapshot holds no state");
|
|
10164
|
+
} catch (error) {
|
|
10165
|
+
const answered = refusal(error);
|
|
10166
|
+
if (answered !== undefined)
|
|
10167
|
+
return { ok: false, reason: "refused", ...answered };
|
|
10168
|
+
options.log.error(`hightea-pipe: ${error instanceof Error ? error.message : "the services snapshot is unreadable"}`);
|
|
10169
|
+
if (timedOut(error))
|
|
10170
|
+
return { ok: false, reason: "timedOut" };
|
|
10171
|
+
return { ok: false, reason: "refused", code: -32603, message: "this host could not read ahpd's services" };
|
|
10172
|
+
} finally {
|
|
10173
|
+
if (subscribed) {
|
|
10174
|
+
try {
|
|
10175
|
+
await options.peer.request("unsubscribe", { channel: SERVICES_CHANNEL }, HOST_LOCAL_TIMEOUT_MS);
|
|
10176
|
+
} catch (error) {
|
|
10177
|
+
options.log.error(`hightea-pipe: dropping the services subscription failed: ${error instanceof Error ? error.name : typeof error}`);
|
|
10178
|
+
}
|
|
10179
|
+
}
|
|
10180
|
+
}
|
|
10181
|
+
return { ok: true, result: state };
|
|
10138
10182
|
}
|
|
10139
10183
|
function rowsOfSnapshot(answer) {
|
|
10140
10184
|
const snapshot = typeof answer === "object" && answer !== null ? answer.snapshot : undefined;
|
|
@@ -10191,26 +10235,42 @@ async function answerHostRequest(input, options) {
|
|
|
10191
10235
|
const params = input.params;
|
|
10192
10236
|
if (!isRecord2(params))
|
|
10193
10237
|
return { ok: false, reason: "outside" };
|
|
10238
|
+
const carriesMember = "agentMemberId" in params;
|
|
10239
|
+
if (carriesMember && (typeof params.agentMemberId !== "string" || params.agentMemberId === ""))
|
|
10240
|
+
return { ok: false, reason: "outside" };
|
|
10241
|
+
const memberId = carriesMember ? params.agentMemberId : meta.agentMemberId;
|
|
10194
10242
|
if (isHostScopedMethod(method)) {
|
|
10195
|
-
if (
|
|
10243
|
+
if (memberId !== undefined)
|
|
10196
10244
|
return { ok: false, reason: "outside" };
|
|
10197
|
-
|
|
10245
|
+
const refused = hostScopedRefusal(method, params);
|
|
10246
|
+
if (refused !== undefined) {
|
|
10247
|
+
options.log.error(`hightea-pipe: refused a host request: ${refused}`);
|
|
10248
|
+
return { ok: false, reason: "outside" };
|
|
10249
|
+
}
|
|
10250
|
+
if (method === "subscribe")
|
|
10251
|
+
return listHostServices(options);
|
|
10252
|
+
return runHostCommand(options, method, params);
|
|
10198
10253
|
}
|
|
10199
10254
|
if (method === "x-ahpd/agents/list") {
|
|
10200
|
-
if (
|
|
10255
|
+
if (memberId !== undefined)
|
|
10201
10256
|
return { ok: false, reason: "outside" };
|
|
10202
10257
|
if (Object.keys(params).length !== 0)
|
|
10203
10258
|
return { ok: false, reason: "outside" };
|
|
10204
10259
|
return listHostAgents(options);
|
|
10205
10260
|
}
|
|
10206
|
-
if (
|
|
10261
|
+
if (memberId === undefined)
|
|
10207
10262
|
return { ok: false, reason: "outside" };
|
|
10208
|
-
const agent = options.agents.get(
|
|
10263
|
+
const agent = options.agents.get(memberId);
|
|
10209
10264
|
if (agent === undefined || agent.provider !== params.id)
|
|
10210
10265
|
return { ok: false, reason: "unmapped" };
|
|
10211
|
-
const
|
|
10266
|
+
const record = carriesMember ? withoutMemberId(params) : params;
|
|
10267
|
+
const forwarded = method === "x-ahpd/agents/put" && isCreate(record) ? { ...record, owner: HOST_RECORD_OWNER } : record;
|
|
10212
10268
|
return runHostCommand(options, method, forwarded);
|
|
10213
10269
|
}
|
|
10270
|
+
function withoutMemberId(params) {
|
|
10271
|
+
const { agentMemberId: _member, ...rest } = params;
|
|
10272
|
+
return rest;
|
|
10273
|
+
}
|
|
10214
10274
|
function metaOf(value) {
|
|
10215
10275
|
const parsed = HostRequestMetaSchema.safeParse(value);
|
|
10216
10276
|
return parsed.success ? parsed.data : undefined;
|
|
@@ -10221,9 +10281,9 @@ function isRecord2(value) {
|
|
|
10221
10281
|
function isHostRequestMethod(method) {
|
|
10222
10282
|
return method === "x-ahpd/agents/list" || method === "x-ahpd/agents/put" || method === "x-ahpd/agents/remove" || method === "x-ahpd/agents/enable" || method === "x-ahpd/agents/pause" || method === "x-ahpd/agents/disable";
|
|
10223
10283
|
}
|
|
10224
|
-
async function runHostCommand(options, method, params
|
|
10284
|
+
async function runHostCommand(options, method, params) {
|
|
10225
10285
|
try {
|
|
10226
|
-
const result = await options.peer.request(
|
|
10286
|
+
const result = await options.peer.request(method, params, HOST_LOCAL_TIMEOUT_MS);
|
|
10227
10287
|
return { ok: true, result: result ?? null };
|
|
10228
10288
|
} catch (error) {
|
|
10229
10289
|
const answered = refusal(error);
|
|
@@ -10615,8 +10675,10 @@ class UnmappedAgent extends Error {
|
|
|
10615
10675
|
|
|
10616
10676
|
class FrameRefusal extends Error {
|
|
10617
10677
|
}
|
|
10618
|
-
function
|
|
10619
|
-
|
|
10678
|
+
function isHostCommandFrame(method, id) {
|
|
10679
|
+
if (!HOST_REQUEST_METHODS.includes(method))
|
|
10680
|
+
return false;
|
|
10681
|
+
return !isHostScopedMethod(method) || typeof id === "string" && id.startsWith(HOST_REQUEST_ID_PREFIX);
|
|
10620
10682
|
}
|
|
10621
10683
|
function dispatchClientSeq(frame) {
|
|
10622
10684
|
const seq = frame.params.clientSeq;
|
|
@@ -10640,7 +10702,7 @@ function cloudOperationFailureCode(error) {
|
|
|
10640
10702
|
return "AGENT_NOT_MAPPED";
|
|
10641
10703
|
return "WAKE_NOT_SENT";
|
|
10642
10704
|
}
|
|
10643
|
-
var SUPPORTED_PROTOCOL =
|
|
10705
|
+
var SUPPORTED_PROTOCOL = AHP_PROTOCOL_VERSION;
|
|
10644
10706
|
var REQUEST_TIMEOUT_MS = 15000;
|
|
10645
10707
|
var attemptKey = (deliveryId, turnId) => JSON.stringify([deliveryId, turnId]);
|
|
10646
10708
|
var PipeStateSchema = object({
|
|
@@ -10654,6 +10716,7 @@ class WakePipe {
|
|
|
10654
10716
|
#sessions = new Map;
|
|
10655
10717
|
#dispatched = new Map;
|
|
10656
10718
|
#active = new Map;
|
|
10719
|
+
#pendingInitialize = [];
|
|
10657
10720
|
#queued = new Map;
|
|
10658
10721
|
#subscribed = new Set;
|
|
10659
10722
|
#lastStatus = new Map;
|
|
@@ -10687,7 +10750,7 @@ class WakePipe {
|
|
|
10687
10750
|
}
|
|
10688
10751
|
const loaded = await this.options.store?.load();
|
|
10689
10752
|
if (loaded === undefined) {
|
|
10690
|
-
this.#
|
|
10753
|
+
this.#ready();
|
|
10691
10754
|
return;
|
|
10692
10755
|
}
|
|
10693
10756
|
const parsed = PipeStateSchema.safeParse(loaded);
|
|
@@ -10752,7 +10815,33 @@ class WakePipe {
|
|
|
10752
10815
|
for (const frame of interrupted)
|
|
10753
10816
|
await this.#status(frame);
|
|
10754
10817
|
await this.#save();
|
|
10818
|
+
this.#ready();
|
|
10819
|
+
}
|
|
10820
|
+
#ready() {
|
|
10755
10821
|
this.#started = true;
|
|
10822
|
+
for (const id of this.#pendingInitialize.splice(0))
|
|
10823
|
+
this.#initializeAnswer(id);
|
|
10824
|
+
}
|
|
10825
|
+
#initialize(id, params) {
|
|
10826
|
+
const offered = typeof params === "object" && params !== null && Array.isArray(params.protocolVersions) ? params.protocolVersions.filter((version) => typeof version === "string") : [];
|
|
10827
|
+
if (!offered.includes(SUPPORTED_PROTOCOL)) {
|
|
10828
|
+
this.cloud.reply(id, { error: { code: -32005, message: "UnsupportedProtocolVersion", data: { supportedVersions: [SUPPORTED_PROTOCOL] } } });
|
|
10829
|
+
return;
|
|
10830
|
+
}
|
|
10831
|
+
if (!this.#started) {
|
|
10832
|
+
this.#pendingInitialize.push(id);
|
|
10833
|
+
return;
|
|
10834
|
+
}
|
|
10835
|
+
this.#initializeAnswer(id);
|
|
10836
|
+
}
|
|
10837
|
+
#initializeAnswer(id) {
|
|
10838
|
+
const handshake = this.options.handshake;
|
|
10839
|
+
this.cloud.reply(id, { result: {
|
|
10840
|
+
protocolVersion: SUPPORTED_PROTOCOL,
|
|
10841
|
+
serverSeq: 0,
|
|
10842
|
+
...handshake === undefined ? {} : { serverInfo: handshake.plugin, _meta: { ahpd: handshake.ahpd } },
|
|
10843
|
+
snapshots: []
|
|
10844
|
+
} });
|
|
10756
10845
|
}
|
|
10757
10846
|
#save() {
|
|
10758
10847
|
const state = {
|
|
@@ -10821,13 +10910,21 @@ class WakePipe {
|
|
|
10821
10910
|
}
|
|
10822
10911
|
async fromCloud(frame) {
|
|
10823
10912
|
const id = frame?.id;
|
|
10913
|
+
if (frame?.method === "initialize") {
|
|
10914
|
+
if (id === undefined) {
|
|
10915
|
+
this.options.log.error("hightea-pipe: an initialize frame carries no id; nothing to answer");
|
|
10916
|
+
return;
|
|
10917
|
+
}
|
|
10918
|
+
this.#initialize(id, frame.params);
|
|
10919
|
+
return;
|
|
10920
|
+
}
|
|
10824
10921
|
if (!this.#started || this.#storeError !== undefined) {
|
|
10825
10922
|
if (id !== undefined)
|
|
10826
10923
|
this.cloud.answer(id, { ok: false, code: "WAKE_NOT_SENT" });
|
|
10827
10924
|
return;
|
|
10828
10925
|
}
|
|
10829
10926
|
const commandMethod = typeof frame?.method === "string" ? frame.method : undefined;
|
|
10830
|
-
if (commandMethod !== undefined &&
|
|
10927
|
+
if (commandMethod !== undefined && isHostCommandFrame(commandMethod, id)) {
|
|
10831
10928
|
const requestId = String(id ?? "");
|
|
10832
10929
|
const answer = await answerHostRequest({
|
|
10833
10930
|
method: commandMethod,
|
|
@@ -11494,6 +11591,7 @@ function createCloudLink(options) {
|
|
|
11494
11591
|
send,
|
|
11495
11592
|
close,
|
|
11496
11593
|
answer: (id, outcome) => send(outcome.ok ? { jsonrpc: "2.0", id, result: null } : { jsonrpc: "2.0", id, error: { code: -32000, message: outcome.code } }),
|
|
11594
|
+
reply: (id, answer) => send("result" in answer ? { jsonrpc: "2.0", id, result: answer.result } : { jsonrpc: "2.0", id, error: answer.error }),
|
|
11497
11595
|
status: (frame) => send({ jsonrpc: "2.0", method: "x-hightea/status", params: frame }),
|
|
11498
11596
|
renewToken: (params) => request(`renew:${randomUUID()}`, "x-hightea/renewToken", { channel: "ahp-root://", ...params }),
|
|
11499
11597
|
sourcePush: (params) => request(`push:${randomUUID()}`, "x-hightea/source/push", params),
|
|
@@ -13630,7 +13728,10 @@ function applyWith(host, options, seams) {
|
|
|
13630
13728
|
startSession: (wanted, named) => host.startSession(wanted, named),
|
|
13631
13729
|
log: host.log,
|
|
13632
13730
|
store: recordsPipeStore(host.records("hightea"), owner, (uri) => host.sessionOwner(uri)),
|
|
13633
|
-
admitTurn: (meta, token) => checks.admit(meta, token)
|
|
13731
|
+
admitTurn: (meta, token) => checks.admit(meta, token),
|
|
13732
|
+
...pluginVersion === undefined ? {} : {
|
|
13733
|
+
handshake: { plugin: { name, version: pluginVersion }, ahpd: options.ahpdVersion }
|
|
13734
|
+
}
|
|
13634
13735
|
});
|
|
13635
13736
|
running = pipe;
|
|
13636
13737
|
}, 100);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hallohuman/hightea",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"description": "The Hightea command line: join this machine to a Hightea workspace as a host.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"prepack": "bun run build"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ahpd/deploy": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
24
|
-
"@ahpd/sdk": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
25
|
-
"@ahpd/server": "https://github.com/beorn/ahpd/releases/download/hh-
|
|
26
|
-
"@
|
|
23
|
+
"@ahpd/deploy": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-deploy-0.15.0-beorn.3a159188.tgz",
|
|
24
|
+
"@ahpd/sdk": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-sdk-0.15.0-beorn.3a159188.tgz",
|
|
25
|
+
"@ahpd/server": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/ahpd-server-0.15.0-beorn.3a159188.tgz",
|
|
26
|
+
"@hallohuman/hightea-services": "https://github.com/beorn/ahpd/releases/download/hh-38277-3a159188/hallohuman-hightea-services-0.16.0-beorn.3a159188.tgz",
|
|
27
27
|
"@silvery/commander": "0.29.3",
|
|
28
28
|
"ws": "8.21.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@hallohuman/hightea-ahp-host": "
|
|
32
|
-
"@hallohuman/hightea-client": "
|
|
31
|
+
"@hallohuman/hightea-ahp-host": "workspace:*",
|
|
32
|
+
"@hallohuman/hightea-client": "workspace:*"
|
|
33
33
|
}
|
|
34
34
|
}
|