UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

4 lines • 4.63 kB
import{D as parseStrictPositiveInteger,E as parseStrictNonNegativeInteger,a as addTimerTimeoutGraceMs}from"./number-coercion-B3CfI447.mjs";import{n as parseBooleanValue}from"./boolean-Dt_JCqyW.mjs";import{r as defaultRuntime}from"./runtime-DIcLIHcp.mjs";import{o as getAsyncWorkSignal}from"./async-work-scope-DBcxYU4O.mjs";import{t as danger}from"./globals-l9I53ZKA.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import{n as callGatewayFromCli}from"./gateway-rpc-17pTfL8i.mjs";import"./number-runtime-G0nhUVZu.mjs";import{t as normalizeBrowserTimerDelayMs}from"./timer-delay-NKpdftBk.mjs";import{i as BROWSER_ACTION_TRANSPORT_SLACK_MS}from"./act-policy-DofIg8XJ.mjs";import"./concurrency-runtime-A2TPGCdf.mjs";import"./runtime-env-Qb8DG6sI.mjs";import"./gateway-runtime-CCd3DVdi.mjs";import{n as runCommandWithRuntime}from"./cli-utils-Dm67QQ71.mjs";import"./cli-runtime-BLVbyFtb.mjs";import{r as BROWSER_REQUEST_GATEWAY_SCOPES,t as BROWSER_REQUEST_GATEWAY_METHOD}from"./browser-gateway-contract-DUx5Ooh0.mjs";import{i as normalizeBrowserRequestPath}from"./request-policy-bWtyFw-o.mjs";import{n as resolveBrowserProxyTimeouts}from"./browser-proxy-timeouts-HOsRWBqZ.mjs"; //!extensions/browser/src/cli/browser-cli-shared.ts const BROWSER_TAB_REFERENCE_HELP=`Tab reference: suggested target id, tab id, label, raw target id, or unique raw prefix`;function withBrowserActionTimeoutSlack(e){return addTimerTimeoutGraceMs(e??2e4,5e3)??1}async function runBrowserCliCommand(e,t=`runtime`){const run=async()=>{try{await e()}catch(e){const t=getAsyncWorkSignal();if(t?.aborted&&e===t.reason)return;throw e}};const reportError=e=>{defaultRuntime.error(danger(String(e)));defaultRuntime.exit(1)};if(t===`runtime`){await runCommandWithRuntime(defaultRuntime,run,reportError);return}try{await run()}catch(e){reportError(e)}}async function runBrowserCliRequest(e){const action=async()=>{const t=e.profile===null?void 0:e.profile??e.parent.browserProfile;const n=await callBrowserRequest(e.parent,{method:e.method??`POST`,path:e.path,query:resolveBrowserProfileQuery(t,e.query),body:e.body},{timeoutMs:e.timeoutMs});if(e.parent.json)defaultRuntime.writeJson(e.json?e.json(n):n);else if(e.print)e.print(n);else if(e.successMessage!==void 0)defaultRuntime.log(typeof e.successMessage===`function`?e.successMessage(n):e.successMessage)};await runBrowserCliCommand(action,e.parent.json?`runtime`:e.errorPolicy)}function printBrowserJsonResult(e,t){if(!e?.json)return false;defaultRuntime.writeJson(t);return true}function printBrowserList(e,t,n,r){if(e.length===0){defaultRuntime.log(t);return}if(r!==void 0)defaultRuntime.log(r);defaultRuntime.log(e.map(n).join(` `))}function resolveBrowserProfileQuery(e,t){const n={...e?{profile:e}:{},...t};return Object.keys(n).length>0?n:void 0}function normalizeQuery(e){if(!e)return;const t={};for(const[n,r]of Object.entries(e)){if(r===void 0)continue;t[n]=String(r)}return Object.keys(t).length?t:void 0}function parseBrowserPositiveIntegerOption(e,t){const n=parseStrictPositiveInteger(e);if(n===void 0)throw new Error(`${t} must be a positive integer.`);return n}function parseBrowserNonNegativeIntegerOption(e,t){const n=parseStrictNonNegativeInteger(e);if(n===void 0)throw new Error(`${t} must be a non-negative integer.`);return n}async function callBrowserRequest(e,t,n){const r=normalizeQuery(t.query);const i=normalizeBrowserRequestPath(t.path);const a=i===`/snapshot`?r?.labels:i===`/errors`||i===`/requests`?r?.clear:void 0;const o=parseBooleanValue(a,{truthy:[`true`,`1`,`yes`]})===true;const s=t.method===`GET`&&!o&&n?.interruptible!==false?getAsyncWorkSignal():void 0;s?.throwIfAborted();const c=typeof n?.timeoutMs===`number`&&Number.isFinite(n.timeoutMs)?normalizeBrowserTimerDelayMs(n.timeoutMs):typeof e.timeout===`string`?normalizeBrowserTimerDelayMs(parseBrowserPositiveIntegerOption(e.timeout,`--timeout`)):void 0;const l=c===void 0?void 0:resolveBrowserProxyTimeouts(c);const u=await callGatewayFromCli(BROWSER_REQUEST_GATEWAY_METHOD,{...e,timeout:l?String(l.gatewayTimeoutMs):e.timeout},{method:t.method,path:t.path,query:r,body:t.body,timeoutMs:l?.proxyTimeoutMs},{scopes:[...BROWSER_REQUEST_GATEWAY_SCOPES],...s?{signal:s}:{}}).catch(e=>{s?.throwIfAborted();throw e});s?.throwIfAborted();if(u===void 0)throw new Error(`Unexpected browser.request response`);return u}export{printBrowserJsonResult as a,runBrowserCliCommand as c,parseBrowserPositiveIntegerOption as i,runBrowserCliRequest as l,callBrowserRequest as n,printBrowserList as o,parseBrowserNonNegativeIntegerOption as r,resolveBrowserProfileQuery as s,BROWSER_TAB_REFERENCE_HELP as t,withBrowserActionTimeoutSlack as u};