waveterm/pkg/aiusechat/openai
Copilot 4ec09cb611
Centralize proxy HTTP client creation in aiutil and remove redundant backend tests (#2961)
`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`

```go
httpClient, err := aiutil.MakeHTTPClient(chatOpts.Config.ProxyURL)
if err != nil {
    return nil, nil, nil, err
}
resp, err := httpClient.Do(req)
```

<!-- START COPILOT CODING AGENT TIPS -->
---

💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
2026-03-02 11:16:50 -08:00
..
openai-backend.go Centralize proxy HTTP client creation in aiutil and remove redundant backend tests (#2961) 2026-03-02 11:16:50 -08:00
openai-convertmessage.go implement openaichat images for APIs that support them (using content parts) (#2849) 2026-02-09 21:48:14 -08:00
openai-util.go New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
stream-sample.txt New AIPanel (#2370) 2025-10-07 13:32:10 -07:00
tool-sample.txt New AIPanel (#2370) 2025-10-07 13:32:10 -07:00