feat: URL-derived provider keys (hs-<hostname>) + dedup providers sharing same gateway URL

- GatewayProviderKey() derives stable key from gateway URL hostname
  e.g. https://llmgw.h.raczylo.com/v1 → hs-llmgw-h-raczylo-com
- AbsorbDuplicateProviders() merges providers sharing the same baseURL
  into our canonical entry; user-crafted model metadata wins for overlaps
- kilo: renders to opencode.jsonc (primary config), deep-merges providers,
  deletes enabled_providers filter that was hiding our gateway
- opencode: absorbs duplicate providers from existing config
- All adapters use GatewayProviderKey() instead of hardcoded string
- Fix goose URL doubling (was /v1/v1/chat/completions → /chat/completions)
- Fix token propagation: api_key written directly (not env var ref)
- Zed: adds prompt_cache_key capability, deletes context_servers key
  to avoid ContextServerSettingsContent serde untagged-enum parse error
This commit is contained in:
2026-05-23 21:13:16 +01:00
parent 77158d9f2b
commit fb02b165d7
16 changed files with 180 additions and 57 deletions
+21 -1
View File
@@ -2,6 +2,7 @@
package opencode
import (
"encoding/json"
"os"
"path/filepath"
@@ -76,8 +77,27 @@ func (a *Adapter) Render(b *canonical.Bundle) (*adapter.FileSet, error) {
cfgPath := filepath.Join(base, "opencode.jsonc")
existing, _ := os.ReadFile(cfgPath)
// Build the provider map, then absorb any existing providers at the same
// gateway URL so duplicates don't accumulate across apply runs.
provMap := common.ProvidersAsMap(&b.Profile)
if len(existing) > 0 {
var base map[string]any
clean := common.StripJSONComments(string(existing))
if json.Unmarshal([]byte(clean), &base) == nil {
if existingProv, ok := base["provider"].(map[string]any); ok {
for k, v := range existingProv {
if _, ours := provMap[k]; !ours {
provMap[k] = v
}
}
provMap = common.AbsorbDuplicateProviders(provMap, common.GatewayProviderKey(b.Profile.Gateway.URL), b.Profile.Gateway.URL)
}
}
}
overlay := map[string]any{
"provider": common.ProvidersAsMap(&b.Profile),
"provider": provMap,
"model": common.KiloModelString(&b.Profile),
}
if mcp := common.BuildMCPMapStyled(&b.MCP, common.MCPOpencodeStyle); len(mcp) > 0 {
+3 -3
View File
@@ -129,15 +129,15 @@ func TestOpencodeRenderProviderHasNpm(t *testing.T) {
// provider map has npm field.
provider, ok := parsed["provider"].(map[string]any)
require.True(t, ok)
gw, ok := provider["harness-sync-gateway"].(map[string]any)
gw, ok := provider["hs-gw"].(map[string]any)
require.True(t, ok)
assert.Equal(t, "@ai-sdk/openai-compatible", gw["npm"])
opts, ok := gw["options"].(map[string]any)
require.True(t, ok)
assert.Equal(t, "https://gw", opts["baseURL"])
// model is "harness-sync-gateway/modelID".
assert.Equal(t, "harness-sync-gateway/claude-sonnet-4-6", parsed["model"])
// model is "hs-gw/modelID".
assert.Equal(t, "hs-gw/claude-sonnet-4-6", parsed["model"])
}
func TestOpencodeImportStripsComments(t *testing.T) {