Repository navigation
refactor(aibridge/intercept): inject actor headers in middleware - #29839
Conversation
| 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())) |
There was a problem hiding this comment.
Thank you for this 🙏 completely forgot about the TODO 🙇♀️
| } | ||
| } | ||
|
|
||
| if cfg.SendActorHeaders { |
There was a problem hiding this comment.
Not necessarly, for this PR, but AFAIK we are not stripping the X-AI-Bridge-Actor-*, meaning that if a user does make a request with these headers, they will still be sent upstream. We should probably strip them
There was a problem hiding this comment.
I can't find any mention in our current documentation regarding what headers we strip. Stripping additional headers would be a behavioural change that I'd rather keep out of scope of this PR. It's worth a follow-up issue though.
| // Preserve actor headers injected by aibridge as per-request SDK options. | ||
| // Preserve actor headers injected by other SDK options. | ||
| for name, values := range sdkHeader { | ||
| if IsActorHeader(name) { |
There was a problem hiding this comment.
IIUC, with SDK-option injection removed, the actors headers are no longer injected in sdkHeader. So we can probably just delete this? 🤔
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