@tonk/cli 0.2.6 → 0.2.7
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/dist/commands/create.d.ts.map +1 -1
- package/dist/commands/create.js +8 -6
- package/dist/commands/create.js.map +1 -1
- package/dist/commands/hello.d.ts.map +1 -1
- package/dist/commands/hello.js +12 -0
- package/dist/commands/hello.js.map +1 -1
- package/dist/commands/kill.d.ts.map +1 -1
- package/dist/commands/kill.js +24 -0
- package/dist/commands/kill.js.map +1 -1
- package/dist/commands/ls.d.ts.map +1 -1
- package/dist/commands/ls.js +18 -0
- package/dist/commands/ls.js.map +1 -1
- package/dist/commands/proxy.d.ts.map +1 -1
- package/dist/commands/proxy.js +18 -0
- package/dist/commands/proxy.js.map +1 -1
- package/dist/commands/ps.d.ts.map +1 -1
- package/dist/commands/ps.js +18 -0
- package/dist/commands/ps.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +25 -1
- package/dist/commands/push.js.map +1 -1
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +19 -0
- package/dist/commands/start.js.map +1 -1
- package/dist/commands/worker/commands.d.ts.map +1 -1
- package/dist/commands/worker/commands.js +331 -5
- package/dist/commands/worker/commands.js.map +1 -1
- package/dist/commands/worker/index.d.ts.map +1 -1
- package/dist/commands/worker/index.js +2 -0
- package/dist/commands/worker/index.js.map +1 -1
- package/dist/commands/worker.d.ts +3 -0
- package/dist/commands/worker.d.ts.map +1 -0
- package/dist/commands/worker.js +527 -0
- package/dist/commands/worker.js.map +1 -0
- package/dist/lib/workerManager.d.ts.map +1 -1
- package/dist/lib/workerManager.js +16 -36
- package/dist/lib/workerManager.js.map +1 -1
- package/dist/tonk.js +8 -0
- package/dist/tonk.js.map +1 -1
- package/dist/utils/analytics.d.ts +26 -0
- package/dist/utils/analytics.d.ts.map +1 -0
- package/dist/utils/analytics.js +155 -0
- package/dist/utils/analytics.js.map +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import * as YAML from 'yaml';
|
|
6
|
+
import Table from 'cli-table3';
|
|
7
|
+
import inquirer from 'inquirer';
|
|
8
|
+
import { TonkWorkerManager } from '../lib/workerManager.js';
|
|
9
|
+
export const workerCommand = new Command('worker')
|
|
10
|
+
.description('Manage Tonk workers')
|
|
11
|
+
.action(async () => {
|
|
12
|
+
// Display help when no subcommand is provided
|
|
13
|
+
workerCommand.help();
|
|
14
|
+
});
|
|
15
|
+
workerCommand
|
|
16
|
+
.command('inspect <id>')
|
|
17
|
+
.description('Inspect a specific worker')
|
|
18
|
+
.option('-s, --start', 'Start the worker')
|
|
19
|
+
.option('-S, --stop', 'Stop the worker')
|
|
20
|
+
.option('-c, --config <path>', 'Path to worker configuration file')
|
|
21
|
+
.option('-p, --ping', 'Ping the worker to check its status')
|
|
22
|
+
.action(async (id, options) => {
|
|
23
|
+
try {
|
|
24
|
+
// Create worker manager
|
|
25
|
+
const workerManager = new TonkWorkerManager();
|
|
26
|
+
// Get worker
|
|
27
|
+
const worker = await workerManager.get(id);
|
|
28
|
+
if (!worker) {
|
|
29
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
// If no options provided, show worker details
|
|
33
|
+
if (!options.start && !options.stop && !options.config && !options.ping) {
|
|
34
|
+
displayWorkerDetails(worker);
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
// Handle ping option
|
|
38
|
+
if (options.ping) {
|
|
39
|
+
console.log(chalk.blue(`Pinging worker '${worker.name}' at ${worker.endpoint}...`));
|
|
40
|
+
// Check worker health
|
|
41
|
+
const isHealthy = await workerManager.checkHealth(id);
|
|
42
|
+
if (isHealthy) {
|
|
43
|
+
console.log(chalk.green(`Worker '${worker.name}' is active!`));
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.log(chalk.red(`Worker '${worker.name}' is not responding.`));
|
|
47
|
+
}
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Handle start option
|
|
51
|
+
if (options.start) {
|
|
52
|
+
console.log(chalk.blue(`Starting worker '${worker.name}'...`));
|
|
53
|
+
await workerManager.start(id);
|
|
54
|
+
console.log(chalk.green(`Worker '${worker.name}' started successfully!`));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
// Handle stop option
|
|
58
|
+
if (options.stop) {
|
|
59
|
+
console.log(chalk.blue(`Stopping worker '${worker.name}'...`));
|
|
60
|
+
await workerManager.stop(id);
|
|
61
|
+
console.log(chalk.green(`Worker '${worker.name}' stopped successfully!`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
// Handle config option
|
|
65
|
+
if (options.config) {
|
|
66
|
+
await updateWorkerConfig(workerManager, worker.id, options.config);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(chalk.red('Failed to manage worker:'), error);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
workerCommand
|
|
74
|
+
.command('ls')
|
|
75
|
+
.description('List all registered workers')
|
|
76
|
+
.action(async () => {
|
|
77
|
+
try {
|
|
78
|
+
// Create worker manager
|
|
79
|
+
const workerManager = new TonkWorkerManager();
|
|
80
|
+
// Get all workers
|
|
81
|
+
const workers = await workerManager.list();
|
|
82
|
+
if (workers.length === 0) {
|
|
83
|
+
console.log(chalk.yellow('No workers registered yet.'));
|
|
84
|
+
console.log(chalk.blue(`Use '${chalk.bold('tonk worker register')}' to register a worker.`));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// Create a table for display
|
|
88
|
+
const table = new Table({
|
|
89
|
+
head: [
|
|
90
|
+
chalk.cyan('ID'),
|
|
91
|
+
chalk.cyan('Name'),
|
|
92
|
+
chalk.cyan('Type'),
|
|
93
|
+
chalk.cyan('Endpoint'),
|
|
94
|
+
chalk.cyan('Protocol'),
|
|
95
|
+
chalk.cyan('Status'),
|
|
96
|
+
chalk.cyan('Last Seen'),
|
|
97
|
+
],
|
|
98
|
+
colWidths: [24, 20, 10, 30, 10, 10, 20],
|
|
99
|
+
});
|
|
100
|
+
// Add workers to table
|
|
101
|
+
workers.forEach(worker => {
|
|
102
|
+
const lastSeen = worker.status.lastSeen
|
|
103
|
+
? new Date(worker.status.lastSeen).toLocaleString()
|
|
104
|
+
: 'Never';
|
|
105
|
+
table.push([
|
|
106
|
+
worker.id,
|
|
107
|
+
worker.name,
|
|
108
|
+
worker.config.type || 'custom',
|
|
109
|
+
worker.endpoint,
|
|
110
|
+
worker.protocol,
|
|
111
|
+
worker.status.active
|
|
112
|
+
? chalk.green('Active')
|
|
113
|
+
: chalk.yellow('Inactive'),
|
|
114
|
+
lastSeen,
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
console.log(chalk.bold(`Registered Workers (${workers.length}):`));
|
|
118
|
+
console.log(table.toString());
|
|
119
|
+
console.log(chalk.blue(`\nUse '${chalk.bold('tonk worker inspect <id>')}' to view details of a specific worker.`));
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error(chalk.red('Failed to list workers:'), error);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
workerCommand
|
|
126
|
+
.command('rm <id>')
|
|
127
|
+
.description('Remove a registered worker')
|
|
128
|
+
.action(async (id) => {
|
|
129
|
+
try {
|
|
130
|
+
// Create worker manager
|
|
131
|
+
const workerManager = new TonkWorkerManager();
|
|
132
|
+
// Get worker
|
|
133
|
+
const worker = await workerManager.get(id);
|
|
134
|
+
if (!worker) {
|
|
135
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// Remove worker
|
|
139
|
+
await workerManager.remove(id);
|
|
140
|
+
console.log(chalk.green(`Worker '${worker.name}' (${id}) removed successfully.`));
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
console.error(chalk.red('Failed to remove worker:'), error);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
workerCommand
|
|
147
|
+
.command('ping <id>')
|
|
148
|
+
.description('Ping a worker to check its status')
|
|
149
|
+
.action(async (id) => {
|
|
150
|
+
try {
|
|
151
|
+
// Create worker manager
|
|
152
|
+
const workerManager = new TonkWorkerManager();
|
|
153
|
+
// Get worker
|
|
154
|
+
const worker = await workerManager.get(id);
|
|
155
|
+
if (!worker) {
|
|
156
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.log(chalk.blue(`Pinging worker '${worker.name}' at ${worker.endpoint}...`));
|
|
160
|
+
// Check worker health
|
|
161
|
+
const isHealthy = await workerManager.checkHealth(id);
|
|
162
|
+
if (isHealthy) {
|
|
163
|
+
console.log(chalk.green(`Worker '${worker.name}' is active!`));
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
console.log(chalk.red(`Worker '${worker.name}' is not responding.`));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error(chalk.red('Failed to ping worker:'), error);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
workerCommand
|
|
174
|
+
.command('start <id>')
|
|
175
|
+
.description('Start a worker')
|
|
176
|
+
.action(async (id) => {
|
|
177
|
+
try {
|
|
178
|
+
// Create worker manager
|
|
179
|
+
const workerManager = new TonkWorkerManager();
|
|
180
|
+
// Get worker
|
|
181
|
+
const worker = await workerManager.get(id);
|
|
182
|
+
if (!worker) {
|
|
183
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
console.log(chalk.blue(`Starting worker '${worker.name}'...`));
|
|
187
|
+
await workerManager.start(id);
|
|
188
|
+
console.log(chalk.green(`Worker '${worker.name}' started successfully!`));
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error(chalk.red('Failed to start worker:'), error);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
workerCommand
|
|
195
|
+
.command('stop <id>')
|
|
196
|
+
.description('Stop a worker')
|
|
197
|
+
.action(async (id) => {
|
|
198
|
+
try {
|
|
199
|
+
// Create worker manager
|
|
200
|
+
const workerManager = new TonkWorkerManager();
|
|
201
|
+
// Get worker
|
|
202
|
+
const worker = await workerManager.get(id);
|
|
203
|
+
if (!worker) {
|
|
204
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
console.log(chalk.blue(`Stopping worker '${worker.name}'...`));
|
|
208
|
+
await workerManager.stop(id);
|
|
209
|
+
console.log(chalk.green(`Worker '${worker.name}' stopped successfully!`));
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
console.error(chalk.red('Failed to stop worker:'), error);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
workerCommand
|
|
216
|
+
.command('logs <id>')
|
|
217
|
+
.description('View logs for a worker')
|
|
218
|
+
.option('-f, --follow', 'Follow log output')
|
|
219
|
+
.option('-l, --lines <n>', 'Number of lines to show', '100')
|
|
220
|
+
.option('-e, --error', 'Show only error logs')
|
|
221
|
+
.option('-o, --out', 'Show only standard output logs')
|
|
222
|
+
.action(async (id, options) => {
|
|
223
|
+
try {
|
|
224
|
+
// Create worker manager
|
|
225
|
+
const workerManager = new TonkWorkerManager();
|
|
226
|
+
// Get worker
|
|
227
|
+
const worker = await workerManager.get(id);
|
|
228
|
+
if (!worker) {
|
|
229
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
console.log(chalk.blue(`Fetching logs for worker '${worker.name}'...`));
|
|
233
|
+
const { spawn } = await import('node:child_process');
|
|
234
|
+
try {
|
|
235
|
+
// Build the PM2 logs command arguments
|
|
236
|
+
const args = ['logs', worker.id];
|
|
237
|
+
// Add options
|
|
238
|
+
if (options.lines) {
|
|
239
|
+
args.push('--lines', options.lines);
|
|
240
|
+
}
|
|
241
|
+
if (options.error) {
|
|
242
|
+
args.push('--err');
|
|
243
|
+
}
|
|
244
|
+
else if (options.out) {
|
|
245
|
+
args.push('--out');
|
|
246
|
+
}
|
|
247
|
+
// Always use --raw to get cleaner output
|
|
248
|
+
args.push('--raw');
|
|
249
|
+
// For non-follow mode, we'll use --lines and then kill the process after a short delay
|
|
250
|
+
if (!options.follow) {
|
|
251
|
+
console.log(chalk.blue(`Showing last ${options.lines || '100'} lines of logs...`));
|
|
252
|
+
const child = spawn('pm2', args, {
|
|
253
|
+
stdio: 'inherit',
|
|
254
|
+
});
|
|
255
|
+
// Kill the process after a short delay to get just the initial output
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
child.kill('SIGINT');
|
|
258
|
+
}, 1000);
|
|
259
|
+
// Wait for the child process to exit
|
|
260
|
+
await new Promise(resolve => {
|
|
261
|
+
child.on('exit', resolve);
|
|
262
|
+
});
|
|
263
|
+
console.log(chalk.blue('\nUse -f or --follow to stream logs in real-time'));
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
// For follow mode
|
|
267
|
+
console.log(chalk.blue('Streaming logs in real-time. Press Ctrl+C to exit.'));
|
|
268
|
+
const child = spawn('pm2', args, {
|
|
269
|
+
stdio: 'inherit',
|
|
270
|
+
});
|
|
271
|
+
// Handle process exit
|
|
272
|
+
process.on('SIGINT', () => {
|
|
273
|
+
child.kill();
|
|
274
|
+
process.exit(0);
|
|
275
|
+
});
|
|
276
|
+
// Wait for the child process to exit
|
|
277
|
+
await new Promise(resolve => {
|
|
278
|
+
child.on('exit', resolve);
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
console.error(chalk.red('Failed to fetch logs:'), error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error(chalk.red('Failed to fetch worker logs:'), error);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
workerCommand
|
|
291
|
+
.command('register')
|
|
292
|
+
.description('Register a worker with Tonk')
|
|
293
|
+
.argument('[dir]', 'Path to worker directory (defaults to current directory)')
|
|
294
|
+
.action(async (dir = '.') => {
|
|
295
|
+
try {
|
|
296
|
+
// Find the worker.yaml file
|
|
297
|
+
const workerDir = await findWorkerRoot(dir);
|
|
298
|
+
if (!workerDir) {
|
|
299
|
+
console.error(chalk.red(`No worker.yaml file found in ${path.resolve(dir)} or its parent directories.`));
|
|
300
|
+
console.log(chalk.yellow('Make sure you are in a valid worker directory or specify the path to one.'));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
console.log(chalk.blue(`Found worker directory at: ${workerDir}`));
|
|
304
|
+
// Read the worker.yaml file
|
|
305
|
+
const workerYamlPath = path.join(workerDir, 'worker.yaml');
|
|
306
|
+
const workerConfig = await readWorkerConfig(workerYamlPath);
|
|
307
|
+
if (!workerConfig) {
|
|
308
|
+
console.error(chalk.red(`Failed to parse worker.yaml file at ${workerYamlPath}`));
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
// Create worker manager
|
|
312
|
+
const workerManager = new TonkWorkerManager();
|
|
313
|
+
// Register worker using the YAML config
|
|
314
|
+
const worker = await workerManager.registerFromYamlConfig(workerConfig);
|
|
315
|
+
console.log(chalk.green(`Worker '${worker.name}' registered successfully!`));
|
|
316
|
+
console.log(chalk.cyan('Worker ID:'), chalk.bold(worker.id));
|
|
317
|
+
console.log(chalk.cyan('Endpoint:'), chalk.bold(worker.endpoint));
|
|
318
|
+
console.log(chalk.cyan('Protocol:'), chalk.bold(worker.protocol));
|
|
319
|
+
console.log(chalk.cyan('Status:'), worker.status.active ? chalk.green('Active') : chalk.yellow('Inactive'));
|
|
320
|
+
if (Object.keys(worker.env).length > 0) {
|
|
321
|
+
console.log(chalk.cyan('Environment Variables:'));
|
|
322
|
+
Object.entries(worker.env).forEach(([key, value]) => {
|
|
323
|
+
console.log(` ${key}=${value}`);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.error(chalk.red('Failed to register worker:'), error);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
workerCommand
|
|
332
|
+
.command('init')
|
|
333
|
+
.description('Initialise a new worker configuration file')
|
|
334
|
+
.option('-d, --dir <directory>', 'Directory to create the configuration file in', '.')
|
|
335
|
+
.option('-n, --name <n>', 'Name of the worker')
|
|
336
|
+
.option('-p, --port <port>', 'Port number for the worker', '5555')
|
|
337
|
+
.action(async (options) => {
|
|
338
|
+
try {
|
|
339
|
+
// Prompt for missing options
|
|
340
|
+
const answers = await promptForMissingOptions(options);
|
|
341
|
+
const mergedOptions = { ...options, ...answers };
|
|
342
|
+
// Create the directory if it doesn't exist
|
|
343
|
+
const targetDir = path.resolve(mergedOptions.dir);
|
|
344
|
+
if (!fs.existsSync(targetDir)) {
|
|
345
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
346
|
+
console.log(chalk.blue(`Created directory: ${targetDir}`));
|
|
347
|
+
}
|
|
348
|
+
// Generate the YAML content
|
|
349
|
+
const yamlContent = generateYamlContent(mergedOptions);
|
|
350
|
+
// Write the YAML file
|
|
351
|
+
const yamlPath = path.join(targetDir, 'worker.yaml');
|
|
352
|
+
fs.writeFileSync(yamlPath, yamlContent);
|
|
353
|
+
console.log(chalk.green(`Worker configuration file created at: ${yamlPath}`));
|
|
354
|
+
console.log(chalk.blue(`\nYou can now register this worker with:`));
|
|
355
|
+
console.log(chalk.cyan(` tonk worker register ${targetDir}`));
|
|
356
|
+
}
|
|
357
|
+
catch (error) {
|
|
358
|
+
console.error(chalk.red('Failed to initialise worker configuration:'), error);
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
// Helper function to display worker details
|
|
362
|
+
function displayWorkerDetails(worker) {
|
|
363
|
+
console.log(chalk.bold(`Worker Details: ${worker.name}`));
|
|
364
|
+
console.log(chalk.cyan('ID:'), worker.id);
|
|
365
|
+
console.log(chalk.cyan('Name:'), worker.name);
|
|
366
|
+
console.log(chalk.cyan('Description:'), worker.description || '(No description)');
|
|
367
|
+
console.log(chalk.cyan('Type:'), worker.config.type || 'custom');
|
|
368
|
+
console.log(chalk.cyan('Endpoint:'), worker.endpoint);
|
|
369
|
+
console.log(chalk.cyan('Protocol:'), worker.protocol);
|
|
370
|
+
console.log(chalk.cyan('Status:'), worker.status.active ? chalk.green('Active') : chalk.yellow('Inactive'));
|
|
371
|
+
if (worker.status.lastSeen) {
|
|
372
|
+
console.log(chalk.cyan('Last Seen:'), new Date(worker.status.lastSeen).toLocaleString());
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
console.log(chalk.cyan('Last Seen:'), 'Never');
|
|
376
|
+
}
|
|
377
|
+
console.log(chalk.cyan('Created:'), new Date(worker.createdAt).toLocaleString());
|
|
378
|
+
console.log(chalk.cyan('Updated:'), new Date(worker.updatedAt).toLocaleString());
|
|
379
|
+
if (Object.keys(worker.env).length > 0) {
|
|
380
|
+
console.log(chalk.cyan('\nEnvironment Variables:'));
|
|
381
|
+
Object.entries(worker.env).forEach(([key, value]) => {
|
|
382
|
+
console.log(` ${key}=${value}`);
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
if (Object.keys(worker.config).length > 0) {
|
|
386
|
+
console.log(chalk.cyan('\nConfiguration:'));
|
|
387
|
+
console.log(JSON.stringify(worker.config, null, 2));
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Helper function to update worker configuration
|
|
391
|
+
async function updateWorkerConfig(workerManager, id, configPath) {
|
|
392
|
+
try {
|
|
393
|
+
// Check if config file exists
|
|
394
|
+
if (!fs.existsSync(configPath)) {
|
|
395
|
+
console.error(chalk.red(`Configuration file not found: ${configPath}`));
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
// Read config file
|
|
399
|
+
const configContent = fs.readFileSync(configPath, 'utf-8');
|
|
400
|
+
let config;
|
|
401
|
+
try {
|
|
402
|
+
config = JSON.parse(configContent);
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
console.error(chalk.red('Invalid JSON in configuration file:'), error);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
// Get worker
|
|
409
|
+
const worker = await workerManager.get(id);
|
|
410
|
+
if (!worker) {
|
|
411
|
+
console.error(chalk.red(`Worker with ID '${id}' not found.`));
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
// Update worker config
|
|
415
|
+
await workerManager.update(id, {
|
|
416
|
+
config: { ...worker.config, ...config },
|
|
417
|
+
});
|
|
418
|
+
console.log(chalk.green(`Worker '${worker.name}' configuration updated successfully!`));
|
|
419
|
+
}
|
|
420
|
+
catch (error) {
|
|
421
|
+
console.error(chalk.red('Failed to update worker configuration:'), error);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Find the worker root directory by looking for worker.yaml
|
|
426
|
+
* Searches in the given directory and parent directories
|
|
427
|
+
*/
|
|
428
|
+
async function findWorkerRoot(startDir) {
|
|
429
|
+
try {
|
|
430
|
+
let currentDir = path.resolve(startDir);
|
|
431
|
+
const rootDir = path.parse(currentDir).root;
|
|
432
|
+
// Search up to the root directory
|
|
433
|
+
while (currentDir !== rootDir) {
|
|
434
|
+
const workerYamlPath = path.join(currentDir, 'worker.yaml');
|
|
435
|
+
if (fs.existsSync(workerYamlPath)) {
|
|
436
|
+
return currentDir;
|
|
437
|
+
}
|
|
438
|
+
// Move up one directory
|
|
439
|
+
const parentDir = path.dirname(currentDir);
|
|
440
|
+
// If we've reached the root, stop searching
|
|
441
|
+
if (parentDir === currentDir) {
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
currentDir = parentDir;
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
console.error('Error finding worker root:', error);
|
|
450
|
+
return null;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Read and parse the worker.yaml file
|
|
455
|
+
*/
|
|
456
|
+
async function readWorkerConfig(configPath) {
|
|
457
|
+
try {
|
|
458
|
+
if (!fs.existsSync(configPath)) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
const fileContent = fs.readFileSync(configPath, 'utf-8');
|
|
462
|
+
return YAML.parse(fileContent);
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
console.error('Error reading worker config:', error);
|
|
466
|
+
return null;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// Helper function to prompt for missing options (for init command)
|
|
470
|
+
async function promptForMissingOptions(options) {
|
|
471
|
+
const questions = [];
|
|
472
|
+
if (!options.name) {
|
|
473
|
+
questions.push({
|
|
474
|
+
type: 'input',
|
|
475
|
+
name: 'name',
|
|
476
|
+
message: 'Enter worker name:',
|
|
477
|
+
validate: (input) => input.trim() !== '' ? true : 'Name is required',
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
if (!options.port) {
|
|
481
|
+
questions.push({
|
|
482
|
+
type: 'input',
|
|
483
|
+
name: 'port',
|
|
484
|
+
message: 'Enter port number for the worker:',
|
|
485
|
+
default: '5555',
|
|
486
|
+
validate: (input) => /^\d+$/.test(input) ? true : 'Port must be a number',
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
return inquirer.prompt(questions);
|
|
490
|
+
}
|
|
491
|
+
// Helper function to generate YAML content (for init command)
|
|
492
|
+
function generateYamlContent(options) {
|
|
493
|
+
const port = options.port || '5555';
|
|
494
|
+
return `# Worker Configuration
|
|
495
|
+
|
|
496
|
+
# Worker Information
|
|
497
|
+
name: ${options.name}
|
|
498
|
+
description: Tonk worker
|
|
499
|
+
version: 1.0.0
|
|
500
|
+
|
|
501
|
+
# Connection Details
|
|
502
|
+
endpoint: http://localhost:${port}/tonk
|
|
503
|
+
protocol: http
|
|
504
|
+
|
|
505
|
+
# Health Check Configuration
|
|
506
|
+
healthCheck:
|
|
507
|
+
endpoint: http://localhost:${port}/health
|
|
508
|
+
method: GET
|
|
509
|
+
interval: 30000
|
|
510
|
+
timeout: 5000
|
|
511
|
+
|
|
512
|
+
# Process Management
|
|
513
|
+
process:
|
|
514
|
+
script: ./dist/index.js
|
|
515
|
+
cwd: ./
|
|
516
|
+
instances: 1
|
|
517
|
+
autorestart: true
|
|
518
|
+
watch: false
|
|
519
|
+
max_memory_restart: 500M
|
|
520
|
+
env:
|
|
521
|
+
NODE_ENV: production
|
|
522
|
+
|
|
523
|
+
# Additional Configuration
|
|
524
|
+
config: {}
|
|
525
|
+
`;
|
|
526
|
+
}
|
|
527
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../src/commands/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAC,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AAE1D,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC;KAC/C,WAAW,CAAC,qBAAqB,CAAC;KAClC,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,8CAA8C;IAC9C,aAAa,CAAC,IAAI,EAAE,CAAC;AACvB,CAAC,CAAC,CAAC;AAEL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AAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workerManager.d.ts","sourceRoot":"","sources":["../../src/lib/workerManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,MAAM,EACN,aAAa,EACb,yBAAyB,EAC1B,MAAM,oBAAoB,CAAC;AAM5B;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,WAAW,CAAS;;IAc5B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IA8CnE;;OAEG;IACG,sBAAsB,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAiC9D;;OAEG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW7C;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBhE;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB/B;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBnE;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoC1C;;;OAGG;IACG,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"workerManager.d.ts","sourceRoot":"","sources":["../../src/lib/workerManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,MAAM,EACN,aAAa,EACb,yBAAyB,EAC1B,MAAM,oBAAoB,CAAC;AAM5B;;GAEG;AACH,qBAAa,iBAAkB,YAAW,aAAa;IACrD,OAAO,CAAC,WAAW,CAAS;;IAc5B;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,MAAM,CAAC;IA8CnE;;OAEG;IACG,sBAAsB,CAAC,UAAU,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAiC9D;;OAEG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAW7C;;;;OAIG;IACG,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgBhE;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgB/B;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAqBnE;;OAEG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoC1C;;;OAGG;IACG,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAuHzC;;OAEG;IACG,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqCxC;;OAEG;IACG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqD/C;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAgBxB;;OAEG;IACH,OAAO,CAAC,eAAe;CA0BxB"}
|
|
@@ -224,43 +224,16 @@ export class TonkWorkerManager {
|
|
|
224
224
|
const errorLogConfig = `--error ${path.join(logDir, `${worker.id}-error.log`)}`;
|
|
225
225
|
// Handle different worker types
|
|
226
226
|
if (worker.config.type === 'npm') {
|
|
227
|
-
// For npm-based workers, we
|
|
227
|
+
// For npm-based workers, we directly use the package name as the command
|
|
228
228
|
const packageName = worker.name;
|
|
229
|
+
// Strip scope from package name for display purposes (e.g., @tonk/worker -> worker)
|
|
230
|
+
const commandName = packageName.replace(/^@[^/]+\//, '');
|
|
229
231
|
try {
|
|
230
|
-
//
|
|
231
|
-
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (fs.existsSync(executablePath)) {
|
|
236
|
-
// Start the npm package with PM2
|
|
237
|
-
const startCmd = `${envVars} pm2 start ${executablePath} --name ${worker.id} ${logConfig} ${errorLogConfig}`;
|
|
238
|
-
await execAsync(startCmd);
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
// Try to find the main entry point
|
|
242
|
-
const { stdout: packageInfo } = await execAsync(`npm list -g ${packageName} --json`);
|
|
243
|
-
const packageData = JSON.parse(packageInfo);
|
|
244
|
-
if (packageData.dependencies &&
|
|
245
|
-
packageData.dependencies[packageName]) {
|
|
246
|
-
const packagePath = packageData.dependencies[packageName].path;
|
|
247
|
-
const packageJsonPath = path.join(packagePath, 'package.json');
|
|
248
|
-
if (fs.existsSync(packageJsonPath)) {
|
|
249
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
250
|
-
const mainScript = packageJson.main || 'index.js';
|
|
251
|
-
const scriptPath = path.join(packagePath, mainScript);
|
|
252
|
-
// Start the npm package with PM2
|
|
253
|
-
const startCmd = `cd ${packagePath} && ${envVars} pm2 start ${scriptPath} --name ${worker.id} ${logConfig} ${errorLogConfig}`;
|
|
254
|
-
await execAsync(startCmd);
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
throw new Error(`Could not find package.json for ${packageName}`);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
throw new Error(`Could not find installed package ${packageName}`);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
232
|
+
// Start the npm package with PM2 using the package name as the command
|
|
233
|
+
// and 'start' as the argument
|
|
234
|
+
const startCmd = `${envVars} pm2 start "${commandName} start" --name ${worker.id} ${logConfig} ${errorLogConfig}`;
|
|
235
|
+
await execAsync(startCmd);
|
|
236
|
+
console.log(`Started npm worker '${packageName}' with command: ${commandName} start`);
|
|
264
237
|
}
|
|
265
238
|
catch (error) {
|
|
266
239
|
console.error(`Error starting npm worker:`, error);
|
|
@@ -396,7 +369,14 @@ export class TonkWorkerManager {
|
|
|
396
369
|
* Generate a worker ID
|
|
397
370
|
*/
|
|
398
371
|
generateWorkerId(name) {
|
|
399
|
-
|
|
372
|
+
// Normalize the name: lowercase and replace non-alphanumeric chars with hyphens
|
|
373
|
+
let normalizedName = name.toLowerCase().replace(/[^a-z0-9]/g, '-');
|
|
374
|
+
// Ensure the name doesn't start with a hyphen (would cause issues with PM2)
|
|
375
|
+
normalizedName = normalizedName.replace(/^-+/, '');
|
|
376
|
+
// If after normalization the name is empty, use a default prefix
|
|
377
|
+
if (!normalizedName) {
|
|
378
|
+
normalizedName = 'worker';
|
|
379
|
+
}
|
|
400
380
|
const timestamp = Date.now().toString(36);
|
|
401
381
|
return `${normalizedName}-${timestamp}`;
|
|
402
382
|
}
|