openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
235 lines (234 loc) • 8.7 kB
JavaScript
import { R as resolveTimerTimeoutMs, a as addTimerTimeoutGraceMs, h as clampPositiveTimerTimeoutMs } from "./number-coercion-D6u-4YD8.mjs";
import { r as asNullableRecord } from "./record-coerce-CVPuDqcc.mjs";
import "./string-coerce-runtime-BwAZZDf5.mjs";
import { d as DEFAULT_BROWSER_SCREENSHOT_TIMEOUT_MS, f as DEFAULT_BROWSER_SNAPSHOT_TIMEOUT_MS, s as DEFAULT_BROWSER_DOWNLOAD_TIMEOUT_MS } from "./constants-ClfCwK7f.mjs";
import "./number-runtime-W4chuk8B.mjs";
import { i as BROWSER_ACTION_TRANSPORT_SLACK_MS, l as resolveBrowserActRequestTimeoutMs, u as resolveBrowserNavigationTimeoutMs } from "./act-policy-fWdzY2YP.mjs";
import { n as postBrowserJson, r as requestBrowserJson, t as browserClientTimeout } from "./client-request-DsI6iek3.mjs";
//#region extensions/browser/src/browser/client-actions.ts
function resolveBrowserOperationRequestTimeoutMs(e) {
const t = clampPositiveTimerTimeoutMs(e) ?? 12e4;
return addTimerTimeoutGraceMs(t, 5e3) ?? 1;
}
function projectBrowserOptions(e, t) {
return Object.fromEntries(t.map((t) => [t, e[t]]));
}
async function browserNavigate(e, t) {
const n = resolveBrowserNavigationTimeoutMs(t.timeoutMs);
return await postBrowserJson(e, "/navigate", {
url: t.url,
targetId: t.targetId,
timeoutMs: n
}, resolveBrowserOperationRequestTimeoutMs(n), t);
}
function createBrowserOperation(e, t, n) {
return async (r, i) => await postBrowserJson(r, e, projectBrowserOptions(i, t), n === "local" ? browserClientTimeout(r, void 0, resolveBrowserOperationRequestTimeoutMs(i.timeoutMs)) : resolveBrowserOperationRequestTimeoutMs(i.timeoutMs), i);
}
const browserArmDialog = createBrowserOperation("/hooks/dialog", [
"accept",
"promptText",
"dialogId",
"targetId",
"timeoutMs"
], "local");
const browserArmFileChooser = createBrowserOperation("/hooks/file-chooser", [
"paths",
"ref",
"inputRef",
"element",
"targetId",
"timeoutMs"
], "local");
const browserWaitForDownload = createBrowserOperation("/wait/download", [
"targetId",
"path",
"timeoutMs"
], "all");
const browserDownload = createBrowserOperation("/download", [
"targetId",
"ref",
"path",
"timeoutMs"
], "all");
async function browserAct(e, t, n) {
return await postBrowserJson(e, "/act", t, resolveTimerTimeoutMs(n?.timeoutMs, resolveBrowserActRequestTimeoutMs(t)), n);
}
async function browserScreenshotAction(e, t) {
const n = clampPositiveTimerTimeoutMs(t.timeoutMs) ?? 2e4;
return await postBrowserJson(e, "/screenshot", {
...projectBrowserOptions(t, [
"targetId",
"fullPage",
"ref",
"element",
"type",
"labels"
]),
timeoutMs: n
}, n, t);
}
function buildQuery(e) {
return Object.fromEntries(Object.entries(e).filter(([, e]) => typeof e === "boolean" || typeof e === "string" && e.length > 0));
}
function readBrowserPageJson(e, t, n, r) {
return requestBrowserJson(e, t, {
query: r,
profile: n.profile,
timeoutMs: browserClientTimeout(e, void 0, 2e4),
signal: n.signal
});
}
async function browserConsoleMessages(e, t = {}) {
return await readBrowserPageJson(e, "/console", t, buildQuery({
level: t.level,
targetId: t.targetId
}));
}
async function browserRequests(e, t = {}) {
return await readBrowserPageJson(e, "/requests", t, buildQuery({
filter: t.filter,
clear: t.clear,
targetId: t.targetId
}));
}
async function browserErrors(e, t = {}) {
return await readBrowserPageJson(e, "/errors", t, buildQuery({
clear: t.clear,
targetId: t.targetId
}));
}
/** Read bounded visible text without executing page-supplied code. */
async function browserPageText(e, t) {
return await readBrowserPageJson(e, "/text", t, {
...buildQuery({
targetId: t.targetId,
selector: t.selector
}),
maxChars: t.maxChars
});
}
async function browserEmulateSetting(e, t) {
return await postBrowserJson(e, `/set/${t.setting}`, t.body, browserClientTimeout(e, void 0, 2e4), t);
}
async function browserPdfSave(e, t = {}) {
return await postBrowserJson(e, "/pdf", { targetId: t.targetId }, browserClientTimeout(e, void 0, 2e4), t);
}
//#endregion
//#region extensions/browser/src/browser/client.ts
const BROWSER_STATUS_REQUEST_TIMEOUT_MS = 7500;
const BROWSER_DOCTOR_REQUEST_TIMEOUT_MS = 7500;
const BROWSER_DEEP_DOCTOR_REQUEST_TIMEOUT_MS = 1e4;
async function sendProfilePost(e, t, n) {
await requestBrowserJson(e, t, {
profile: n?.profile,
method: "POST",
timeoutMs: browserClientTimeout(e, n?.timeoutMs, 15e3),
signal: n?.signal
});
}
async function browserStatus(e, t) {
return await requestBrowserJson(e, "/", {
profile: t?.profile,
timeoutMs: browserClientTimeout(e, t?.timeoutMs, BROWSER_STATUS_REQUEST_TIMEOUT_MS),
signal: t?.signal
});
}
async function browserDoctor(e, t) {
return await requestBrowserJson(e, "/doctor", {
profile: t?.profile,
query: t?.deep ? { deep: "true" } : void 0,
timeoutMs: browserClientTimeout(e, void 0, t?.deep ? BROWSER_DEEP_DOCTOR_REQUEST_TIMEOUT_MS : BROWSER_DOCTOR_REQUEST_TIMEOUT_MS),
signal: t?.signal
});
}
async function browserProfiles(e, t) {
return (await requestBrowserJson(e, "/profiles", {
timeoutMs: browserClientTimeout(e, t?.timeoutMs, 3e3),
signal: t?.signal
})).profiles ?? [];
}
async function browserSystemProfiles(e, t) {
return (await requestBrowserJson(e, "/system-profiles", {
timeoutMs: browserClientTimeout(e, t?.timeoutMs, 3e3),
signal: t?.signal
})).systemProfiles ?? [];
}
async function browserImportProfile(e, t) {
return await postBrowserJson(e, "/profiles/import", {
browser: t.browser,
systemProfile: t.systemProfile,
into: t.into,
domains: t.domains
}, 12e4, { signal: t.signal });
}
async function browserStart(e, t) {
await sendProfilePost(e, "/start", t);
}
async function browserStop(e, t) {
await sendProfilePost(e, "/stop", t);
}
function normalizeBrowserTabsResult(e) {
const t = asNullableRecord(e);
if (t?.running === false) return {
running: false,
tabs: []
};
return {
running: true,
tabs: Array.isArray(t?.tabs) ? t.tabs : []
};
}
async function browserTabs(e, t) {
return normalizeBrowserTabsResult(await requestBrowserJson(e, "/tabs", {
profile: t?.profile,
timeoutMs: browserClientTimeout(e, t?.timeoutMs, 3e3),
signal: t?.signal
}));
}
async function browserOpenTab(e, t, n) {
const r = n?.timeoutMs === void 0 ? void 0 : resolveBrowserNavigationTimeoutMs(n.timeoutMs);
return await postBrowserJson(e, "/tabs/open", {
url: t,
...n?.label ? { label: n.label } : {},
...n?.managedOnly ? { managedOnly: true } : {},
...r === void 0 ? {} : { timeoutMs: r }
}, Math.max(clampPositiveTimerTimeoutMs(n?.requestTimeoutMs) ?? 0, resolveBrowserOperationRequestTimeoutMs(r ?? 3e4)), n);
}
async function browserFocusTab(e, t, n) {
return await postBrowserJson(e, "/tabs/focus", { targetId: t }, browserClientTimeout(e, n?.timeoutMs, 5e3), n);
}
async function browserCloseTab(e, t, n) {
const r = `/tabs/${encodeURIComponent(t)}`;
return await requestBrowserJson(e, r, {
profile: n?.profile,
method: "DELETE",
timeoutMs: browserClientTimeout(e, n?.timeoutMs, 5e3),
signal: n?.signal
});
}
async function browserSnapshot(e, t) {
const n = clampPositiveTimerTimeoutMs(t.timeoutMs) ?? 2e4;
return await requestBrowserJson(e, "/snapshot", {
query: {
...t.format ? { format: t.format } : {},
...t.targetId ? { targetId: t.targetId } : {},
...typeof t.limit === "number" ? { limit: t.limit } : {},
...typeof t.maxChars === "number" && Number.isFinite(t.maxChars) ? { maxChars: t.maxChars } : {},
...t.refs === "aria" || t.refs === "role" ? { refs: t.refs } : {},
...typeof t.interactive === "boolean" ? { interactive: t.interactive } : {},
...typeof t.compact === "boolean" ? { compact: t.compact } : {},
...typeof t.depth === "number" && Number.isFinite(t.depth) ? { depth: t.depth } : {},
...t.selector?.trim() ? { selector: t.selector.trim() } : {},
...t.frame?.trim() ? { frame: t.frame.trim() } : {},
...t.labels === true ? { labels: "1" } : {},
...t.urls === true ? { urls: "1" } : {},
...t.mode ? { mode: t.mode } : {},
timeoutMs: n
},
profile: t.profile,
timeoutMs: n,
signal: t.signal
});
}
//#endregion
export { browserRequests as C, browserPdfSave as S, browserWaitForDownload as T, browserDownload as _, browserOpenTab as a, browserNavigate as b, browserStart as c, browserSystemProfiles as d, browserTabs as f, browserConsoleMessages as g, browserArmFileChooser as h, browserImportProfile as i, browserStatus as l, browserArmDialog as m, browserDoctor as n, browserProfiles as o, browserAct as p, browserFocusTab as r, browserSnapshot as s, browserCloseTab as t, browserStop as u, browserEmulateSetting as v, browserScreenshotAction as w, browserPageText as x, browserErrors as y };