Files
opencode2api/internal/config/server_keys.go
T
Jason Xu 81ad2842c7 refactor: drop new prefixes, unify v1/v2 lane naming, audit comments
- Remove the new/New prefix from constructors; rename the colliding
  types semantically (ModelCatalog, RuntimeController, Metrics,
  LogBroker, Redactor, proxyTransports, upstreamNodes, ...).
- Unify upstream lane naming on v1 (/zen, OpenCode 1.x shape) and v2
  (/inference and /zen/go, 2.x CLI shape); add models.IsV1Upstream and
  drop the duplicated lane detection.
- Fix inaccurate, truncated and stale comments across all packages and
  document exported symbols plus non-obvious internals.
- Fix anthropicThinking passing "enabled"/"adaptive" through as an
  effort; derive the level from the budget instead.
- Delete dead code (identity.StableID, unused protocol decoders and
  stream parser wrappers).
- Export EffectiveListeners, rename modelsDev* metadata constants, and
  describe the metadata source as the OpenCode endpoint.
- Rename the forced-collapse log event to stream_collapse_failed and
  add an anonymous field.
- Correct the README upstream.zen default and add upstream.anonymous.
2026-10-19 03:46:09 +08:00

31 lines
1003 B
Go

package config
import "time"
// ServerKeyMetadata holds the WebUI-managed details of one server key: its
// display name, whether it is disabled, and when it was created. It is keyed
// by the existing key fingerprint; secret values remain in server_keys for
// compatibility with existing configuration and clients.
type ServerKeyMetadata struct {
Name string `json:"name"`
Disabled bool `json:"disabled,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
}
// ServerKeyEnabled reports whether key may authenticate clients. A key
// without metadata is enabled.
func (c Config) ServerKeyEnabled(key string) bool {
return !c.ServerKeyMetadata[Fingerprint(key)].Disabled
}
// FirstEnabledServerKey returns the first enabled server key, or "" when every
// key is disabled. The Playground sends its requests with this key.
func (c Config) FirstEnabledServerKey() string {
for _, key := range c.ServerKeys {
if c.ServerKeyEnabled(key) {
return key
}
}
return ""
}