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.
23 lines
656 B
Go
23 lines
656 B
Go
package telemetry
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"opencode2api/internal/protocol"
|
|
)
|
|
|
|
// Recover turns a panic in next into a logged error and a 500 response in the
|
|
// Chat error format.
|
|
func Recover(logger *slog.Logger, next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
defer func() {
|
|
if value := recover(); value != nil {
|
|
logger.Error("request handler panicked", "component", "http", "event", "request_panic", "error", value)
|
|
protocol.WriteError(w, protocol.Chat, http.StatusInternalServerError, "internal server error", "server_error", "")
|
|
}
|
|
}()
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|