mirror of
https://github.com/lukaszraczylo/harness-sync.git
synced 2026-10-12 00:45:22 +00:00
- 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
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package common
|
|
|
|
import "maps"
|
|
|
|
// AbsorbDuplicateProviders scans provMap for entries (other than ourKey) whose
|
|
// options.baseURL matches gatewayURL and absorbs their models into our entry.
|
|
//
|
|
// Merge strategy:
|
|
// - Models only in the duplicate: added to our provider.
|
|
// - Models only in our canonical entry: kept as-is.
|
|
// - Models in both: the DUPLICATE's entry wins (preserves user-crafted display
|
|
// names and custom limits that are often more descriptive than the profile
|
|
// alias).
|
|
//
|
|
// Absorbed entries are deleted from the returned map. Returns provMap unchanged
|
|
// when gatewayURL is empty or our entry is absent.
|
|
func AbsorbDuplicateProviders(provMap map[string]any, ourKey, gatewayURL string) map[string]any {
|
|
if gatewayURL == "" || provMap == nil {
|
|
return provMap
|
|
}
|
|
ourEntry, ok := provMap[ourKey].(map[string]any)
|
|
if !ok {
|
|
return provMap
|
|
}
|
|
|
|
// Clone top-level so we don't mutate the caller's map.
|
|
result := make(map[string]any, len(provMap))
|
|
maps.Copy(result, provMap)
|
|
|
|
ourModels, _ := ourEntry["models"].(map[string]any)
|
|
if ourModels == nil {
|
|
ourModels = map[string]any{}
|
|
}
|
|
|
|
// merged starts with our canonical models; duplicates may override per-model.
|
|
merged := make(map[string]any, len(ourModels))
|
|
maps.Copy(merged, ourModels)
|
|
|
|
for k, v := range result {
|
|
if k == ourKey {
|
|
continue
|
|
}
|
|
entry, ok := v.(map[string]any)
|
|
if !ok {
|
|
continue
|
|
}
|
|
opts, _ := entry["options"].(map[string]any)
|
|
if opts == nil {
|
|
continue
|
|
}
|
|
if opts["baseURL"] != gatewayURL {
|
|
continue
|
|
}
|
|
// Same gateway URL — absorb and delete.
|
|
if dupModels, ok := entry["models"].(map[string]any); ok {
|
|
// Duplicate (user-crafted) wins for overlapping IDs.
|
|
maps.Copy(merged, dupModels)
|
|
}
|
|
delete(result, k)
|
|
}
|
|
|
|
updated := make(map[string]any, len(ourEntry))
|
|
maps.Copy(updated, ourEntry)
|
|
if len(merged) > 0 {
|
|
updated["models"] = merged
|
|
}
|
|
result[ourKey] = updated
|
|
return result
|
|
}
|