collabSupport/services/voiceDiag/checks/dectBaseRelay.js
jmcqueen 7dc326c404 Split voice commands into status vs diag and redesign MPP phone output.
Replace /phonestatus follow-ups with /voicestatus, /wanstatus, /phonediag, and /dectdiag; extend /voicediag with relay probes and section-based MPP diagnostics.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-29 13:55:41 -04:00

105 lines
2.7 KiB
JavaScript

// services/voiceDiag/checks/dectBaseRelay.js
//
// Summarises DECT base relay collect results for /voicediag.
export const DECT_BASE_RELAY_STANDARDS = Object.freeze({
healthy: true,
});
export const dectBaseRelayCheck = {
id: 'dectBaseRelay',
label: 'DECT Base (relay)',
requires: ['phoneStatus'],
scope: null,
standards: DECT_BASE_RELAY_STANDARDS,
async run(ctx) {
if (!process.env.DECT_RELAY_AGENT_TOKEN) {
return {
status: 'skipped',
message: 'Relay not configured (`DECT_RELAY_AGENT_TOKEN` unset) — run `/dectdiag` when relay is available.',
details: null,
remediation: null,
};
}
const results = ctx.dectRelayResults;
if (!Array.isArray(results)) {
return {
status: 'skipped',
message: 'DECT relay collect was not run (no bases discovered on 10.x).',
details: null,
remediation: null,
};
}
if (results.length === 0) {
return {
status: 'skipped',
message: 'No DECT bases discovered on 10.x for relay collect.',
details: null,
remediation: null,
};
}
const bases = [];
let errorCount = 0;
for (const r of results) {
const label = r.base?.name || r.base?.mac || '?';
const ip = r.base?.ip || '?';
if (!r.ok) {
errorCount += 1;
bases.push({
label,
ip,
ok: false,
error: r.error?.message || 'collect failed',
});
continue;
}
const verdict = r.verdict || {};
const data = r.data || {};
const warnings = Array.isArray(verdict.warnings) ? verdict.warnings : [];
const powerLoss = (data.rebootLog || []).find((entry) => entry.reasonCode === 80);
const unhealthy = !verdict.healthy;
if (unhealthy) errorCount += 1;
bases.push({
label,
ip,
ok: true,
healthy: verdict.healthy !== false,
uptime: data.time?.operatingTime || null,
warnings,
powerLoss: powerLoss ? { at: powerLoss.at, sequence: powerLoss.sequence } : null,
activeRtp: data.rtp?.current || 0,
});
}
const summary =
`${results.length} DECT base(s) collected via relay. ` +
`${errorCount === 0 ? 'All bases healthy.' : `${errorCount} base(s) need attention.`}`;
const details = { bases, collected: results.length, attentionCount: errorCount };
if (errorCount > 0) {
return {
status: 'error',
message: summary + ' Run `/dectdiag` for full dump and reboot controls.',
details,
remediation: null,
};
}
return {
status: 'ok',
message: summary,
details,
remediation: null,
};
},
};