@myassis/gateway 1.0.24 → 1.0.26

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.
@@ -123,7 +123,6 @@ router.post('/create', ensureAgentManager, async (req, res) => {
123
123
  router.put('/:id', ensureAgentManager, async (req, res) => {
124
124
  try {
125
125
  const userId = req.userId;
126
- logger.debug('update agent', req.body);
127
126
  const { name, description, systemPrompt, avatar, config } = req.body;
128
127
  const agentManager = AgentManager_js_1.agentManagerMap.get(userId);
129
128
  const agent = agentManager.updateAgent(req.params.id, {
@@ -378,21 +378,92 @@ async function updateService() {
378
378
  return { success: true, message: `已是最新版本 ${check.currentVersion}` };
379
379
  }
380
380
  console.log(`发现新版本 ${check.latestVersion},正在更新...`);
381
- const { stdout, stderr } = await execAsync('npm install -g @myassis/gateway@latest', { timeout: 120000 });
382
- if (stdout)
383
- console.log(stdout);
384
- if (stderr)
385
- console.error(stderr);
386
- console.log('✅ npm 更新完成');
387
- const info = await getServiceInfo();
388
- if (info.installed) {
389
- console.log('正在重启服务...');
390
- const r = await restartService();
391
- if (!r.success) {
392
- return { success: false, message: `更新成功但服务重启失败: ${r.message}` };
381
+ if (isPackagedExe()) {
382
+ // pkg 环境:从 COS 下载对应平台的 exe
383
+ // ❗ 关键:不能在这里 stopService,进程本身即为服务进程,停止后后续代码不执行
384
+ // 方案:下载到临时文件后,spawn 一个独立延迟替换进程,本进程直接返回
385
+ const platform = process.platform === 'win32' ? 'win' : 'linux';
386
+ const isWin = platform === 'win';
387
+ const downloadUrl = isWin
388
+ ? `https://myassis-1251246038.cos.ap-guangzhou.myqcloud.com/myassis-1251246038/installs/myassis-gateway-win.exe`
389
+ : `https://myassis-1251246038.cos.ap-guangzhou.myqcloud.com/myassis-1251246038/installs/myassis-gateway-linux`;
390
+ const currentExe = process.execPath;
391
+ const tmpExe = currentExe + '.new';
392
+ console.log(`正在下载 ${downloadUrl} ...`);
393
+ const response = await (0, axios_1.default)({
394
+ method: 'GET',
395
+ url: downloadUrl,
396
+ responseType: 'stream',
397
+ timeout: 300000,
398
+ });
399
+ const writeStream = fs_1.default.createWriteStream(tmpExe);
400
+ await new Promise((resolve, reject) => {
401
+ response.data.pipe(writeStream);
402
+ writeStream.on('finish', resolve);
403
+ writeStream.on('error', reject);
404
+ response.data.on('error', reject);
405
+ });
406
+ console.log('✅ 下载完成');
407
+ // 生成延迟替换脚本,spawn 为独立进程(当前进程 return 后不影响它)
408
+ if (isWin) {
409
+ const psScript = [
410
+ `Start-Sleep -Seconds 5`,
411
+ `Stop-Service -Name '${exports.SERVICE_NAME}' -ErrorAction SilentlyContinue`,
412
+ `Start-Sleep -Seconds 2`,
413
+ `while (Test-Path '${currentExe}') { try { Move-Item '${currentExe}' '${currentExe}.bak' -Force; break } catch { Start-Sleep -Seconds 1 } }`,
414
+ `Move-Item '${tmpExe}' '${currentExe}' -Force`,
415
+ `Start-Sleep -Seconds 1`,
416
+ `Start-Service -Name '${exports.SERVICE_NAME}'`,
417
+ `Remove-Item '${currentExe}.bak' -Force -ErrorAction SilentlyContinue`,
418
+ `Remove-Item '${tmpExe}' -Force -ErrorAction SilentlyContinue`,
419
+ ].join('; ');
420
+ const args = ['-NoProfile', '-NonInteractive', '-Command', psScript];
421
+ const child = (0, child_process_1.spawn)('powershell.exe', args, {
422
+ detached: true,
423
+ stdio: 'ignore',
424
+ windowsHide: true,
425
+ });
426
+ child.unref();
427
+ }
428
+ else {
429
+ // Linux: bash 延迟替换
430
+ const bashScript = [
431
+ 'sleep 5',
432
+ `systemctl stop ${exports.SERVICE_NAME} 2>/dev/null || true`,
433
+ 'sleep 2',
434
+ `mv -f '${currentExe}' '${currentExe}.bak' 2>/dev/null; true`,
435
+ `mv -f '${tmpExe}' '${currentExe}'`,
436
+ 'sleep 1',
437
+ `systemctl start ${exports.SERVICE_NAME} 2>/dev/null || true`,
438
+ `rm -f '${currentExe}.bak' '${tmpExe}'`,
439
+ ].join('; ');
440
+ const child = (0, child_process_1.spawn)('bash', ['-c', bashScript], {
441
+ detached: true,
442
+ stdio: 'ignore',
443
+ });
444
+ child.unref();
445
+ }
446
+ console.log('✅ 后台替换进程已启动,服务将在几秒后自动重启');
447
+ return { success: true, message: `更新成功: ${check.currentVersion} → ${check.latestVersion},服务正在后台替换...` };
448
+ }
449
+ else {
450
+ // npm 环境
451
+ const { stdout, stderr } = await execAsync('npm install -g @myassis/gateway@latest', { timeout: 120000 });
452
+ if (stdout)
453
+ console.log(stdout);
454
+ if (stderr)
455
+ console.error(stderr);
456
+ console.log('✅ npm 更新完成');
457
+ const info = await getServiceInfo();
458
+ if (info.installed) {
459
+ console.log('正在重启服务...');
460
+ const r = await restartService();
461
+ if (!r.success) {
462
+ return { success: false, message: `更新成功但服务重启失败: ${r.message}` };
463
+ }
393
464
  }
465
+ return { success: true, message: `更新成功: ${check.currentVersion} → ${check.latestVersion}` };
394
466
  }
395
- return { success: true, message: `更新成功: ${check.currentVersion} → ${check.latestVersion}` };
396
467
  }
397
468
  catch (err) {
398
469
  return { success: false, message: `更新失败: ${err.message}` };
@@ -0,0 +1,3 @@
1
+ -- Add feedback column to messages table
2
+ -- feedback 存储用户对消息的反馈(如 'like', 'dislike',或 JSON 字符串)
3
+ alter table messages add column feedback text default null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {