Files
meatbag/request_watch_approval.ps1

45 lines
1.2 KiB
PowerShell
Raw Normal View History

param(
[string]$Prompt,
[string]$Target = "system-agent"
)
$ErrorActionPreference = "Stop"
# Read API key
if (Test-Path ".meatbag_key") {
$apiKey = (Get-Content ".meatbag_key").Trim()
} else {
Write-Error "No .meatbag_key file found!"
exit 1
}
# Create request payload
$requestId = "cmd_" + [guid]::NewGuid().ToString().Substring(0, 8)
$body = @{
type = "ApprovalRequest"
id = $requestId
prompt = $Prompt
target = $Target
} | ConvertTo-Json
# Send request to Ktor server and wait for response
Write-Host "Sending watch approval request: '$Prompt' (target: $Target)..."
try {
$response = Invoke-RestMethod -Uri "http://localhost:8080/api/request?attentionTier=OVERRIDE_SCREEN" `
-Method Post `
-Headers @{ "X-Meatbag-API-Key" = $apiKey } `
-ContentType "application/json; charset=utf-8" `
-Body $body
$approved = $response.approved
Write-Host "Response received: approved=$approved"
if ($approved -eq $true) {
exit 0
} else {
exit 1
}
} catch {
Write-Error "Failed to request approval: $_"
exit 1
}