/**
* Claude Skill: Find Outdated Devices
*
* This skill helps identify devices that haven't checked in recently,
* which could indicate they're offline, decommissioned, or need attention.
*/
import { SkillContext, SkillResult } from '../types.js';
import { buildErrorContext } from '../../utils/error-handler.js';
interface FindOutdatedDevicesParams {
daysSinceLastContact: number;
includeDetails?: boolean;
}
export async function findOutdatedDevices(
context: SkillContext,
params: FindOutdatedDevicesParams
): Promise<SkillResult> {
try {
// Use the checkDeviceCompliance tool to find outdated devices
const result = await context.callTool('checkDeviceCompliance', {
days: params.daysSinceLastContact,
includeDetails: params.includeDetails || false
});
const devices = result.data?.devices || [];
const totalDevices = result.data?.totalDevices || 0;
const compliantDevices = result.data?.compliant || 0;
const nonCompliantDevices = result.data?.nonCompliant || 0;
// Format the response
let response = `## Device Check-in Status Report\n\n`;
response += `- **Total Devices**: ${totalDevices}\n`;
response += `- **Active (checked in within ${params.daysSinceLastContact} days)**: ${compliantDevices}\n`;
response += `- **Outdated**: ${nonCompliantDevices}\n\n`;
if (nonCompliantDevices > 0) {
response += `### Devices Requiring Attention\n\n`;
if (params.includeDetails && devices.length > 0) {
response += `| Device Name | Serial Number | Last Check-in | Days Since |\n`;
response += `|-------------|---------------|---------------|------------|\n`;
devices.forEach((device: any) => {
const daysSince = Math.floor((Date.now() - new Date(device.lastContactTime).getTime()) / (1000 * 60 * 60 * 24));
response += `| ${device.name} | ${device.serialNumber} | ${new Date(device.lastContactTime).toLocaleDateString()} | ${daysSince} days |\n`;
});
} else {
response += `Run with \`includeDetails: true\` to see the full list of outdated devices.\n`;
}
} else {
response += `✅ All devices have checked in within the last ${params.daysSinceLastContact} days!\n`;
}
return {
success: true,
message: response,
data: {
totalDevices,
activeDevices: compliantDevices,
outdatedDevices: nonCompliantDevices,
devices: params.includeDetails ? devices : undefined
}
};
} catch (error: unknown) {
const errorContext = buildErrorContext(
error,
'Find outdated devices',
'find-outdated-devices',
{ daysSinceLastContact: params.daysSinceLastContact }
);
return {
success: false,
message: `Failed to check device status: ${errorContext.message}${errorContext.suggestions ? ` (${errorContext.suggestions[0]})` : ''}`,
error: error instanceof Error ? error : new Error(errorContext.message),
data: {
errorCode: errorContext.code,
timestamp: errorContext.timestamp,
}
};
}
}
// Skill metadata
export const metadata: any = {
name: 'find-outdated-devices',
description: 'Identify devices that haven\'t checked in recently',
parameters: {
daysSinceLastContact: {
type: 'number' as const,
description: 'Number of days to consider a device outdated',
required: true,
default: 30
},
includeDetails: {
type: 'boolean' as const,
description: 'Include detailed device list',
required: false,
default: false
}
},
examples: [
{
description: 'Find devices not seen in 30 days',
params: { daysSinceLastContact: 30 }
},
{
description: 'Get detailed list of devices not seen in 7 days',
params: { daysSinceLastContact: 7, includeDetails: true }
}
]
};