Files
roboco/alembic/versions/039_seed_grok_provider.py
T
Renn F a956083f9f feat(providers): pluggable agent providers + Grok (xAI) backend
Add a roboco/llm/providers/ seam — an AgentProvider lifecycle ABC and a
ProviderRegistry keyed by ModelProvider — so the orchestrator can drive
agent backends other than Claude Code.

The first non-Claude backend is GrokProvider for xAI's grok-build-0.1.
xAI is OpenAI-compatible only (no Anthropic-Messages endpoint), so a Grok
agent runs an OpenAI-protocol runtime pointed at https://api.x.ai/v1
rather than the ANTHROPIC_BASE_URL injection the other providers use. It
reuses the orchestrator's existing mount/auth assembly, so it inherits the
same MCP gateway + tool-manifest wiring as every other agent by
construction, and passes its prompt via env (never an argv positional).

The change is purely additive: only GROK routes through the registry;
Anthropic / Ollama Cloud / self-hosted spawns run the existing
_spawn_container path unchanged.

Includes:
- ModelProvider.GROK (migration 038) + a seeded Grok provider row
  (migration 039) + a grok-build-0.1 catalog entry
- GET/PUT /api/providers/grok-key to store the xAI key (Fernet-encrypted,
  reusing the existing provider-key machinery)
- ClaudeCodeProvider reference adapter over the current spawn
- unit tests for the registry, GrokProvider (gateway wiring, no
  ANTHROPIC_* leak, prompt-injection safety, failure paths) and routing

The dedicated roboco-agent-grok image and the exact OpenAI-protocol CLI
invocation are the remaining piece to finalise with xAI.
2026-06-18 06:14:27 +02:00

61 lines
1.8 KiB
Python

"""Idempotently seed the Grok (xAI) provider row.
The ``modelprovider`` enum carries ``'grok'`` as of migration 038. This
migration seeds the corresponding ``provider_configs`` row so the Settings UI
can store the xAI key without an extra provisioning call.
The row starts disabled with the public xAI base URL and no key — the operator
sets the key via PUT /api/providers/grok/key, which encrypts it and enables the
provider. ON CONFLICT (name) DO NOTHING keeps this safe to re-run.
Revision ID: 039_seed_grok_provider
Revises: 038_modelprovider_grok
Create Date: 2026-06-18
"""
from __future__ import annotations
import sqlalchemy as sa
from alembic import op
revision = "039_seed_grok_provider"
down_revision = "038_modelprovider_grok"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute(
sa.text(
"""
INSERT INTO provider_configs
(id, name, type, base_url, auth_token_encrypted, enabled, created_at)
VALUES
(
gen_random_uuid(),
'Grok (xAI)',
'grok',
'https://api.x.ai/v1',
NULL,
false,
now()
)
ON CONFLICT (name) DO NOTHING
"""
)
)
def downgrade() -> None:
# Drop model_assignments pointing at the Grok row first to avoid a FK
# RESTRICT violation on provider_configs.id.
op.execute(
sa.text(
"DELETE FROM model_assignments "
"WHERE provider_config_id IN ("
" SELECT id FROM provider_configs WHERE name = 'Grok (xAI)'"
")"
)
)
op.execute(sa.text("DELETE FROM provider_configs WHERE name = 'Grok (xAI)'"))