UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

32 lines (31 loc) • 1.24 kB
import { describeRejectedValue } from "./tool-search-setting.js"; export class SchedulerError extends Error { code; cause; constructor(code, message, cause) { super(message); this.code = code; this.cause = cause; this.name = "SchedulerError"; } } const SCOPE_KEYS = ["lane", "bare"]; export function declaresLaneKeys(capabilities) { return typeof capabilities === "object" && capabilities !== null && capabilities.scopeKeys === "lane"; } export function describeScopeKeys(value) { return SCOPE_KEYS.includes(value) ? value : describeRejectedValue(value); } export function readSchedulerDeclaration(env) { const e = env; if (typeof e.schedule !== "function" || typeof e.cancel !== "function" || typeof e.list !== "function") return { kind: "none" }; const capabilities = e.schedulerCapabilities; if (typeof capabilities !== "object" || capabilities === null || capabilities.supported !== true) return { kind: "none" }; const held = capabilities; return { kind: declaresLaneKeys(held) ? "mounted" : "unmoved", seam: env, capabilities: held }; } export function hasScheduler(env) { return readSchedulerDeclaration(env).kind === "mounted"; }