Files
pikasTech-agentrun/deploy/runtime/boot/agentrun-boot-report.mjs
T
2026-07-20 09:37:55 +02:00

30 lines
1.3 KiB
JavaScript

const managerUrl = process.env.AGENTRUN_MGR_URL;
const runnerJobId = process.env.AGENTRUN_RUNNER_JOB_ID;
const phase = process.argv[2];
const attempt = Number(process.argv[3]);
if (!managerUrl || !runnerJobId || !phase || !Number.isSafeInteger(attempt) || attempt < 1) process.exit(2);
const body = {
phase,
attempt,
runId: process.env.AGENTRUN_RUN_ID,
commandId: process.env.AGENTRUN_COMMAND_ID,
attemptId: process.env.AGENTRUN_ATTEMPT_ID,
runnerId: process.env.AGENTRUN_RUNNER_ID,
};
if (process.argv[4]) body.code = process.argv[4];
if (process.argv[5]) body.summary = process.argv[5];
const headers = { "content-type": "application/json" };
if (process.env.AGENTRUN_API_KEY) headers.authorization = `Bearer ${process.env.AGENTRUN_API_KEY}`;
const response = await fetch(new URL(`/api/v1/runner-jobs/${encodeURIComponent(runnerJobId)}/boot-observations`, managerUrl), {
method: "POST",
headers,
body: JSON.stringify(body),
});
const envelope = await response.json();
if (!response.ok || envelope?.ok !== true) {
process.stderr.write(`${JSON.stringify({ ok: false, event: "agentrun-boot-report", status: response.status, failureKind: envelope?.failureKind ?? "infra-failed", message: envelope?.message ?? "manager boot observation failed" })}\n`);
process.exit(1);
}
process.stdout.write(`${JSON.stringify(envelope.data)}\n`);