UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

61 lines (60 loc) • 2.88 kB
import { l as normalizeOptionalString } from "./string-coerce-CCIiB4H7.mjs"; import { r as defaultRuntime } from "./runtime-B-SLYP-m.mjs"; import { p as shortenHomePath } from "./utils-C8YECn2Q.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./text-utility-runtime-Ds8jsG0J.mjs"; import "./runtime-env-D-Pa5lD6.mjs"; import { i as parseBrowserPositiveIntegerOption, l as runBrowserCliRequest, t as BROWSER_TAB_REFERENCE_HELP, u as withBrowserActionTimeoutSlack } from "./browser-cli-shared-BEDAHNiM.mjs"; //#region extensions/browser/src/cli/browser-cli-actions-observe.ts const BROWSER_CONSOLE_LEVELS = [ "error", "warn", "info" ]; function parseBrowserConsoleLevel(e) { const t = BROWSER_CONSOLE_LEVELS.find((t) => t === e); if (!t) throw new Error(`--level must be ${BROWSER_CONSOLE_LEVELS.slice(0, -1).join(", ")}, or ${BROWSER_CONSOLE_LEVELS.at(-1)}.`); return t; } function registerBrowserActionObserveCommands(e, t) { e.command("console").description("Get recent console messages").option("--level <level>", `Filter by level (${BROWSER_CONSOLE_LEVELS.join(", ")})`, parseBrowserConsoleLevel).option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (e, n) => { await runBrowserCliRequest({ parent: t(n), method: "GET", path: "/console", query: { level: normalizeOptionalString(e.level), targetId: normalizeOptionalString(e.targetId) }, print: (e) => defaultRuntime.writeJson(e.messages) }); }); e.command("pdf").description("Save page as PDF").option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).action(async (e, n) => { await runBrowserCliRequest({ parent: t(n), path: "/pdf", body: { targetId: normalizeOptionalString(e.targetId) }, successMessage: (e) => `PDF: ${shortenHomePath(e.path)}` }); }); e.command("responsebody").description("Wait for a network response and return its body").argument("<url>", "URL (exact, substring, or glob like **/api)").option("--target-id <id>", BROWSER_TAB_REFERENCE_HELP).option("--timeout-ms <ms>", "How long to wait for the complete response body (default: 20000)", (e) => parseBrowserPositiveIntegerOption(e, "--timeout-ms")).option("--max-chars <n>", "Max body chars to return (default: 200000)", (e) => parseBrowserPositiveIntegerOption(e, "--max-chars")).action(async (e, n, r) => { const i = n.timeoutMs; await runBrowserCliRequest({ parent: t(r), path: "/response/body", body: { url: e, targetId: normalizeOptionalString(n.targetId), timeoutMs: i, maxChars: n.maxChars }, timeoutMs: withBrowserActionTimeoutSlack(i), print: (e) => { defaultRuntime.log(e.response.body); if (e.response.truncated === true) defaultRuntime.error("Warning: response body is a truncated prefix. Use --json to inspect response metadata."); } }); }); } //#endregion export { registerBrowserActionObserveCommands };