openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
71 lines (70 loc) • 2.13 kB
JavaScript
import { s as asFiniteNumber } from "./number-coercion-D6u-4YD8.mjs";
import { o as asRecord } from "./record-coerce-CVPuDqcc.mjs";
import { n as coerceErrorMessage } from "./error-coercion-hDrHOSGy.mjs";
import { n as resolvePreferredOpenClawTmpDir } from "./tmp-openclaw-dir-Bf0oU1Cn.mjs";
import { n as runExec } from "./exec-aRIvS9s4.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import "./process-runtime-DcBPEA8Y.mjs";
import "./error-runtime-BM740gJj.mjs";
import "./temp-path-CW7QMeae.mjs";
import path from "node:path";
import { randomUUID } from "node:crypto";
import { chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
//#region extensions/logbook/src/node-host.ts
const LOGBOOK_SNAPSHOT_EXEC_TIMEOUT_MS = 25e3;
async function handleLogbookSnapshot(e) {
if (process.platform !== "darwin") return { error: `logbook.snapshot is not supported on ${process.platform}` };
const t = asRecord(e);
const n = Math.max(0, Math.round(asFiniteNumber(t.screenIndex) ?? 0));
const r = asFiniteNumber(t.maxWidth);
const i = r && r >= 480 ? Math.round(r) : 1440;
const a = asFiniteNumber(t.quality);
const o = Math.min(100, Math.max(10, Math.round((a && a > 0 && a <= 1 ? a : .6) * 100)));
const s = path.join(resolvePreferredOpenClawTmpDir(), "logbook");
await mkdir(s, {
recursive: true,
mode: 448
});
await chmod(s, 448);
const c = path.join(s, `logbook-snapshot-${randomUUID()}.jpg`);
try {
await writeFile(c, "", { mode: 384 });
const e = AbortSignal.timeout(LOGBOOK_SNAPSHOT_EXEC_TIMEOUT_MS);
await runExec("screencapture", [
"-x",
"-C",
"-D",
String(n + 1),
"-t",
"jpg",
c
], {
logOutput: false,
signal: e
});
await runExec("sips", [
"--resampleHeightWidthMax",
String(i),
"-s",
"format",
"jpeg",
"-s",
"formatOptions",
String(o),
c
], {
logOutput: false,
signal: e
});
return {
format: "jpeg",
base64: (await readFile(c)).toString("base64")
};
} catch (e) {
return { error: coerceErrorMessage(e) };
} finally {
await rm(c, { force: true });
}
}
//#endregion
export { handleLogbookSnapshot };