Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 03:37 UTC
| 1 | # Composio CLI installer for Windows x64 (experimental). |
| 2 | # |
| 3 | # irm https://raw.githubusercontent.com/ComposioHQ/composio/next/install.ps1 | iex |
| 4 | # |
| 5 | # Configure it with environment variables, like install.sh: |
| 6 | # COMPOSIO_INSTALL_VERSION Release to install, such as 0.3.1 or 0.3.1-beta.329. Default: latest stable. |
| 7 | # COMPOSIO_INSTALL_DIR Directory for the CLI bundle. Default: ~\.composio |
| 8 | # COMPOSIO_INSTALL_SHELL Set to "none" to leave PATH unchanged. |
| 9 | |
| 10 | # The script block keeps variables and preferences out of the caller's session under `iex`. |
| 11 | & { |
| 12 | $ErrorActionPreference = 'Stop' |
| 13 | # Windows PowerShell redraws its progress bar per chunk, which slows downloads to a crawl. |
| 14 | $ProgressPreference = 'SilentlyContinue' |
| 15 | |
| 16 | # A 32-bit PowerShell on 64-bit Windows reports the real architecture in PROCESSOR_ARCHITEW6432. |
| 17 | $arch = if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE } |
| 18 | if ($env:OS -ne 'Windows_NT' -or $arch -ne 'AMD64') { |
| 19 | throw 'This installer requires Windows x64. On Linux, macOS, or WSL, run: curl -fsSL https://composio.dev/install | sh' |
| 20 | } |
| 21 | |
| 22 | # The checksum only proves the archive matches checksums.txt, and both come from the same |
| 23 | # server. So every download must use HTTPS; plain HTTP is accepted from this machine only. |
| 24 | function Assert-TrustedUrl([string]$Url) { |
| 25 | $uri = $Url -as [uri] |
| 26 | $trusted = $uri -and $uri.IsAbsoluteUri -and -not $uri.UserInfo -and |
| 27 | ($uri.Scheme -eq 'https' -or ($uri.Scheme -eq 'http' -and $uri.IsLoopback)) |
| 28 | if (-not $trusted) { throw "Refusing to download from `"$Url`". The URL must use HTTPS and carry no credentials." } |
| 29 | } |
| 30 | |
| 31 | $archiveName = 'composio-windows-x64.zip' |
| 32 | $installDir = if ($env:COMPOSIO_INSTALL_DIR) { $env:COMPOSIO_INSTALL_DIR } else { Join-Path $HOME '.composio' } |
| 33 | $installDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($installDir) |
| 34 | |
| 35 | # Find the release: the requested version, or the newest stable one that ships a Windows archive. |
| 36 | $api = if ($env:COMPOSIO_GITHUB_API_BASE_URL) { $env:COMPOSIO_GITHUB_API_BASE_URL.TrimEnd('/') } else { 'https://api.github.com' } |
| 37 | Assert-TrustedUrl $api |
| 38 | # CI can authenticate metadata requests to avoid GitHub's shared runner-IP |
| 39 | # limit. Never send the token to a custom API base or to asset hosts. |
| 40 | $apiRequest = @{} |
| 41 | if ($api -ceq 'https://api.github.com' -and $env:COMPOSIO_GITHUB_API_TOKEN) { |
| 42 | $apiRequest.Headers = @{ Authorization = "Bearer $env:COMPOSIO_GITHUB_API_TOKEN" } |
| 43 | $apiRequest.MaximumRedirection = 0 |
| 44 | } |
| 45 | $releasesUrl = "$api/repos/ComposioHQ/composio/releases" |
| 46 | $release = $null |
| 47 | if ($env:COMPOSIO_INSTALL_VERSION) { |
| 48 | $version = $env:COMPOSIO_INSTALL_VERSION -replace '^@composio/cli@', '' |
| 49 | if ($version -notmatch '^\d+\.\d+\.\d+(-beta\.\d+)?$') { |
| 50 | throw "Invalid Composio CLI version `"$env:COMPOSIO_INSTALL_VERSION`". Expected X.Y.Z or X.Y.Z-beta.N." |
| 51 | } |
| 52 | $release = Invoke-RestMethod "$releasesUrl/tags/$([uri]::EscapeDataString("@composio/cli@$version"))" @apiRequest |
| 53 | } else { |
| 54 | Write-Host 'Finding latest stable CLI release...' |
| 55 | for ($page = 1; $page -le 5 -and -not $release; $page++) { |
| 56 | # Assign before piping: Windows PowerShell emits the JSON array as a single object. |
| 57 | $candidates = Invoke-RestMethod "${releasesUrl}?per_page=100&page=$page" @apiRequest |
| 58 | if (-not $candidates) { break } |
| 59 | $release = $candidates | Where-Object { |
| 60 | $_.tag_name -match '^@composio/cli@\d+\.\d+\.\d+$' -and -not $_.draft -and -not $_.prerelease -and |
| 61 | $_.assets.name -contains $archiveName |
| 62 | } | Select-Object -First 1 |
| 63 | } |
| 64 | if (-not $release) { throw 'No stable CLI release with a Windows x64 archive was found. Set COMPOSIO_INSTALL_VERSION to choose one.' } |
| 65 | } |
| 66 | $tag = $release.tag_name |
| 67 | $archiveUrl = ($release.assets | Where-Object { $_.name -eq $archiveName }).browser_download_url |
| 68 | $checksumsUrl = ($release.assets | Where-Object { $_.name -eq 'checksums.txt' }).browser_download_url |
| 69 | if (-not $archiveUrl) { throw "Release $tag has no Windows x64 archive." } |
| 70 | if (-not $checksumsUrl) { throw "Release $tag has no checksums.txt, so it cannot be verified. Refusing to install." } |
| 71 | Assert-TrustedUrl $archiveUrl |
| 72 | Assert-TrustedUrl $checksumsUrl |
| 73 | |
| 74 | $tempDir = Join-Path ([IO.Path]::GetTempPath()) "composio-install-$([Guid]::NewGuid())" |
| 75 | New-Item -ItemType Directory -Path $tempDir | Out-Null |
| 76 | try { |
| 77 | Write-Host "Installing Composio CLI $tag for windows-x64" |
| 78 | $archivePath = Join-Path $tempDir $archiveName |
| 79 | $checksumsPath = Join-Path $tempDir 'checksums.txt' |
| 80 | Invoke-WebRequest $archiveUrl -OutFile $archivePath -UseBasicParsing |
| 81 | Invoke-WebRequest $checksumsUrl -OutFile $checksumsPath -UseBasicParsing |
| 82 | |
| 83 | $entry = Select-String -LiteralPath $checksumsPath -Pattern '^([0-9a-f]{64})\s+\*?composio-windows-x64\.zip$' | Select-Object -First 1 |
| 84 | if (-not $entry) { throw "checksums.txt has no entry for $archiveName. Refusing to install." } |
| 85 | if ((Get-FileHash -LiteralPath $archivePath -Algorithm SHA256).Hash -ne $entry.Matches[0].Groups[1].Value) { |
| 86 | throw "Checksum mismatch for $archiveName. Refusing to install." |
| 87 | } |
| 88 | |
| 89 | Expand-Archive -LiteralPath $archivePath -DestinationPath $tempDir |
| 90 | $bundle = Join-Path $tempDir 'composio-windows-x64' |
| 91 | if (-not (Test-Path -LiteralPath (Join-Path $bundle 'composio.exe') -PathType Leaf)) { |
| 92 | throw 'The archive has no composio.exe. Refusing to install.' |
| 93 | } |
| 94 | |
| 95 | # Windows cannot overwrite a running executable, but it can rename one. Copy the new |
| 96 | # executable next to the current one first, so the only step that leaves the directory |
| 97 | # without composio.exe is a pair of renames. Everything else in that directory |
| 98 | # (credentials, configuration) stays untouched. |
| 99 | New-Item -ItemType Directory -Path $installDir -Force | Out-Null |
| 100 | $exe = Join-Path $installDir 'composio.exe' |
| 101 | $stagedExe = "$exe.new" |
| 102 | $previousExe = "$exe.old" |
| 103 | try { |
| 104 | if (Test-Path -LiteralPath $previousExe) { Remove-Item -LiteralPath $previousExe -Force } |
| 105 | } catch { |
| 106 | throw "Could not remove $previousExe. Close other Composio processes and retry. $($_.Exception.Message)" |
| 107 | } |
| 108 | Copy-Item -LiteralPath (Join-Path $bundle 'composio.exe') -Destination $stagedExe -Force |
| 109 | Get-ChildItem -LiteralPath $bundle -Force | Where-Object { $_.Name -ne 'composio.exe' } | |
| 110 | Copy-Item -Destination $installDir -Recurse -Force |
| 111 | |
| 112 | $hadExe = Test-Path -LiteralPath $exe |
| 113 | if ($hadExe) { Move-Item -LiteralPath $exe -Destination $previousExe } |
| 114 | try { |
| 115 | Move-Item -LiteralPath $stagedExe -Destination $exe |
| 116 | } catch { |
| 117 | if ($hadExe) { Move-Item -LiteralPath $previousExe -Destination $exe -Force } |
| 118 | throw |
| 119 | } |
| 120 | # Fails only while the previous executable is still running; the next install removes it. |
| 121 | Remove-Item -LiteralPath $previousExe -Force -ErrorAction SilentlyContinue |
| 122 | } finally { |
| 123 | Remove-Item -LiteralPath $tempDir -Recurse -Force -ErrorAction SilentlyContinue |
| 124 | } |
| 125 | |
| 126 | if ($env:COMPOSIO_INSTALL_SHELL -ne 'none') { |
| 127 | $userPath = [Environment]::GetEnvironmentVariable('Path', 'User') |
| 128 | if (($userPath -split ';') -notcontains $installDir) { |
| 129 | [Environment]::SetEnvironmentVariable('Path', ((@($installDir, $userPath) | Where-Object { $_ }) -join ';'), 'User') |
| 130 | } |
| 131 | # Also update this session, so `composio` works without opening a new terminal. |
| 132 | if (($env:Path -split ';') -notcontains $installDir) { $env:Path = "$installDir;$env:Path" } |
| 133 | } |
| 134 | |
| 135 | Write-Host "Installed $tag in $installDir" |
| 136 | Write-Host 'Windows support is experimental. Report problems at https://github.com/ComposioHQ/composio/issues' |
| 137 | Write-Host 'Run "composio login" to connect your account.' |
| 138 | } |