@sema-agent/core
Version:
Stateless, task-oriented AI agent core
23 lines (22 loc) • 1.51 kB
JavaScript
import { steerPriorityOf } from "./task-notification.js";
export const STEER_REPLAY_FACETS = Object.freeze(["text", "trusted", "priority", "actor"]);
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,
};
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 } };
}