agent-window 1.0.4 → 1.0.5
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
CHANGED
|
@@ -210,8 +210,19 @@ export async function registerInstanceRoutes(fastify) {
|
|
|
210
210
|
}, async (request, reply) => {
|
|
211
211
|
try {
|
|
212
212
|
const { name } = request.params;
|
|
213
|
-
const
|
|
214
|
-
|
|
213
|
+
const instance = await getInstance(name);
|
|
214
|
+
|
|
215
|
+
if (!instance) {
|
|
216
|
+
return reply.code(404).send({
|
|
217
|
+
error: 'Instance not found',
|
|
218
|
+
name
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Use botName for PM2 lookup, default to bot-{name}
|
|
223
|
+
const botName = instance.botName || `bot-${name}`;
|
|
224
|
+
const status = await getStatus(botName);
|
|
225
|
+
return { ...status, instanceName: name };
|
|
215
226
|
} catch (error) {
|
|
216
227
|
reply.code(500).send({
|
|
217
228
|
error: 'Failed to get status',
|
|
@@ -240,7 +251,16 @@ export async function registerInstanceRoutes(fastify) {
|
|
|
240
251
|
const { name } = request.params;
|
|
241
252
|
const { lines = 100, logType = 'all' } = request.query;
|
|
242
253
|
|
|
243
|
-
const
|
|
254
|
+
const instance = await getInstance(name);
|
|
255
|
+
if (!instance) {
|
|
256
|
+
return reply.code(404).send({
|
|
257
|
+
error: 'Instance not found',
|
|
258
|
+
name
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const botName = instance.botName || `bot-${name}`;
|
|
263
|
+
const logs = await getLogs(botName, { lines, type: logType });
|
|
244
264
|
return { logs };
|
|
245
265
|
} catch (error) {
|
|
246
266
|
reply.code(500).send({
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
stopProcess,
|
|
13
13
|
restartProcess
|
|
14
14
|
} from '../../core/instance/pm2-bridge.js';
|
|
15
|
+
import { getInstance } from '../../core/instance/manager.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Register operation routes
|
|
@@ -32,7 +33,17 @@ export async function registerOperationRoutes(fastify) {
|
|
|
32
33
|
}, async (request, reply) => {
|
|
33
34
|
try {
|
|
34
35
|
const { name } = request.params;
|
|
35
|
-
const
|
|
36
|
+
const instance = await getInstance(name);
|
|
37
|
+
|
|
38
|
+
if (!instance) {
|
|
39
|
+
return reply.code(404).send({
|
|
40
|
+
error: 'Instance not found',
|
|
41
|
+
name
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const botName = instance.botName || `bot-${name}`;
|
|
46
|
+
const result = await startProcess(botName);
|
|
36
47
|
|
|
37
48
|
if (!result.success) {
|
|
38
49
|
return reply.code(400).send({
|
|
@@ -64,7 +75,17 @@ export async function registerOperationRoutes(fastify) {
|
|
|
64
75
|
}, async (request, reply) => {
|
|
65
76
|
try {
|
|
66
77
|
const { name } = request.params;
|
|
67
|
-
const
|
|
78
|
+
const instance = await getInstance(name);
|
|
79
|
+
|
|
80
|
+
if (!instance) {
|
|
81
|
+
return reply.code(404).send({
|
|
82
|
+
error: 'Instance not found',
|
|
83
|
+
name
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const botName = instance.botName || `bot-${name}`;
|
|
88
|
+
const result = await stopProcess(botName);
|
|
68
89
|
|
|
69
90
|
if (!result.success) {
|
|
70
91
|
return reply.code(400).send({
|
|
@@ -96,7 +117,17 @@ export async function registerOperationRoutes(fastify) {
|
|
|
96
117
|
}, async (request, reply) => {
|
|
97
118
|
try {
|
|
98
119
|
const { name } = request.params;
|
|
99
|
-
const
|
|
120
|
+
const instance = await getInstance(name);
|
|
121
|
+
|
|
122
|
+
if (!instance) {
|
|
123
|
+
return reply.code(404).send({
|
|
124
|
+
error: 'Instance not found',
|
|
125
|
+
name
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const botName = instance.botName || `bot-${name}`;
|
|
130
|
+
const result = await restartProcess(botName);
|
|
100
131
|
|
|
101
132
|
if (!result.success) {
|
|
102
133
|
return reply.code(400).send({
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import { spawn } from 'child_process';
|
|
9
9
|
import { isWindows, isWSLAvailable } from '../../core/platform/detector.js';
|
|
10
|
+
import { getInstance } from '../../core/instance/manager.js';
|
|
10
11
|
|
|
11
12
|
// Active log streams by instance name
|
|
12
13
|
const activeStreams = new Map();
|
|
@@ -21,9 +22,13 @@ export async function registerLogStream(fastify) {
|
|
|
21
22
|
* Stream logs for a specific instance
|
|
22
23
|
*/
|
|
23
24
|
fastify.register(async function (fastify) {
|
|
24
|
-
fastify.get('/ws/logs/:name', { websocket: true }, (connection, req) => {
|
|
25
|
+
fastify.get('/ws/logs/:name', { websocket: true }, async (connection, req) => {
|
|
25
26
|
const { name } = req.params;
|
|
26
27
|
|
|
28
|
+
// Get instance to find botName
|
|
29
|
+
const instance = await getInstance(name);
|
|
30
|
+
const botName = instance?.botName || `bot-${name}`;
|
|
31
|
+
|
|
27
32
|
// Close existing stream for this instance if any
|
|
28
33
|
if (activeStreams.has(name)) {
|
|
29
34
|
const existing = activeStreams.get(name);
|
|
@@ -32,7 +37,7 @@ export async function registerLogStream(fastify) {
|
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
connection.socket.on('open', () => {
|
|
35
|
-
fastify.log.info(`Log stream started for: ${name}`);
|
|
40
|
+
fastify.log.info(`Log stream started for: ${name} (${botName})`);
|
|
36
41
|
});
|
|
37
42
|
|
|
38
43
|
// Send initial connection message
|
|
@@ -44,7 +49,7 @@ export async function registerLogStream(fastify) {
|
|
|
44
49
|
|
|
45
50
|
// Start PM2 log stream
|
|
46
51
|
let pm2Cmd = 'pm2';
|
|
47
|
-
let pm2Args = ['logs',
|
|
52
|
+
let pm2Args = ['logs', botName, '--lines', '50', '--raw', '--nostream'];
|
|
48
53
|
|
|
49
54
|
// On Windows, use WSL if available
|
|
50
55
|
if (isWindows()) {
|