@myassis/gateway 1.0.69 → 1.0.71
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.
|
@@ -746,12 +746,19 @@ async function updateService() {
|
|
|
746
746
|
`$tmpExe = '${escapePowerShellString(tmpExe)}'`,
|
|
747
747
|
`$backupExe = '${escapePowerShellString(`${currentExe}.bak`)}'`,
|
|
748
748
|
`$pidFile = '${escapePowerShellString(GATEWAY_PID_FILE)}'`,
|
|
749
|
+
`$daemonPidFile = '${escapePowerShellString(GATEWAY_DAEMON_PID_FILE)}'`,
|
|
750
|
+
`$stopFlag = '${escapePowerShellString(GATEWAY_STOP_FLAG_FILE)}'`,
|
|
749
751
|
`$launcher = '${escapePowerShellString(GATEWAY_LAUNCHER_FILE)}'`,
|
|
750
752
|
`$logPath = Join-Path $env:TEMP 'myassis-gateway-update.log'`,
|
|
751
753
|
`$logDir = Split-Path -Parent $logPath`,
|
|
752
754
|
`if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }`,
|
|
753
755
|
`function Write-UpdateLog { param([string]$Message) Add-Content -Path $logPath -Encoding UTF8 -Value \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $Message\" }`,
|
|
754
756
|
`function Stop-GatewayProcess {`,
|
|
757
|
+
` # 先写停止标记,告诉守护进程这是主动停止,不要自动重启`,
|
|
758
|
+
` try {`,
|
|
759
|
+
` New-Item -ItemType File -Path $stopFlag -Force | Out-Null`,
|
|
760
|
+
` Write-UpdateLog 'stop flag written'`,
|
|
761
|
+
` } catch { Write-UpdateLog \"write stop flag failed: $($_.Exception.Message)\" }`,
|
|
755
762
|
` $stoppedPids = @{}`,
|
|
756
763
|
` if (Test-Path $pidFile) {`,
|
|
757
764
|
` try {`,
|
|
@@ -786,6 +793,33 @@ async function updateService() {
|
|
|
786
793
|
` Start-Sleep -Milliseconds 500`,
|
|
787
794
|
` }`,
|
|
788
795
|
` }`,
|
|
796
|
+
` # 等待守护进程退出:gateway 退出后,守护检测到 stop-flag 会自行 break 退出`,
|
|
797
|
+
` $daemonPid = $null`,
|
|
798
|
+
` if (Test-Path $daemonPidFile) {`,
|
|
799
|
+
` try {`,
|
|
800
|
+
` $dpStr = (Get-Content $daemonPidFile -Raw).Trim()`,
|
|
801
|
+
` if ($dpStr) { $daemonPid = [int]$dpStr }`,
|
|
802
|
+
` } catch { Write-UpdateLog \"read daemon pid failed: $($_.Exception.Message)\" }`,
|
|
803
|
+
` }`,
|
|
804
|
+
` if ($daemonPid) {`,
|
|
805
|
+
` Write-UpdateLog \"waiting daemon exit pid=$daemonPid\"`,
|
|
806
|
+
` $daemonGone = $false`,
|
|
807
|
+
` for ($w = 0; $w -lt 60; $w++) {`,
|
|
808
|
+
` $dp = Get-Process -Id $daemonPid -ErrorAction SilentlyContinue`,
|
|
809
|
+
` if (-not $dp) { $daemonGone = $true; break }`,
|
|
810
|
+
` Start-Sleep -Milliseconds 500`,
|
|
811
|
+
` }`,
|
|
812
|
+
` if ($daemonGone) {`,
|
|
813
|
+
` Write-UpdateLog 'daemon exited gracefully'`,
|
|
814
|
+
` } else {`,
|
|
815
|
+
` Write-UpdateLog \"daemon still alive after 30s, force kill pid=$daemonPid\"`,
|
|
816
|
+
` try { Stop-Process -Id $daemonPid -Force -ErrorAction Stop } catch { Write-UpdateLog \"kill daemon failed: $($_.Exception.Message)\" }`,
|
|
817
|
+
` Start-Sleep -Milliseconds 1000`,
|
|
818
|
+
` }`,
|
|
819
|
+
` Remove-Item $daemonPidFile -Force -ErrorAction SilentlyContinue`,
|
|
820
|
+
` } else { Write-UpdateLog 'daemon pid file not found, skip daemon wait' }`,
|
|
821
|
+
` # 清理停止标记,避免影响后续启动`,
|
|
822
|
+
` Remove-Item $stopFlag -Force -ErrorAction SilentlyContinue`,
|
|
789
823
|
`}`,
|
|
790
824
|
`function Start-GatewayProcess {`,
|
|
791
825
|
` if (-not (Test-Path $launcher)) { Write-UpdateLog \"launcher script not found: $launcher\"; return }`,
|
|
@@ -197,7 +197,7 @@ exports.execTool = {
|
|
|
197
197
|
},
|
|
198
198
|
cwd: {
|
|
199
199
|
type: 'string',
|
|
200
|
-
description: '
|
|
200
|
+
description: '命令执行的工作目录',
|
|
201
201
|
},
|
|
202
202
|
timeout: {
|
|
203
203
|
type: 'number',
|
|
@@ -216,6 +216,14 @@ exports.execTool = {
|
|
|
216
216
|
return new Promise(async (resolve) => {
|
|
217
217
|
const { cwd, timeout = 60000, approved, isUserAsk = false } = args;
|
|
218
218
|
let command = args.command;
|
|
219
|
+
// 没有指定工作目录,直接返回错误信息给大模型
|
|
220
|
+
if (!cwd || (typeof cwd === 'string' && cwd.trim() === '')) {
|
|
221
|
+
resolve({
|
|
222
|
+
success: false,
|
|
223
|
+
errorMessage: '执行命令必须指定工作目录(cwd),请提供 cwd 参数后重试。',
|
|
224
|
+
});
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
219
227
|
// 检查危险命令(如果已批准或用户主动要求则跳过拦截)
|
|
220
228
|
if (!approved && isDangerousCommand(command)) {
|
|
221
229
|
if (isUserAsk) {
|