collabSupport/services/voiceDiag/checks/mppDeskPhoneRelay.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/mppDeskPhoneRelay.js
//
// Summarises MPP desk-phone relay probe results for /voicediag.
import { collectIssues } from '../../renderers/mppPhoneFormatters.js';
import { isLineRegistered } from '../../renderers/mppPhoneFormatters.js';
export const MPP_DESK_PHONE_RELAY_STANDARDS = Object.freeze({
registered: true,
noIssues: true,
});
export const mppDeskPhoneRelayCheck = {
id: 'mppDeskPhoneRelay',
label: 'MPP Desk Phone (relay)',
requires: ['phoneStatus'],
scope: null,
standards: MPP_DESK_PHONE_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 `/phonediag` when relay is available.',
details: null,
remediation: null,
};
}
const results = ctx.mppRelayResults;
if (!Array.isArray(results)) {
return {
status: 'skipped',
message: 'MPP relay probe was not run (no desk phones discovered on 10.x).',
details: null,
remediation: null,
};
}
if (results.length === 0) {
return {
status: 'skipped',
message: 'No MPP desk phones discovered on 10.x for relay probe.',
details: null,
remediation: null,
};
}
const phones = [];
let errorCount = 0;
for (const r of results) {
const label = r.phone?.name || r.phone?.product || r.phone?.mac || '?';
const ip = r.phone?.ip || '?';
if (!r.ok) {
errorCount += 1;
phones.push({
label,
ip,
ok: false,
error: r.error?.message || 'probe failed',
});
continue;
}
const parsed = r.mpp?.parsed || r.parsed || {};
const line1 = parsed.lines?.find((l) => l.index === 1) || parsed.lines?.[0];
const issues = collectIssues(r.mpp || {}, parsed);
const registered = line1 ? isLineRegistered(line1) : null;
if (!registered || issues.length > 0) errorCount += 1;
phones.push({
label,
ip,
ok: true,
registered: line1?.registrationState || null,
issues,
});
}
const summary =
`${results.length} MPP phone(s) probed via relay. ` +
`${errorCount === 0 ? 'All registered with no issues.' : `${errorCount} phone(s) need attention.`}`;
const details = { phones, probed: results.length, attentionCount: errorCount };
if (errorCount > 0) {
return {
status: 'error',
message: summary + ' Run `/phonediag` for full section layout.',
details,
remediation: null,
};
}
return {
status: 'ok',
message: summary,
details,
remediation: null,
};
},
};