mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 16:04:01 +00:00
feat(diagnostics): pin a Playground request to one relay (#167)
Resolved against #170 so a relay pin clears the per-attempt WARP choice (attemptUseWARP). The relay list is now credential-redacted, and a pin may name a relay by its redacted URL.
This commit is contained in:
1 parent
46eb13ea03
commit
b296a61d0e
7 files changed
+235
-7
No files matched your search
+28
-5
@@ -31,9 +31,10 @@ type DebugKeySelection struct {
|
||||
// expressed in, which upstream key to test (Mode "auto" or "selected", the
|
||||
// latter naming Tier and ID), and the request body itself.
|
||||
type DebugInferenceRequest struct {
|
||||
Protocol protocol.Protocol `json:"protocol"`
|
||||
Key DebugKeySelection `json:"key,omitempty"`
|
||||
Request map[string]any `json:"request"`
|
||||
Protocol protocol.Protocol `json:"protocol"`
|
||||
Key DebugKeySelection `json:"key,omitempty"`
|
||||
Relay gateway.RelaySelection `json:"relay,omitempty"`
|
||||
Request map[string]any `json:"request"`
|
||||
}
|
||||
|
||||
// DebugInferenceResult is the outcome of a Playground request: the status and
|
||||
@@ -49,6 +50,7 @@ type DebugInferenceResult struct {
|
||||
Route modelcatalog.RouteDiagnostic `json:"route"`
|
||||
SelectedKey *gateway.DebugKeyView `json:"selected_key,omitempty"`
|
||||
KeyTest string `json:"key_test,omitempty"`
|
||||
RelayTest string `json:"relay_test,omitempty"`
|
||||
Response any `json:"response"`
|
||||
}
|
||||
|
||||
@@ -59,11 +61,12 @@ func (a *Server) handleDebugModels(w http.ResponseWriter, _ *http.Request) {
|
||||
models, metadata := a.manager.DebugModels()
|
||||
catalog := a.manager.Resources().Models
|
||||
keys := a.manager.DebugKeys()
|
||||
relays := a.manager.DebugRelays()
|
||||
a.mu.Lock()
|
||||
last := a.lastInference
|
||||
a.mu.Unlock()
|
||||
w.Header().Set("Cache-Control", "no-store")
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"models": models, "keys": keys, "metadata": metadata, "catalog": catalog, "last_inference": last})
|
||||
httpx.WriteJSON(w, http.StatusOK, map[string]any{"models": models, "keys": keys, "metadata": metadata, "catalog": catalog, "relays": relays, "last_inference": last})
|
||||
}
|
||||
|
||||
// handleDebugInference runs a request through the gateway itself, in process
|
||||
@@ -112,6 +115,23 @@ func (a *Server) handleDebugInference(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if !input.Relay.Empty() {
|
||||
known := false
|
||||
for index, name := range a.manager.DebugRelays() {
|
||||
if input.Relay.Index != nil && *input.Relay.Index != index {
|
||||
continue
|
||||
}
|
||||
if input.Relay.Name != "" && input.Relay.Name != name {
|
||||
continue
|
||||
}
|
||||
known = true
|
||||
break
|
||||
}
|
||||
if !known {
|
||||
writeAdminError(w, http.StatusBadRequest, "unknown_relay", "relay.index or relay.name does not match a configured relay")
|
||||
return
|
||||
}
|
||||
}
|
||||
route := a.manager.DebugRoute(model, input.Protocol)
|
||||
if selectedKey != nil {
|
||||
selected, routeErr := a.manager.DebugRouteForTier(model, selectedKey.Tier)
|
||||
@@ -140,6 +160,9 @@ func (a *Server) handleDebugInference(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
request.Header.Set("Authorization", "Bearer "+cfg.FirstEnabledServerKey())
|
||||
if !input.Relay.Empty() {
|
||||
request = request.WithContext(gateway.WithRelayOverride(request.Context(), input.Relay))
|
||||
}
|
||||
if selectedKey != nil {
|
||||
request = request.WithContext(gateway.WithDebugKeyOverride(request.Context(), gateway.DebugKeyOverride{Tier: selectedKey.Tier, KeyID: selectedKey.ID}))
|
||||
}
|
||||
@@ -178,7 +201,7 @@ func (a *Server) handleDebugInference(w http.ResponseWriter, r *http.Request) {
|
||||
result := DebugInferenceResult{
|
||||
OK: recorder.status >= 200 && recorder.status < 300, HTTPStatus: recorder.status,
|
||||
DurationMS: max(duration.Milliseconds(), 0), RequestID: requestID, Route: route,
|
||||
SelectedKey: selectedKey, KeyTest: keyTest, Response: raw,
|
||||
SelectedKey: selectedKey, KeyTest: keyTest, RelayTest: trace.Proxy, Response: raw,
|
||||
}
|
||||
a.mu.Lock()
|
||||
a.lastInference = &result
|
||||
|
||||
Reference in new issue
Block a user