mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 14:16:08 +00:00
fix(browser): return MEDIA: path from screenshot instead of truncated base64 (#8)
handleScreenshot returned a truncated base64 string (first 100 chars only), which meant the screenshot data was effectively lost and never delivered to channels (Telegram, Discord, etc.) via the media pipeline. The media pipeline in loop.go looks for "MEDIA:" prefix in tool results to collect files for channel delivery (e.g. sendPhoto on Telegram). Without this prefix, screenshots were silently discarded. Fix: save screenshot bytes to a temp file and return MEDIA:/path, matching the pattern used by create_image and tts tools.
This commit is contained in:
1 parent
370c290642
commit
e76aabb3a4
1 file changed
+10
-3
+10
-3
@@ -2,9 +2,11 @@ package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/nextlevelbuilder/goclaw/internal/tools"
|
||||
)
|
||||
@@ -247,8 +249,13 @@ func (t *BrowserTool) handleScreenshot(ctx context.Context, args map[string]inte
|
||||
return tools.ErrorResult(fmt.Sprintf("screenshot failed: %v", err))
|
||||
}
|
||||
|
||||
encoded := base64.StdEncoding.EncodeToString(data)
|
||||
return tools.NewResult(fmt.Sprintf("Screenshot captured (%d bytes). Base64: %s", len(data), encoded[:min(100, len(encoded))]))
|
||||
// Save to temp file so the media pipeline can deliver it (e.g. Telegram sendPhoto)
|
||||
imagePath := filepath.Join(os.TempDir(), fmt.Sprintf("goclaw_screenshot_%d.png", time.Now().UnixNano()))
|
||||
if err := os.WriteFile(imagePath, data, 0644); err != nil {
|
||||
return tools.ErrorResult(fmt.Sprintf("failed to save screenshot: %v", err))
|
||||
}
|
||||
|
||||
return &tools.Result{ForLLM: fmt.Sprintf("MEDIA:%s", imagePath)}
|
||||
}
|
||||
|
||||
func (t *BrowserTool) handleNavigate(ctx context.Context, args map[string]interface{}) *tools.Result {
|
||||
|
||||
Reference in new issue
Block a user