refactor(aibridge/intercept): inject actor headers in middleware (#29839)
Move actor-header injection into the shared upstream-header middleware for Messages, Chat Completions, and Responses. Read the authenticated actor from the request context and remove the duplicated SDK-option injection from blocking and streaming paths, completing the TODO from @ssncferreira. Preserve the existing header names and forwarding toggle. This is the first PR in the actor-header stack: #29839 → #29840 (email forwarding) → #29812 (configurable names). Refs https://linear.app/codercom/issue/AIGOV-601 > 🤖 Generated by AI with human input.
This commit is contained in:
1 parent
442b08fee5
commit
9a4cb3aebd
14 files changed
+115
-171
No files matched your search
@@ -4,9 +4,6 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
ant_option "github.com/anthropics/anthropic-sdk-go/option"
|
||||
oai_option "github.com/openai/openai-go/v3/option"
|
||||
|
||||
"github.com/coder/coder/v2/aibridge/context"
|
||||
)
|
||||
|
||||
@@ -26,40 +23,6 @@ func IsActorHeader(name string) bool {
|
||||
return strings.HasPrefix(strings.ToLower(name), strings.ToLower(prefix))
|
||||
}
|
||||
|
||||
// ActorHeadersAsOpenAIOpts produces a slice of headers using OpenAI's RequestOption type.
|
||||
func ActorHeadersAsOpenAIOpts(actor *context.Actor) []oai_option.RequestOption {
|
||||
var opts []oai_option.RequestOption
|
||||
|
||||
headers := headersFromActor(actor)
|
||||
if len(headers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, v := range headers {
|
||||
// [k] will be canonicalized, see [http.Header]'s [Add] method.
|
||||
opts = append(opts, oai_option.WithHeaderAdd(k, v))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// ActorHeadersAsAnthropicOpts produces a slice of headers using Anthropic's RequestOption type.
|
||||
func ActorHeadersAsAnthropicOpts(actor *context.Actor) []ant_option.RequestOption {
|
||||
var opts []ant_option.RequestOption
|
||||
|
||||
headers := headersFromActor(actor)
|
||||
if len(headers) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for k, v := range headers {
|
||||
// [k] will be canonicalized, see [http.Header]'s [Add] method.
|
||||
opts = append(opts, ant_option.WithHeaderAdd(k, v))
|
||||
}
|
||||
|
||||
return opts
|
||||
}
|
||||
|
||||
// headersFromActor produces a map of headers from a given [context.Actor].
|
||||
func headersFromActor(actor *context.Actor) map[string]string {
|
||||
if actor == nil {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package intercept
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/recorder"
|
||||
)
|
||||
|
||||
func TestHeadersFromActor(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
actor *context.Actor
|
||||
want map[string]string
|
||||
}{
|
||||
{name: "nil actor"},
|
||||
{
|
||||
name: "id only",
|
||||
actor: &context.Actor{ID: "user-123"},
|
||||
want: map[string]string{"X-AI-Bridge-Actor-ID": "user-123"},
|
||||
},
|
||||
{
|
||||
name: "metadata",
|
||||
actor: &context.Actor{
|
||||
ID: "user-123",
|
||||
Metadata: recorder.Metadata{
|
||||
"Username": "alice",
|
||||
"Count": 42,
|
||||
},
|
||||
},
|
||||
want: map[string]string{
|
||||
"X-AI-Bridge-Actor-ID": "user-123",
|
||||
"X-AI-Bridge-Actor-Metadata-Username": "alice",
|
||||
"X-AI-Bridge-Actor-Metadata-Count": "42",
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require.Equal(t, tc.want, headersFromActor(tc.actor))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package intercept_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/recorder"
|
||||
)
|
||||
|
||||
func TestNilActor(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
require.Nil(t, intercept.ActorHeadersAsOpenAIOpts(nil))
|
||||
require.Nil(t, intercept.ActorHeadersAsAnthropicOpts(nil))
|
||||
}
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actorID := uuid.NewString()
|
||||
actor := &context.Actor{
|
||||
ID: actorID,
|
||||
}
|
||||
|
||||
// We can't peek inside since these opts require an internal type to apply onto.
|
||||
// All we can do is check the length.
|
||||
// See TestActorHeaders for an integration test.
|
||||
oaiOpts := intercept.ActorHeadersAsOpenAIOpts(actor)
|
||||
require.Len(t, oaiOpts, 1)
|
||||
antOpts := intercept.ActorHeadersAsAnthropicOpts(actor)
|
||||
require.Len(t, antOpts, 1)
|
||||
}
|
||||
|
||||
func TestBasicAndMetadata(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actorID := uuid.NewString()
|
||||
actor := &context.Actor{
|
||||
ID: actorID,
|
||||
Metadata: recorder.Metadata{
|
||||
"This": "That",
|
||||
"And": "The other",
|
||||
},
|
||||
}
|
||||
|
||||
// We can't peek inside since these opts require an internal type to apply onto.
|
||||
// All we can do is check the length.
|
||||
// See TestActorHeaders for an integration test.
|
||||
oaiOpts := intercept.ActorHeadersAsOpenAIOpts(actor)
|
||||
require.Len(t, oaiOpts, 1+len(actor.Metadata))
|
||||
antOpts := intercept.ActorHeadersAsAnthropicOpts(actor)
|
||||
require.Len(t, antOpts, 1+len(actor.Metadata))
|
||||
}
|
||||
@@ -82,7 +82,7 @@ func (i *interceptionBase) newCompletionsService(ctx context.Context) openai.Cha
|
||||
// client headers plus provider auth.
|
||||
if i.clientHeaders != nil {
|
||||
opts = append(opts, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) {
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader())
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader(), i.cfg, aibcontext.ActorFromContext(req.Context()))
|
||||
return next(req)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/awssig"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/eventstream"
|
||||
@@ -126,12 +125,6 @@ func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Req
|
||||
var opts []option.RequestOption
|
||||
opts = append(opts, option.WithRequestTimeout(time.Second*600))
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsOpenAIOpts(actor)...)
|
||||
}
|
||||
|
||||
var keyAttempts int
|
||||
completion, keyAttempts, err = i.newChatCompletion(ctx, svc, opts)
|
||||
totalKeyAttempts += keyAttempts
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/awssig"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/eventstream"
|
||||
@@ -207,12 +206,6 @@ func (i *StreamingInterception) ProcessRequest(w http.ResponseWriter, r *http.Re
|
||||
totalKeyAttempts += walker.Attempts()
|
||||
}
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsOpenAIOpts(actor)...)
|
||||
}
|
||||
|
||||
// We take control of request body here and pass it to the SDK as a raw byte slice.
|
||||
// This is because the SDK's serialization applies hidden request options that result in
|
||||
// unexpected, breaking behavior. See https://github.com/coder/aibridge/pull/164
|
||||
|
||||
@@ -2,6 +2,8 @@ package intercept
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
)
|
||||
|
||||
// hopByHopHeaders are connection-level headers specific to the connection
|
||||
@@ -79,22 +81,23 @@ func PrepareClientHeaders(clientHeaders http.Header) http.Header {
|
||||
}
|
||||
|
||||
// BuildUpstreamHeaders produces the header set for an upstream SDK request.
|
||||
// It starts from the prepared client headers, then preserves specific
|
||||
// headers from the SDK-built request that must not be overwritten.
|
||||
func BuildUpstreamHeaders(sdkHeader http.Header, clientHeaders http.Header, authHeaderName string) http.Header {
|
||||
// It starts from the prepared client headers, preserves provider auth, then
|
||||
// applies identity from the authenticated request actor.
|
||||
func BuildUpstreamHeaders(sdkHeader http.Header, clientHeaders http.Header, authHeaderName string, cfg Config, actor *aibcontext.Actor) http.Header {
|
||||
headers := PrepareClientHeaders(clientHeaders)
|
||||
if headers == nil {
|
||||
headers = make(http.Header)
|
||||
}
|
||||
|
||||
// Preserve the auth header set by the SDK from the provider configuration.
|
||||
if v := sdkHeader.Get(authHeaderName); v != "" {
|
||||
headers.Set(authHeaderName, v)
|
||||
}
|
||||
|
||||
// Preserve actor headers injected by aibridge as per-request SDK options.
|
||||
for name, values := range sdkHeader {
|
||||
if IsActorHeader(name) {
|
||||
headers[name] = values
|
||||
if cfg.SendActorHeaders {
|
||||
for name, value := range headersFromActor(actor) {
|
||||
headers.Set(name, value)
|
||||
}
|
||||
}
|
||||
|
||||
return headers
|
||||
}
|
||||
@@ -7,7 +7,9 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/recorder"
|
||||
)
|
||||
|
||||
func TestPrepareClientHeaders(t *testing.T) {
|
||||
@@ -153,7 +155,7 @@ func TestBuildUpstreamHeaders(t *testing.T) {
|
||||
"User-Agent": {"claude-code/1.0"},
|
||||
}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization")
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization", intercept.Config{}, nil)
|
||||
|
||||
assert.Equal(t, "Bearer sk-provider-key", result.Get("Authorization"))
|
||||
assert.Equal(t, "claude-code/1.0", result.Get("User-Agent"))
|
||||
@@ -171,34 +173,13 @@ func TestBuildUpstreamHeaders(t *testing.T) {
|
||||
"Anthropic-Beta": {"prompt-caching-2024-07-31"},
|
||||
}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "X-Api-Key")
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "X-Api-Key", intercept.Config{}, nil)
|
||||
|
||||
assert.Equal(t, "sk-ant-provider-key", result.Get("X-Api-Key"))
|
||||
assert.Empty(t, result.Get("Authorization"))
|
||||
assert.Equal(t, "prompt-caching-2024-07-31", result.Get("Anthropic-Beta"))
|
||||
})
|
||||
|
||||
t.Run("preserves actor headers from SDK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
sdkHeader := http.Header{
|
||||
"Authorization": {"Bearer sk-key"},
|
||||
"X-Ai-Bridge-Actor-Id": {"user-123"},
|
||||
"X-Ai-Bridge-Actor-Metadata-Name": {"alice"},
|
||||
}
|
||||
clientHeaders := http.Header{
|
||||
"Authorization": {"Bearer coder-token"},
|
||||
"User-Agent": {"claude-code/1.0"},
|
||||
}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization")
|
||||
|
||||
assert.Equal(t, "Bearer sk-key", result.Get("Authorization"))
|
||||
assert.Equal(t, "user-123", result.Get("X-Ai-Bridge-Actor-Id"))
|
||||
assert.Equal(t, "alice", result.Get("X-Ai-Bridge-Actor-Metadata-Name"))
|
||||
assert.Equal(t, "claude-code/1.0", result.Get("User-Agent"))
|
||||
})
|
||||
|
||||
t.Run("strips hop-by-hop and transport headers", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -214,7 +195,7 @@ func TestBuildUpstreamHeaders(t *testing.T) {
|
||||
"User-Agent": {"claude-code/1.0"},
|
||||
}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization")
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization", intercept.Config{}, nil)
|
||||
|
||||
assert.Empty(t, result.Get("Connection"))
|
||||
assert.Empty(t, result.Get("Host"))
|
||||
@@ -232,7 +213,7 @@ func TestBuildUpstreamHeaders(t *testing.T) {
|
||||
"User-Agent": {"claude-code/1.0"},
|
||||
}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization")
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization", intercept.Config{}, nil)
|
||||
|
||||
assert.Empty(t, result.Get("Authorization"))
|
||||
assert.Equal(t, "claude-code/1.0", result.Get("User-Agent"))
|
||||
@@ -251,9 +232,56 @@ func TestBuildUpstreamHeaders(t *testing.T) {
|
||||
sdkCopy := sdkHeader.Clone()
|
||||
clientCopy := clientHeaders.Clone()
|
||||
|
||||
_ = intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization")
|
||||
_ = intercept.BuildUpstreamHeaders(sdkHeader, clientHeaders, "Authorization", intercept.Config{}, nil)
|
||||
|
||||
require.Equal(t, sdkCopy, sdkHeader)
|
||||
require.Equal(t, clientCopy, clientHeaders)
|
||||
})
|
||||
|
||||
t.Run("authenticated actor overrides client and SDK values", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
sdkHeaders := http.Header{
|
||||
"Authorization": {"Bearer provider-key"},
|
||||
"X-Ai-Bridge-Actor-Id": {"sdk-id"},
|
||||
"X-Ai-Bridge-Actor-Metadata-Username": {"sdk-name"},
|
||||
}
|
||||
clientHeaders := http.Header{
|
||||
"X-Ai-Bridge-Actor-Id": {"client-id"},
|
||||
"X-Ai-Bridge-Actor-Metadata-Username": {"client-name"},
|
||||
}
|
||||
sdkCopy, clientCopy := sdkHeaders.Clone(), clientHeaders.Clone()
|
||||
actor := &context.Actor{ID: "user-123", Metadata: recorder.Metadata{"Username": "alice"}}
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(sdkHeaders, clientHeaders, "Authorization", intercept.Config{SendActorHeaders: true}, actor)
|
||||
|
||||
require.Equal(t, []string{"user-123"}, result.Values(intercept.ActorIDHeader()))
|
||||
require.Equal(t, []string{"alice"}, result.Values(intercept.ActorMetadataHeader("Username")))
|
||||
require.Equal(t, "Bearer provider-key", result.Get("Authorization"))
|
||||
require.Equal(t, sdkCopy, sdkHeaders)
|
||||
require.Equal(t, clientCopy, clientHeaders)
|
||||
})
|
||||
|
||||
t.Run("actor forwarding with nil client headers", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
actor := &context.Actor{ID: "user-123"}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
send bool
|
||||
actor *context.Actor
|
||||
want string
|
||||
}{
|
||||
{name: "enabled", send: true, actor: actor, want: actor.ID},
|
||||
{name: "disabled", actor: actor},
|
||||
{name: "nil actor", send: true},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
result := intercept.BuildUpstreamHeaders(nil, nil, "Authorization", intercept.Config{SendActorHeaders: tc.send}, tc.actor)
|
||||
require.Equal(t, tc.want, result.Get(intercept.ActorIDHeader()))
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -347,7 +347,7 @@ func (i *interceptionBase) newMessagesService(ctx context.Context, opts ...optio
|
||||
// client headers plus provider auth.
|
||||
if i.clientHeaders != nil {
|
||||
opts = append(opts, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) {
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader())
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader(), i.cfg, aibcontext.ActorFromContext(req.Context()))
|
||||
return next(req)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/eventstream"
|
||||
"github.com/coder/coder/v2/aibridge/keypool"
|
||||
@@ -82,12 +81,7 @@ func (i *BlockingInterception) ProcessRequest(w http.ResponseWriter, r *http.Req
|
||||
prompt = &promptText
|
||||
}
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
opts := []option.RequestOption{option.WithRequestTimeout(time.Second * 600)}
|
||||
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsAnthropicOpts(actor)...)
|
||||
}
|
||||
|
||||
svc, err := i.newMessagesService(ctx, opts...)
|
||||
if err != nil {
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/eventstream"
|
||||
"github.com/coder/coder/v2/aibridge/keypool"
|
||||
@@ -124,12 +123,7 @@ func (i *StreamingInterception) ProcessRequest(w http.ResponseWriter, r *http.Re
|
||||
streamCtx, streamCancel := context.WithCancelCause(ctx)
|
||||
defer streamCancel(xerrors.New("deferred"))
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
var opts []option.RequestOption
|
||||
if actor := aibcontext.ActorFromContext(ctx); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsAnthropicOpts(actor)...)
|
||||
}
|
||||
|
||||
svc, err := i.newMessagesService(streamCtx, opts...)
|
||||
if err != nil {
|
||||
|
||||
@@ -108,7 +108,7 @@ func (i *responsesInterceptionBase) newResponsesService(ctx context.Context) res
|
||||
// client headers plus provider auth.
|
||||
if i.clientHeaders != nil {
|
||||
opts = append(opts, option.WithMiddleware(func(req *http.Request, next option.MiddlewareNext) (*http.Response, error) {
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader())
|
||||
req.Header = intercept.BuildUpstreamHeaders(req.Header, i.clientHeaders, i.cred.AuthHeader(), i.cfg, aibcontext.ActorFromContext(req.Context()))
|
||||
return next(req)
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/awssig"
|
||||
"github.com/coder/coder/v2/aibridge/keypool"
|
||||
@@ -127,12 +126,6 @@ func (i *BlockingResponsesInterceptor) ProcessRequest(w http.ResponseWriter, r *
|
||||
opts := i.requestOptions(&respCopy)
|
||||
opts = append(opts, option.WithRequestTimeout(time.Second*600))
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsOpenAIOpts(actor)...)
|
||||
}
|
||||
|
||||
var keyAttempts int
|
||||
response, keyAttempts, upstreamErr = i.newResponse(ctx, srv, opts)
|
||||
totalKeyAttempts += keyAttempts
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog/v3"
|
||||
aibcontext "github.com/coder/coder/v2/aibridge/context"
|
||||
"github.com/coder/coder/v2/aibridge/intercept"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/awssig"
|
||||
"github.com/coder/coder/v2/aibridge/intercept/eventstream"
|
||||
@@ -162,12 +161,6 @@ func (i *StreamingResponsesInterceptor) ProcessRequest(w http.ResponseWriter, r
|
||||
respCopy = responseCopier{}
|
||||
opts := i.requestOptions(&respCopy)
|
||||
|
||||
// TODO(ssncferreira): inject actor headers directly in the client-header
|
||||
// middleware instead of using SDK options.
|
||||
if actor := aibcontext.ActorFromContext(r.Context()); actor != nil && i.cfg.SendActorHeaders {
|
||||
opts = append(opts, intercept.ActorHeadersAsOpenAIOpts(actor)...)
|
||||
}
|
||||
|
||||
var currentPoolKey *keypool.Key
|
||||
if isPool && walker != nil {
|
||||
key, keyPoolErr := cp.NextKey(walker)
|
||||
|
||||
Reference in new issue
Block a user