mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-14 22:17:36 +00:00
fix(media): save browser screenshots and TTS audio to workspace instead of /tmp
Screenshots saved to {workspace}/screenshots/, TTS audio to {workspace}/tts/.
Agents can now access these files via read_file. Falls back to os.TempDir()
when workspace is unavailable.
This commit is contained in:
1 parent
4b780bbffa
commit
da98a54393
2 files changed
+20
-5
No files matched your search
+10
-3
@@ -101,9 +101,16 @@ func (t *TtsTool) Execute(ctx context.Context, args map[string]any) *Result {
|
||||
return &Result{ForLLM: fmt.Sprintf("error: tts failed: %s", err.Error()), IsError: true}
|
||||
}
|
||||
|
||||
// Write audio to temp file
|
||||
tmpDir := os.TempDir()
|
||||
audioPath := filepath.Join(tmpDir, fmt.Sprintf("tts-%d.%s", time.Now().UnixNano(), result.Extension))
|
||||
// Write audio to workspace/tts/ so the agent can access the file.
|
||||
// Falls back to os.TempDir() if workspace is not available.
|
||||
ttsDir := os.TempDir()
|
||||
if ws := ToolWorkspaceFromCtx(ctx); ws != "" {
|
||||
ttsDir = filepath.Join(ws, "tts")
|
||||
}
|
||||
if err := os.MkdirAll(ttsDir, 0755); err != nil {
|
||||
return &Result{ForLLM: fmt.Sprintf("error: create tts directory: %s", err.Error()), IsError: true}
|
||||
}
|
||||
audioPath := filepath.Join(ttsDir, fmt.Sprintf("tts-%d.%s", time.Now().UnixNano(), result.Extension))
|
||||
if err := os.WriteFile(audioPath, result.Audio, 0644); err != nil {
|
||||
return &Result{ForLLM: fmt.Sprintf("error: write tts audio: %s", err.Error()), IsError: true}
|
||||
}
|
||||
|
||||
+10
-2
@@ -275,8 +275,16 @@ func (t *BrowserTool) handleScreenshot(ctx context.Context, args map[string]any)
|
||||
return tools.ErrorResult(fmt.Sprintf("screenshot failed: %v", err))
|
||||
}
|
||||
|
||||
// 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()))
|
||||
// Save to workspace/screenshots/ so the agent can access the file.
|
||||
// Falls back to os.TempDir() if workspace is not available.
|
||||
screenshotDir := filepath.Join(os.TempDir(), "goclaw_screenshots")
|
||||
if ws := tools.ToolWorkspaceFromCtx(ctx); ws != "" {
|
||||
screenshotDir = filepath.Join(ws, "screenshots")
|
||||
}
|
||||
if err := os.MkdirAll(screenshotDir, 0755); err != nil {
|
||||
return tools.ErrorResult(fmt.Sprintf("failed to create screenshots directory: %v", err))
|
||||
}
|
||||
imagePath := filepath.Join(screenshotDir, fmt.Sprintf("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))
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user