@saleso.innovations/bridge 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/README.md +1 -1
- package/dist/cronList.d.ts +5 -0
- package/dist/cronList.d.ts.map +1 -0
- package/dist/cronList.js +62 -0
- package/dist/hermesCommands.d.ts +1 -1
- package/dist/hermesCommands.d.ts.map +1 -1
- package/dist/hermesCommands.js +13 -1
- package/dist/hermesUpdate.d.ts +8 -0
- package/dist/hermesUpdate.d.ts.map +1 -0
- package/dist/hermesUpdate.js +26 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ This installs the latest package, refreshes the CLI symlink, and restarts `cleos
|
|
|
34
34
|
To pin a specific release (e.g. after a Cleos update):
|
|
35
35
|
|
|
36
36
|
```bash
|
|
37
|
-
curl -fsSL https://amicable-elephant-407.convex.site/update-bridge.sh | bash -s -- 0.1.
|
|
37
|
+
curl -fsSL https://amicable-elephant-407.convex.site/update-bridge.sh | bash -s -- 0.1.15
|
|
38
38
|
```
|
|
39
39
|
|
|
40
40
|
## Manual usage
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cronList.d.ts","sourceRoot":"","sources":["../src/cronList.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AA6CF,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,yBAA8B,GACtC,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
package/dist/cronList.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
const HERMES_CRON_JOBS_FILE = join(homedir(), ".hermes", "cron", "jobs.json");
|
|
8
|
+
const LIST_TIMEOUT_MS = 30_000;
|
|
9
|
+
const MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
10
|
+
function normalizeJobsPayload(value) {
|
|
11
|
+
if (Array.isArray(value)) {
|
|
12
|
+
return { jobs: value };
|
|
13
|
+
}
|
|
14
|
+
if (value && typeof value === "object") {
|
|
15
|
+
const record = value;
|
|
16
|
+
for (const key of ["jobs", "items", "data", "results"]) {
|
|
17
|
+
if (Array.isArray(record[key])) {
|
|
18
|
+
return { jobs: record[key] };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
return { jobs: [] };
|
|
24
|
+
}
|
|
25
|
+
function readJobsFromFile() {
|
|
26
|
+
if (!existsSync(HERMES_CRON_JOBS_FILE)) {
|
|
27
|
+
return { jobs: [] };
|
|
28
|
+
}
|
|
29
|
+
const raw = readFileSync(HERMES_CRON_JOBS_FILE, "utf8");
|
|
30
|
+
return normalizeJobsPayload(JSON.parse(raw));
|
|
31
|
+
}
|
|
32
|
+
async function runHermesCronListJson(all) {
|
|
33
|
+
const args = ["cron", "list"];
|
|
34
|
+
if (all)
|
|
35
|
+
args.push("--all");
|
|
36
|
+
args.push("--json");
|
|
37
|
+
try {
|
|
38
|
+
const { stdout } = await execFileAsync("hermes", args, {
|
|
39
|
+
timeout: LIST_TIMEOUT_MS,
|
|
40
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
41
|
+
env: process.env,
|
|
42
|
+
});
|
|
43
|
+
const trimmed = stdout.trim();
|
|
44
|
+
if (!trimmed)
|
|
45
|
+
return null;
|
|
46
|
+
return normalizeJobsPayload(JSON.parse(trimmed));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export async function listHermesCronJobs(options = {}) {
|
|
53
|
+
const includeAll = options.all === true;
|
|
54
|
+
const jsonResult = await runHermesCronListJson(includeAll);
|
|
55
|
+
if (jsonResult != null) {
|
|
56
|
+
return jsonResult;
|
|
57
|
+
}
|
|
58
|
+
if (includeAll) {
|
|
59
|
+
return readJobsFromFile();
|
|
60
|
+
}
|
|
61
|
+
throw new Error("Could not list Hermes cron jobs. Ensure `hermes` is installed and supports `hermes cron list --json`.");
|
|
62
|
+
}
|
package/dist/hermesCommands.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const HERMES_COMMAND_NAMES: readonly ["runtime.health", "runtime.detailedHealth", "runtime.capabilities", "models.list", "model.set", "responses.create", "runs.create", "runs.status", "runs.stop", "jobs.list", "jobs.get", "jobs.create", "jobs.update", "jobs.pause", "jobs.resume", "jobs.runNow", "jobs.delete", "profiles.list", "profiles.create", "gateway.start", "gateway.stop", "gateway.restart"];
|
|
1
|
+
export declare const HERMES_COMMAND_NAMES: readonly ["runtime.health", "runtime.detailedHealth", "runtime.capabilities", "models.list", "model.set", "responses.create", "runs.create", "runs.status", "runs.stop", "jobs.list", "jobs.get", "jobs.create", "jobs.update", "jobs.pause", "jobs.resume", "jobs.runNow", "jobs.delete", "profiles.list", "profiles.create", "gateway.start", "gateway.stop", "gateway.restart", "hermes.update"];
|
|
2
2
|
export type HermesCommandName = (typeof HERMES_COMMAND_NAMES)[number];
|
|
3
3
|
export declare function isHermesCommandName(value: string): value is HermesCommandName;
|
|
4
4
|
export type HermesCommandErrorCode = "command_unsupported" | "hermes_unreachable" | "hermes_request_failed" | "invalid_command_args" | "unsupported_by_http";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hermesCommands.d.ts","sourceRoot":"","sources":["../src/hermesCommands.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hermesCommands.d.ts","sourceRoot":"","sources":["../src/hermesCommands.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,oBAAoB,qYAwBvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,iBAAiB,CAE7E;AAED,MAAM,MAAM,sBAAsB,GAC9B,qBAAqB,GACrB,oBAAoB,GACpB,uBAAuB,GACvB,sBAAsB,GACtB,qBAAqB,CAAC;AAE1B,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,IAAI,EAAE,sBAAsB,CAAC;gBAE1B,IAAI,EAAE,sBAAsB,EAAE,OAAO,EAAE,MAAM;CAI1D;AAuFD,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GACjE,OAAO,CAAC,OAAO,CAAC,CAkKlB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,sBAAsB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAetG"}
|
package/dist/hermesCommands.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { resolveHermesApiConfig } from "./hermesForwarder.js";
|
|
2
2
|
import { restartHermesGateway, startHermesGateway, stopHermesGateway } from "./gatewayControl.js";
|
|
3
|
+
import { listHermesCronJobs } from "./cronList.js";
|
|
4
|
+
import { runHermesUpdate } from "./hermesUpdate.js";
|
|
3
5
|
export const HERMES_COMMAND_NAMES = [
|
|
4
6
|
"runtime.health",
|
|
5
7
|
"runtime.detailedHealth",
|
|
@@ -23,6 +25,7 @@ export const HERMES_COMMAND_NAMES = [
|
|
|
23
25
|
"gateway.start",
|
|
24
26
|
"gateway.stop",
|
|
25
27
|
"gateway.restart",
|
|
28
|
+
"hermes.update",
|
|
26
29
|
];
|
|
27
30
|
export function isHermesCommandName(value) {
|
|
28
31
|
return HERMES_COMMAND_NAMES.includes(value);
|
|
@@ -175,8 +178,13 @@ export async function executeHermesCommand(command, args, options = {}) {
|
|
|
175
178
|
body: JSON.stringify({}),
|
|
176
179
|
});
|
|
177
180
|
}
|
|
178
|
-
case "jobs.list":
|
|
181
|
+
case "jobs.list": {
|
|
182
|
+
const includeAll = args.all === true || args.includeInactive === true;
|
|
183
|
+
if (includeAll) {
|
|
184
|
+
return await listHermesCronJobs({ all: true });
|
|
185
|
+
}
|
|
179
186
|
return await hermesFetchJson(config, "/api/jobs");
|
|
187
|
+
}
|
|
180
188
|
case "jobs.get": {
|
|
181
189
|
const jobId = requireString(args, "jobId");
|
|
182
190
|
return await hermesFetchJson(config, `/api/jobs/${encodeURIComponent(jobId)}`);
|
|
@@ -244,6 +252,10 @@ export async function executeHermesCommand(command, args, options = {}) {
|
|
|
244
252
|
return await stopHermesGateway();
|
|
245
253
|
case "gateway.restart":
|
|
246
254
|
return await restartHermesGateway();
|
|
255
|
+
case "hermes.update": {
|
|
256
|
+
const restartGateway = args.restartGateway === true || args.restart_gateway === true;
|
|
257
|
+
return await runHermesUpdate({ restartGateway });
|
|
258
|
+
}
|
|
247
259
|
default: {
|
|
248
260
|
const _exhaustive = command;
|
|
249
261
|
throw new HermesCommandError("command_unsupported", `Unsupported command: ${String(_exhaustive)}`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hermesUpdate.d.ts","sourceRoot":"","sources":["../src/hermesUpdate.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF,wBAAsB,eAAe,CACnC,OAAO,GAAE,sBAA2B,GACnC,OAAO,CAAC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAqBvC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const execFileAsync = promisify(execFile);
|
|
4
|
+
const UPDATE_TIMEOUT_MS = 600_000;
|
|
5
|
+
const MAX_OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
6
|
+
export async function runHermesUpdate(options = {}) {
|
|
7
|
+
const args = ["update"];
|
|
8
|
+
if (options.restartGateway) {
|
|
9
|
+
args.push("--restart-gateway");
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
const { stdout, stderr } = await execFileAsync("hermes", args, {
|
|
13
|
+
timeout: UPDATE_TIMEOUT_MS,
|
|
14
|
+
maxBuffer: MAX_OUTPUT_BYTES,
|
|
15
|
+
env: process.env,
|
|
16
|
+
});
|
|
17
|
+
const output = [stdout, stderr].filter((chunk) => chunk.trim().length > 0).join("\n").trim();
|
|
18
|
+
return { ok: true, output: output || "Hermes updated successfully." };
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const message = error instanceof Error && error.message.trim().length > 0
|
|
22
|
+
? error.message
|
|
23
|
+
: "Hermes update failed.";
|
|
24
|
+
throw new Error(message);
|
|
25
|
+
}
|
|
26
|
+
}
|