mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-10-26 01:34:51 +08:00
OpenCode 2.0 accepts native provider declarations under `providers` next
to the legacy `provider` map. CC Switch only read `provider`, so native
providers were invisible and writes landed in the map OpenCode ignored.
- Read both containers. For the same ID a valid native declaration wins
regardless of key order; an invalid one does not shadow a valid legacy
entry and is left untouched, matching OpenCode's normalizer (schema as
of v2.0.12). Unknown extension fields are kept.
- Provider meta records the source format (opencodeConfigFormat), so
`{}` and models-only built-in overrides stay native across database
round-trips and re-enabling.
- Native providers are written under `providers` through the
comment-preserving JSONC editor; legacy writes shadowed by a valid
native declaration are rejected, and removing a provider deletes the
ID from both containers.
- Native JSON is validated before it is saved and the error names the
first invalid field, so a rejected edit no longer leaves the database
ahead of the live file.
- Native providers are edited in the JSON editor; legacy ones keep the
structured form. Existing native IDs are kept as-is, new native IDs
need a package and at least one model, and duplicating a native card
checks `package`.
- Common config extraction also skips native settings.apiKey/baseURL.
Refs #7382
Co-authored-by: Jason <farion1231@gmail.com>