agent-window 1.0.4 → 1.0.6
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()) {
|
|
@@ -244,15 +244,22 @@ export async function discoverInstances() {
|
|
|
244
244
|
// Extract instance name from bot-name
|
|
245
245
|
const instanceName = proc.name.replace(/^bot-/, '');
|
|
246
246
|
|
|
247
|
-
//
|
|
247
|
+
// Determine project path and config path
|
|
248
248
|
let projectPath = null;
|
|
249
|
+
let configPath = null;
|
|
249
250
|
let pluginPath = null;
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
252
|
+
// Priority 1: Use CONFIG_PATH from environment variables
|
|
253
|
+
if (proc.configPath) {
|
|
254
|
+
configPath = proc.configPath;
|
|
255
|
+
projectPath = path.dirname(configPath);
|
|
256
|
+
}
|
|
257
|
+
// Priority 2: Use cwd
|
|
258
|
+
else if (proc.cwd) {
|
|
259
|
+
projectPath = proc.cwd;
|
|
253
260
|
}
|
|
254
261
|
|
|
255
|
-
// Check if it's a BMAD project
|
|
262
|
+
// Check if it's a BMAD project (has _bmad directory)
|
|
256
263
|
if (projectPath && existsSync(path.join(projectPath, '_bmad'))) {
|
|
257
264
|
pluginPath = path.join(projectPath, '_agent-bridge', 'src');
|
|
258
265
|
} else if (projectPath && existsSync(path.join(projectPath, 'src', 'bot.js'))) {
|
|
@@ -265,6 +272,7 @@ export async function discoverInstances() {
|
|
|
265
272
|
name: instanceName,
|
|
266
273
|
displayName: instanceName.charAt(0).toUpperCase() + instanceName.slice(1),
|
|
267
274
|
projectPath,
|
|
275
|
+
configPath,
|
|
268
276
|
pluginPath,
|
|
269
277
|
status: proc.status || 'unknown',
|
|
270
278
|
pid: proc.pid,
|
|
@@ -314,6 +322,7 @@ export async function importInstance(discovered) {
|
|
|
314
322
|
name: discovered.name,
|
|
315
323
|
displayName: discovered.displayName,
|
|
316
324
|
projectPath: validatedPath,
|
|
325
|
+
configPath: discovered.configPath,
|
|
317
326
|
pluginPath: validatedPluginPath,
|
|
318
327
|
botName: discovered.botName,
|
|
319
328
|
addedAt: new Date().toISOString(),
|
|
@@ -88,7 +88,10 @@ async function list(options = {}) {
|
|
|
88
88
|
cpu: p.monit?.cpu || 0,
|
|
89
89
|
restarts: p.pm2_env?.restart_time || 0,
|
|
90
90
|
cwd: p.pm2_env?.cwd || null,
|
|
91
|
-
script: p.pm2_env?.pm_cwd || null
|
|
91
|
+
script: p.pm2_env?.pm_cwd || null,
|
|
92
|
+
// Environment variables
|
|
93
|
+
env: p.pm2_env?.env || {},
|
|
94
|
+
configPath: p.pm2_env?.env?.CONFIG_PATH || null
|
|
92
95
|
}));
|
|
93
96
|
} catch {
|
|
94
97
|
return [];
|