@yeaft/webchat-agent 0.0.7 → 0.0.9

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/service.js +44 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeaft/webchat-agent",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Remote agent for Yeaft WebChat — connects worker machines to the central server",
5
5
  "main": "index.js",
6
6
  "type": "module",
package/service.js CHANGED
@@ -392,8 +392,10 @@ 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
- const batContent = `@echo off\r\n${envLines.join('\r\n')}\r\n"${nodePath}" "${cliPath}"\r\n`;
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 batContent = `@echo off\r\n${envLines.join('\r\n')}\r\n"${nodePath}" "${cliPath}" >> "${logFile}" 2>&1\r\n`;
397
399
  const batPath = getWinBatPath();
398
400
  writeFileSync(batPath, batContent);
399
401
 
@@ -406,21 +408,35 @@ function winInstall(config) {
406
408
  try { execSync(`schtasks /delete /tn "${WIN_TASK_NAME}" /f 2>nul`, { stdio: 'pipe' }); } catch {}
407
409
 
408
410
  // Create scheduled task that runs at logon
409
- // Try with highest privilege first, fall back to limited (no admin required)
411
+ // Try schtasks first (highest limited), fall back to Startup folder
412
+ let usedStartupFolder = false;
410
413
  try {
411
414
  execSync(
412
415
  `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl highest /f`,
413
416
  { stdio: 'pipe' }
414
417
  );
415
418
  } catch {
416
- execSync(
417
- `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl limited /f`,
418
- { stdio: 'pipe' }
419
- );
419
+ try {
420
+ execSync(
421
+ `schtasks /create /tn "${WIN_TASK_NAME}" /tr "wscript.exe \\"${vbsPath}\\"" /sc onlogon /rl limited /f`,
422
+ { stdio: 'pipe' }
423
+ );
424
+ } catch {
425
+ // schtasks not available (no admin) — use Startup folder
426
+ const startupDir = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup');
427
+ const startupVbs = join(startupDir, `${WIN_TASK_NAME}.vbs`);
428
+ writeFileSync(startupVbs, vbsContent);
429
+ usedStartupFolder = true;
430
+ console.log(' (Using Startup folder for auto-start — no admin required)');
431
+ }
420
432
  }
421
433
 
422
434
  // Also start it now
423
- execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
435
+ if (usedStartupFolder) {
436
+ execSync(`wscript.exe "${vbsPath}"`, { stdio: 'pipe' });
437
+ } else {
438
+ execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
439
+ }
424
440
 
425
441
  console.log('Service installed and started.');
426
442
  console.log(`\nManage with:`);
@@ -438,6 +454,9 @@ function winUninstall() {
438
454
  const batPath = getWinBatPath();
439
455
  if (existsSync(vbsPath)) unlinkSync(vbsPath);
440
456
  if (existsSync(batPath)) unlinkSync(batPath);
457
+ // Clean up Startup folder shortcut
458
+ const startupVbs = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', `${WIN_TASK_NAME}.vbs`);
459
+ if (existsSync(startupVbs)) unlinkSync(startupVbs);
441
460
  console.log('Service uninstalled.');
442
461
  }
443
462
 
@@ -446,8 +465,15 @@ function winStart() {
446
465
  execSync(`schtasks /run /tn "${WIN_TASK_NAME}"`, { stdio: 'pipe' });
447
466
  console.log('Service started.');
448
467
  } catch {
449
- console.error('Service not installed. Run "yeaft-agent install" first.');
450
- process.exit(1);
468
+ // No schtasks try direct launch via VBS
469
+ const vbsPath = getWinWrapperPath();
470
+ if (existsSync(vbsPath)) {
471
+ execSync(`wscript.exe "${vbsPath}"`, { stdio: 'pipe' });
472
+ console.log('Service started.');
473
+ } else {
474
+ console.error('Service not installed. Run "yeaft-agent install" first.');
475
+ process.exit(1);
476
+ }
451
477
  }
452
478
  }
453
479
 
@@ -494,7 +520,14 @@ function winStatus() {
494
520
  console.log(`Task name: ${WIN_TASK_NAME}`);
495
521
  }
496
522
  } catch {
497
- console.log('Service is not installed.');
523
+ // Check Startup folder fallback
524
+ const startupVbs = join(process.env.APPDATA, 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Startup', `${WIN_TASK_NAME}.vbs`);
525
+ if (existsSync(startupVbs)) {
526
+ console.log('Service installed via Startup folder (no admin).');
527
+ console.log(`Startup script: ${startupVbs}`);
528
+ } else {
529
+ console.log('Service is not installed.');
530
+ }
498
531
  }
499
532
  }
500
533