fix: address PR review - remove duplicate transcription, dead config, fix comment, trim EOF

This commit is contained in:
virat-mankali 2026-03-08 23:27:47 +05:30
parent dfe65da016
commit 65fd049022
3 changed files with 8 additions and 50 deletions

View file

@ -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}
}

View file

@ -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_"`

View file

@ -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"`