Skip to content

Centralize proxy HTTP client creation in aiutil and remove redundant backend tests#2961

Merged
sawka merged 5 commits intomainfrom
copilot/add-proxyurl-to-aimodeconfigtype
Mar 2, 2026
Merged

Centralize proxy HTTP client creation in aiutil and remove redundant backend tests#2961
sawka merged 5 commits intomainfrom
copilot/add-proxyurl-to-aimodeconfigtype

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

makeHTTPClient(proxyURL) had been duplicated across AI backends with equivalent behavior. This change consolidates the logic into a single helper in aiutil and updates backends to consume it, then removes backend-local tests that only re-verified that shared utility behavior.

  • Shared client construction

    • Added aiutil.MakeHTTPClient(proxyURL string) (*http.Client, error) in pkg/aiusechat/aiutil/aiutil.go.
    • Standardizes proxy parsing and http.Transport.Proxy setup in one place.
    • Keeps streaming-safe client semantics (Timeout: 0) and existing invalid proxy URL error behavior.
  • Backend refactor

    • Removed duplicated client/proxy setup blocks from:
      • pkg/aiusechat/openaichat/openaichat-backend.go
      • pkg/aiusechat/gemini/gemini-backend.go
      • pkg/aiusechat/openai/openai-backend.go
      • pkg/aiusechat/anthropic/anthropic-backend.go
    • Replaced with direct calls to the shared helper.
  • Test cleanup

    • Deleted backend tests that only covered basic proxy client creation and no backend-specific behavior:
      • pkg/aiusechat/openaichat/openaichat-backend_test.go
      • pkg/aiusechat/gemini/gemini-backend_test.go
httpClient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL)
if err != nil {
    return nil, nil, nil, err
}
resp, err := httpClient.Do(req)

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 28, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1019c2a
Status: ✅  Deploy successful!
Preview URL: https://912998a2.waveterm.pages.dev
Branch Preview URL: https://copilot-add-proxyurl-to-aimo.waveterm.pages.dev

View logs

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ProxyUrl to AIModeConfigType and clean up unused config Add ai:proxyurl to Wave AI mode config and wire proxy support through Gemini/OpenAI Chat Feb 28, 2026
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Add ai:proxyurl to Wave AI mode config and wire proxy support through Gemini/OpenAI Chat Deduplicate AI backend proxy client creation via aiutil.MakeHTTPClient Mar 2, 2026
Copilot finished work on behalf of sawka March 2, 2026 18:47
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Deduplicate AI backend proxy client creation via aiutil.MakeHTTPClient Centralize proxy HTTP client creation in aiutil and remove redundant backend tests Mar 2, 2026
Copilot finished work on behalf of sawka March 2, 2026 19:05
@sawka sawka marked this pull request as ready for review March 2, 2026 19:06
@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 2, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (9 files)
  • pkg/aiusechat/aiutil/aiutil.go - Added shared MakeHTTPClient utility function
  • pkg/aiusechat/anthropic/anthropic-backend.go - Refactored to use shared utility
  • pkg/aiusechat/gemini/gemini-backend.go - Refactored to use shared utility
  • pkg/aiusechat/openai/openai-backend.go - Refactored to use shared utility
  • pkg/aiusechat/openaichat/openaichat-backend.go - Refactored to use shared utility
  • pkg/aiusechat/uctypes/uctypes.go - Removed duplicate AIModeConfig type
  • pkg/aiusechat/usechat.go - Added ProxyURL to AIOptsType initialization
  • pkg/wconfig/settingsconfig.go - Added ProxyURL field to AIModeConfigType
  • pkg/aiusechat/usechat_mode_test.go - Added test for ProxyURL preservation

Review Notes

This PR successfully adds proxy URL support to all AI backends through a clean refactoring:

Code Quality: Excellent code deduplication by extracting duplicate proxy setup logic into a shared utility function

Error Handling: All error cases properly handled with descriptive error messages

Test Coverage: Added appropriate test to verify ProxyURL is preserved through provider defaults

Consistency: All AI backends (Anthropic, OpenAI, Gemini, OpenAIChat) now use the same proxy implementation

Backward Compatible: Empty ProxyURL means no proxy, maintaining existing behavior

Schema Updated: JSON schema correctly updated with the new field

The implementation follows the project's coding conventions and best practices.

@sawka sawka merged commit 4ec09cb into main Mar 2, 2026
6 checks passed
@sawka sawka deleted the copilot/add-proxyurl-to-aimodeconfigtype branch March 2, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants