$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition $configDir = Join-Path $scriptDir "config" $configFile = Join-Path $configDir "aza_runtime.env" Write-Host "" Write-Host "=== AZA - OpenAI API-Schluessel einrichten ===" Write-Host "" if (-not (Test-Path $configDir)) { New-Item -ItemType Directory -Path $configDir -Force | Out-Null } $existingKey = "" if (Test-Path $configFile) { $lines = Get-Content $configFile -Encoding UTF8 foreach ($line in $lines) { $trimmed = $line.Trim() if ($trimmed -match '^OPENAI_API_KEY\s*=\s*(.+)$') { $existingKey = $matches[1].Trim().Trim('"').Trim("'") } } } if ($existingKey) { $masked = $existingKey.Substring(0, [Math]::Min(7, $existingKey.Length)) + "..." Write-Host "Ein OpenAI API-Schluessel ist bereits konfiguriert ($masked)." Write-Host "" $overwrite = Read-Host "Soll der Schluessel ersetzt werden? (j/n)" if ($overwrite -ne "j") { Write-Host "Keine Aenderung. Beenden." Write-Host "" pause exit 0 } } Write-Host "Bitte geben Sie Ihren OpenAI API-Schluessel ein." Write-Host "(Der Schluessel beginnt normalerweise mit 'sk-')" Write-Host "" $newKey = Read-Host "OPENAI_API_KEY" if (-not $newKey -or $newKey.Trim().Length -lt 10) { Write-Host "" Write-Host "Ungueltige Eingabe. Kein Schluessel gespeichert." Write-Host "" pause exit 1 } $newKey = $newKey.Trim() if (Test-Path $configFile) { $lines = Get-Content $configFile -Encoding UTF8 $found = $false $newLines = @() foreach ($line in $lines) { if ($line.Trim() -match '^OPENAI_API_KEY\s*=') { $newLines += "OPENAI_API_KEY=$newKey" $found = $true } else { $newLines += $line } } if (-not $found) { $newLines += "OPENAI_API_KEY=$newKey" } $newLines | Set-Content $configFile -Encoding UTF8 } else { @( "# AZA Runtime-Konfiguration", "# Diese Datei wird bei Updates NICHT ueberschrieben.", "", "OPENAI_API_KEY=$newKey" ) | Set-Content $configFile -Encoding UTF8 } Write-Host "" Write-Host "OpenAI API-Schluessel wurde gespeichert." Write-Host "Konfigurationsdatei: $configFile" Write-Host "" Write-Host "Bitte starten Sie AZA Desktop neu, damit der Schluessel aktiv wird." Write-Host "" pause