osai-agent 4.2.30 → 4.2.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/commands/run.js +18 -6
- package/src/commands/usage.js +23 -12
package/package.json
CHANGED
package/src/commands/run.js
CHANGED
|
@@ -11,6 +11,7 @@ import { toHttpUrl } from '../services/server-url.js';
|
|
|
11
11
|
import { MODES } from '../utils/constants.js';
|
|
12
12
|
import { printNotLoggedIn } from '../ui/terminal.js';
|
|
13
13
|
import { disableMouseReporting } from '../ui/mouse-scroll.js';
|
|
14
|
+
import WebSocket from 'ws';
|
|
14
15
|
import { logger } from '../utils/logger.js';
|
|
15
16
|
|
|
16
17
|
export const run = async ({ server: serverOverride, noConfirm = false, osOverride, coding = false, fromSession = null, local = false } = {}) => {
|
|
@@ -33,15 +34,26 @@ export const run = async ({ server: serverOverride, noConfirm = false, osOverrid
|
|
|
33
34
|
|
|
34
35
|
if (!effectiveLocal && token && server) {
|
|
35
36
|
try {
|
|
36
|
-
const
|
|
37
|
-
|
|
37
|
+
const wsUrl = server.replace('http://', 'ws://').replace('https://', 'wss://');
|
|
38
|
+
await new Promise((resolve, reject) => {
|
|
39
|
+
const ws = new WebSocket(`${wsUrl}/ws`, { handshakeTimeout: 5000 });
|
|
40
|
+
const timeout = setTimeout(() => { ws.close(); resolve(); }, 3000);
|
|
41
|
+
ws.on('open', () => ws.send(JSON.stringify({ type: 'REGISTER', token })));
|
|
42
|
+
ws.on('message', (data) => {
|
|
43
|
+
try {
|
|
44
|
+
const msg = JSON.parse(data.toString());
|
|
45
|
+
if (msg.type === 'REGISTERED') { clearTimeout(timeout); ws.close(); resolve(); }
|
|
46
|
+
else if (msg.type === 'ERROR') { clearTimeout(timeout); ws.close(); reject(new Error(msg.message)); }
|
|
47
|
+
} catch { resolve(); }
|
|
48
|
+
});
|
|
49
|
+
ws.on('error', () => { clearTimeout(timeout); resolve(); });
|
|
38
50
|
});
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
console.log(chalk.red(`\n ${
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err.message.toLowerCase().includes('disabled')) {
|
|
53
|
+
console.log(chalk.red(`\n ${err.message}\n`));
|
|
42
54
|
process.exit(1);
|
|
43
55
|
}
|
|
44
|
-
}
|
|
56
|
+
}
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
const resumedMode = Object.values(MODES).includes(fromSession?.mode) ? fromSession.mode : null;
|
package/src/commands/usage.js
CHANGED
|
@@ -15,7 +15,7 @@ export const usageStats = async ({ server, days, json }) => {
|
|
|
15
15
|
console.log(chalk.hex('#4a9eff').bold(`\n Admin — Usage Stats (last ${summary.period_days} days)\n`));
|
|
16
16
|
console.log(` ${chalk.white('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}`);
|
|
17
17
|
|
|
18
|
-
const activePct = summary.total_users > 0 ? Math.round(summary.active / summary.total_users * 100) : 0;
|
|
18
|
+
const activePct = summary.total_users > 0 ? Math.round((summary.active || 0) / summary.total_users * 100) : 0;
|
|
19
19
|
const proPct = summary.total_users > 0 ? Math.round(summary.pro / summary.total_users * 100) : 0;
|
|
20
20
|
|
|
21
21
|
console.log(
|
|
@@ -30,7 +30,7 @@ export const usageStats = async ({ server, days, json }) => {
|
|
|
30
30
|
);
|
|
31
31
|
console.log(
|
|
32
32
|
` Sessions: ${chalk.white(summary.total_sessions)}` +
|
|
33
|
-
` | Commands: ${chalk.white(summary.total_commands.toLocaleString())}` +
|
|
33
|
+
` | Commands: ${chalk.white((summary.total_commands || 0).toLocaleString())}` +
|
|
34
34
|
` | Pro keys claimed: ${chalk.white(summary.claimed_pro_keys)}`
|
|
35
35
|
);
|
|
36
36
|
|
|
@@ -41,12 +41,21 @@ export const usageStats = async ({ server, days, json }) => {
|
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const header =
|
|
44
|
+
const header =
|
|
45
|
+
` ${chalk.dim('Email'.padEnd(36))} ` +
|
|
46
|
+
`${chalk.dim('Plan'.padEnd(5))} ` +
|
|
47
|
+
`${chalk.dim('Status'.padEnd(8))} ` +
|
|
48
|
+
`${chalk.dim('Logs')} ` +
|
|
49
|
+
`${chalk.dim('Cmd')} ` +
|
|
50
|
+
`${chalk.dim('Last active')}`;
|
|
45
51
|
console.log(header);
|
|
46
52
|
|
|
47
53
|
for (const u of users) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
54
|
+
const planStr = u.plan === 'pro' ? 'pro' : 'free';
|
|
55
|
+
const statusStr = !u.status || u.status === 'active' ? 'active' : 'disabled';
|
|
56
|
+
const planBadge = planStr === 'pro' ? chalk.hex('#ff9e64')(planStr.padEnd(5)) : chalk.gray(planStr.padEnd(5));
|
|
57
|
+
const statusBadge = statusStr === 'disabled' ? chalk.red(statusStr.padEnd(8)) : chalk.green(statusStr.padEnd(8));
|
|
58
|
+
|
|
50
59
|
const lastActive = u.last_active
|
|
51
60
|
? (() => {
|
|
52
61
|
const d = new Date(u.last_active);
|
|
@@ -59,15 +68,17 @@ export const usageStats = async ({ server, days, json }) => {
|
|
|
59
68
|
})()
|
|
60
69
|
: chalk.gray('never');
|
|
61
70
|
|
|
62
|
-
const
|
|
63
|
-
const
|
|
71
|
+
const logsRaw = u.total_logs > 0 ? String(u.total_logs) : '0';
|
|
72
|
+
const cmdRaw = u.total_commands > 0 ? String(u.total_commands) : '0';
|
|
73
|
+
const logsStr = u.total_logs > 0 ? chalk.white(logsRaw.padStart(2)) : chalk.gray(logsRaw.padStart(2));
|
|
74
|
+
const cmdStr = u.total_commands > 0 ? chalk.white(cmdRaw.padStart(4)) : chalk.gray(cmdRaw.padStart(4));
|
|
64
75
|
|
|
65
76
|
console.log(
|
|
66
|
-
` ${chalk.white(u.email.padEnd(36))}` +
|
|
67
|
-
`${planBadge
|
|
68
|
-
`${statusBadge
|
|
69
|
-
`${logsStr
|
|
70
|
-
`${cmdStr
|
|
77
|
+
` ${chalk.white(u.email.padEnd(36))} ` +
|
|
78
|
+
`${planBadge} ` +
|
|
79
|
+
`${statusBadge} ` +
|
|
80
|
+
`${logsStr} ` +
|
|
81
|
+
`${cmdStr} ` +
|
|
71
82
|
`${lastActive}`
|
|
72
83
|
);
|
|
73
84
|
}
|