osai-agent 4.2.30 → 4.2.31
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/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;
|