@sema-agent/core
Version:
Stateless, task-oriented AI agent core
38 lines (37 loc) • 2.23 kB
JavaScript
import { isBlankInput } from "./input-author.js";
import { sanitizeUntrustedText, sentinelTagRefusal } from "./untrusted-text.js";
export function writtenFeedback(feedback) {
const trimmed = feedback?.trim();
return trimmed === undefined || isBlankInput(trimmed) ? undefined : trimmed;
}
export function unfitFeedbackOf(words, arm) {
if (words === undefined)
return undefined;
if (!arm.allowed)
return "on_a_deny";
if (!arm.byPerson)
return "by_a_machine";
return sanitizeUntrustedText(words) !== words ? "reminder_tag" : undefined;
}
export function liveWordsOf(feedback, answer) {
const who = `the approver for "${answer.toolName}" attached \`feedback\``;
if (feedback !== undefined && typeof feedback !== "string") {
return { kind: "refused", message: `${who} that is not a plain string (got ${feedback === null ? "null" : typeof feedback}) — the approving person's words are plain text; denied fail-closed` };
}
const words = writtenFeedback(feedback);
if (words === undefined)
return { kind: "words", words };
if (!answer.hasCarrier) {
return { kind: "refused", message: `${who} on a seat that has no lane to deliver words to the model — denied fail-closed (the words ride an approval card's allow through the run's own approver seat)` };
}
switch (unfitFeedbackOf(words, answer)) {
case undefined:
return { kind: "words", words };
case "on_a_deny":
return { kind: "refused", message: `${who} to a refusal — feedback is the approving person's words on an allow (a refusal's words are \`reason\`); denied fail-closed rather than dropping them silently` };
case "by_a_machine":
return { kind: "refused", message: `${who} to an answer no person gave (settledBy "policy", or an approver the deployment declared a policy) — feedback is delivered to the model as the user's own words, which only a person's answer can be; denied fail-closed rather than attributing a machine's text to the user` };
case "reminder_tag":
return { kind: "refused", message: `${who}: ${sentinelTagRefusal("approval allow feedback")}; denied fail-closed` };
}
}