UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

33 lines (32 loc) • 1.71 kB
import { INLINE_TRUNCATION_MARK, inlineUntrusted } from "./untrusted-text.js"; import { callerText } from "./caller-text.js"; export const TOOL_AXES_SURFACES = { mcp: { key: "tool", declarer: "MCP server", refused: "the engine cannot read", standing: "A per-tool safety-axis declaration is the caller's trust root for the approval gate" }, a2a: { key: "skill", declarer: "A2A peer", nameMax: 32, refused: "the engine does not take", standing: "A declaration on an A2A peer only raises the question its calls ask", afterLowering: 'The deployment sets what calls to a peer ask ("boundary").', }, }; export function isToolAxesSurface(at) { return typeof at === "string" && Object.hasOwn(TOOL_AXES_SURFACES, at); } export const toolAxesSurfaceList = () => Object.keys(TOOL_AXES_SURFACES).map((s) => JSON.stringify(s)).join(" | "); const DECLARER_NAME_SHOWN = 80; const DECLARER_NAME_READ = 4096; export const declarerNameOf = (name) => { if (typeof name !== "string") return callerText(name); if (name.length <= DECLARER_NAME_READ) return inlineUntrusted(JSON.stringify(name), DECLARER_NAME_SHOWN); const last = name.charCodeAt(DECLARER_NAME_READ - 1); const read = name.slice(0, last >= 0xd800 && last <= 0xdbff ? DECLARER_NAME_READ - 1 : DECLARER_NAME_READ); const shown = inlineUntrusted(JSON.stringify(read).slice(0, -1), DECLARER_NAME_SHOWN); return shown.endsWith(INLINE_TRUNCATION_MARK) ? shown : `${shown}${INLINE_TRUNCATION_MARK}`; }; export function declarationSubject(at, declarer) { return `${TOOL_AXES_SURFACES[at].declarer}${declarer === undefined ? "" : ` ${declarerNameOf(declarer)}`}`; }