probe-simulate-full.ps1 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Login + probe simulate dialogue
  2. # Usage:
  3. # .\probe-simulate-full.ps1 -Token "eyJ..." -TemplateId 22
  4. # $env:LOBSTER_API_TOKEN="eyJ..."; .\probe-simulate-full.ps1 -TemplateId 22
  5. # .\probe-simulate-full.ps1 -TenantCode test001 -Password "yourpwd" -TemplateId 22
  6. param(
  7. [string]$BaseUrl = "http://127.0.0.1:8004",
  8. [string]$Token = $env:LOBSTER_API_TOKEN,
  9. [string]$TenantCode = "test001",
  10. [string]$Username = "admin",
  11. [string]$Password = "",
  12. [long]$TemplateId = 0,
  13. [string]$Content = "你好,芹菜能治疗糖尿病吗?对糖尿病有好处么?"
  14. )
  15. $ErrorActionPreference = "Stop"
  16. [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
  17. if ([string]::IsNullOrWhiteSpace($Token)) {
  18. if ([string]::IsNullOrWhiteSpace($Password)) {
  19. Write-Host "Need -Token or -Password (or env LOBSTER_API_TOKEN)" -ForegroundColor Red
  20. Write-Host "Get token: login saas-mgnui -> DevTools -> Application -> Cookies -> Admin-Token"
  21. exit 1
  22. }
  23. Write-Host "=== Step 1: Login ($TenantCode) ===" -ForegroundColor Cyan
  24. $loginBody = @{
  25. username = $Username
  26. password = $Password
  27. tenantCode = $TenantCode
  28. code = ""
  29. uuid = ""
  30. } | ConvertTo-Json -Compress
  31. try {
  32. $loginResp = Invoke-RestMethod -Uri "$BaseUrl/login" -Method Post -Body $loginBody -ContentType "application/json; charset=utf-8" -TimeoutSec 30
  33. } catch {
  34. Write-Host "Login HTTP error: $($_.Exception.Message)" -ForegroundColor Red
  35. exit 1
  36. }
  37. if (-not $loginResp.token) {
  38. Write-Host "Login failed: $($loginResp.msg)" -ForegroundColor Red
  39. exit 1
  40. }
  41. $Token = "Bearer $($loginResp.token)"
  42. Write-Host "Login OK" -ForegroundColor Green
  43. } else {
  44. if ($Token -notmatch "^Bearer ") { $Token = "Bearer $Token" }
  45. Write-Host "Using provided token" -ForegroundColor Green
  46. }
  47. if ($TemplateId -le 0) {
  48. Write-Host "`n=== Step 2: List templates ===" -ForegroundColor Cyan
  49. $headers = @{ Authorization = $Token }
  50. try {
  51. $tplResp = Invoke-RestMethod -Uri "$BaseUrl/workflow/lobster/template/list?page=1&size=20" -Method Get -Headers $headers -TimeoutSec 30
  52. $templates = $tplResp.data
  53. if ($templates -and $templates.Count -gt 0) {
  54. $active = $templates | Where-Object { $_.status -eq 1 } | Select-Object -First 1
  55. if (-not $active) { $active = $templates[0] }
  56. $TemplateId = [long]$active.id
  57. Write-Host "Using template id=$TemplateId name=$($active.templateName)"
  58. } else {
  59. Write-Host "No templates; use -TemplateId 22 (test001) or 70 (cs1)" -ForegroundColor Yellow
  60. exit 2
  61. }
  62. } catch {
  63. Write-Host "List templates failed: $($_.Exception.Message)" -ForegroundColor Yellow
  64. exit 2
  65. }
  66. }
  67. Write-Host "`n=== Step 3: Simulate ===" -ForegroundColor Cyan
  68. & "$PSScriptRoot\probe-simulate-dialogue.ps1" -BaseUrl $BaseUrl -Token $Token -TemplateId $TemplateId -Content $Content
  69. exit $LASTEXITCODE