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
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

linters:
disable:
- unused
Expand Down
6 changes: 3 additions & 3 deletions pkg/aiusechat/openai/openai-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/aiusechat/openai/openai-convertmessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions pkg/aiusechat/usechat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -143,7 +144,6 @@ func shouldUsePremium() bool {
}

func updateRateLimit(info *uctypes.RateLimitInfo) {
log.Printf("updateRateLimit: %#v\n", info)
if info == nil {
return
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
17 changes: 17 additions & 0 deletions pkg/util/logutil/logutil.go
Original file line number Diff line number Diff line change
@@ -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...)
}
}
Loading