UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 1.79 kB
import{s as asFiniteNumber}from"./number-coercion-B3CfI447.mjs";import{n as coerceErrorMessage}from"./error-coercion-DlKnt6w-.mjs";import{o as asRecord}from"./record-coerce-BTbqdJ3-.mjs";import{r as resolvePreferredOpenClawTmpDir}from"./tmp-openclaw-dir-DapBruir.mjs";import{n as runExec}from"./exec-c5tqm8tb.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import"./process-runtime-Co5MR2hI.mjs";import"./error-runtime-DW-sj0iq.mjs";import"./temp-path-B-Bci5oK.mjs";import path from"node:path";import{randomUUID}from"node:crypto";import{chmod,mkdir,readFile,rm,writeFile}from"node:fs/promises"; //!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})}}export{handleLogbookSnapshot};