mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-14 06:33:09 -06:00
68771ebdfe
Run script payloads through the shared headless code-mode executor with payload-grade budgets and success-only trigger.state persistence. Reuse cron delivery, wake, pacing, and dangerous trigger-gate contracts for notify, wake, and nextCheck results.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { CronPayload } from "./types.js";
|
|
|
|
export const DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS = 300;
|
|
export const MAX_CRON_SCRIPT_TIMEOUT_SECONDS = 900;
|
|
export const DEFAULT_CRON_SCRIPT_TOOL_BUDGET = 50;
|
|
export const MAX_CRON_SCRIPT_TOOL_BUDGET = 200;
|
|
|
|
function clampPositiveInteger(value: unknown, fallback: number, maximum: number): number {
|
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
return fallback;
|
|
}
|
|
return Math.min(maximum, Math.max(1, Math.floor(value)));
|
|
}
|
|
|
|
/** Applies the persisted defaults and hard caps for unattended script payloads. */
|
|
export function normalizeCronScriptPayload(
|
|
payload: Extract<CronPayload, { kind: "script" }>,
|
|
): Extract<CronPayload, { kind: "script" }> {
|
|
return {
|
|
...payload,
|
|
script: payload.script.trim(),
|
|
timeoutSeconds: clampPositiveInteger(
|
|
payload.timeoutSeconds,
|
|
DEFAULT_CRON_SCRIPT_TIMEOUT_SECONDS,
|
|
MAX_CRON_SCRIPT_TIMEOUT_SECONDS,
|
|
),
|
|
toolBudget: clampPositiveInteger(
|
|
payload.toolBudget,
|
|
DEFAULT_CRON_SCRIPT_TOOL_BUDGET,
|
|
MAX_CRON_SCRIPT_TOOL_BUDGET,
|
|
),
|
|
};
|
|
}
|