# Login + probe simulate dialogue # Usage: # .\probe-simulate-full.ps1 -Token "eyJ..." -TemplateId 22 # $env:LOBSTER_API_TOKEN="eyJ..."; .\probe-simulate-full.ps1 -TemplateId 22 # .\probe-simulate-full.ps1 -TenantCode test001 -Password "yourpwd" -TemplateId 22 param( [string]$BaseUrl = "http://127.0.0.1:8004", [string]$Token = $env:LOBSTER_API_TOKEN, [string]$TenantCode = "test001", [string]$Username = "admin", [string]$Password = "", [long]$TemplateId = 0, [string]$Content = "你好,芹菜能治疗糖尿病吗?对糖尿病有好处么?" ) $ErrorActionPreference = "Stop" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 if ([string]::IsNullOrWhiteSpace($Token)) { if ([string]::IsNullOrWhiteSpace($Password)) { Write-Host "Need -Token or -Password (or env LOBSTER_API_TOKEN)" -ForegroundColor Red Write-Host "Get token: login saas-mgnui -> DevTools -> Application -> Cookies -> Admin-Token" exit 1 } Write-Host "=== Step 1: Login ($TenantCode) ===" -ForegroundColor Cyan $loginBody = @{ username = $Username password = $Password tenantCode = $TenantCode code = "" uuid = "" } | ConvertTo-Json -Compress try { $loginResp = Invoke-RestMethod -Uri "$BaseUrl/login" -Method Post -Body $loginBody -ContentType "application/json; charset=utf-8" -TimeoutSec 30 } catch { Write-Host "Login HTTP error: $($_.Exception.Message)" -ForegroundColor Red exit 1 } if (-not $loginResp.token) { Write-Host "Login failed: $($loginResp.msg)" -ForegroundColor Red exit 1 } $Token = "Bearer $($loginResp.token)" Write-Host "Login OK" -ForegroundColor Green } else { if ($Token -notmatch "^Bearer ") { $Token = "Bearer $Token" } Write-Host "Using provided token" -ForegroundColor Green } if ($TemplateId -le 0) { Write-Host "`n=== Step 2: List templates ===" -ForegroundColor Cyan $headers = @{ Authorization = $Token } try { $tplResp = Invoke-RestMethod -Uri "$BaseUrl/workflow/lobster/template/list?page=1&size=20" -Method Get -Headers $headers -TimeoutSec 30 $templates = $tplResp.data if ($templates -and $templates.Count -gt 0) { $active = $templates | Where-Object { $_.status -eq 1 } | Select-Object -First 1 if (-not $active) { $active = $templates[0] } $TemplateId = [long]$active.id Write-Host "Using template id=$TemplateId name=$($active.templateName)" } else { Write-Host "No templates; use -TemplateId 22 (test001) or 70 (cs1)" -ForegroundColor Yellow exit 2 } } catch { Write-Host "List templates failed: $($_.Exception.Message)" -ForegroundColor Yellow exit 2 } } Write-Host "`n=== Step 3: Simulate ===" -ForegroundColor Cyan & "$PSScriptRoot\probe-simulate-dialogue.ps1" -BaseUrl $BaseUrl -Token $Token -TemplateId $TemplateId -Content $Content exit $LASTEXITCODE