Skip to content
Merged
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
1 change: 1 addition & 0 deletions pkg/telemetry/telemetrydata/telemetrydata.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type TEventProps struct {
PanicType string `json:"debug:panictype,omitempty"`
BlockView string `json:"block:view,omitempty"`
AiBackendType string `json:"ai:backendtype,omitempty"`
AiLocal bool `json:"ai:local,omitempty"`
WshCmd string `json:"wsh:cmd,omitempty"`
WshHadError bool `json:"wsh:haderror,omitempty"`
ConnType string `json:"conn:conntype,omitempty"`
Expand Down
18 changes: 18 additions & 0 deletions pkg/waveai/waveai.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package waveai
import (
"context"
"log"
"net/url"
"strings"

"github.com/wavetermdev/waveterm/pkg/telemetry"
"github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata"
Expand Down Expand Up @@ -52,6 +54,20 @@ func IsCloudAIRequest(opts *wshrpc.WaveAIOptsType) bool {
return opts.BaseURL == "" && opts.APIToken == ""
}

func isLocalURL(baseURL string) bool {
if baseURL == "" {
return false
}

u, err := url.Parse(baseURL)
if err != nil {
return false
}

host := strings.ToLower(u.Hostname())
return host == "localhost" || host == "127.0.0.1" || host == "0.0.0.0" || strings.HasPrefix(host, "192.168.") || strings.HasPrefix(host, "10.") || (strings.HasPrefix(host, "172.") && len(host) > 4)
}

func makeAIError(err error) wshrpc.RespOrErrorUnion[wshrpc.WaveAIPacketType] {
return wshrpc.RespOrErrorUnion[wshrpc.WaveAIPacketType]{Error: err}
}
Expand Down Expand Up @@ -88,10 +104,12 @@ func RunAICommand(ctx context.Context, request wshrpc.WaveAIStreamRequest) chan
log.Printf("no backend found for %s\n", request.Opts.APIType)
return nil
}
aiLocal := backendType != "wave" && isLocalURL(request.Opts.BaseURL)
telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{
Event: "action:runaicmd",
Props: telemetrydata.TEventProps{
AiBackendType: backendType,
AiLocal: aiLocal,
},
})

Expand Down
Loading