Files
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

52 lines
2.0 KiB
Go

// Package protocol converts request bodies, response bodies and SSE streams
// between the OpenAI Chat Completions, OpenAI Responses and Anthropic Messages
// protocols through a shared bridge model.
//
// System One is recognized but never translated: Valid accepts it, Path maps
// it to its endpoint and WriteError gives it the OpenAI error envelope. It has
// no bridge encoding, so a cross-protocol conversion fails, and the gateway
// forwards its decision payloads verbatim.
package protocol
// Protocol names the wire protocol of a client-facing endpoint or of an
// upstream model.
type Protocol string
// The protocol constants name the wire protocol of a client endpoint or an
// upstream model, and each is both: the gateway serves a request in the
// client's protocol and speaks the route's protocol upstream, converting
// between the two when they differ. Chat is OpenAI Chat Completions, Responses
// is OpenAI Responses, Anthropic is Anthropic Messages, and SystemOne is
// described below.
const (
Chat Protocol = "chat"
Responses Protocol = "responses"
Anthropic Protocol = "anthropic"
// SystemOne is OpenCode Zen's structured decision endpoint. A request pairs
// a free-form state with typed questions and the reply carries typed
// answers, so the payload shares no shape with the message protocols the
// bridge converts and is forwarded as-is.
SystemOne Protocol = "systemone"
)
// Valid reports whether p is one of the protocols defined above.
func Valid(p Protocol) bool {
return p == Chat || p == Responses || p == Anthropic || p == SystemOne
}
// Path returns the endpoint path that serves a protocol, relative to an API
// base. The gateway's own routes and the upstream endpoints share these
// paths. An unknown protocol gets the Chat path.
func Path(protocol Protocol) string {
switch protocol {
case Responses:
return "/v1/responses"
case Anthropic:
return "/v1/messages"
case SystemOne:
return "/v1/systemone"
default:
return "/v1/chat/completions"
}
}