mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 16:04:01 +00:00
- 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.
25 lines
972 B
Go
25 lines
972 B
Go
package protocol
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"opencode2api/internal/httpx"
|
|
)
|
|
|
|
// WriteError writes a JSON error response with the given status in the
|
|
// envelope the protocol's clients expect: {"type":"error","error":{...}} for
|
|
// Anthropic, and the OpenAI {"error":{message,type,param,code}} shape for
|
|
// every other protocol, System One included. kind becomes the error type, and
|
|
// a non-empty requestID is echoed in the x-request-id header.
|
|
func WriteError(w http.ResponseWriter, protocol Protocol, status int, message, kind, requestID string) {
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if requestID != "" {
|
|
w.Header().Set("x-request-id", requestID)
|
|
}
|
|
if protocol == Anthropic {
|
|
httpx.WriteJSONStatus(w, status, map[string]any{"type": "error", "error": map[string]any{"type": kind, "message": message}})
|
|
return
|
|
}
|
|
httpx.WriteJSONStatus(w, status, map[string]any{"error": map[string]any{"message": message, "type": kind, "param": nil, "code": nil}})
|
|
}
|