UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

44 lines (43 loc) • 1.96 kB
import { mintSystemReminder } from "../reminder-mint.js"; import { restateToldSeat } from "./conversation-segment.js"; export function advisorInstructionFrame(told, mounted, say) { if (mounted && told === undefined) return { body: say("core/event.advisor-tool"), value: "announced" }; if (mounted && told === "withdrawn") return { body: say("core/event.advisor-tool.abbreviated"), value: "announced" }; if (!mounted && told === "announced") return { body: say("core/event.advisor-tool.removed"), value: "withdrawn" }; return undefined; } export function advisorFrameText(prepared) { const owed = prepared.advisorInstruction?.owed; return owed === undefined ? undefined : mintSystemReminder(owed.body, prepared.reminderMark); } export function registerAdvisorReceipt(prepared, text) { if (prepared.advisorInstruction?.owed !== undefined) prepared.frameReceipts.pending.push({ source: "advisor_tool", text, commit: () => settleAdvisorInstruction(prepared) }); } export function settleAdvisorInstruction(prepared) { const seat = prepared.advisorInstruction; const owed = seat?.owed; if (seat === undefined || owed === undefined) return; seat.owed = undefined; if (seat.segment === undefined) return; prepared.announcedListingsRef.advisor = { state: owed.value, segment: seat.segment }; prepared.frameReceipts.listingSnapshotOwed = true; } export function appendAdvisorRestate(prepared) { const seat = prepared.advisorInstruction; if (seat?.mounted !== true) return Promise.resolve(); const full = prepared.engineText("core/event.advisor-tool"); return restateToldSeat(prepared, seat, { body: full, value: "announced", what: "the advisor instructions", carried: seat.owed?.body === full, record: (state, segment) => void (prepared.announcedListingsRef.advisor = { state, segment }), }); }