|
| 1 | +export const ACT_MAX_BATCH_ACTIONS = 100; |
| 2 | +export const ACT_MAX_BATCH_DEPTH = 5; |
| 3 | +export const ACT_MAX_CLICK_DELAY_MS = 5_000; |
| 4 | +export const ACT_MAX_WAIT_TIME_MS = 30_000; |
| 5 | + |
| 6 | +const ACT_MIN_TIMEOUT_MS = 500; |
| 7 | +const ACT_MAX_INTERACTION_TIMEOUT_MS = 60_000; |
| 8 | +const ACT_MAX_WAIT_TIMEOUT_MS = 120_000; |
| 9 | +const ACT_DEFAULT_INTERACTION_TIMEOUT_MS = 8_000; |
| 10 | +const ACT_DEFAULT_WAIT_TIMEOUT_MS = 20_000; |
| 11 | + |
| 12 | +export function normalizeActBoundedNonNegativeMs( |
| 13 | + value: number | undefined, |
| 14 | + fieldName: string, |
| 15 | + maxMs: number, |
| 16 | +): number | undefined { |
| 17 | + if (value === undefined) { |
| 18 | + return undefined; |
| 19 | + } |
| 20 | + if (!Number.isFinite(value) || value < 0) { |
| 21 | + throw new Error(`${fieldName} must be >= 0`); |
| 22 | + } |
| 23 | + const normalized = Math.floor(value); |
| 24 | + if (normalized > maxMs) { |
| 25 | + throw new Error(`${fieldName} exceeds maximum of ${maxMs}ms`); |
| 26 | + } |
| 27 | + return normalized; |
| 28 | +} |
| 29 | + |
| 30 | +export function resolveActInteractionTimeoutMs(timeoutMs?: number): number { |
| 31 | + const normalized = |
| 32 | + typeof timeoutMs === "number" && Number.isFinite(timeoutMs) |
| 33 | + ? Math.floor(timeoutMs) |
| 34 | + : ACT_DEFAULT_INTERACTION_TIMEOUT_MS; |
| 35 | + return Math.max(ACT_MIN_TIMEOUT_MS, Math.min(ACT_MAX_INTERACTION_TIMEOUT_MS, normalized)); |
| 36 | +} |
| 37 | + |
| 38 | +export function resolveActWaitTimeoutMs(timeoutMs?: number): number { |
| 39 | + const normalized = |
| 40 | + typeof timeoutMs === "number" && Number.isFinite(timeoutMs) |
| 41 | + ? Math.floor(timeoutMs) |
| 42 | + : ACT_DEFAULT_WAIT_TIMEOUT_MS; |
| 43 | + return Math.max(ACT_MIN_TIMEOUT_MS, Math.min(ACT_MAX_WAIT_TIMEOUT_MS, normalized)); |
| 44 | +} |
0 commit comments