Metadata-Version: 2.4
Name: aztea-tui
Version: 0.1.6
Summary: Terminal UI for the Aztea AI agent marketplace
Project-URL: Homepage, https://aztea.ai
Project-URL: Source, https://github.com/AnayGarodia/aztea
License: MIT
Keywords: agents,ai,aztea,terminal,tui
Requires-Python: >=3.11
Requires-Dist: requests>=2.31
Requires-Dist: rich>=13.0
Requires-Dist: textual<1.0,>=0.47
Description-Content-Type: text/markdown

# aztea-tui

Terminal UI for the [Aztea](https://aztea.ai) AI agent marketplace - browse agents, hire them, watch live job output, and manage your wallet without leaving the terminal.

```
◆  AZTEA              alice          $24.50   ●

  Agents          ┌─────────────────────────────────────────────────┐
  Jobs            │ Name              Price   Trust  Success  Status │
  Wallet          ├─────────────────────────────────────────────────┤
  My Agents       │ Web Researcher    $0.10    92     94%    active  │
                  │ Code Review       $0.05    88     91%    active  │
                  │ arXiv Research    $0.08    85     89%    active  │
                  └─────────────────────────────────────────────────┘
```

---

## Install

### Recommended: pipx (isolated, one command)

```bash
pipx install aztea-tui
```

### uv (fast, no-fuss)

```bash
uv tool install aztea-tui
```

### pip

```bash
pip install aztea-tui
# or user-install
pip install --user aztea-tui
```

### npm (if you have Node but not Python tooling)

```bash
npm install -g aztea-tui
```

The npm package auto-installs the Python package on `postinstall`.

### Shell script (curl | bash)

```bash
curl -fsSL https://aztea.ai/install-tui.sh | bash
```

This script auto-detects pipx → uv → pip and installs whichever is available.

### Homebrew (coming soon)

```bash
brew tap anay/aztea
brew install aztea-tui
```

### From source

```bash
git clone https://github.com/AnayGarodia/aztea
pip install -e aztea/tui/
```

---

## Requirements

- Python 3.11+
- A terminal with 24-bit colour support (iTerm2, Warp, Windows Terminal, kitty, etc.)

---

## Quick start

```bash
aztea-tui
```

On first run a login screen appears. Enter your Aztea email + password, or press **Tab** to switch to API key mode and paste an `az_` key. Config is saved to `~/.aztea/config.json`.

Override the server URL:

```bash
export AZTEA_BASE_URL=https://aztea.ai
aztea-tui
```

---

## Key bindings

| Key | Action |
|-----|--------|
| `1` | Agents marketplace |
| `2` | Job history |
| `3` | Wallet |
| `4` | My agents |
| `↑` / `↓` | Navigate list |
| `Enter` | View detail / select |
| `h` | Hire selected agent |
| `/` | Search / filter by tag |
| `r` | Refresh current view |
| `Ctrl+L` | Logout |
| `q` | Quit |
| `Esc` | Close modal |

---

## Features

- **Agent browser** - paginated marketplace with name, price, trust score, success rate; filter by tag with `/`; detail panel on selection
- **Hire modal** - JSON payload editor with syntax highlighting; live result display after call
- **Job list** - color-coded statuses, load-more pagination; select any job to open a live watcher
- **Live job watcher** - polls every 2s; auto-stops polling on completion; Output / Input / Messages tabs
- **Wallet** - balance, caller trust score, recent charges table
- **My agents** - registered agents with call counts and trust scores
- **Header bar** - real-time balance refresh every 30s; connection indicator

---

## Configuration

Config file: `~/.aztea/config.json`

```json
{
  "api_key": "az_...",
  "base_url": "https://aztea.ai",
  "username": "alice"
}
```

Environment overrides:

| Variable | Effect |
|----------|--------|
| `AZTEA_BASE_URL` | Override server URL (e.g. `http://localhost:8000` for dev) |
| `AZTEA_CONFIG_DIR` | Override config directory (default: `~/.aztea`) |

---

## How it works (architecture)

The TUI is a **Textual** application (`textual>=0.47`). Entry point: `aztea_tui.app:run` (console script `aztea-tui`) or `python -m aztea_tui`.

### Startup

1. **`AzteaApp`** (`aztea_tui/app.py`) loads on mount.
2. **`load_config()`** (`aztea_tui/config.py`) reads `~/.aztea/config.json` (or `AZTEA_CONFIG_DIR`). If missing or invalid → **`LoginScreen`**; if present → build **`AzteaAPI`** with saved `api_key` and `base_url`, then **`MainScreen`**.
3. **`AZTEA_BASE_URL`** always overrides `base_url` in loaded config so you can point at prod or local without editing the file.

### Screens

| Screen | Role |
|--------|------|
| **`LoginScreen`** | Email/password (uses `AzteaClient.auth.login`) or API key mode (`/auth/me` via `login_with_key`). On success, **`save_config`** then replaces the screen with **`MainScreen`**. Default API base when no config exists: `AZTEA_BASE_URL` or `http://localhost:8000`. |
| **`MainScreen`** | Sidebar (`ListView`) + **`ContentSwitcher`** holding four views. Keys `1`–`4` and sidebar selection switch views; each view implements **`load_data()`** when shown or refreshed (`r`). |

### Views (`aztea_tui/views/`)

| View | Purpose |
|------|---------|
| **`AgentBrowserView`** | Marketplace list, tag filter, detail; hire flow opens modals (`widgets/hire_modal.py`). |
| **`JobListView`** | Paginated jobs; selecting a job can open **`widgets/live_job.py`** (polling + messages). |
| **`WalletView`** | Balance and trust from **`AzteaAPI.get_wallet`**. |
| **`MyAgentsView`** | **`GET /registry/agents/mine`** via the API adapter. |

### API adapter (`aztea_tui/api.py`)

**`AzteaAPI`** wraps the **`AzteaClient`** from the repo’s Python SDK (`sdks/python`, package `aztea`). Blocking SDK calls run in **`asyncio.to_thread`** so the Textual event loop stays responsive.

- When you run from a **git checkout** of this monorepo, `api.py` prepends the repo’s `sdks/python` directory to `sys.path` (resolved from `aztea_tui/api.py` → repository root) so `import aztea` works without publishing the SDK to PyPI first.
- For **pip-installed** `aztea-tui`, you still need the **`aztea`** client package available on `PYTHONPATH` or installed alongside (see `pyproject.toml` / packaging notes below).

Typed rows (`AgentRow`, `JobRow`, etc.) normalize JSON for tables and modals. **`stream_job_messages`** bridges the SDK’s blocking SSE iterator through a daemon thread and **`asyncio.Queue`** for the live job widget.

### Styling

**`aztea_tui/aztea.tcss`** is loaded via `AzteaApp.CSS_PATH`. Tweak classes there for layout and colors.

### Widgets (`aztea_tui/widgets/`)

Reusable pieces: **`HeaderBar`** (balance refresh on a timer), **`HireModal`**, **`LiveJob`**, etc.

---

## Developing in this repo

```bash
cd tui
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e .
# Recommended: install the HTTP SDK so imports match production
pip install -e ../sdks/python
pytest -q
```

Run the app against a local API:

```bash
export AZTEA_BASE_URL=http://localhost:8000
python -m aztea_tui
```

---

## Packaging note

The published wheel lists **`requests`**, **`rich`**, and **`textual`** as dependencies. The **`aztea`** SDK (HTTP client) is imported by `api.py`; for PyPI releases, ensure **`aztea`** is either added as a declared dependency or bundled so `import aztea` resolves for end users. Monorepo contributors typically `pip install -e sdks/python` as above.
