UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

29 lines (28 loc) • 1.63 kB
import { compileAllowList, isRetiredLeftOut } from "./allow-entry.js"; import { accountOfRetired } from "./retired-tool-name-account.js"; const NO_ROSTER = new Set(); function shownValue(v) { if (typeof v === "string") return JSON.stringify(v.length > 40 ? `${v.slice(0, 40)}…` : v); return v === null ? "null" : Array.isArray(v) ? "an array" : typeof v; } function refuseTable(problem) { throw Object.assign(new TypeError(`retiredToolNameAccount: ${problem} — no account is made`), { code: "config.invalid_argument" }); } export function retiredToolNameAccount(table, roster = NO_ROSTER) { if (typeof table !== "object" || table === null) return refuseTable(`the table is an object { field, source, entries }, not ${shownValue(table)}`); const { field, source, entries } = table; if (field !== "deny" && field !== "ask") return refuseTable(`field ${shownValue(field)} is not a restricting list ("deny" or "ask")`); if (typeof source !== "string" || source.trim() === "") return refuseTable(`source ${shownValue(source)} names no table — it is the table's name in the sentence`); if (!Array.isArray(entries)) return refuseTable(`entries are a list of tool names, not ${shownValue(entries)}`); const retired = []; for (const e of compileAllowList(entries, "deny", roster).inert) { if (isRetiredLeftOut(e, roster) && e.guidance !== undefined) retired.push({ field, entry: e.entry, layer: "host_table", guidance: e.guidance, source }); } return retired.length === 0 ? undefined : accountOfRetired("host_table", retired); }