UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

32 lines (31 loc) • 970 B
export class SchedulerError extends Error { code; cause; constructor(code, message, cause) { super(message); this.code = code; this.cause = cause; this.name = "SchedulerError"; } } export function hasScheduler(env) { const e = env; return (typeof e.schedule === "function" && typeof e.cancel === "function" && typeof e.list === "function" && typeof e.schedulerCapabilities === "object" && e.schedulerCapabilities !== null && e.schedulerCapabilities.supported === true); } const CRON_EXPR_RE = /^[0-9*/,\-\s]+$/; export function isValidCronExpr(expr) { if (typeof expr !== "string") return false; const trimmed = expr.trim(); if (trimmed.length === 0 || trimmed.length > 100) return false; if (!CRON_EXPR_RE.test(trimmed)) return false; const fields = trimmed.split(/\s+/); return fields.length === 5 || fields.length === 6; }