feat(browser): implement screenshot path saving
- Add `browser.screenshotDir` setting (tools tab) for a persistent default screenshot directory, configurable via /settings - Honour the existing `path` parameter in the screenshot action, which was declared in the schema but never consumed by the implementation - Resolution order: params.path (abs) > join(screenshotDir, params.path) > join(screenshotDir, screenshot-<timestamp>.png) > /tmp only - Writes full-resolution buffer to disk (not the API-compressed copy) - Creates destination directory recursively if it doesn't exist - details.screenshotPath reflects the actual saved location Fixes: path param silently ignored since removal in v11.5.0
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import * as os from "node:os";
|
||||
import * as path from "node:path";
|
||||
import * as fs from "node:fs/promises";
|
||||
import { Readability } from "@mozilla/readability";
|
||||
import type { AgentTool, AgentToolContext, AgentToolResult, AgentToolUpdateCallback } from "@oh-my-pi/pi-agent-core";
|
||||
import { StringEnum } from "@oh-my-pi/pi-ai";
|
||||
@@ -1368,6 +1369,24 @@ export class BrowserTool implements AgentTool<typeof browserSchema, BrowserToolD
|
||||
const tempFile = path.join(os.tmpdir(), `omp-sshots-${Snowflake.next()}.png`);
|
||||
await Bun.write(tempFile, resized.buffer);
|
||||
details.screenshotPath = tempFile;
|
||||
// Persist to user-defined location if configured.
|
||||
// Note: screenshotDir containing '~' is NOT expanded — use absolute paths.
|
||||
const screenshotDir = this.session.settings.get("browser.screenshotDir") as string | undefined;
|
||||
const paramPath = params.path as string | undefined;
|
||||
if (paramPath || screenshotDir) {
|
||||
let dest: string;
|
||||
if (paramPath) {
|
||||
dest = path.isAbsolute(paramPath)
|
||||
? paramPath
|
||||
: path.join(screenshotDir ?? process.cwd(), paramPath);
|
||||
} else {
|
||||
const ts = new Date().toISOString().replace(/[:.]/g, "-").slice(0, -1);
|
||||
dest = path.join(screenshotDir!, `screenshot-${ts}.png`);
|
||||
}
|
||||
await fs.mkdir(path.dirname(dest), { recursive: true });
|
||||
await Bun.write(dest, buffer);
|
||||
details.screenshotPath = dest;
|
||||
}
|
||||
details.mimeType = resized.mimeType;
|
||||
details.bytes = resized.buffer.length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user