UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

45 lines (44 loc) • 2.12 kB
import { legNoticeTaskId } from "../mods/stations.js"; import { deliverEngineNotice } from "../types.js"; export function haltConsumed(c) { return c?.turnCut === "halt" || c?.boundaryStop?.sources.includes("halt") === true; } export function endingCutConsumed(c) { return c?.turnCut === "halt" || c?.turnCut === "extension"; } export function turnAbortedByOf(c) { return c?.turnCut === "extension" ? c.turnCutBy : undefined; } export function discloseUnconsumedEndings(input) { let minted = false; if (input.accepted && !haltConsumed(input.consumption)) { deliverEngineNotice(input.onNotice, { code: "task.halt_unconsumed", message: "a user halt was accepted, but the run ended for its own reason before the halt stopped or cut anything: " + "no turn was settled as its cut and no boundary stopped for it — the run's own ending stands, and the result " + "will not report this halt as a stop by the user.", detail: { source: "halt", sessionId: input.sessionId, runId: input.runId, ...legNoticeTaskId(input) }, }); minted = true; } for (const cut of input.consumption?.unconsumedCuts ?? []) { if (cut.source !== "extension") continue; deliverEngineNotice(input.onNotice, { code: "mods.turn_abort_unconsumed", message: `the extension "${cut.by ?? ""}" asked to end model turn ${cut.turn ?? "?"} and the cut was accepted, but nothing ` + "settled that turn as its cut: the turn had already ended on its own outcome, or the run's own ending won — that " + "outcome stands, and the result will not report that cut.", detail: { source: "extension", ...(cut.by !== undefined ? { extension: cut.by } : {}), ...(cut.turn !== undefined ? { turn: cut.turn } : {}), sessionId: input.sessionId, runId: input.runId, ...legNoticeTaskId(input), }, }); minted = true; } return minted; }