Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion circuitbreaker/circuitbreaker.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package circuitbreaker

import (
"bufio"
"errors"
"fmt"
"net"
"net/http"
"sync"
"time"
Expand Down Expand Up @@ -101,7 +103,8 @@ func (p *ProviderCircuitBreakers) Get(endpoint, model string) *gobreaker.Circuit
}

// statusCapturingWriter wraps http.ResponseWriter to capture the status code.
// It also implements http.Flusher to support streaming responses.
// It implements http.Flusher to support streaming and http.Hijacker to
// satisfy the FullResponseWriter lint rule.
type statusCapturingWriter struct {
http.ResponseWriter
statusCode int
Expand Down Expand Up @@ -130,6 +133,14 @@ func (w *statusCapturingWriter) Flush() {
}
}

func (w *statusCapturingWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
h, ok := w.ResponseWriter.(http.Hijacker)
if !ok {
return nil, nil, xerrors.New("upstream ResponseWriter does not support hijacking")
}
return h.Hijack()
}

// Unwrap returns the underlying ResponseWriter for interface checks.
func (w *statusCapturingWriter) Unwrap() http.ResponseWriter {
return w.ResponseWriter
Expand Down
4 changes: 2 additions & 2 deletions intercept/chatcompletions/paramswrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (c *ChatCompletionNewParamsWrapper) lastUserPrompt() (*string, error) {
// We only care if the last message was issued by a user.
msg := c.Messages[len(c.Messages)-1]
if msg.OfUser == nil {
return nil, nil
return nil, nil //nolint:nilnil // no user prompt found is not an error
}

if msg.OfUser.Content.OfString.String() != "" {
Expand All @@ -69,5 +69,5 @@ func (c *ChatCompletionNewParamsWrapper) lastUserPrompt() (*string, error) {
}
}

return nil, nil
return nil, nil //nolint:nilnil // no text content found is not an error
}
2 changes: 1 addition & 1 deletion intercept/messages/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ func (m *mockServerProxier) GetTool(id string) *mcp.Tool {
}

func (*mockServerProxier) CallTool(context.Context, string, any) (*mcpgo.CallToolResult, error) {
return nil, nil
return nil, nil //nolint:nilnil // mock: no-op implementation
}

func TestFilterBedrockBetaFlags(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion intercept/messages/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,11 @@ newStream:
}

shutdownCtx, shutdownCancel := context.WithTimeout(ctx, time.Second*30)
defer shutdownCancel()
// Give the events stream 30 seconds (TODO: configurable) to gracefully shutdown.
if err := events.Shutdown(shutdownCtx); err != nil {
logger.Warn(ctx, "event stream shutdown", slog.Error(err))
}
shutdownCancel()

// Cancel the stream context, we're now done.
if interceptionErr != nil {
Expand Down
8 changes: 7 additions & 1 deletion intercept/responses/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ func (i *responsesInterceptionBase) validateRequest(ctx context.Context, w http.
// sendCustomErr sends custom responses.Error error to the client
// it should only be called before any data is sent back to the client
func (i *responsesInterceptionBase) sendCustomErr(ctx context.Context, w http.ResponseWriter, code int, err error) {
respErr := responses.Error{
// Same JSON shape as responses.Error but using a plain struct because
// responses.Error embeds *http.Request whose GetBody func field
// is not JSON-marshalable (SA1026).
respErr := struct {
Code string `json:"code"`
Message string `json:"message"`
}{
Code: strconv.Itoa(code),
Message: err.Error(),
}
Expand Down
2 changes: 1 addition & 1 deletion internal/testutil/mockprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func (m *MockProvider) CreateInterceptor(w http.ResponseWriter, r *http.Request,
if m.InterceptorFunc != nil {
return m.InterceptorFunc(w, r, tracer)
}
return nil, nil
return nil, nil //nolint:nilnil // mock: no interceptor configured is not an error
}
Loading