@senpi-ai/runtime 3.0.104 → 3.0.106
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/cli/guide-commands.d.ts.map +1 -1
- package/dist/cli/guide-commands.js +38 -0
- package/dist/cli/guide-commands.js.map +1 -1
- package/dist/cli/senpi-commands.d.ts.map +1 -1
- package/dist/cli/senpi-commands.js +29 -1
- package/dist/cli/senpi-commands.js.map +1 -1
- package/dist/cli/update-command.d.ts +69 -0
- package/dist/cli/update-command.d.ts.map +1 -0
- package/dist/cli/update-command.js +153 -0
- package/dist/cli/update-command.js.map +1 -0
- package/dist/dsl/plugin/index.d.ts +35 -1
- package/dist/dsl/plugin/index.d.ts.map +1 -1
- package/dist/dsl/plugin/index.js +62 -7
- package/dist/dsl/plugin/index.js.map +1 -1
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -11
- package/dist/index.js.map +1 -1
- package/dist/runtime/effective-config.d.ts +67 -0
- package/dist/runtime/effective-config.d.ts.map +1 -0
- package/dist/runtime/effective-config.js +324 -0
- package/dist/runtime/effective-config.js.map +1 -0
- package/dist/runtime/lifecycle-events.d.ts +19 -0
- package/dist/runtime/lifecycle-events.d.ts.map +1 -1
- package/dist/runtime/lifecycle-events.js +27 -0
- package/dist/runtime/lifecycle-events.js.map +1 -1
- package/dist/runtime/rebuild-errors.d.ts +26 -0
- package/dist/runtime/rebuild-errors.d.ts.map +1 -0
- package/dist/runtime/rebuild-errors.js +36 -0
- package/dist/runtime/rebuild-errors.js.map +1 -0
- package/dist/runtime/run.d.ts +10 -0
- package/dist/runtime/run.d.ts.map +1 -1
- package/dist/runtime/run.js +13 -1
- package/dist/runtime/run.js.map +1 -1
- package/dist/runtime/runtime.d.ts +140 -1
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +494 -149
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/strategy-registry.d.ts +1 -0
- package/dist/runtime/strategy-registry.d.ts.map +1 -1
- package/dist/runtime/strategy-registry.js +19 -0
- package/dist/runtime/strategy-registry.js.map +1 -1
- package/dist/runtime/update-apply-deps.d.ts +101 -0
- package/dist/runtime/update-apply-deps.d.ts.map +1 -0
- package/dist/runtime/update-apply-deps.js +159 -0
- package/dist/runtime/update-apply-deps.js.map +1 -0
- package/dist/runtime/update-handler.d.ts +197 -0
- package/dist/runtime/update-handler.d.ts.map +1 -0
- package/dist/runtime/update-handler.js +381 -0
- package/dist/runtime/update-handler.js.map +1 -0
- package/dist/runtime/update-plan.d.ts +60 -0
- package/dist/runtime/update-plan.d.ts.map +1 -0
- package/dist/runtime/update-plan.js +203 -0
- package/dist/runtime/update-plan.js.map +1 -0
- package/dist/runtime/update-register.d.ts +67 -0
- package/dist/runtime/update-register.d.ts.map +1 -0
- package/dist/runtime/update-register.js +173 -0
- package/dist/runtime/update-register.js.map +1 -0
- package/dist/runtime/update-report.d.ts +125 -0
- package/dist/runtime/update-report.d.ts.map +1 -0
- package/dist/runtime/update-report.js +215 -0
- package/dist/runtime/update-report.js.map +1 -0
- package/dist/utils/event-catalog.d.ts +26 -0
- package/dist/utils/event-catalog.d.ts.map +1 -1
- package/dist/utils/event-catalog.js +1 -0
- package/dist/utils/event-catalog.js.map +1 -1
- package/dist/widgets/errors.d.ts +11 -0
- package/dist/widgets/errors.d.ts.map +1 -0
- package/dist/widgets/errors.js +16 -0
- package/dist/widgets/errors.js.map +1 -0
- package/dist/widgets/index.d.ts +32 -0
- package/dist/widgets/index.d.ts.map +1 -0
- package/dist/widgets/index.js +33 -0
- package/dist/widgets/index.js.map +1 -0
- package/dist/widgets/registry.d.ts +24 -0
- package/dist/widgets/registry.d.ts.map +1 -0
- package/dist/widgets/registry.js +33 -0
- package/dist/widgets/registry.js.map +1 -0
- package/dist/widgets/tool.d.ts +48 -0
- package/dist/widgets/tool.d.ts.map +1 -0
- package/dist/widgets/tool.js +140 -0
- package/dist/widgets/tool.js.map +1 -0
- package/dist/widgets/types.d.ts +53 -0
- package/dist/widgets/types.d.ts.map +1 -0
- package/dist/widgets/types.js +10 -0
- package/dist/widgets/types.js.map +1 -0
- package/dist/widgets/widgets/fund-user-wallet.d.ts +12 -0
- package/dist/widgets/widgets/fund-user-wallet.d.ts.map +1 -0
- package/dist/widgets/widgets/fund-user-wallet.js +38 -0
- package/dist/widgets/widgets/fund-user-wallet.js.map +1 -0
- package/openclaw.plugin.json +13 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12,11 +12,14 @@
|
|
|
12
12
|
* the loader's relative-import path entirely.
|
|
13
13
|
*/
|
|
14
14
|
import { readFileSync } from "node:fs";
|
|
15
|
+
import { parse as parseYaml } from "yaml";
|
|
15
16
|
import { join, dirname } from "node:path";
|
|
16
17
|
import { SenpiClient } from "./senpi/client.js";
|
|
17
18
|
import { buildWalletStatusHint } from "./senpi/strategy-status.js";
|
|
18
19
|
import { DeployJobController } from "./deploy/job.js";
|
|
19
20
|
import { registerDeployGatewayMethods } from "./deploy/register.js";
|
|
21
|
+
import { registerUpdateGatewayMethod } from "./runtime/update-register.js";
|
|
22
|
+
import { checkProofCoversRecipe, makeApplyToRuntime, makeWriteRegistry, } from "./runtime/update-apply-deps.js";
|
|
20
23
|
import { INSTALL_DEADLINE_MS, WALLET_INSTALL_IN_FLIGHT_CODE } from "./deploy/deadlines.js";
|
|
21
24
|
import { AuditQueryError } from "./runtime/audit-query.types.js";
|
|
22
25
|
import { buildRuntimeStateDir, archiveStateDir } from "./runtime/state-layout.js";
|
|
@@ -46,9 +49,10 @@ import { getLogLevel, getLogLevelSource, parseLogLevel, setLogLevel, } from "./u
|
|
|
46
49
|
import { ExternalScannerIngestError, } from "./scanners/external-scanner-receiver.js";
|
|
47
50
|
import { createLogger } from "./utils/logger.js";
|
|
48
51
|
import { registerToolApprovalGate, resolveToolApprovalsMode, } from "./approvals/tool-approval-gate.js";
|
|
52
|
+
import { registerShowWidgetTool } from "./widgets/index.js";
|
|
49
53
|
import { EVENT_NAME, SENPI_ERROR_CODE, eventAttrs, scannerUnwiredErrorCode } from "./utils/event-catalog.js";
|
|
50
54
|
import { emitEvent } from "./actions/event-derivation.js";
|
|
51
|
-
import { buildRuntimeCreatedEvent, buildRuntimeDeletedEvent } from "./runtime/lifecycle-events.js";
|
|
55
|
+
import { buildRuntimeCreatedEvent, buildRuntimeDeletedEvent, buildRuntimeUpdatedEvent } from "./runtime/lifecycle-events.js";
|
|
52
56
|
import { isWalletAddress } from "./utils/wallet-address.js";
|
|
53
57
|
import { fileURLToPath } from "node:url";
|
|
54
58
|
import { loadApiConfig } from "./runtime-api/config.js";
|
|
@@ -176,8 +180,21 @@ const senpiRuntimePlugin = {
|
|
|
176
180
|
},
|
|
177
181
|
},
|
|
178
182
|
register(api) {
|
|
183
|
+
// `--json` promises ONE document on stdout, and `api.logger.info` writes there. Startup
|
|
184
|
+
// diagnostics therefore land ahead of the document and no consumer can parse it — measured on a
|
|
185
|
+
// live box, where `senpi update --json`, `runtime list --json` and `dsl positions --json` were
|
|
186
|
+
// all unparseable, and not even recoverable by skipping to the first `{` because the ANSI colour
|
|
187
|
+
// codes contain braces.
|
|
188
|
+
//
|
|
189
|
+
// The diagnostics are not dropped, only moved to stderr where diagnostics belong. Warnings and
|
|
190
|
+
// errors are left on the logger untouched: those are not routine chatter, and a caller piping
|
|
191
|
+
// stdout to a parser still wants them visible.
|
|
192
|
+
const jsonMode = process.argv.includes("--json");
|
|
179
193
|
const pluginLogger = {
|
|
180
|
-
info: (...args) =>
|
|
194
|
+
info: (...args) =>
|
|
195
|
+
// No added prefix: these messages already carry their own `[senpi-runtime]` /
|
|
196
|
+
// `[senpi-tool-approvals]` tag, and prepending another produced doubled labels on stderr.
|
|
197
|
+
jsonMode ? console.error(...args) : api.logger.info(...args),
|
|
181
198
|
warn: (...args) => api.logger.warn(...args),
|
|
182
199
|
error: (message, meta) => api.logger.error(message, meta),
|
|
183
200
|
};
|
|
@@ -284,6 +301,22 @@ const senpiRuntimePlugin = {
|
|
|
284
301
|
err: err instanceof Error ? err.message : String(err),
|
|
285
302
|
});
|
|
286
303
|
}
|
|
304
|
+
// show_widget — the agent renders a native card in the Senpi chat clients
|
|
305
|
+
// instead of describing it in text. One tool, one `widget_type` enum
|
|
306
|
+
// generated from src/widgets/registry.ts; the client reads the tool call
|
|
307
|
+
// off the gateway websocket and renders its own component.
|
|
308
|
+
try {
|
|
309
|
+
registerShowWidgetTool({
|
|
310
|
+
api,
|
|
311
|
+
widgetsConfig: config.widgets,
|
|
312
|
+
logger: pluginLogger,
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
pluginLogger.warn("[senpi-runtime] failed to register show_widget tool", {
|
|
317
|
+
err: err instanceof Error ? err.message : String(err),
|
|
318
|
+
});
|
|
319
|
+
}
|
|
287
320
|
const runtimeHandles = new Map();
|
|
288
321
|
let apiHandle;
|
|
289
322
|
// Supervised scanner state — module-scoped so stop() can reach them.
|
|
@@ -770,7 +803,7 @@ const senpiRuntimePlugin = {
|
|
|
770
803
|
async function installRuntimeCore(params) {
|
|
771
804
|
const toError = (message) => ({ code: "INVALID_REQUEST", message });
|
|
772
805
|
const toUnavailable = (message) => ({ code: "UNAVAILABLE", message });
|
|
773
|
-
const { readRegistry, writeRegistry, validateEntry, hasId, findByWallet, deriveRuntimeId, sanitizeId } = await import("./runtime/strategy-registry.js");
|
|
806
|
+
const { readRegistry, writeRegistry, withRegistryLock, validateEntry, hasId, findByWallet, deriveRuntimeId, sanitizeId } = await import("./runtime/strategy-registry.js");
|
|
774
807
|
const id = typeof params?.id === "string" ? params.id : undefined;
|
|
775
808
|
const runtimeYamlPath = typeof params?.runtimeYamlPath === "string" ? params.runtimeYamlPath : undefined;
|
|
776
809
|
const runtimeYamlContent = typeof params?.runtimeYamlContent === "string" ? params.runtimeYamlContent : undefined;
|
|
@@ -1028,8 +1061,13 @@ const senpiRuntimePlugin = {
|
|
|
1028
1061
|
if (!valid.ok) {
|
|
1029
1062
|
return { ok: false, error: toError(valid.error) };
|
|
1030
1063
|
}
|
|
1031
|
-
registry
|
|
1032
|
-
|
|
1064
|
+
// Re-read under the registry lock rather than writing back `registry`: that snapshot predates
|
|
1065
|
+
// the gate and the checks above, and writing it would drop whatever another writer (an
|
|
1066
|
+
// update, a delete) changed in between. Same for the rollback and for delete below.
|
|
1067
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1068
|
+
const current = await readRegistry(baseStateDir);
|
|
1069
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: [...current.runtimes, entry] });
|
|
1070
|
+
});
|
|
1033
1071
|
/**
|
|
1034
1072
|
* The unwired verdict for THIS install, tracked locally rather than read back out of
|
|
1035
1073
|
* `unwiredRuntimes`, so the result reports what this call did and never a leftover verdict
|
|
@@ -1150,8 +1188,10 @@ const senpiRuntimePlugin = {
|
|
|
1150
1188
|
};
|
|
1151
1189
|
}
|
|
1152
1190
|
catch (err) {
|
|
1153
|
-
|
|
1154
|
-
|
|
1191
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1192
|
+
const current = await readRegistry(baseStateDir);
|
|
1193
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: current.runtimes.filter((e) => e.id !== resolvedId) });
|
|
1194
|
+
});
|
|
1155
1195
|
const msg = err instanceof Error ? err.message : String(err);
|
|
1156
1196
|
return { ok: false, error: toUnavailable(`Could not start the runtime. This is usually due to invalid or incomplete YAML.\n\n${msg}`) };
|
|
1157
1197
|
}
|
|
@@ -1205,7 +1245,7 @@ const senpiRuntimePlugin = {
|
|
|
1205
1245
|
* unwired-verdict cleanup all happen exactly once, here.
|
|
1206
1246
|
*/
|
|
1207
1247
|
async function deleteRuntimeCore(params) {
|
|
1208
|
-
const { readRegistry, writeRegistry } = await import("./runtime/strategy-registry.js");
|
|
1248
|
+
const { readRegistry, writeRegistry, withRegistryLock } = await import("./runtime/strategy-registry.js");
|
|
1209
1249
|
const registry = await readRegistry(baseStateDir);
|
|
1210
1250
|
let targetId = typeof params?.id === "string" ? params.id : undefined;
|
|
1211
1251
|
const targetAddress = typeof params?.address === "string" ? params.address : undefined;
|
|
@@ -1266,8 +1306,10 @@ const senpiRuntimePlugin = {
|
|
|
1266
1306
|
}
|
|
1267
1307
|
}
|
|
1268
1308
|
if (deletedEntry) {
|
|
1269
|
-
|
|
1270
|
-
|
|
1309
|
+
await withRegistryLock(baseStateDir, async () => {
|
|
1310
|
+
const current = await readRegistry(baseStateDir);
|
|
1311
|
+
await writeRegistry(baseStateDir, { ...current, runtimes: current.runtimes.filter((e) => e.id !== targetId) });
|
|
1312
|
+
});
|
|
1271
1313
|
}
|
|
1272
1314
|
// Registry delete fact — the permanent-removal discriminator a transient runtime.stopped can't
|
|
1273
1315
|
// give. Unconditional (a never-booted runtime stops no handle, so emits no runtime.stopped) and
|
|
@@ -1340,6 +1382,165 @@ const senpiRuntimePlugin = {
|
|
|
1340
1382
|
return null;
|
|
1341
1383
|
}
|
|
1342
1384
|
}
|
|
1385
|
+
// `senpi update` — plan only. Internal transport for the CLI verb, like senpi.deploy.*.
|
|
1386
|
+
registerUpdateGatewayMethod(api, {
|
|
1387
|
+
listRuntimes: async () => {
|
|
1388
|
+
const { readRegistry } = await import("./runtime/strategy-registry.js");
|
|
1389
|
+
const registry = await readRegistry(baseStateDir);
|
|
1390
|
+
return registry.runtimes.map((e) => ({
|
|
1391
|
+
id: e.id,
|
|
1392
|
+
wallet: e.wallet ?? "",
|
|
1393
|
+
source: typeof e.runtimeYamlPath === "string" && e.runtimeYamlPath.length > 0
|
|
1394
|
+
? { path: e.runtimeYamlPath }
|
|
1395
|
+
: {
|
|
1396
|
+
content: e.runtimeYamlContent ?? "",
|
|
1397
|
+
...(e.runtimeYamlDir ? { dir: e.runtimeYamlDir } : {}),
|
|
1398
|
+
},
|
|
1399
|
+
}));
|
|
1400
|
+
},
|
|
1401
|
+
parseConfig: async (source) => {
|
|
1402
|
+
const { loadRuntimeConfig } = await import("./runtime/load-runtime-config.js");
|
|
1403
|
+
return source.path !== undefined
|
|
1404
|
+
? loadRuntimeConfig(source.path, { fromPath: true })
|
|
1405
|
+
: loadRuntimeConfig(source.content ?? "", { fromPath: false });
|
|
1406
|
+
},
|
|
1407
|
+
// Full DslState rather than the position summaries: the report needs `handoffStatus` to say
|
|
1408
|
+
// which positions the backend ratchet owns, and the summary shape drops it.
|
|
1409
|
+
activePositions: async (runtimeId) => {
|
|
1410
|
+
const handle = runtimeHandles.get(runtimeId);
|
|
1411
|
+
return handle?.dsl?.listActiveDslStates() ?? [];
|
|
1412
|
+
},
|
|
1413
|
+
recipeFindings: async (source) => {
|
|
1414
|
+
const { collectRecipeFindings } = await import("./validate/recipe.js");
|
|
1415
|
+
const baseDir = source.path !== undefined ? dirname(source.path) : source.dir;
|
|
1416
|
+
const result = await collectRecipeFindings(source.path !== undefined
|
|
1417
|
+
? { path: source.path, baseDir }
|
|
1418
|
+
: { content: source.content ?? "", baseDir });
|
|
1419
|
+
return result.findings;
|
|
1420
|
+
},
|
|
1421
|
+
installGate: async (findings) => {
|
|
1422
|
+
const { checkInstallGate } = await import("./validate/install-gate.js");
|
|
1423
|
+
const gate = checkInstallGate(findings);
|
|
1424
|
+
return { ok: gate.ok, blocking: gate.blocking };
|
|
1425
|
+
},
|
|
1426
|
+
verifyProof: async (packageDir, appliedRecipe) => {
|
|
1427
|
+
const { verifyProof } = await import("./validate/index.js");
|
|
1428
|
+
return checkProofCoversRecipe(packageDir, verifyProof(packageDir), appliedRecipe, (f) => readFileSync(f, "utf8"));
|
|
1429
|
+
},
|
|
1430
|
+
applyToRuntime: makeApplyToRuntime(runtimeHandles, async (runtimeId, next, recipe) => {
|
|
1431
|
+
// Restart this runtime's external scanner children against the new package.
|
|
1432
|
+
//
|
|
1433
|
+
// The rebuild swaps in-process components; these are separate OS processes, spawned once
|
|
1434
|
+
// from a launch config written at install and reading their entrypoint at spawn. Without
|
|
1435
|
+
// this, an apply reported success while every external scanner went on running the code,
|
|
1436
|
+
// `inputs` and cadence it booted with.
|
|
1437
|
+
//
|
|
1438
|
+
// Same shape as the hot-install path above, plus stopping the outgoing launcher first.
|
|
1439
|
+
if (!sharedIntakeContext || process.env.SENPI_RUNTIME_API_DISABLED === "true")
|
|
1440
|
+
return {};
|
|
1441
|
+
const wallet = runtimeHandles.get(runtimeId)?.wallet ?? "";
|
|
1442
|
+
const previous = launchers.get(runtimeId);
|
|
1443
|
+
if (previous) {
|
|
1444
|
+
// Stopped before the replacement is built: two supervisors on one scanner would both
|
|
1445
|
+
// spawn a child against the same state directory and delivery journal.
|
|
1446
|
+
await previous.stop().catch(() => { });
|
|
1447
|
+
launchers.delete(runtimeId);
|
|
1448
|
+
}
|
|
1449
|
+
let launcher = null;
|
|
1450
|
+
try {
|
|
1451
|
+
const apiConfig = loadApiConfig(api.pluginConfig);
|
|
1452
|
+
launcher = wireRuntime({
|
|
1453
|
+
runtimeConfig: next,
|
|
1454
|
+
// Where a scanner's relative `path: ./scanners` resolves. The apply carries the package
|
|
1455
|
+
// directory precisely so this keeps working for a recipe supplied as content.
|
|
1456
|
+
recipeDir: recipe.dir ?? (recipe.path !== undefined ? dirname(recipe.path) : undefined),
|
|
1457
|
+
runtimeId,
|
|
1458
|
+
wallet,
|
|
1459
|
+
sharedCtx: sharedIntakeContext,
|
|
1460
|
+
runtimeHandles,
|
|
1461
|
+
intakeUrl: intakeUrlFor(apiConfig.host, apiConfig.port),
|
|
1462
|
+
scaffoldPackageDir: fileURLToPath(new URL("./scanners/external", import.meta.url)),
|
|
1463
|
+
runtimeStateDir: buildRuntimeStateDir(baseStateDir, runtimeId, wallet),
|
|
1464
|
+
logger: apiLogger,
|
|
1465
|
+
});
|
|
1466
|
+
if (!launcher) {
|
|
1467
|
+
// The new recipe declares no external scanners. The old children are already stopped,
|
|
1468
|
+
// and reporting "not unwired, no rows" is the truth rather than a fault.
|
|
1469
|
+
unwiredRuntimes.delete(runtimeId);
|
|
1470
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({ unwired: false, rows: [] }));
|
|
1471
|
+
return {};
|
|
1472
|
+
}
|
|
1473
|
+
await launcher.start();
|
|
1474
|
+
launchers.set(runtimeId, launcher);
|
|
1475
|
+
unwiredRuntimes.delete(runtimeId);
|
|
1476
|
+
const started = launcher;
|
|
1477
|
+
// Re-pointed at the NEW launcher: the runtime remembers the source it was handed, but
|
|
1478
|
+
// that closure reads the outgoing launcher, which is now stopped.
|
|
1479
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
|
|
1480
|
+
unwired: false,
|
|
1481
|
+
rows: started.describeSupervision(),
|
|
1482
|
+
}));
|
|
1483
|
+
return {};
|
|
1484
|
+
}
|
|
1485
|
+
catch (err) {
|
|
1486
|
+
// `start()` loops over every scanner, so a throw on the third leaves the first two
|
|
1487
|
+
// supervisors already spawning and restarting children. `launchers.set` never ran, so
|
|
1488
|
+
// the object is unreachable — neither shutdown nor `runtime delete` iterate to it — and
|
|
1489
|
+
// those children would be respawned for the life of the gateway process. The hot-install
|
|
1490
|
+
// path stops a half-started launcher for exactly this reason; this one must too.
|
|
1491
|
+
if (launcher)
|
|
1492
|
+
await launcher.stop().catch(() => { });
|
|
1493
|
+
// Deliberately not rethrown. The recipe is already live in-process, so failing the apply
|
|
1494
|
+
// here would report FAILED over a change that did land. It is a degraded runtime —
|
|
1495
|
+
// recorded the same way a failed hot-install launch is, and visible in scanner health.
|
|
1496
|
+
unwiredRuntimes.set(runtimeId, "update_launch");
|
|
1497
|
+
runtimeHandles.get(runtimeId)?.attachSupervisionSource(() => ({
|
|
1498
|
+
unwired: true,
|
|
1499
|
+
unwiredPhase: "update_launch",
|
|
1500
|
+
rows: [],
|
|
1501
|
+
}));
|
|
1502
|
+
eventScannersUnwired("update_launch", runtimeId, wallet, appendCause("[senpi-runtime] scanner relaunch after update failed — runtime is running the new " +
|
|
1503
|
+
"recipe with NO external scanners", err), err);
|
|
1504
|
+
// Reported, not thrown: the recipe IS live, so this is a degraded runtime rather than a
|
|
1505
|
+
// failed apply. The caller renders it as a warning on an otherwise successful report.
|
|
1506
|
+
return { unwired: err instanceof Error ? err.message : String(err) };
|
|
1507
|
+
}
|
|
1508
|
+
}),
|
|
1509
|
+
writeRegistry: makeWriteRegistry(baseStateDir),
|
|
1510
|
+
onApplied: (info) => {
|
|
1511
|
+
// The audit answer to "who changed this strategy and to what". Hashed over the UNRESOLVED
|
|
1512
|
+
// recipe so the value is comparable with the one `runtime.started` stamps — otherwise the
|
|
1513
|
+
// same attribute name would carry two incomparable hashes and a restart could not be told
|
|
1514
|
+
// apart from a revert. Inside emitEvent's guard so telemetry never fails an apply that has
|
|
1515
|
+
// already landed.
|
|
1516
|
+
emitEvent(apiLogger, () => {
|
|
1517
|
+
const unresolved = (source) => {
|
|
1518
|
+
try {
|
|
1519
|
+
const raw = source.path !== undefined
|
|
1520
|
+
? readFileSync(source.path, "utf8")
|
|
1521
|
+
: (source.content ?? "");
|
|
1522
|
+
return parseYaml(raw);
|
|
1523
|
+
}
|
|
1524
|
+
catch {
|
|
1525
|
+
// A hash is worth less than the event carrying it; an unreadable previous recipe must
|
|
1526
|
+
// not swallow the record that the update happened.
|
|
1527
|
+
return undefined;
|
|
1528
|
+
}
|
|
1529
|
+
};
|
|
1530
|
+
return buildRuntimeUpdatedEvent({
|
|
1531
|
+
runtimeId: info.runtimeId,
|
|
1532
|
+
...(info.address ? { address: info.address } : {}),
|
|
1533
|
+
...(unresolved(info.recipe) ? { unresolvedConfig: unresolved(info.recipe) } : {}),
|
|
1534
|
+
...(unresolved(info.previousRecipe)
|
|
1535
|
+
? { previousUnresolvedConfig: unresolved(info.previousRecipe) }
|
|
1536
|
+
: {}),
|
|
1537
|
+
exitPresetChanged: info.exitPresetChanged,
|
|
1538
|
+
openPositions: info.openPositions,
|
|
1539
|
+
...(info.slots !== undefined ? { slots: info.slots } : {}),
|
|
1540
|
+
});
|
|
1541
|
+
});
|
|
1542
|
+
},
|
|
1543
|
+
});
|
|
1343
1544
|
registerDeployGatewayMethods(api, {
|
|
1344
1545
|
controller: deployController,
|
|
1345
1546
|
withSenpiClient,
|
|
@@ -1950,7 +2151,7 @@ const senpiRuntimePlugin = {
|
|
|
1950
2151
|
});
|
|
1951
2152
|
}
|
|
1952
2153
|
}, { scope: "operator.write" });
|
|
1953
|
-
|
|
2154
|
+
pluginLogger.info(`[senpi-runtime] v${VERSION} plugin registered — stateDir: ${baseStateDir}`);
|
|
1954
2155
|
},
|
|
1955
2156
|
};
|
|
1956
2157
|
function getRuntimeHandleOrRespond(runtimeHandles, runtimeId, respond) {
|