diff --git a/OpenJibo/docs/live-jibo-capture.md b/OpenJibo/docs/live-jibo-capture.md index b2ca47c..818c08d 100644 --- a/OpenJibo/docs/live-jibo-capture.md +++ b/OpenJibo/docs/live-jibo-capture.md @@ -59,3 +59,9 @@ Artifacts: 4. Inspect the captured websocket events and exported fixtures. 5. Convert the best captures into sanitized checked-in fixtures and tests. 6. Keep Node available to compare any surprising turn behavior before changing infrastructure. + +Useful helper scripts: + +- [scripts/cloud/Invoke-LiveJiboPrep.ps1](C:/Projects/JiboExperiments/OpenJibo/scripts/cloud/Invoke-LiveJiboPrep.ps1) +- [scripts/cloud/Get-WebSocketCaptureSummary.ps1](C:/Projects/JiboExperiments/OpenJibo/scripts/cloud/Get-WebSocketCaptureSummary.ps1) +- [scripts/cloud/Import-WebSocketCaptureFixture.ps1](C:/Projects/JiboExperiments/OpenJibo/scripts/cloud/Import-WebSocketCaptureFixture.ps1) diff --git a/OpenJibo/scripts/cloud/Import-WebSocketCaptureFixture.ps1 b/OpenJibo/scripts/cloud/Import-WebSocketCaptureFixture.ps1 new file mode 100644 index 0000000..27f221c --- /dev/null +++ b/OpenJibo/scripts/cloud/Import-WebSocketCaptureFixture.ps1 @@ -0,0 +1,75 @@ +param( + [Parameter(Mandatory = $true)] + [string]$SourcePath, + [Parameter(Mandatory = $true)] + [string]$FixtureName, + [string]$DestinationDirectory = "..\..\src\Jibo.Cloud\node\fixtures\websocket", + [switch]$Overwrite +) + +$ErrorActionPreference = "Stop" + +function Redact-Object { + param( + [Parameter(Mandatory = $true)] + $Value + ) + + if ($null -eq $Value) { + return $null + } + + if ($Value -is [string]) { + if ($Value -match "token" -or $Value -match "bearer" -or $Value -match "session") { + return "[redacted]" + } + + return $Value + } + + if ($Value -is [System.Collections.IEnumerable] -and -not ($Value -is [string])) { + $items = @() + foreach ($item in $Value) { + $items += ,(Redact-Object -Value $item) + } + + return $items + } + + if ($Value.PSObject -and $Value.PSObject.Properties.Count -gt 0) { + $result = [ordered]@{} + foreach ($property in $Value.PSObject.Properties) { + if ($property.Name -match "token" -or $property.Name -match "authorization") { + $result[$property.Name] = "[redacted]" + continue + } + + $result[$property.Name] = Redact-Object -Value $property.Value + } + + return [pscustomobject]$result + } + + return $Value +} + +$resolvedSourcePath = Resolve-Path -LiteralPath $SourcePath -ErrorAction Stop +$resolvedDestinationDirectory = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot $DestinationDirectory)) +New-Item -ItemType Directory -Force -Path $resolvedDestinationDirectory | Out-Null + +$fixture = Get-Content -LiteralPath $resolvedSourcePath -Raw | ConvertFrom-Json -Depth 50 +$sanitized = Redact-Object -Value $fixture +$sanitized.name = $FixtureName +$sanitized.session.token = "[redacted]" + +$destinationPath = Join-Path $resolvedDestinationDirectory ($FixtureName + ".flow.json") +if ((Test-Path -LiteralPath $destinationPath) -and -not $Overwrite) { + throw "Destination fixture already exists: $destinationPath. Use -Overwrite to replace it." +} + +$json = $sanitized | ConvertTo-Json -Depth 50 +[System.IO.File]::WriteAllText($destinationPath, $json + [Environment]::NewLine) + +Write-Host "Imported sanitized websocket fixture:" +Write-Host " - source: $resolvedSourcePath" +Write-Host " - destination: $destinationPath" diff --git a/OpenJibo/scripts/cloud/Invoke-LiveJiboPrep.ps1 b/OpenJibo/scripts/cloud/Invoke-LiveJiboPrep.ps1 new file mode 100644 index 0000000..63ec4ae --- /dev/null +++ b/OpenJibo/scripts/cloud/Invoke-LiveJiboPrep.ps1 @@ -0,0 +1,44 @@ +param( + [string]$BaseUrl = "https://localhost:5001", + [string[]]$ExpectedHosts = @( + "api.jibo.com", + "api-socket.jibo.com", + "neo-hub.jibo.com" + ), + [string]$CaptureDirectory = "..\..\src\Jibo.Cloud\dotnet\src\Jibo.Cloud.Api\bin\Debug\net10.0\captures\websocket" +) + +$ErrorActionPreference = "Stop" + +Write-Host "OpenJibo live Jibo prep" +Write-Host "" + +Write-Host "1. HTTP health check" +try { + $health = Invoke-RestMethod -Uri ($BaseUrl.TrimEnd("/") + "/health") -Method Get + $health | ConvertTo-Json -Depth 5 +} catch { + Write-Error "Health check failed against $BaseUrl. Start the .NET cloud and verify TLS/routing before continuing. $_" +} + +Write-Host "" +Write-Host "2. Expected robot-facing hosts" +$ExpectedHosts | ForEach-Object { Write-Host " - $_" } + +Write-Host "" +Write-Host "3. Capture directory" +$resolvedCaptureDirectory = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot $CaptureDirectory)) +Write-Host " - $resolvedCaptureDirectory" +if (-not (Test-Path -LiteralPath $resolvedCaptureDirectory)) { + New-Item -ItemType Directory -Force -Path $resolvedCaptureDirectory | Out-Null + Write-Host " - created" +} + +Write-Host "" +Write-Host "4. Live-run checklist" +Write-Host " - keep the Ubuntu/Jibo routing setup in place" +Write-Host " - keep the Node server available as a fallback" +Write-Host " - point Jibo at the .NET server using the same controlled network settings" +Write-Host " - perform one startup check, one chat turn, and one joke turn" +Write-Host " - after the run, inspect capture output with scripts/cloud/Get-WebSocketCaptureSummary.ps1" +Write-Host " - import the best exported fixture with scripts/cloud/Import-WebSocketCaptureFixture.ps1" diff --git a/OpenJibo/scripts/cloud/README.md b/OpenJibo/scripts/cloud/README.md index 94cf548..deea33a 100644 --- a/OpenJibo/scripts/cloud/README.md +++ b/OpenJibo/scripts/cloud/README.md @@ -8,3 +8,7 @@ These scripts help exercise the new .NET hosted cloud locally. Replays a sanitized HTTP fixture against a running local instance. - `Get-WebSocketCaptureSummary.ps1` Summarizes captured websocket telemetry events and exported live-run fixtures from the .NET cloud. +- `Invoke-LiveJiboPrep.ps1` + Runs a small readiness checklist before the first physical Jibo test against the .NET cloud. +- `Import-WebSocketCaptureFixture.ps1` + Sanitizes an exported websocket capture fixture and copies it into the checked-in websocket fixture set. diff --git a/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Api/appsettings.json b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Api/appsettings.json new file mode 100644 index 0000000..91b2d43 --- /dev/null +++ b/OpenJibo/src/Jibo.Cloud/dotnet/src/Jibo.Cloud.Api/appsettings.json @@ -0,0 +1,9 @@ +{ + "OpenJibo": { + "Telemetry": { + "Enabled": true, + "ExportFixtures": true, + "DirectoryPath": "captures/websocket" + } + } +}