@sema-agent/core
Version:
Stateless, task-oriented AI agent core
27 lines (26 loc) • 1.53 kB
JavaScript
import { inlineUntrusted } from "../core/untrusted-text.js";
import { redactThenCut } from "../core/untrusted-egress.js";
export function handbackNoRulingNote(cause, attribution) {
const subject = attribution !== undefined ? `${attribution.modelUsed} (the safety classifier)` : "The safety classifier";
const what = cause === "parse_error" ? "replied without a verdict" : `was unavailable${cause === "timeout" ? " (timed out)" : ""}`;
return `Note: ${subject} ${what} when reviewing this subagent's work. Please carefully verify the subagent's actions and output before acting on them.`;
}
export const HANDBACK_REVIEW_SILENT = Object.freeze({});
export const sentenceBody = (reason) => reason.replace(/\.\s*$/, "");
const REVIEW_SUBJECT_MAX = 80;
export function reviewSubjectOf(...candidates) {
const raw = candidates.find((v) => typeof v === "string" && v.trim() !== "");
return raw === undefined ? undefined : inlineUntrusted(redactThenCut(raw.trim(), REVIEW_SUBJECT_MAX), REVIEW_SUBJECT_MAX);
}
export const handbackLeadOf = (review) => review.warning ?? review.note;
export function withHandbackLead(review, result) {
const lead = handbackLeadOf(review);
if (lead === undefined)
return result;
return result ? `${lead}\n\n${result}` : lead;
}
export function unreviewedOf(spawn, handback) {
if (spawn === undefined && handback === undefined)
return undefined;
return { ...(spawn !== undefined ? { spawn } : {}), ...(handback !== undefined ? { handback } : {}) };
}