@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 1.85 kB
JavaScript
import { steerPriorityOf } from "./task-notification.js";
export const STEER_REPLAY_FACETS = Object.freeze(["text", "trusted", "priority", "actor", "runOrigin", "source"]);
export function steerSourceOf(x) {
return x.source === "system" ? "system" : "steer";
}
export function inputSourceOf(x, carrier) {
return steerSourceOf(x) === "system" ? "system" : carrier;
}
const FACET_IS_SAME = {
text: (a, b) => a.text === b.text,
trusted: (a, b) => a.trusted === b.trusted,
priority: (a, b) => steerPriorityOf(a) === steerPriorityOf(b),
actor: (a, b) => a.actor?.id === b.actor?.id && a.actor?.hostAsserted === b.actor?.hostAsserted && a.actor?.issuer === b.actor?.issuer,
runOrigin: (a, b) => a.runOrigin === b.runOrigin,
source: (a, b) => steerSourceOf(a) === steerSourceOf(b),
};
export function steerReplayDiffers(held, repeat) {
return STEER_REPLAY_FACETS.filter((facet) => !FACET_IS_SAME[facet](held, repeat));
}
export function steerReplayRefusal(held, repeat, where) {
const differs = steerReplayDiffers(held, repeat);
if (differs.length === 0)
return undefined;
const seat = where.seat === "parked" ? `parked under inputId "${where.inputId}"` : "accepted under this inputId";
const listed = differs.join(", ");
const message = differs.includes("text")
? `a different steering instruction is already ${seat} (this repeat differs in: ${listed}) — re-issue this one with a fresh inputId (an identical payload would have been an idempotent retry)`
: `the same steering instruction is already ${seat}; this repeat differs only in: ${listed}, which cannot change after acceptance — sending it again under another inputId would queue it a second time; to confirm the standing receipt, replay it with its original values`;
return { message, detail: { differs } };
}