diff --git a/.golangci.yml b/.golangci.yml index bc74bcbeb6..c33efd501d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,5 @@ +version: 2 + linters: disable: - unused diff --git a/pkg/aiusechat/openai/openai-backend.go b/pkg/aiusechat/openai/openai-backend.go index d667234227..a61b31f8d2 100644 --- a/pkg/aiusechat/openai/openai-backend.go +++ b/pkg/aiusechat/openai/openai-backend.go @@ -19,6 +19,7 @@ import ( "github.com/launchdarkly/eventsource" "github.com/wavetermdev/waveterm/pkg/aiusechat/chatstore" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" + "github.com/wavetermdev/waveterm/pkg/util/logutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/wcore" "github.com/wavetermdev/waveterm/pkg/web/sse" @@ -503,7 +504,7 @@ func parseOpenAIHTTPError(resp *http.Response) error { return fmt.Errorf("openai %s: failed to read error response: %v", resp.Status, err) } - log.Printf("full error: %s\n", body) + logutil.DevPrintf("openai full error: %s\n", body) // Try to parse as OpenAI error format first var errorResp openAIErrorResponse @@ -836,8 +837,7 @@ func handleOpenAIEvent( return nil, nil default: - // log unknown events for debugging - log.Printf("OpenAI: unknown event: %s, data: %s", eventName, data) + logutil.DevPrintf("OpenAI: unknown event: %s, data: %s", eventName, data) return nil, nil } } diff --git a/pkg/aiusechat/openai/openai-convertmessage.go b/pkg/aiusechat/openai/openai-convertmessage.go index 8c9559d699..4a32c12af3 100644 --- a/pkg/aiusechat/openai/openai-convertmessage.go +++ b/pkg/aiusechat/openai/openai-convertmessage.go @@ -18,6 +18,7 @@ import ( "github.com/google/uuid" "github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes" "github.com/wavetermdev/waveterm/pkg/util/utilfn" + "github.com/wavetermdev/waveterm/pkg/wavebase" ) const ( @@ -129,6 +130,9 @@ func ConvertToolDefinitionToOpenAI(tool uctypes.ToolDefinition) OpenAIRequestToo } func debugPrintReq(req *OpenAIRequest, endpoint string) { + if !wavebase.IsDevMode() { + return + } var toolNames []string for _, tool := range req.Tools { toolNames = append(toolNames, tool.Name) diff --git a/pkg/aiusechat/usechat.go b/pkg/aiusechat/usechat.go index cdad22db6e..a5cd8e8974 100644 --- a/pkg/aiusechat/usechat.go +++ b/pkg/aiusechat/usechat.go @@ -22,6 +22,7 @@ import ( "github.com/wavetermdev/waveterm/pkg/telemetry" "github.com/wavetermdev/waveterm/pkg/telemetry/telemetrydata" "github.com/wavetermdev/waveterm/pkg/util/ds" + "github.com/wavetermdev/waveterm/pkg/util/logutil" "github.com/wavetermdev/waveterm/pkg/util/utilfn" "github.com/wavetermdev/waveterm/pkg/waveobj" "github.com/wavetermdev/waveterm/pkg/web/sse" @@ -143,7 +144,6 @@ func shouldUsePremium() bool { } func updateRateLimit(info *uctypes.RateLimitInfo) { - log.Printf("updateRateLimit: %#v\n", info) if info == nil { return } @@ -234,7 +234,7 @@ func processToolCall(toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpt } inputJSON, _ := json.Marshal(toolCall.Input) - log.Printf("TOOLUSE name=%s id=%s input=%s approval=%q\n", toolCall.Name, toolCall.ID, utilfn.TruncateString(string(inputJSON), 40), toolCall.ToolUseData.Approval) + logutil.DevPrintf("TOOLUSE name=%s id=%s input=%s approval=%q\n", toolCall.Name, toolCall.ID, utilfn.TruncateString(string(inputJSON), 40), toolCall.ToolUseData.Approval) if toolCall.ToolUseData.Status == uctypes.ToolUseStatusError { errorMsg := toolCall.ToolUseData.ErrorMessage @@ -349,7 +349,6 @@ func processToolCalls(stopReason *uctypes.WaveStopReason, chatOpts uctypes.WaveC } func RunAIChat(ctx context.Context, sseHandler *sse.SSEHandlerCh, chatOpts uctypes.WaveChatOpts) (*uctypes.AIMetrics, error) { - log.Printf("RunAIChat\n") if !activeChats.SetUnless(chatOpts.ChatId, true) { return nil, fmt.Errorf("chat %s is already running", chatOpts.ChatId) } @@ -488,7 +487,6 @@ func ResolveToolCall(toolCall uctypes.WaveToolCall, chatOpts uctypes.WaveChatOpt } func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, message *uctypes.AIMessage, chatOpts uctypes.WaveChatOpts) error { - log.Printf("WaveAIPostMessageWrap\n") startTime := time.Now() // Convert AIMessage to Anthropic chat message @@ -531,7 +529,7 @@ func WaveAIPostMessageWrap(ctx context.Context, sseHandler *sse.SSEHandlerCh, me } } } - log.Printf("metrics: requests=%d tools=%d premium=%d proxy=%d images=%d pdfs=%d textdocs=%d textlen=%d duration=%dms error=%v\n", + log.Printf("WaveAI call metrics: requests=%d tools=%d premium=%d proxy=%d images=%d pdfs=%d textdocs=%d textlen=%d duration=%dms error=%v\n", metrics.RequestCount, metrics.ToolUseCount, metrics.PremiumReqCount, metrics.ProxyReqCount, metrics.ImageCount, metrics.PDFCount, metrics.TextDocCount, metrics.TextLen, metrics.RequestDuration, metrics.HadError) diff --git a/pkg/util/logutil/logutil.go b/pkg/util/logutil/logutil.go new file mode 100644 index 0000000000..f023cd62cc --- /dev/null +++ b/pkg/util/logutil/logutil.go @@ -0,0 +1,17 @@ +// Copyright 2025, Command Line Inc. +// SPDX-License-Identifier: Apache-2.0 + +package logutil + +import ( + "log" + + "github.com/wavetermdev/waveterm/pkg/wavebase" +) + +// DevPrintf logs using log.Printf only if running in dev mode +func DevPrintf(format string, v ...any) { + if wavebase.IsDevMode() { + log.Printf(format, v...) + } +} \ No newline at end of file