-
Notifications
You must be signed in to change notification settings - Fork 332
feat: add custom headers and base_url env expansion for providers #2108
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
Open
alindsilva
wants to merge
23
commits into
docker:main
Choose a base branch
from
alindsilva:feature/provider-custom-headers-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ee35e1a
feat: add custom headers support for provider configs
alindsilva 19147d9
fix: forward Start/Stop to inner toolsets in teamloader wrappers
alindsilva 14eb42d
fix: normalize anyOf schemas and add API error response body logging
alindsilva 11167d7
feat: add custom headers and base_url env expansion to all providers
alindsilva cac998e
Merge feature/provider-custom-headers-pr: add custom headers and base…
alindsilva 8d15048
fix: add Headers field to v4/v5/v6 config types and address PR review…
alindsilva cce9e24
fix: address lint errors from CI/CD pipeline
alindsilva 60aa6ae
Merge main into feature/provider-custom-headers-pr
alindsilva 2b0d2fa
fix: resolve merge conflict - add missing alias handling section
alindsilva d688dde
chore: update devcontainer to use mise instead of go-task
alindsilva 6d6d986
fix: correct function scope in applyProviderDefaults
alindsilva 5e55a09
docs: merge troubleshooting guide for custom headers PR
alindsilva 3827213
fix: address lint errors in custom headers code
alindsilva 05e96db
fix: remove orphaned code causing syntax error in applyProviderDefaults
alindsilva 4abc8c9
Apply suggestion from @Copilot
alindsilva 2393865
fix: prevent header map mutation in model-level merge
alindsilva b8792b5
Merge branch 'feature/provider-custom-headers-pr' of https://github.c…
alindsilva 175d517
fix: preserve full schema when normalizing nullable anyOf
alindsilva 9f8e453
fix: use expanded base URL for WebSocket pool initialization
Copilot 3f8cb3d
Update examples/custom_provider.yaml
alindsilva 5e79266
fix: align WebSocket auth with HTTP for custom providers without toke…
Copilot 03e2857
chore: update devcontainer name from cagent to docker-agent
alindsilva f1ff8eb
Merge branch 'feature/provider-custom-headers-pr' of https://github.c…
alindsilva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package provider | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/docker/docker-agent/pkg/config/latest" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestApplyProviderDefaults_WithHeaders(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| providerName string | ||
| providerCfg latest.ProviderConfig | ||
| modelCfg latest.ModelConfig | ||
| expectedHeaders map[string]string | ||
| headersInOpts bool | ||
| }{ | ||
| { | ||
| name: "custom provider with headers", | ||
| providerName: "custom", | ||
| providerCfg: latest.ProviderConfig{ | ||
| BaseURL: "https://gateway.example.com/v1", | ||
| Headers: map[string]string{ | ||
| "cf-aig-authorization": "Bearer token123", | ||
| "x-custom-header": "value", | ||
| }, | ||
| }, | ||
| modelCfg: latest.ModelConfig{ | ||
| Provider: "custom", | ||
| Model: "gpt-4o", | ||
| }, | ||
| expectedHeaders: map[string]string{ | ||
| "cf-aig-authorization": "Bearer token123", | ||
| "x-custom-header": "value", | ||
| }, | ||
| headersInOpts: true, | ||
| }, | ||
| { | ||
| name: "custom provider without headers", | ||
| providerName: "custom", | ||
| providerCfg: latest.ProviderConfig{ | ||
| BaseURL: "https://api.example.com/v1", | ||
| }, | ||
| modelCfg: latest.ModelConfig{ | ||
| Provider: "custom", | ||
| Model: "gpt-4o", | ||
| }, | ||
| headersInOpts: false, | ||
| }, | ||
| { | ||
| name: "custom provider with empty headers", | ||
| providerName: "custom", | ||
| providerCfg: latest.ProviderConfig{ | ||
| BaseURL: "https://api.example.com/v1", | ||
| Headers: map[string]string{}, | ||
| }, | ||
| modelCfg: latest.ModelConfig{ | ||
| Provider: "custom", | ||
| Model: "gpt-4o", | ||
| }, | ||
| headersInOpts: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| providers := map[string]latest.ProviderConfig{ | ||
| tt.providerName: tt.providerCfg, | ||
| } | ||
|
|
||
| result := applyProviderDefaults(&tt.modelCfg, providers) | ||
| require.NotNil(t, result) | ||
|
|
||
| if tt.headersInOpts { | ||
| require.NotNil(t, result.ProviderOpts, "ProviderOpts should not be nil") | ||
| headers, ok := result.ProviderOpts["headers"] | ||
| require.True(t, ok, "headers should be in ProviderOpts") | ||
|
|
||
| headerMap, ok := headers.(map[string]string) | ||
| require.True(t, ok, "headers should be map[string]string") | ||
| assert.Equal(t, tt.expectedHeaders, headerMap, "headers should match") | ||
| } else { | ||
| if result.ProviderOpts != nil { | ||
| _, hasHeaders := result.ProviderOpts["headers"] | ||
| assert.False(t, hasHeaders, "headers should not be in ProviderOpts") | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyProviderDefaults_HeadersDoNotOverrideExisting(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| providerCfg := latest.ProviderConfig{ | ||
| BaseURL: "https://gateway.example.com/v1", | ||
| Headers: map[string]string{ | ||
| "x-provider-header": "from-provider", | ||
| }, | ||
| } | ||
|
|
||
| modelCfg := latest.ModelConfig{ | ||
| Provider: "custom", | ||
| Model: "gpt-4o", | ||
| ProviderOpts: map[string]any{ | ||
| "headers": map[string]string{ | ||
| "x-model-header": "from-model", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| providers := map[string]latest.ProviderConfig{ | ||
| "custom": providerCfg, | ||
| } | ||
|
|
||
| result := applyProviderDefaults(&modelCfg, providers) | ||
| require.NotNil(t, result) | ||
|
|
||
| // Model config's headers should take precedence (not be overwritten) | ||
| require.NotNil(t, result.ProviderOpts) | ||
| headers, ok := result.ProviderOpts["headers"] | ||
| require.True(t, ok) | ||
|
|
||
| headerMap, ok := headers.(map[string]string) | ||
| require.True(t, ok) | ||
|
|
||
| // Should have model's header, not provider's header | ||
| assert.Equal(t, map[string]string{"x-model-header": "from-model"}, headerMap) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.