@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 1.54 kB
JavaScript
import { boundInputHashOf } from "./canonical-json.js";
export const BOUND_GRANT_ABSENCES = Object.freeze(["not_bindable", "unreadable"]);
const BOUND_GRANT_ABSENCE_SET = new Set(BOUND_GRANT_ABSENCES);
const isBoundGrantAbsence = (v) => BOUND_GRANT_ABSENCE_SET.has(v);
export function readBoundSkillGrants(raw) {
if (typeof raw !== "object" || raw === null)
return undefined;
const { skill, allowedTools: allowed, disallowedTools: disallowed } = raw;
if (skill !== null && typeof skill !== "string")
return undefined;
const entries = (list) => {
if (!Array.isArray(list))
return undefined;
const copy = Array.from(list);
return copy.every((e) => typeof e === "string") ? copy : undefined;
};
const allowedTools = entries(allowed);
const disallowedTools = entries(disallowed);
return allowedTools !== undefined && disallowedTools !== undefined ? { skill, allowedTools, disallowedTools } : undefined;
}
export const NOT_BINDABLE = Object.freeze({ boundGrantAbsence: "not_bindable" });
export function readBoundBinding(row) {
const digest = row.boundGrantDigest;
if (typeof digest === "string") {
const grants = readBoundSkillGrants(row.boundGrants);
return { boundGrantDigest: digest, ...(grants !== undefined && boundInputHashOf(grants) === digest ? { boundGrants: grants } : {}) };
}
const word = row.boundGrantAbsence;
return { boundGrantAbsence: digest === undefined && isBoundGrantAbsence(word) ? word : "unreadable" };
}