main
1import { Type } from "@sinclair/typebox";
2import { Tool } from "./types.js";
3import * as os from "os";
4
5const StatusParams = Type.Object({});
6
7type StatusArgs = typeof StatusParams.static;
8
9export function createStatusTool(): Tool<StatusArgs> {
10 return {
11 name: "status",
12 description:
13 "Get system status including uptime, memory usage, and bot information",
14 parameters: StatusParams,
15 execute: async () => {
16 const uptime = process.uptime();
17 const memUsage = process.memoryUsage();
18 const systemUptime = os.uptime();
19
20 const formatBytes = (bytes: number): string => {
21 const mb = bytes / 1024 / 1024;
22 return `${mb.toFixed(1)} MB`;
23 };
24
25 const formatDuration = (seconds: number): string => {
26 const days = Math.floor(seconds / 86400);
27 const hours = Math.floor((seconds % 86400) / 3600);
28 const mins = Math.floor((seconds % 3600) / 60);
29 const secs = Math.floor(seconds % 60);
30
31 const parts = [];
32 if (days > 0) parts.push(`${days}d`);
33 if (hours > 0) parts.push(`${hours}h`);
34 if (mins > 0) parts.push(`${mins}m`);
35 if (secs > 0 || parts.length === 0) parts.push(`${secs}s`);
36 return parts.join(" ");
37 };
38
39 return JSON.stringify(
40 {
41 bot: {
42 name: "Daneel",
43 version: "0.1.0",
44 uptime: formatDuration(uptime),
45 },
46 system: {
47 hostname: os.hostname(),
48 platform: os.platform(),
49 arch: os.arch(),
50 uptime: formatDuration(systemUptime),
51 loadAvg: os.loadavg().map((l) => l.toFixed(2)),
52 },
53 memory: {
54 process: {
55 heapUsed: formatBytes(memUsage.heapUsed),
56 heapTotal: formatBytes(memUsage.heapTotal),
57 rss: formatBytes(memUsage.rss),
58 },
59 system: {
60 total: formatBytes(os.totalmem()),
61 free: formatBytes(os.freemem()),
62 used: formatBytes(os.totalmem() - os.freemem()),
63 },
64 },
65 },
66 null,
67 2
68 );
69 },
70 };
71}