Commit 800ded6
feat(auth): browser-based Stytch OAuth login + environment switching (#6)
* feat(auth): add auth package skeleton and endpoint config
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(auth): build Stytch B2B OAuth discovery start URL
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(auth): add fixed-port loopback callback server
* feat(auth): add AMS http client (discover/exchange/auth/projects/tokens)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* chore(auth): satisfy ruff S/BLE lints in auth tests
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(auth): orchestrate browser+AMS login into an API key
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(auth): aai login uses Stytch OAuth, keeps --api-key escape hatch
* chore(packaging): rename distribution to aai-cli to avoid PyPI collision
The PyPI name "assemblyai-cli" is already taken by a third party, which
blocks the clean `uv tool install` / `pipx install` / Homebrew path. Rename
the distribution to the available "aai-cli". The `aai` command and the
`assemblyai_cli` import package are unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* refactor: rename package assemblyai_cli → aai_cli
Match the new distribution name (aai-cli). Renames the package directory,
updates all imports, the `aai` console-script entry point, hatchling wheel
packages, mypy files, scripts, and the uv.lock root package name. No behavior
change; the keyring service name ("assemblyai-cli") is intentionally preserved
to keep already-stored credentials readable.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(auth): sandbox Stytch/AMS config + OAuth state-cookie fix
Fixes found during end-to-end sandbox testing:
- Start B2B OAuth discovery on test.stytch.com (Stytch's API domain), not the
vanity *.customers.stytch.dev CNAME, so the CSRF state cookie is set on the
same domain as the OAuth callback — fixes `oauth_invalid_state`.
- Point at the Stytch project that ams.sandbox000 is bound to
(public-token-test-a161155e…) so AMS authenticates the discovery token.
- Add env-overridable SIGNUP_URL (sandbox default) and surface it in the
friendlier 0-org "no AssemblyAI account yet" message.
Verified end-to-end against sandbox: browser login → AMS discover/exchange →
find-or-create "AssemblyAI CLI" key → stored in keychain; second login reuses
the same key (idempotent).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat: --env/--sandbox environment switching, bound to profile
Add a named-environment registry (production, sandbox000) mapping the full
backend host set: api_base (/v2 upload+transcript), streaming_host (/v3/ws),
llm_gateway_base (/v1), AMS, and Stytch domain/public-token/signup URL.
Select with the global --env <name> / --sandbox flags or AAI_ENV; `aai login`
records the resolved env on the profile so a credential and its hosts always
stay matched — this structurally prevents the sandbox-key-against-prod-host
rejection (HTTP 1008 / 401). Precedence: --env > AAI_ENV > profile > default.
client.py (SDK base_url + streaming api_host), llm.py (gateway base), and the
auth modules now resolve hosts from the active environment instead of hardcoded
prod literals; whoami reports the active env. Default is sandbox000 for now;
flip DEFAULT_ENV to production once prod AMS/Stytch values are stood up.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(llm): surface LLM Gateway access errors instead of "run aai login"
The gateway returns 401/403 both for an invalid key and for a plan-entitlement
block ("Your account does not have access to LLM Gateway"). Mapping that to
auth_failure() told unpaid accounts to re-run `aai login`, which never helps.
Surface the gateway's own message as APIError so the cause is actionable.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(auth): harden OAuth login flow and env handling against bad input
Address code-review findings in the new browser-OAuth login + environment
switching. All changes are defensive; the happy path is unchanged.
- loopback: map a port-bind OSError (port 8585 already in use) to a clean
APIError instead of letting a raw traceback escape run_login_flow.
- flow: tolerate AMS responses that key the token name as `token_name`
(not `name`) and skip tokens whose `api_key` the list omits, so an
existing CLI token is reused rather than crashing or duplicated.
- flow: note the chosen organization when an identity has more than one,
instead of silently picking the first.
- flow: wrap required response fields in `_require()` so an unexpected 200
shape surfaces as "Run 'aai login' again" rather than a KeyError.
- flow: read the account id from the exchange() response instead of a
second GET /v1/auth round-trip.
- config: map a malformed config.toml (TOMLDecodeError) to a clean CLIError
so every command no longer aborts with a traceback.
- context/main: warn when an explicit --env contradicts the profile's
stored env (the stored key won't authenticate against the other hosts).
- ams: extract a shared _client() helper for the five httpx.Client blocks.
Adds regression tests for each (TDD). 545 pass, 93% branch coverage.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(packaging): refresh uv.lock after aai-cli rename
`uv lock` relocates the editable root-package entry under its new
`aai-cli` name; no dependency versions change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* style: apply ruff 0.15.16 formatting (matches uv.lock)
CI runs `ruff format --check` with the locked ruff 0.15.16; reformat the
files whose style differs under that version. No behavior change.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Alex Kroman <alex@assemblyai.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent ffcf11b commit 800ded6
92 files changed
Lines changed: 1523 additions & 543 deletions
File tree
- aai_cli
- agent
- auth
- code_gen
- commands
- streaming
- assemblyai_cli
- scripts
- tests
- e2e
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
File renamed without changes.
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
| 9 | + | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
| 294 | + | |
295 | 295 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments