UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

30 lines (29 loc) • 1.9 kB
import { describeRejectedValue } from "./tool-search-setting.js"; import { inlineUntrusted } from "./untrusted-text.js"; export const OUTPUT_STYLE_NAME_MAX = 256; const OUTPUT_STYLE_DEFAULT_TURN_REMINDER = "Remember to follow the specific guidelines for this style."; export function renderOutputStyle(name, turnReminder) { return `${inlineUntrusted(name, OUTPUT_STYLE_NAME_MAX)} output style is active. ${turnReminder ?? OUTPUT_STYLE_DEFAULT_TURN_REMINDER}`; } export function resolveOutputStyleFrame(seat) { if (seat === undefined) return undefined; const refuse = (why) => { const e = new Error(`TaskSpec.outputStyle ${why} — refused rather than ignored: a declared style the engine did not state would run as no style.`); e.code = "config.output_style_invalid"; throw e; }; if (seat === null || typeof seat !== "object" || Array.isArray(seat)) return refuse(`must be an object { name, turnReminder? } (got ${describeRejectedValue(seat)})`); const extra = Object.keys(seat).filter((k) => k !== "name" && k !== "turnReminder"); if (extra.length > 0) return refuse(`carries ${extra.map((k) => JSON.stringify(k)).join(", ")}, which the seat does not read (members: "name", "turnReminder")`); const { name, turnReminder } = seat; if (typeof name !== "string" || name.trim() === "") return refuse(`.name must be a non-empty string (got ${describeRejectedValue(name)})`); if (name.length > OUTPUT_STYLE_NAME_MAX) return refuse(`.name is ${name.length} characters, over the ${OUTPUT_STYLE_NAME_MAX}-character bound`); if (turnReminder !== undefined && (typeof turnReminder !== "string" || turnReminder.trim() === "")) return refuse(`.turnReminder must be a non-empty string when present (got ${describeRejectedValue(turnReminder)})`); return renderOutputStyle(name, turnReminder); }