Clean up OpenCode ProviderModelNotFoundError messages

- Detect ProviderModelNotFoundError and show clean message
- Extract provider and model IDs from error
- Suggest: connect provider in opencode, use --provider flag, or edit in UI
- Truncate other stderr to 200 chars to avoid code dumps

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rob 2025-12-30 01:25:15 -04:00
parent 9d783af2f9
commit b67d44ac8b
1 changed files with 22 additions and 1 deletions

View File

@ -199,7 +199,28 @@ def call_provider(provider_name: str, prompt: str, timeout: int = 300) -> Provid
# Warn if output is empty (provider ran but returned nothing) # Warn if output is empty (provider ran but returned nothing)
if not result.stdout.strip(): if not result.stdout.strip():
stderr_hint = f" (stderr: {result.stderr.strip()})" if result.stderr.strip() else "" stderr = result.stderr.strip()
# Check for OpenCode's ProviderModelNotFoundError
if "ProviderModelNotFoundError" in stderr or "ModelNotFoundError" in stderr:
# Extract provider and model info if possible
import re
provider_match = re.search(r'providerID:\s*"([^"]+)"', stderr)
model_match = re.search(r'modelID:\s*"([^"]+)"', stderr)
provider_id = provider_match.group(1) if provider_match else "unknown"
model_id = model_match.group(1) if model_match else "unknown"
return ProviderResult(
text="",
success=False,
error=f"Model '{model_id}' from provider '{provider_id}' is not available.\n\n"
f"To fix this, either:\n"
f" 1. Run 'opencode' to connect the {provider_id} provider\n"
f" 2. Use --provider to pick a different model (e.g., --provider opencode-pickle)\n"
f" 3. Run 'smarttools ui' to edit the tool's default provider"
)
stderr_hint = f" (stderr: {stderr[:200]}...)" if len(stderr) > 200 else (f" (stderr: {stderr})" if stderr else "")
return ProviderResult( return ProviderResult(
text="", text="",
success=False, success=False,