@sema-agent/core
Version:
Stateless, task-oriented AI agent core
45 lines (44 loc) • 2.03 kB
JavaScript
import { assertRestoreGatedToolsValue } from "./tool-model-gate.js";
function toolFaceListRefusal(message, reason) {
const e = new Error(message);
e.code = "config.tool_face_control";
e.detail = { reason };
return e;
}
function assertWholeFaceSwitchValue(value) {
if (value === undefined || typeof value === "boolean")
return;
throw toolFaceListRefusal(`TaskSpec.excludeAllTools must be a boolean or absent (got ${value === null ? "null" : typeof value}) — a garbage switch must refuse loudly, never be read as "off" (every tool mounted). Give \`true\` to unmount the whole tool face, or leave it out.`, "not_a_boolean");
}
function toolNameList(value, seat) {
if (value === undefined)
return undefined;
if (!Array.isArray(value)) {
throw toolFaceListRefusal(`TaskSpec.${seat} must be an array of tool names or absent (got ${value === null ? "null" : typeof value}) — a garbage list must refuse loudly, never be read as "no ${seat}".`, "not_a_list");
}
const entries = value;
const names = [];
for (const entry of entries) {
if (typeof entry !== "string") {
throw toolFaceListRefusal(`TaskSpec.${seat} entries must be strings (got ${entry === null ? "null" : typeof entry}).`, "not_a_string");
}
names.push(entry);
}
return Object.freeze(names);
}
export function readToolFaceLists(spec) {
const restore = spec.restoreGatedTools;
assertRestoreGatedToolsValue(restore);
const allow = toolNameList(spec.allowTools, "allowTools");
const exclude = toolNameList(spec.excludeTools, "excludeTools");
const defer = toolNameList(spec.deferTools, "deferTools");
const alwaysLoad = toolNameList(spec.alwaysLoadTools, "alwaysLoadTools");
assertWholeFaceSwitchValue(spec.excludeAllTools);
return {
allow,
exclude,
defer,
alwaysLoad,
restoreGated: restore === true ? true : restore !== undefined ? Object.freeze([...restore]) : undefined,
};
}