-
Notifications
You must be signed in to change notification settings - Fork 6
feat: byok-observability for aibridge #239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ec6ae45
8d7a6b6
be0295d
08c98cb
11709db
74503bd
a2e538f
c963324
3f63615
d6594a2
43ee727
9faf167
ec24b93
bd91a8f
fefb191
7604eba
4e51696
f6b2dff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package intercept | ||
|
|
||
| import "github.com/coder/aibridge/utils" | ||
|
|
||
| // CredentialKind identifies how a request was authenticated. | ||
| // Keep in sync with the credential_kind enum in coderd's database. | ||
| type CredentialKind string | ||
|
|
||
| // Credential kind constants for interception recording. | ||
| const ( | ||
| CredentialKindCentralized CredentialKind = "centralized" | ||
| CredentialKindBYOK CredentialKind = "byok" | ||
| ) | ||
|
|
||
| // CredentialInfo holds credential metadata for an interception. | ||
| type CredentialInfo struct { | ||
| Kind CredentialKind | ||
| Hint string | ||
| Length int | ||
| } | ||
|
|
||
| // NewCredentialInfo creates a CredentialInfo from a raw credential. | ||
| // The credential is automatically masked before storage so that the | ||
| // original secret is never retained. | ||
| func NewCredentialInfo(kind CredentialKind, credential string) CredentialInfo { | ||
| return CredentialInfo{ | ||
| Kind: kind, | ||
| Hint: utils.MaskSecret(credential), | ||
| Length: len(credential), | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,6 +145,8 @@ func (p *Copilot) CreateInterceptor(_ http.ResponseWriter, r *http.Request, trac | |
| ExtraHeaders: extractCopilotHeaders(r), | ||
| } | ||
|
|
||
| cred := intercept.NewCredentialInfo(intercept.CredentialKindBYOK, key) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if it makes sense to add the github token here 🤔 I don't think the copilot case fits the reasoning for logging and debugging on the UI.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ssncferreira |
||
|
|
||
| var interceptor intercept.Interceptor | ||
|
|
||
| path := strings.TrimPrefix(r.URL.Path, p.RoutePrefix()) | ||
|
|
@@ -156,9 +158,9 @@ func (p *Copilot) CreateInterceptor(_ http.ResponseWriter, r *http.Request, trac | |
| } | ||
|
|
||
| if req.Stream { | ||
| interceptor = chatcompletions.NewStreamingInterceptor(id, &req, p.Name(), cfg, r.Header, p.AuthHeader(), tracer) | ||
| interceptor = chatcompletions.NewStreamingInterceptor(id, &req, p.Name(), cfg, r.Header, p.AuthHeader(), tracer, cred) | ||
| } else { | ||
| interceptor = chatcompletions.NewBlockingInterceptor(id, &req, p.Name(), cfg, r.Header, p.AuthHeader(), tracer) | ||
| interceptor = chatcompletions.NewBlockingInterceptor(id, &req, p.Name(), cfg, r.Header, p.AuthHeader(), tracer, cred) | ||
| } | ||
|
|
||
| case routeCopilotResponses: | ||
|
|
@@ -172,9 +174,9 @@ func (p *Copilot) CreateInterceptor(_ http.ResponseWriter, r *http.Request, trac | |
| } | ||
|
|
||
| if reqPayload.Stream() { | ||
| interceptor = responses.NewStreamingInterceptor(id, reqPayload, p.Name(), cfg, r.Header, p.AuthHeader(), tracer) | ||
| interceptor = responses.NewStreamingInterceptor(id, reqPayload, p.Name(), cfg, r.Header, p.AuthHeader(), tracer, cred) | ||
| } else { | ||
| interceptor = responses.NewBlockingInterceptor(id, reqPayload, p.Name(), cfg, r.Header, p.AuthHeader(), tracer) | ||
| interceptor = responses.NewBlockingInterceptor(id, reqPayload, p.Name(), cfg, r.Header, p.AuthHeader(), tracer, cred) | ||
| } | ||
|
|
||
| default: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.