Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 21 additions & 2 deletions pkg/aiusechat/gemini/gemini-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ func appendPartToLastUserMessage(contents []GeminiContent, text string) {
}
}

func makeHTTPClient(proxyURL string) (*http.Client, error) {
httpClient := &http.Client{
Timeout: 0, // rely on ctx; streaming can be long
}
if proxyURL == "" {
return httpClient, nil
}

pURL, err := url.Parse(proxyURL)
if err != nil {
return nil, fmt.Errorf("invalid proxy URL: %w", err)
}
httpClient.Transport = &http.Transport{
Proxy: http.ProxyURL(pURL),
}
return httpClient, nil
}

// buildGeminiHTTPRequest creates an HTTP request for the Gemini API
func buildGeminiHTTPRequest(ctx context.Context, contents []GeminiContent, chatOpts uctypes.WaveChatOpts) (*http.Request, error) {
opts := chatOpts.Config
Expand Down Expand Up @@ -231,8 +249,9 @@ func RunGeminiChatStep(
return nil, nil, nil, err
}

httpClient := &http.Client{
Timeout: 0, // rely on ctx; streaming can be long
httpClient, err := makeHTTPClient(chatOpts.Config.ProxyURL)
if err != nil {
return nil, nil, nil, err
}

resp, err := httpClient.Do(req)
Expand Down
23 changes: 23 additions & 0 deletions pkg/aiusechat/gemini/gemini-backend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package gemini

import "testing"

func TestMakeHTTPClientProxy(t *testing.T) {
client, err := makeHTTPClient("http://localhost:8080")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if client.Transport == nil {
t.Fatalf("expected proxy transport to be set")
}
}

func TestMakeHTTPClientInvalidProxy(t *testing.T) {
_, err := makeHTTPClient("://bad-url")
if err == nil {
t.Fatalf("expected invalid proxy URL error")
}
}
22 changes: 21 additions & 1 deletion pkg/aiusechat/openaichat/openaichat-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"strings"
"time"

Expand All @@ -21,6 +22,22 @@ import (
"github.com/wavetermdev/waveterm/pkg/web/sse"
)

func makeHTTPClient(proxyURL string) (*http.Client, error) {
client := &http.Client{}
if proxyURL == "" {
return client, nil
}

pURL, err := url.Parse(proxyURL)
if err != nil {
return nil, fmt.Errorf("invalid proxy URL: %w", err)
}
client.Transport = &http.Transport{
Proxy: http.ProxyURL(pURL),
}
return client, nil
}

// RunChatStep executes a chat step using the chat completions API
func RunChatStep(
ctx context.Context,
Expand Down Expand Up @@ -60,7 +77,10 @@ func RunChatStep(
return nil, nil, nil, err
}

client := &http.Client{}
client, err := makeHTTPClient(chatOpts.Config.ProxyURL)
if err != nil {
return nil, nil, nil, err
}
resp, err := client.Do(req)
if err != nil {
return nil, nil, nil, fmt.Errorf("request failed: %w", err)
Expand Down
23 changes: 23 additions & 0 deletions pkg/aiusechat/openaichat/openaichat-backend_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package openaichat

import "testing"

func TestMakeHTTPClientProxy(t *testing.T) {
client, err := makeHTTPClient("http://localhost:8080")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if client.Transport == nil {
t.Fatalf("expected proxy transport to be set")
}
}

func TestMakeHTTPClientInvalidProxy(t *testing.T) {
_, err := makeHTTPClient("://bad-url")
if err == nil {
t.Fatalf("expected invalid proxy URL error")
}
}
23 changes: 0 additions & 23 deletions pkg/aiusechat/uctypes/uctypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,29 +189,6 @@ const (
ApprovalCanceled = "canceled"
)

type AIModeConfig struct {
Mode string `json:"mode"`
DisplayName string `json:"display:name"`
DisplayOrder float64 `json:"display:order,omitempty"`
DisplayIcon string `json:"display:icon"`
Provider string `json:"provider,omitempty"`
APIType string `json:"apitype"`
Model string `json:"model"`
ThinkingLevel string `json:"thinkinglevel"`
BaseURL string `json:"baseurl,omitempty"`
WaveAICloud bool `json:"waveaicloud,omitempty"`
APIVersion string `json:"apiversion,omitempty"`
APIToken string `json:"apitoken,omitempty"`
APITokenSecretName string `json:"apitokensecretname,omitempty"`
Premium bool `json:"premium"`
Description string `json:"description"`
Capabilities []string `json:"capabilities,omitempty"`
}

func (c *AIModeConfig) HasCapability(cap string) bool {
return slices.Contains(c.Capabilities, cap)
}

// when updating this struct, also modify frontend/app/aipanel/aitypes.ts WaveUIDataTypes.tooluse
type UIMessageDataToolUse struct {
ToolCallId string `json:"toolcallid"`
Expand Down
1 change: 1 addition & 0 deletions pkg/aiusechat/usechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func getWaveAISettings(premium bool, builderMode bool, rtInfo waveobj.ObjRTInfo,
Verbosity: verbosity,
AIMode: aiMode,
Endpoint: baseUrl,
ProxyURL: config.ProxyURL,
Capabilities: config.Capabilities,
WaveAIPremium: config.WaveAIPremium,
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/aiusechat/usechat_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ func TestApplyProviderDefaultsGroq(t *testing.T) {
t.Fatalf("expected API token secret name %q, got %q", GroqAPITokenSecretName, config.APITokenSecretName)
}
}

func TestApplyProviderDefaultsKeepsProxyURL(t *testing.T) {
config := wconfig.AIModeConfigType{
Provider: uctypes.AIProvider_OpenAI,
Model: "gpt-5-mini",
ProxyURL: "http://localhost:8080",
}
applyProviderDefaults(&config)
if config.ProxyURL != "http://localhost:8080" {
t.Fatalf("expected proxy URL to be preserved, got %q", config.ProxyURL)
}
}
1 change: 1 addition & 0 deletions pkg/wconfig/settingsconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ type AIModeConfigType struct {
ThinkingLevel string `json:"ai:thinkinglevel,omitempty" jsonschema:"enum=low,enum=medium,enum=high"`
Verbosity string `json:"ai:verbosity,omitempty" jsonschema:"enum=low,enum=medium,enum=high,description=Text verbosity level (OpenAI Responses API only)"`
Endpoint string `json:"ai:endpoint,omitempty"`
ProxyURL string `json:"ai:proxyurl,omitempty"`
AzureAPIVersion string `json:"ai:azureapiversion,omitempty"`
APIToken string `json:"ai:apitoken,omitempty"`
APITokenSecretName string `json:"ai:apitokensecretname,omitempty"`
Expand Down
5 changes: 4 additions & 1 deletion schema/waveai.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"ai:endpoint": {
"type": "string"
},
"ai:proxyurl": {
"type": "string"
},
"ai:azureapiversion": {
"type": "string"
},
Expand Down Expand Up @@ -109,4 +112,4 @@
"$ref": "#/$defs/AIModeConfigType"
},
"type": "object"
}
}