Move reflex-hosting-cli onto reflex-build-sdk
reflex_cli/utils/hosting.py was a 3487-line hand-rolled HTTP layer: an AuthenticatedClient carrying a raw token, a per-function httpx.<verb>(urljoin(...), headers=authorization_header(...)), its own presigned-upload and retry machinery, and a bespoke error-to-string conversion at every call site. reflex-build-sdk already covers every endpoint the CLI reaches, with typed results, retries that only repeat what is safe to repeat, and typed errors — so the CLI now goes through it.
The module drops to 1645 lines and keeps only what is the CLI's own: interactive name resolution, the config files, the browser login, ScaleParams, and build-log sanitising. AuthenticatedClient becomes the SDK client paired with the identity its token authenticates as, and the v2 command modules call the SDK directly rather than through a wrapper.
Two helpers replace the idioms that are gone:
reporting_api_errors()wraps a command body, so a refusal reads as the sentence the API wrote and an expired token says to runreflex loginwherever it turns up — not only where the command started by authenticating.as_json_document()renders a typed result as the plain data a--jsondocument is made of, so the documents keep the shape they had when response bodies were printed straight through.
Deploys now always reserve signed upload URLs and PUT to storage; the multipart relay fallback for control planes without /deployments/reserve is gone, and upload progress is wired to the existing transfer bar. The SDK imports live inside the functions that use them: importing reflex_build_sdk pulls in httpx and aiohttp, and reflex cloud --help must not pay for an HTTP stack it will not use (tests/units/test_reflex.py guards this).
Behaviour changes
Declared in +build-sdk.breaking.md, each forced by the SDK's shapes:
- A refused request exits non-zero rather than printing a
"... failed: ..."line and exiting 0, and--jsonwrites no document on that path.apps stop,apps startandapps deleteare the ones most likely to be scripted against. apps history --jsonreports the deployment'surlin place ofhostname.apps logs --jsonreturns every line in the window with anullcursor instead of one page. The old cursor was never consumable — there was no--cursoroption to pass it back to.project role-permissionslists permission names rather than objects.reflex deployrequires a control plane that signs upload URLs.
Two smaller ones worth calling out in review:
- The SDK's status classifier does not read
"deployment failed"as a failure; the CLI's predicate always has, sodeployment_status_failedkeeps the stricter reading as an explicit override. Worth deciding whether the SDK should match. - A watch that loses its connection now warns that it stopped following and points at
reflex cloud apps status --watch, rather than looping forever. It exits 0: the deployment was submitted and is still running, so claiming failure would be a wrong guess.
Notes for the reviewer
AppSummarycarries no project name, so the interactive conflict table and the deploy confirmation prompt look the project up — one extra request, only when disambiguating.set_instance_boundsreads the app first, because the endpoint replaces both bounds and the CLI's contract is to change only what was passed.v2/apps.pystill resolves an app id two different ways (_resolve_app_idprefers--app-nameover the configured appid; three inline copies prefer the config). Consolidating would change behaviour, so both are left as they were.
Verification
ruff check/format, pyright, check_min_deps.py (all 20 packages) and --check-dev-pins clean; full unit suite 9599 passed at 78.87% coverage. The real commands were also driven against the live API read-only (vmtypes, regions, apps.list, secrets.list, projects.list).