openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 5.97 kB
JavaScript
import{R as resolveTimerTimeoutMs,T as parseStrictInteger,a as addTimerTimeoutGraceMs,h as clampPositiveTimerTimeoutMs,n as MAX_TIMER_TIMEOUT_MS}from"./number-coercion-B3CfI447.mjs";import{l as isRecord}from"./record-coerce-BTbqdJ3-.mjs";import"./string-coerce-runtime-BYDH9Quw.mjs";import{a as DEFAULT_BROWSER_ACTION_TIMEOUT_MS}from"./constants-zheKkSzJ.mjs";import{t as BROWSER_ACT_KIND_FACTS}from"./act-kinds-C3a0vP37.mjs";import"./number-runtime-G0nhUVZu.mjs";import{t as normalizeBrowserTimerDelayMs}from"./timer-delay-NKpdftBk.mjs";
//!extensions/browser/src/browser/act-policy.ts
const ACT_MAX_CLICK_DELAY_MS=5e3;const ACT_MAX_WAIT_TIME_MS=3e4;const ACT_MAX_VIEWPORT_DIMENSION=8192;const ACT_MIN_TIMEOUT_MS=500;const ACT_MAX_INTERACTION_TIMEOUT_MS=6e4;const ACT_MAX_WAIT_TIMEOUT_MS=12e4;const ACT_DEFAULT_INTERACTION_TIMEOUT_MS=8e3;const ACT_DEFAULT_WAIT_TIMEOUT_MS=2e4;const BROWSER_ACTION_TRANSPORT_SLACK_MS=5e3;const BROWSER_ACTION_NAVIGATION_GRACE_MS=250;const EXISTING_SESSION_NAVIGATION_RECHECK_DELAYS_MS=[0,250,500];const EXISTING_SESSION_NAVIGATION_GRACE_MS=EXISTING_SESSION_NAVIGATION_RECHECK_DELAYS_MS.reduce((e,t)=>e+t,0)+(EXISTING_SESSION_NAVIGATION_RECHECK_DELAYS_MS.at(-1)??0);function resolveBrowserNavigationTimeoutMs(e){return Math.min(12e4,resolveTimerTimeoutMs(e,2e4,1e3))}function normalizeActBoundedNonNegativeMs(e,t,n){if(e===void 0)return;if(!Number.isFinite(e)||e<0)throw new Error(`${t} must be >= 0`);const r=Math.floor(e);if(r>n)throw new Error(`${t} exceeds maximum of ${n}ms`);return r}function resolveActInteractionTimeoutMs(e){return Math.min(ACT_MAX_INTERACTION_TIMEOUT_MS,resolveTimerTimeoutMs(e,ACT_DEFAULT_INTERACTION_TIMEOUT_MS,ACT_MIN_TIMEOUT_MS))}function resolveActWaitTimeoutMs(e){return Math.min(ACT_MAX_WAIT_TIMEOUT_MS,resolveTimerTimeoutMs(e,ACT_DEFAULT_WAIT_TIMEOUT_MS,ACT_MIN_TIMEOUT_MS))}function parseTimerInteger(e){return typeof e===`number`&&Number.isFinite(e)?Math.floor(e):parseStrictInteger(e)}function resolveNonNegativeTimerMs(e){const t=parseTimerInteger(e);return t!==void 0&&t>=0?resolveTimerTimeoutMs(t,0,0):0}function addExecutionBudgetMs(e,t){return Math.min(MAX_TIMER_TIMEOUT_MS,e+t)}function multiplyExecutionBudgetMs(e,t){return Math.min(MAX_TIMER_TIMEOUT_MS,e*t)}function resolveInteractionTimeoutMs(e){return resolveActInteractionTimeoutMs(parseTimerInteger(`timeoutMs`in e?e.timeoutMs:void 0))}function addNavigationGraceMs(e,t=1){return addExecutionBudgetMs(e,multiplyExecutionBudgetMs(250,t))}function resolveLeafExecutionBudgetMs(e){switch(e.kind){case`click`:{const t=resolveInteractionTimeoutMs(e);const n=Math.min(ACT_MAX_CLICK_DELAY_MS,resolveNonNegativeTimerMs(e.delayMs));return addNavigationGraceMs(n>0?addExecutionBudgetMs(t*2,n):t)}case`clickCoords`:{const t=Math.min(ACT_MAX_CLICK_DELAY_MS,resolveNonNegativeTimerMs(e.delayMs));return addNavigationGraceMs(addExecutionBudgetMs(clampPositiveTimerTimeoutMs(parseTimerInteger(e.timeoutMs))??0,multiplyExecutionBudgetMs(t,e.doubleClick?3:1)))}case`type`:{const t=(e.slowly?2:1)+(e.submit?1:0);return addNavigationGraceMs(multiplyExecutionBudgetMs(resolveInteractionTimeoutMs(e),t))}case`press`:return addNavigationGraceMs(resolveNonNegativeTimerMs(e.delayMs));case`insertText`:return addNavigationGraceMs(0);case`fill`:{const t=(Array.isArray(e.fields)?e.fields:[]).filter(e=>Boolean(e)&&typeof e===`object`&&typeof e.ref===`string`&&Boolean(e.ref.trim())).length;return addNavigationGraceMs(multiplyExecutionBudgetMs(resolveInteractionTimeoutMs(e),t),t)}case`evaluate`:case`scrollIntoView`:return addNavigationGraceMs(resolveActWaitTimeoutMs(parseTimerInteger(e.timeoutMs)));case`hover`:case`drag`:case`select`:return addNavigationGraceMs(resolveInteractionTimeoutMs(e));case`resize`:case`close`:return 0}return 0}function resolveExecutionBudgetMs(e){if(e.kind===`batch`)return(Array.isArray(e.actions)?e.actions.filter(isRecord):[]).reduce((e,t)=>addExecutionBudgetMs(e,resolveExecutionBudgetMs(t)),0);if(e.kind!==`wait`)return resolveLeafExecutionBudgetMs(e);const t=[Boolean(e.text),Boolean(e.textGone),typeof e.selector===`string`&&Boolean(e.selector.trim()),typeof e.url===`string`&&Boolean(e.url.trim()),Boolean(e.loadState),typeof e.fn===`string`&&Boolean(e.fn.trim())].filter(Boolean).length;const n=resolveActWaitTimeoutMs(parseTimerInteger(e.timeoutMs));return addExecutionBudgetMs(resolveNonNegativeTimerMs(e.timeMs),multiplyExecutionBudgetMs(n,t))}function resolveExistingSessionActTimeouts(e){const t=BROWSER_ACT_KIND_FACTS[e.kind]?.existingSessionTimeout&&`timeoutMs`in e?parseTimerInteger(e.timeoutMs):void 0;const n=normalizeBrowserTimerDelayMs(t??6e4);let r=n;if(e.kind===`wait`){const t=resolveNonNegativeTimerMs(e.timeMs);r=[e.text,e.textGone,e.selector,e.url,e.loadState,e.fn].some(e=>typeof e===`string`&&Boolean(e.trim()))?addExecutionBudgetMs(t,Math.max(250,n)):Math.max(t,n)}const i=e.kind===`resize`||e.kind===`close`?0:addExecutionBudgetMs(n,EXISTING_SESSION_NAVIGATION_GRACE_MS);return{timeoutMs:n,bodyTimeoutMs:e.kind===`wait`?void 0:r,verificationTimeoutMs:i,requestTimeoutMs:addExecutionBudgetMs(r,i)}}function resolveBrowserActExecutionBudgetMs(e){const t=resolveExecutionBudgetMs(e);if(e.kind===`wait`)return t;return(e.kind===`batch`?void 0:clampPositiveTimerTimeoutMs(parseTimerInteger(`timeoutMs`in e?e.timeoutMs:void 0)))===void 0?Math.max(DEFAULT_BROWSER_ACTION_TIMEOUT_MS,t):t}function resolveBrowserActRequestTimeoutMs(e){const t=e.kind===`batch`?0:resolveExistingSessionActTimeouts(e).requestTimeoutMs;return addTimerTimeoutGraceMs(Math.max(resolveBrowserActExecutionBudgetMs(e),t),5e3)??1}export{EXISTING_SESSION_NAVIGATION_RECHECK_DELAYS_MS as a,resolveActWaitTimeoutMs as c,resolveExistingSessionActTimeouts as d,BROWSER_ACTION_TRANSPORT_SLACK_MS as i,resolveBrowserActRequestTimeoutMs as l,ACT_MAX_VIEWPORT_DIMENSION as n,normalizeActBoundedNonNegativeMs as o,ACT_MAX_WAIT_TIME_MS as r,resolveActInteractionTimeoutMs as s,ACT_MAX_CLICK_DELAY_MS as t,resolveBrowserNavigationTimeoutMs as u};