@yeaft/webchat-agent 0.0.8 → 0.0.10
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/service.js +16 -7
package/package.json
CHANGED
package/service.js
CHANGED
|
@@ -392,13 +392,16 @@ function winInstall(config) {
|
|
|
392
392
|
if (config.agentSecret) envLines.push(`set "AGENT_SECRET=${config.agentSecret}"`);
|
|
393
393
|
if (config.workDir) envLines.push(`set "WORK_DIR=${config.workDir}"`);
|
|
394
394
|
|
|
395
|
-
// Create a batch file that sets env vars and starts node
|
|
396
|
-
|
|
395
|
+
// Create a batch file that sets env vars and starts node (with log redirection)
|
|
396
|
+
mkdirSync(logDir, { recursive: true });
|
|
397
|
+
const logFile = join(logDir, 'out.log');
|
|
398
|
+
const cliDir = dirname(cliPath);
|
|
399
|
+
const batContent = `@echo off\r\ncd /d "${cliDir}"\r\n${envLines.join('\r\n')}\r\n"${nodePath}" "${cliPath}" >> "${logFile}" 2>&1\r\n`;
|
|
397
400
|
const batPath = getWinBatPath();
|
|
398
401
|
writeFileSync(batPath, batContent);
|
|
399
402
|
|
|
400
403
|
// Create VBS wrapper to run hidden (no console window)
|
|
401
|
-
const vbsContent = `Set WshShell = CreateObject("WScript.Shell")\r\nWshShell.Run """${batPath}""", 0, False\r\n`;
|
|
404
|
+
const vbsContent = `Set WshShell = CreateObject("WScript.Shell")\r\nWshShell.CurrentDirectory = "${cliDir}"\r\nWshShell.Run """${batPath}""", 0, False\r\n`;
|
|
402
405
|
const vbsPath = getWinWrapperPath();
|
|
403
406
|
writeFileSync(vbsPath, vbsContent);
|
|
404
407
|
|
|
@@ -431,12 +434,17 @@ function winInstall(config) {
|
|
|
431
434
|
|
|
432
435
|
// Also start it now
|
|
433
436
|
if (usedStartupFolder) {
|
|
434
|
-
|
|
437
|
+
execSync(`wscript.exe "${vbsPath}"`, { stdio: 'pipe' });
|
|
435
438
|
} else {
|
|
436
439
|
execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
|
|
437
440
|
}
|
|
438
441
|
|
|
439
442
|
console.log('Service installed and started.');
|
|
443
|
+
console.log(` Bat: ${batPath}`);
|
|
444
|
+
console.log(` VBS: ${vbsPath}`);
|
|
445
|
+
console.log(` Log: ${logFile}`);
|
|
446
|
+
console.log(` Node: ${nodePath}`);
|
|
447
|
+
console.log(` CLI: ${cliPath}`);
|
|
440
448
|
console.log(`\nManage with:`);
|
|
441
449
|
console.log(` yeaft-agent status`);
|
|
442
450
|
console.log(` yeaft-agent logs`);
|
|
@@ -466,7 +474,7 @@ function winStart() {
|
|
|
466
474
|
// No schtasks — try direct launch via VBS
|
|
467
475
|
const vbsPath = getWinWrapperPath();
|
|
468
476
|
if (existsSync(vbsPath)) {
|
|
469
|
-
|
|
477
|
+
execSync(`wscript.exe "${vbsPath}"`, { stdio: 'pipe' });
|
|
470
478
|
console.log('Service started.');
|
|
471
479
|
} else {
|
|
472
480
|
console.error('Service not installed. Run "yeaft-agent install" first.');
|
|
@@ -476,13 +484,14 @@ function winStart() {
|
|
|
476
484
|
}
|
|
477
485
|
|
|
478
486
|
function winStop() {
|
|
479
|
-
// Find and kill the node process running cli.js
|
|
487
|
+
// Find and kill the node process running our cli.js
|
|
480
488
|
try {
|
|
481
489
|
const output = execSync('wmic process where "name=\'node.exe\'" get processid,commandline /format:csv', {
|
|
482
490
|
encoding: 'utf-8', stdio: ['pipe', 'pipe', 'pipe']
|
|
483
491
|
});
|
|
492
|
+
const cliPath = getCliPath();
|
|
484
493
|
for (const line of output.split('\n')) {
|
|
485
|
-
if (line.includes('cli.js') && line.includes(SERVICE_NAME)) {
|
|
494
|
+
if (line.includes('cli.js') && (line.includes(SERVICE_NAME) || line.includes('webchat-agent'))) {
|
|
486
495
|
const pid = line.trim().split(',').pop();
|
|
487
496
|
if (pid && /^\d+$/.test(pid)) {
|
|
488
497
|
execSync(`taskkill /pid ${pid} /f`, { stdio: 'pipe' });
|