Skip to content

Commit 5bd630d

Browse files
authored
track if AI requests are local to see feature usage (#2313)
1 parent 5165e72 commit 5bd630d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkg/telemetry/telemetrydata/telemetrydata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type TEventProps struct {
7777
PanicType string `json:"debug:panictype,omitempty"`
7878
BlockView string `json:"block:view,omitempty"`
7979
AiBackendType string `json:"ai:backendtype,omitempty"`
80+
AiLocal bool `json:"ai:local,omitempty"`
8081
WshCmd string `json:"wsh:cmd,omitempty"`
8182
WshHadError bool `json:"wsh:haderror,omitempty"`
8283
ConnType string `json:"conn:conntype,omitempty"`

pkg/waveai/waveai.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package waveai
66
import (
77
"context"
88
"log"
9+
"net/url"
10+
"strings"
911

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

57+
func isLocalURL(baseURL string) bool {
58+
if baseURL == "" {
59+
return false
60+
}
61+
62+
u, err := url.Parse(baseURL)
63+
if err != nil {
64+
return false
65+
}
66+
67+
host := strings.ToLower(u.Hostname())
68+
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)
69+
}
70+
5571
func makeAIError(err error) wshrpc.RespOrErrorUnion[wshrpc.WaveAIPacketType] {
5672
return wshrpc.RespOrErrorUnion[wshrpc.WaveAIPacketType]{Error: err}
5773
}
@@ -88,10 +104,12 @@ func RunAICommand(ctx context.Context, request wshrpc.WaveAIStreamRequest) chan
88104
log.Printf("no backend found for %s\n", request.Opts.APIType)
89105
return nil
90106
}
107+
aiLocal := backendType != "wave" && isLocalURL(request.Opts.BaseURL)
91108
telemetry.GoRecordTEventWrap(&telemetrydata.TEvent{
92109
Event: "action:runaicmd",
93110
Props: telemetrydata.TEventProps{
94111
AiBackendType: backendType,
112+
AiLocal: aiLocal,
95113
},
96114
})
97115

0 commit comments

Comments
 (0)