openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
57 lines (56 loc) • 2.25 kB
JavaScript
import { n as sha256Hex } from "./node-crypto-B6yuTjmm.mjs";
//#region src/agents/tools/computer-tool-shared.ts
const COMPUTER_ACT_COMMAND = "computer.act";
const SCREEN_SNAPSHOT_COMMAND = "screen.snapshot";
const COMPUTER_REF_WIDTH = 1280;
const SCREENSHOT_QUALITY = .85;
const COMPUTER_OBSERVATION_ACTIONS = /* @__PURE__ */ new Set([
"screenshot",
"wait",
"list_apps",
"list_windows",
"get_accessibility_tree",
"get_cursor_position",
"get_window_state",
"zoom",
"get_browser_state",
"get_recording_state"
]);
function isComputerObservationAction(e, t) {
return e !== void 0 && (COMPUTER_OBSERVATION_ACTIONS.has(e) || e === "browser_dialog" && t === "inspect");
}
function computerHostKey(e) {
return e.host === "gateway" ? "gateway" : `node:${e.nodeId}`;
}
function computerTargetDetails(e) {
return e.host === "gateway" ? { target: "gateway" } : {
node: e.nodeId,
...e.environmentId ? { environmentId: e.environmentId } : {}
};
}
function computerFrameImageIdentity(e) {
const [t, n] = e.filter((e) => e.type === "image");
if (!t || n) return;
return sha256Hex(JSON.stringify([t.mimeType, t.data]));
}
function invalidateComputerFrame(e) {
if (e.frameToolCallId === void 0 && e.frameImageIdentity === void 0) return false;
e.value += 1;
delete e.frameToolCallId;
delete e.frameImageIdentity;
return true;
}
/**
* Invalidate screenshot coordinates when the final model context no longer
* contains the image produced by the tracked computer tool result.
*/
function invalidateComputerFrameIfMissing(e) {
const t = e.contextEpoch.frameToolCallId;
if (t === void 0 || e.imagesBlocked) return invalidateComputerFrame(e.contextEpoch);
const n = e.messages.findLast((e) => e?.role === "toolResult" && e.toolName === "computer" && e.toolCallId === t);
const r = n ? computerFrameImageIdentity(n.content) : void 0;
if (r !== void 0 && r === e.contextEpoch.frameImageIdentity) return false;
return invalidateComputerFrame(e.contextEpoch);
}
//#endregion
export { computerFrameImageIdentity as a, invalidateComputerFrameIfMissing as c, SCREEN_SNAPSHOT_COMMAND as i, isComputerObservationAction as l, COMPUTER_REF_WIDTH as n, computerHostKey as o, SCREENSHOT_QUALITY as r, computerTargetDetails as s, COMPUTER_ACT_COMMAND as t };