run-mineru-agent-demo.ps1 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. param(
  2. [string]$SampleDir,
  3. [string]$OutDir,
  4. [int]$TimeoutSeconds = 600,
  5. [int]$IntervalSeconds = 3
  6. )
  7. $ErrorActionPreference = "Stop"
  8. $OutputEncoding = [System.Text.Encoding]::UTF8
  9. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  10. [Console]::InputEncoding = [System.Text.Encoding]::UTF8
  11. $TestFilesName = "$([char]0x6D4B)$([char]0x8BD5)$([char]0x6587)$([char]0x4EF6)"
  12. $CompareName = "$([char]0x5BF9)$([char]0x6BD4)$([char]0x7ED3)$([char]0x679C)"
  13. if ([string]::IsNullOrWhiteSpace($SampleDir)) { $SampleDir = Join-Path $PSScriptRoot $TestFilesName }
  14. if ([string]::IsNullOrWhiteSpace($OutDir)) { $OutDir = Join-Path $PSScriptRoot (Join-Path $CompareName "mineru-agent") }
  15. function Write-Log {
  16. param([string]$Message)
  17. Write-Host ("[{0:yyyy-MM-dd HH:mm:ss}] {1}" -f (Get-Date), $Message)
  18. }
  19. if (Test-Path $OutDir) { Remove-Item $OutDir -Recurse -Force }
  20. New-Item -ItemType Directory -Force $OutDir | Out-Null
  21. $LogFile = Join-Path $OutDir "run.log"
  22. Start-Transcript -Path $LogFile | Out-Null
  23. try {
  24. $ProjectDir = Join-Path $PSScriptRoot "mineru-agent-demo"
  25. Write-Log "MinerU agent demo started"
  26. Write-Log "SampleDir=$SampleDir"
  27. Write-Log "OutDir=$OutDir"
  28. Write-Log "ProjectDir=$ProjectDir"
  29. Write-Log "timeout=$TimeoutSeconds interval=$IntervalSeconds"
  30. Write-Log "No token is used. No Authorization header is sent by this demo."
  31. if (!(Test-Path $SampleDir)) { throw "SampleDir not found: $SampleDir" }
  32. if (!(Test-Path $ProjectDir)) { throw "ProjectDir not found: $ProjectDir" }
  33. Push-Location $ProjectDir
  34. try {
  35. if (!(Test-Path "node_modules")) {
  36. Write-Log "node_modules not found, running npm install"
  37. npm install
  38. }
  39. npm run smoke -- "$SampleDir" --out-dir "$OutDir" --timeout $TimeoutSeconds --interval $IntervalSeconds
  40. Write-Log "npm exit code: $LASTEXITCODE"
  41. } finally {
  42. Pop-Location
  43. }
  44. Write-Log "MinerU agent demo finished"
  45. } catch {
  46. Write-Log ("Failed: {0}" -f $_.Exception.Message)
  47. throw
  48. } finally {
  49. Stop-Transcript | Out-Null
  50. }