Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,38 @@ GROK_API_KEY=your_grok_api_key_here

# Optional: Telegram bot token for /connect → Telegram (see README)
# TELEGRAM_BOT_TOKEN=123456:ABC...

# ----------------------------------------------------------------------
# Vertex AI Grok backend (optional)
#
# When GROK_PROVIDER=vertex (or `--provider vertex`) is set, the CLI
# routes Grok traffic through Google Cloud Vertex AI instead of the
# native xAI API. Authenticate locally with:
#
# gcloud auth application-default login
#
# and verify with:
#
# gcloud auth application-default print-access-token
# ----------------------------------------------------------------------

# Select the Vertex backend. Default is "xai".
# GROK_PROVIDER=vertex

# Required for Vertex mode. The Google Cloud project that hosts the
# Vertex AI API call. Falls back to GCP_PROJECT_ID if unset.
# GROK_VERTEX_PROJECT_ID=my-gcp-project

# Optional. Vertex region for the partner-model endpoint. Default is
# "global", which routes to the global Vertex endpoint as documented
# in the Grok-on-Vertex model cards. Use a region (e.g. us-central1,
# europe-west1) only when required by org policy or quota.
# GROK_VERTEX_LOCATION=global

# Optional. Override the Vertex API host (default: https://aiplatform.googleapis.com).
# Rarely needed; useful for proxies or staging endpoints.
# GROK_VERTEX_BASE_URL=https://aiplatform.googleapis.com

# Authentication is currently ADC only (`gcloud auth application-default login`).
# Pre-minted OAuth tokens and service-account-bound API keys are tracked as a
# follow-up; no env var to set here for v1.
17 changes: 16 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Source files (only include built dist/)
src/
tsconfig.json
vitest.config.ts
biome.json
test-vertex-integration.ts

# Lock files from other package managers
yarn.lock
Expand Down Expand Up @@ -50,6 +53,9 @@ tests/
*.test.ts
*.spec.js
*.spec.ts
dist/**/*.test.*
dist/**/*.spec.*
dist/grok-standalone*
coverage/
.nyc_output/

Expand All @@ -62,6 +68,15 @@ docs/
.git/
.gitignore

# Local development, agent, and editor runtime state
.cursor/
.omx/
.codex/
.agents/
.claude/
.grok/
.husky/

# CI/CD files
.github/
.gitlab-ci.yml
Expand All @@ -77,4 +92,4 @@ appveyor.yml

# Include only what's needed for the package
# The dist/ folder should be included (not ignored)
# package.json and README.md should be included
# package.json and README.md should be included
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- **Vertex AI Grok backend.** Select with `--provider vertex` or `GROK_PROVIDER=vertex`. Authenticates via Google Application Default Credentials (`gcloud auth application-default login`), uses the documented Vertex Grok partner-model endpoint, and exposes the four official SKUs (`grok-4.20-{reasoning,non-reasoning}`, `grok-4.1-fast-{reasoning,non-reasoning}`). xAI behavior is unchanged for existing users; the active provider is settable via env var, the new `--provider` CLI flag, or `provider` in `~/.grok/user-settings.json`.
- New `GrokProviderAdapter` contract at `src/providers/`. The Agent, tools, media, and helpers now depend on a backend-agnostic interface with explicit capability flags. xAI-only features (Batch API, hosted web/X search, image and video generation, Telegram STT) return typed errors instead of opaque transport failures when used under a Vertex session.
- Dedicated grep tool powered by npm ripgrep WASM (#263)
- `/btw` command for side questions (#264)

### Fixed
- TUI: plan-mode questions no longer leak into the chat input.
- TUI: async tool-result and plan-question updates now repaint without waiting for a keyboard event.
- TUI: typing a status nudge ("continue", "status") during an active turn now triggers a repaint instead of enqueueing an accidental follow-up message.
- npm package no longer ships local agent/editor runtime state, stale dist artifacts, or platform-specific standalone binaries; the installed `grok` entrypoint now retains its executable bit across `tsc` builds.
- Local PR-tested installs no longer get clobbered by the auto-updater pulling the latest public release.

### Changed
- Switched Telegram voice/audio transcription from whisper.cpp to Grok STT (`/v1/stt`); removed `whisper-cli`, `ffmpeg`, and model-download requirements (#266, #265)
- Install script warns when auto-resolving to a pre-release version (#269)
Expand Down
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,75 @@ Optional: `**GROK_BASE_URL**` (default `https://api.x.ai/v1`), `**GROK_MODEL**`,

---

## Vertex AI Grok (Google Cloud backend)

`grok-cli` can route Grok traffic through **Google Cloud Vertex AI** instead of the native xAI API. The four documented Vertex Grok SKUs are supported:

- `grok-4.20-reasoning` (200K context — default chat model)
- `grok-4.20-non-reasoning`
- `grok-4.1-fast-reasoning` (128K context)
- `grok-4.1-fast-non-reasoning` (128K context — default title/recap model)

### Prerequisites

1. Enable the Vertex AI API on your GCP project.
2. Authenticate locally with **Application Default Credentials**:
```bash
gcloud auth application-default login
gcloud auth application-default print-access-token # verify
```

### Run

```bash
# CLI flag
grok --provider vertex

# Or via env var
GROK_PROVIDER=vertex GROK_VERTEX_PROJECT_ID=my-gcp-project grok

# Or save in ~/.grok/user-settings.json
{
"provider": "vertex",
"vertex": {
"projectId": "my-gcp-project",
"location": "global"
}
}
```

### What works on Vertex

- Chat and streaming
- Local function/tool calling (bash, file edits, LSP, etc.)
- Structured outputs
- Image inputs (vision)
- Reasoning vs non-reasoning by SKU selection

### What's xAI-only (returns a typed error on Vertex)

- xAI `/responses` endpoint and the multi-agent SKUs
- Hosted web search and X search (`search_web`, `search_x`)
- Image generation (`grok-imagine-image`) and video generation (`grok-imagine-video`)
- xAI Batch API (`--batch-api`)
- Telegram audio transcription via Grok STT

### Vertex environment variables

| Var | Purpose | Default |
|---|---|---|
| `GROK_PROVIDER` | Active backend (`xai` or `vertex`) | `xai` |
| `GROK_VERTEX_PROJECT_ID` | GCP project for Vertex requests | — |
| `GCP_PROJECT_ID` | Fallback for `GROK_VERTEX_PROJECT_ID` | — |
| `GROK_VERTEX_LOCATION` | Vertex region (e.g. `us-central1`) | `global` |
| `GROK_VERTEX_BASE_URL` | Vertex API host override | `https://aiplatform.googleapis.com` |

> Authentication is currently **ADC only** (`gcloud auth application-default login`). Pre-minted OAuth tokens and service-account-bound API keys are documented in the Google Cloud quickstart but require additional CLI plumbing — tracked as a follow-up.

> **Disclaimer:** Vertex AI access to Grok is provided by Google Cloud as a partner integration. This project is independent of both xAI Corp. and Google. Pricing and availability are governed by your Google Cloud contract.

---

## Telegram (remote control) — short version

1. Create a bot with [@BotFather](https://t.me/BotFather), copy the token.
Expand Down
33 changes: 33 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
},
"scripts": {
"dev": "bun run src/index.ts",
"build": "tsc",
"clean:dist": "bun -e \"import { rmSync } from 'node:fs'; rmSync('dist', { recursive: true, force: true })\"",
"build": "bun run clean:dist && tsc && bun -e \"import { chmodSync } from 'node:fs'; chmodSync('dist/index.js', 0o755)\"",
"build:binary": "bun build --compile --outfile dist/grok-standalone ./src/index.ts",
"prepack": "bun run build",
"start": "bun run dist/index.js",
"typecheck": "tsc --noEmit",
"test": "bunx vitest run",
Expand Down Expand Up @@ -56,6 +58,7 @@
"commander": "^12.1.0",
"diff": "^8.0.3",
"dotenv": "^16.6.1",
"google-auth-library": "^10.6.2",
"grammy": "^1.41.1",
"react": "^19.2.4",
"ripgrep": "^0.3.1",
Expand Down
Loading