param( [string]$DownloadBaseUrl = 'https://gitlab.com/comluojian/agent-tools/-/raw/main/codex/windows/desktop/latest', [string]$PackageSha256 = 'E25ED6017A789E278389C6D2F8E302721CBCE8FF089A22EB3F85EF95AD996418' ) $ErrorActionPreference = 'Stop' $downloadUri = New-Object System.Uri($DownloadBaseUrl) if (-not $downloadUri.IsAbsoluteUri -or $downloadUri.Scheme -notin @('http', 'https')) { throw 'DownloadBaseUrl 必须是完整的 HTTP/HTTPS 地址。' } $baseUrl = $DownloadBaseUrl.TrimEnd('/') $installerUrl = "$baseUrl/Setup-CodexCompany.ps1" $packageUrl = "$baseUrl/Codex白名单测试版-同事分发包.zip" $installerPath = Join-Path ([System.IO.Path]::GetTempPath()) ('Setup-CodexCompany-' + [guid]::NewGuid().ToString('N') + '.ps1') try { Invoke-WebRequest -UseBasicParsing -Uri $installerUrl -OutFile $installerPath $powershellCommand = Get-Command powershell.exe -ErrorAction SilentlyContinue if (-not $powershellCommand) { $powershellCommand = Get-Command pwsh.exe -ErrorAction SilentlyContinue } if (-not $powershellCommand) { throw '没有找到 PowerShell。' } $arguments = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $installerPath, '-PackageUrl', $packageUrl) if (-not [string]::IsNullOrWhiteSpace($PackageSha256)) { $arguments += @('-PackageSha256', $PackageSha256) } & $powershellCommand.Source @arguments if ($LASTEXITCODE -ne 0) { throw "Codex 自定义模型配置失败,退出码:$LASTEXITCODE" } } finally { if (Test-Path -LiteralPath $installerPath) { Remove-Item -LiteralPath $installerPath -Force } }