UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

33 lines (32 loc) • 1.84 kB
const HANDS_BAND_MEMBERS = { bashReadonlyAllow: { takes: "a list of command-name strings", ok: (v) => Array.isArray(v) && v.every((c) => typeof c === "string") }, commitCoAuthor: { takes: "a string or false", ok: (v) => typeof v === "string" || v === false }, readImageDownsampler: { takes: "a function or false", ok: (v) => typeof v === "function" || v === false }, beforeWrite: { takes: "a function", ok: (v) => typeof v === "function" }, autoBackgroundOnTimeout: { takes: "a boolean", ok: (v) => typeof v === "boolean" }, }; const kindOf = (v) => (v === null ? "null" : Array.isArray(v) ? "an array" : typeof v); export function screenHandsBandOptions(value) { if (value === undefined) return; const refuse = (field, problem) => { const e = new Error(`${field} ${problem} — a hands band setting the engine cannot read is refused rather than ignored.`); e.code = "config.invalid_argument"; e.detail = { field }; throw e; }; const proto = typeof value === "object" && value !== null ? Object.getPrototypeOf(value) : undefined; if (typeof value !== "object" || value === null || Array.isArray(value) || (proto !== Object.prototype && proto !== null)) { refuse("RunnerDeps.hands", `must be a plain record of hands band settings (got ${kindOf(value)})`); } for (const key of Object.keys(value)) { const v = value[key]; if (v === undefined) continue; if (!Object.hasOwn(HANDS_BAND_MEMBERS, key)) refuse(`RunnerDeps.hands.${key}`, `is not a hands band setting (the settings: ${Object.keys(HANDS_BAND_MEMBERS).join(", ")})`); const member = HANDS_BAND_MEMBERS[key]; if (!member.ok(v)) refuse(`RunnerDeps.hands.${key}`, `must be ${member.takes} (got ${kindOf(v)})`); } }