UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

38 lines (37 loc) • 1.77 kB
import { callUnderView, NO_RETIRED_READING } from "../tool-name-aliases.js"; import { wrapToolPolicy } from "../tool-policy.js"; import { POLICY_NAME_REFUSAL_CODE } from "../retired-tool-name-account.js"; import { UNMATCHED_TOOL_NAMES_CODE } from "../unmatched-tool-names.js"; export function policyUnderRetiredView(p, view) { if (view === NO_RETIRED_READING) return p; const refusals = p.wholeToolRefusals; return { ...wrapToolPolicy(p, (req, signal) => p.check(callUnderView(req, view), signal)), ...(refusals !== undefined ? { wholeToolRefusals: async (signal) => { const judge = await refusals.call(p, signal); return (tool) => judge(callUnderView(tool, view)); }, } : {}), }; } export function retiredContentRefusal(field, entry, successor, layer) { return { message: `tool policy ${field}-list entry "${entry}" is a RETIRED tool name (read as "${successor}") holding a rule content, which was read in "${entry}"'s own grammar when the policy was built and is not read again in "${successor}"'s — so this entry would silently guard nothing. Write the rule with "${successor}".`, problem: { code: POLICY_NAME_REFUSAL_CODE, field, entry, reason: "retired", layer }, }; } export function tellReadAsSuccessor(onError, readings, sessionId) { if (readings.length === 0) return; const e = new Error(`toolPolicy name audit: ${[...new Set(readings)].join(", ")} — a retired tool name in a rule is read as the tool's current name; write the current name.`); e.code = UNMATCHED_TOOL_NAMES_CODE; try { onError?.(e, { phase: "config", sessionId }); } catch { } }