From 65fd049022c4545e345aa633d0e1d20b00ce5448 Mon Sep 17 00:00:00 2001 From: virat-mankali Date: Sun, 8 Mar 2026 23:27:47 +0530 Subject: [PATCH] fix: address PR review - remove duplicate transcription, dead config, fix comment, trim EOF --- pkg/agent/loop.go | 41 ++----------------------- pkg/config/config.go | 7 ----- pkg/providers/openai_compat/provider.go | 10 +++--- 3 files changed, 8 insertions(+), 50 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 345bcb962..af94294e9 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -622,45 +622,10 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage) "route_channel": route.Channel, }) - // Transcribe any audio media refs before passing to the agent. + // transcribeAudioInMessage already ran earlier in processMessage, + // so msg.Content has transcripts injected. Use it directly. userMessage := msg.Content - if al.transcriber != nil && len(msg.Media) > 0 && al.mediaStore != nil { - for _, ref := range msg.Media { - localPath, meta, err := al.mediaStore.ResolveWithMeta(ref) - if err != nil { - continue - } - - mediaType := inferMediaType(meta.Filename, meta.ContentType) - - // Handle audio transcription - if mediaType == "audio" { - logger.InfoCF("agent", "Transcribing audio", map[string]any{ - "ref": ref, "path": localPath, "filename": meta.Filename, - }) - result, err := al.transcriber.Transcribe(ctx, localPath) - if err != nil { - logger.WarnCF("agent", "Audio transcription failed", map[string]any{ - "ref": ref, "error": err.Error(), - }) - continue - } - logger.InfoCF("agent", "Transcribed audio", map[string]any{ - "ref": ref, "length": len(result.Text), - }) - // Replace the [voice]/[audio] placeholder with the actual transcript - userMessage = strings.NewReplacer("[voice]", "", "[audio]", "").Replace(userMessage) - userMessage = strings.TrimSpace(userMessage) - if userMessage != "" { - userMessage = userMessage + "\n\n[Voice transcript]: " + result.Text - } else { - userMessage = result.Text - } - } - } - } - return al.runAgentLoop(ctx, agent, processOptions{ SessionKey: sessionKey, Channel: msg.Channel, @@ -1750,5 +1715,3 @@ func extractParentPeer(msg bus.InboundMessage) *routing.RoutePeer { } return &routing.RoutePeer{Kind: parentKind, ID: parentID} } - - diff --git a/pkg/config/config.go b/pkg/config/config.go index 0855aba8c..a584a4279 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -659,12 +659,6 @@ type MediaCleanupConfig struct { Interval int ` env:"PICOCLAW_MEDIA_CLEANUP_INTERVAL" json:"interval_minutes"` } -type TranscribeConfig struct { - Enabled bool `json:"enabled" env:"PICOCLAW_TRANSCRIBE_ENABLED"` - APIKey string `json:"api_key" env:"PICOCLAW_TRANSCRIBE_API_KEY"` - Model string `json:"model" env:"PICOCLAW_TRANSCRIBE_MODEL"` -} - type ToolsConfig struct { AllowReadPaths []string `json:"allow_read_paths" env:"PICOCLAW_TOOLS_ALLOW_READ_PATHS"` AllowWritePaths []string `json:"allow_write_paths" env:"PICOCLAW_TOOLS_ALLOW_WRITE_PATHS"` @@ -673,7 +667,6 @@ type ToolsConfig struct { Exec ExecConfig `json:"exec"` Skills SkillsToolsConfig `json:"skills"` MediaCleanup MediaCleanupConfig `json:"media_cleanup"` - Transcribe TranscribeConfig `json:"transcribe"` MCP MCPConfig `json:"mcp"` AppendFile ToolConfig `json:"append_file" envPrefix:"PICOCLAW_TOOLS_APPEND_FILE_"` EditFile ToolConfig `json:"edit_file" envPrefix:"PICOCLAW_TOOLS_EDIT_FILE_"` diff --git a/pkg/providers/openai_compat/provider.go b/pkg/providers/openai_compat/provider.go index 43e5e1cf8..ec6dd5dc3 100644 --- a/pkg/providers/openai_compat/provider.go +++ b/pkg/providers/openai_compat/provider.go @@ -361,10 +361,12 @@ func parseResponse(body io.Reader) (*LLMResponse, error) { }, nil } -// openaiMessage is the wire-format message for OpenAI-compatible APIs. -// It mirrors protocoltypes.Message but omits SystemParts, which is an -// internal field that would be unknown to third-party endpoints. -// Content can be either a string or an array of content blocks for multimodal messages. +// openaiMessage is the wire-format message for OpenAI-compatible APIs for +// simple text-only messages. It mirrors protocoltypes.Message but omits +// SystemParts, which is an internal field that would be unknown to +// third-party endpoints. For messages that include media, serializeMessages +// constructs a map[string]any where "content" is an array of content blocks, +// instead of using this struct. type openaiMessage struct { Role string `json:"role"` Content string `json:"content"`