feat: add dynamic model discovery and routing for OpenCode provider

- Update isOpencodeModel() to detect dynamic models with provider/model format
  (e.g., github-copilot/gpt-4o, google/gemini-2.5-pro, zai-coding-plan/glm-4.7)
- Update resolveModelString() to recognize and pass through OpenCode models
- Update enhance route to route OpenCode models to OpenCode provider
- Fix OpenCode CLI command format: use --format json (not stream-json)
- Remove unsupported -q and - flags from CLI arguments
- Update normalizeEvent() to handle actual OpenCode JSON event format
- Add dynamic model configuration UI with provider grouping
- Cache providers and models in app store for snappier navigation
- Show authenticated providers in OpenCode CLI status card

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Stefan de Vogelaere
2026-01-11 20:08:25 +01:00
committed by DhanushSantosh
parent ed65f70315
commit 6c5206daf4
13 changed files with 2247 additions and 265 deletions

View File

@@ -95,8 +95,9 @@ export function isCodexModel(model: string | undefined | null): boolean {
* - 'opencode/' prefix (OpenCode free tier models)
* - 'amazon-bedrock/' prefix (AWS Bedrock models via OpenCode)
* - Full model ID from OPENCODE_MODEL_CONFIG_MAP
* - Dynamic models from OpenCode CLI with provider/model format (e.g., "github-copilot/gpt-4o", "google/gemini-2.5-pro")
*
* @param model - Model string to check (e.g., "opencode-sonnet", "opencode/big-pickle", "amazon-bedrock/anthropic.claude-sonnet-4-5-20250929-v1:0")
* @param model - Model string to check
* @returns true if the model is an OpenCode model
*/
export function isOpencodeModel(model: string | undefined | null): boolean {
@@ -113,12 +114,26 @@ export function isOpencodeModel(model: string | undefined | null): boolean {
}
// Check for OpenCode native model prefixes
// - opencode/ = OpenCode free tier models (e.g., opencode/big-pickle)
// - amazon-bedrock/ = AWS Bedrock models (e.g., amazon-bedrock/anthropic.claude-*)
// - opencode/ = OpenCode free tier models
// - amazon-bedrock/ = AWS Bedrock models
if (model.startsWith('opencode/') || model.startsWith('amazon-bedrock/')) {
return true;
}
// Check for dynamic models from OpenCode CLI with provider/model format
// These are models discovered dynamically from authenticated providers like:
// - github-copilot/gpt-4o
// - google/gemini-2.5-pro
// - xai/grok-3
// Pattern: provider-id/model-name (must have exactly one / and not be a URL)
if (model.includes('/') && !model.includes('://')) {
const parts = model.split('/');
// Valid dynamic model format: provider/model-name (exactly 2 parts)
if (parts.length === 2 && parts[0].length > 0 && parts[1].length > 0) {
return true;
}
}
return false;
}