opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: api.kilo.ai/api support

Open dzianisv opened this issue 1 month ago • 0 comments

Summary Screenshot 2025-12-17 at 13 42 09

This PR adds support for Kilo Code as a new AI provider in opencode, complete with device authentication and dynamic model discovery. Changes Authentication (src/cli/cmd/auth.ts)

  • Added open import for browser automation
  • Implemented complete Kilo Code authentication flow using device code verification
  • Added spinner UI for better UX during auth process
  • Handles authorization approval, denial, expiration, and timeouts
  • Integrated Kilo Code as priority level 7 in provider selection Model Discovery (src/provider/models.ts)
  • Added Kilo Code provider configuration with Claude 3.5 Sonnet as default model
  • Implemented dynamic model discovery via Kilo Code API
  • Added local caching mechanism for models to improve performance
  • Graceful fallback to cached models if API is unavailable
  • Automatic background refresh of model list Provider Integration (src/provider/provider.ts)
  • Added Kilo Code provider configuration using OpenAI-compatible SDK
  • Configured proper headers and user agent for API requests
  • Added proper model merging logic with cost, limit, and options handling Configuration (sst.config.ts)
  • Updated SST config syntax from CommonJS to ES modules
  • Standardized import statements and semicolon usage Technical Details
  • Authentication: OAuth2 device code flow with 5-minute timeout
  • Model Caching: Stored in ~/.cache/opencode/kilocode-models.json
  • API Integration: Uses Kilo Code's OpenRouter-compatible endpoints
  • Error Handling: Comprehensive error handling for network issues and auth failures Testing The implementation includes proper error handling and fallback mechanisms. The device code flow supports the full OAuth2 standard with support for approval, denial, expiration, and timeout scenarios. Breaking Changes None. This is an additive feature that doesn't modify existing functionality.

dzianisv avatar Dec 17 '25 21:12 dzianisv