quick-verify-training-package.ps1 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # Quick verification script for training package
  2. # Usage: .\scripts\quick-verify-training-package.ps1 D:\qiwei-training
  3. param(
  4. [Parameter(Mandatory=$true)]
  5. [string]$TrainingDir,
  6. [int]$TimeoutSeconds = 15
  7. )
  8. $ErrorActionPreference = "Stop"
  9. Write-Host "`n=== Training Package Quick Verification ===" -ForegroundColor Cyan
  10. Write-Host "Target directory: $TrainingDir`n"
  11. # Step 1: Check directory structure
  12. Write-Host "[1/7] Checking directory structure..." -ForegroundColor Yellow
  13. $requiredFiles = @(
  14. "qiwei-workbench.exe",
  15. "web\index.html",
  16. "web\app.js",
  17. "knowledge\rules.md",
  18. ".env.local",
  19. ".mcp.json",
  20. "README.md"
  21. )
  22. $missing = @()
  23. foreach ($file in $requiredFiles) {
  24. $path = Join-Path $TrainingDir $file
  25. if (-not (Test-Path $path)) {
  26. $missing += $file
  27. }
  28. }
  29. if ($missing.Count -gt 0) {
  30. Write-Host "[X] Missing files:" -ForegroundColor Red
  31. $missing | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
  32. exit 1
  33. }
  34. Write-Host "[OK] Directory structure complete`n" -ForegroundColor Green
  35. # Step 1b: Check portable MCP registration before starting the dashboard.
  36. Write-Host "[1b/7] Checking MCP registration and tool discovery..." -ForegroundColor Yellow
  37. $mcpConfig = Get-Content (Join-Path $TrainingDir ".mcp.json") -Raw | ConvertFrom-Json
  38. $mcpEntry = $mcpConfig.mcpServers.'qiwei-assistant'
  39. if (-not $mcpEntry) {
  40. Write-Host "[X] .mcp.json does not register qiwei-assistant" -ForegroundColor Red
  41. exit 1
  42. }
  43. if (-not ($mcpEntry.args -contains "mcp")) {
  44. Write-Host "[X] qiwei-assistant is missing the mcp subcommand" -ForegroundColor Red
  45. exit 1
  46. }
  47. $mcpVerifier = Join-Path $PSScriptRoot "verify-training-package-mcp.js"
  48. if (Get-Command node -ErrorAction SilentlyContinue) {
  49. $mcpResult = & node $mcpVerifier $TrainingDir 2>&1
  50. if ($LASTEXITCODE -ne 0) {
  51. Write-Host "[X] MCP handshake failed: $mcpResult" -ForegroundColor Red
  52. exit 1
  53. }
  54. Write-Host "[OK] MCP registered and tools discovered: $mcpResult`n" -ForegroundColor Green
  55. } else {
  56. Write-Host "[WARN] Node.js not found; registration structure checked, handshake deferred" -ForegroundColor Yellow
  57. }
  58. # Step 2: Check port availability
  59. Write-Host "[2/7] Checking port availability..." -ForegroundColor Yellow
  60. $ports = @(4320, 4310)
  61. $occupied = @()
  62. foreach ($port in $ports) {
  63. $conn = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue
  64. if ($conn) {
  65. $occupied += $port
  66. }
  67. }
  68. if ($occupied.Count -gt 0) {
  69. Write-Host "[X] Ports occupied: $($occupied -join ', ')" -ForegroundColor Red
  70. Write-Host " Please stop processes or use different ports" -ForegroundColor Yellow
  71. exit 1
  72. }
  73. Write-Host "[OK] Ports available`n" -ForegroundColor Green
  74. # Step 3: Start workbench
  75. Write-Host "[3/7] Starting workbench..." -ForegroundColor Yellow
  76. $exePath = Join-Path $TrainingDir "qiwei-workbench.exe"
  77. $process = Start-Process -FilePath $exePath -ArgumentList "--no-open" -WorkingDirectory $TrainingDir -PassThru -WindowStyle Hidden
  78. Start-Sleep -Seconds 5
  79. if ($process.HasExited) {
  80. Write-Host "[X] Workbench exited immediately" -ForegroundColor Red
  81. exit 1
  82. }
  83. Write-Host "[OK] Workbench started (PID: $($process.Id))`n" -ForegroundColor Green
  84. # Step 4: Check Dashboard response
  85. Write-Host "[4/7] Checking Dashboard response..." -ForegroundColor Yellow
  86. $maxRetries = 5
  87. $retryCount = 0
  88. $dashboardOk = $false
  89. while ($retryCount -lt $maxRetries) {
  90. try {
  91. $response = Invoke-WebRequest -Uri "http://127.0.0.1:4320/api/status" -Method GET -UseBasicParsing -TimeoutSec 3
  92. if ($response.StatusCode -eq 200) {
  93. $dashboardOk = $true
  94. break
  95. }
  96. } catch {
  97. $retryCount++
  98. Start-Sleep -Seconds 2
  99. }
  100. }
  101. if (-not $dashboardOk) {
  102. Write-Host "[X] Dashboard not responding" -ForegroundColor Red
  103. Stop-Process -Id $process.Id -Force
  104. exit 1
  105. }
  106. $status = $response.Content | ConvertFrom-Json
  107. Write-Host "[OK] Dashboard responding`n" -ForegroundColor Green
  108. # Step 5: Verify status data
  109. Write-Host "[5/7] Verifying status data..." -ForegroundColor Yellow
  110. $authStatus = if ($status.summary.authConfigured) { "[OK]" } else { "[NO]" }
  111. $subStatus = if ($status.summary.subscribed) { "[OK]" } else { "[NO]" }
  112. $onlineStatus = if ($status.summary.online) { "[OK]" } else { "[NO]" }
  113. Write-Host " Token configured: $authStatus"
  114. Write-Host " Subscription: $subStatus"
  115. Write-Host " Account online: $onlineStatus"
  116. if (-not $status.summary.authConfigured) {
  117. Write-Host "`n NOTE: Token not detected, need manual input" -ForegroundColor Cyan
  118. }
  119. if (-not $status.summary.subscribed) {
  120. Write-Host " NOTE: Need subscription at http://127.0.0.1:4310" -ForegroundColor Cyan
  121. }
  122. if (-not $status.summary.online) {
  123. Write-Host " NOTE: Need WeChat Work QR code login" -ForegroundColor Cyan
  124. }
  125. Write-Host ""
  126. # Step 6: Check Runtime
  127. Write-Host "[6/7] Checking Runtime..." -ForegroundColor Yellow
  128. $runtimeStatePath = Join-Path $TrainingDir "outputs\runtime\qiwei-runtime.json"
  129. if (Test-Path $runtimeStatePath) {
  130. $runtimeState = Get-Content $runtimeStatePath -Raw | ConvertFrom-Json
  131. Write-Host "[OK] Runtime running" -ForegroundColor Green
  132. Write-Host " PID: $($runtimeState.pid)" -ForegroundColor Gray
  133. Write-Host " Mode: $($runtimeState.mode)" -ForegroundColor Gray
  134. Write-Host " Status: $($runtimeState.status)" -ForegroundColor Gray
  135. } else {
  136. Write-Host "[WARN] Runtime state file not found" -ForegroundColor Yellow
  137. }
  138. Write-Host ""
  139. # Step 7: Check knowledge base
  140. Write-Host "[7/7] Checking knowledge base..." -ForegroundColor Yellow
  141. try {
  142. $configResponse = Invoke-WebRequest -Uri "http://127.0.0.1:4320/api/agent/config" -UseBasicParsing -TimeoutSec 3
  143. $config = $configResponse.Content | ConvertFrom-Json
  144. $knowledgeCount = if ($config.knowledge.chunks) { $config.knowledge.chunks.Count } else { 0 }
  145. Write-Host "[OK] Knowledge base loaded ($knowledgeCount chunks)" -ForegroundColor Green
  146. Write-Host " Conversation mode: $($config.conversationMode)" -ForegroundColor Gray
  147. Write-Host " Provider: $($config.provider)" -ForegroundColor Gray
  148. } catch {
  149. Write-Host "[WARN] Knowledge API not responding" -ForegroundColor Yellow
  150. }
  151. Write-Host ""
  152. # Summary
  153. Write-Host "=== Verification Complete ===" -ForegroundColor Cyan
  154. Write-Host "`nWorkbench URL: http://127.0.0.1:4320/#status" -ForegroundColor Cyan
  155. Write-Host "Press Ctrl+C to stop...`n"
  156. # Wait for interruption
  157. try {
  158. while ($true) {
  159. Start-Sleep -Seconds 1
  160. if ($process.HasExited) {
  161. Write-Host "Workbench process exited" -ForegroundColor Yellow
  162. break
  163. }
  164. }
  165. } finally {
  166. Write-Host "`nStopping workbench..." -ForegroundColor Yellow
  167. if (-not $process.HasExited) {
  168. Stop-Process -Id $process.Id -Force
  169. }
  170. Write-Host "[OK] Stopped`n" -ForegroundColor Green
  171. }