mirror of
https://github.com/wavetermdev/waveterm
synced 2026-05-23 08:48:28 +00:00
track if AI requests are local to see feature usage (#2313)
This commit is contained in:
parent
5165e725af
commit
5bd630d906
2 changed files with 19 additions and 0 deletions
|
|
@ -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"`
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -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}
|
||||
}
|
||||
|
|
@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue