@sema-agent/core
Version:
Stateless, task-oriented AI agent core
29 lines (28 loc) • 2.06 kB
JavaScript
import { callerKey } from "./caller-text.js";
import { describeRejectedValue } from "./tool-search-setting.js";
import { inlineUntrusted } from "./untrusted-text.js";
import { optionKeys, receiveMembers } from "./own-property-receipt.js";
const OUTPUT_STYLE_KEYS = optionKeys()({ name: 0, turnReminder: 0 });
export const OUTPUT_STYLE_NAME_MAX = 256;
export function renderOutputStyle(seat, say) {
return say("core/event.output-style", { name: inlineUntrusted(seat.name, OUTPUT_STYLE_NAME_MAX), reminder: seat.turnReminder ?? say("core/event.output-style.default-reminder") });
}
export function screenOutputStyle(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 { name, turnReminder } = receiveMembers(seat, { subject: "TaskSpec.outputStyle", unit: "member", moment: "when the seat is read" }, OUTPUT_STYLE_KEYS, (_, extra) => refuse(`carries ${extra.map((k) => callerKey(k)).join(", ")}, which the seat does not read (members: "name", "turnReminder")`));
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 Object.freeze({ name, ...(typeof turnReminder === "string" ? { turnReminder } : {}) });
}