UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

30 lines (29 loc) • 1.64 kB
//#region src/agents/embedded-agent-runner/run/midturn-precheck.ts /** Stable messages used to identify synthetic mid-turn signals in session cleanup. */ const MID_TURN_PRECHECK_ERROR_MESSAGE = "Context overflow: prompt too large for the model (mid-turn precheck)."; const MID_TURN_MAINTENANCE_MESSAGE = "Context maintenance scheduled at a settled tool boundary."; /** * Internal control-flow signal thrown after a tool result makes the next prompt * exceed budget. The attempt runner catches it and routes through the overflow * recovery path instead of treating it as an ordinary provider failure. */ var MidTurnPrecheckSignal = class extends Error { constructor(e) { super(e.pressure === "overflow" ? MID_TURN_PRECHECK_ERROR_MESSAGE : MID_TURN_MAINTENANCE_MESSAGE); this.name = "MidTurnPrecheckSignal"; this.request = e; } }; function isMidTurnPrecheckSignal(e) { return e instanceof MidTurnPrecheckSignal; } /** This local routing signal is not a provider response or durable conversation item. */ function isMidTurnPrecheckAssistantError(e) { return e?.role === "assistant" && e.stopReason === "error" && (e.errorMessage === MID_TURN_PRECHECK_ERROR_MESSAGE || e.errorMessage === MID_TURN_MAINTENANCE_MESSAGE); } /** Maintenance is not a failure; lifecycle observers must not report it as one. */ function isMidTurnMaintenanceAssistantSignal(e) { return e?.role === "assistant" && e.stopReason === "error" && e.errorMessage === MID_TURN_MAINTENANCE_MESSAGE; } //#endregion export { isMidTurnPrecheckSignal as i, isMidTurnMaintenanceAssistantSignal as n, isMidTurnPrecheckAssistantError as r, MidTurnPrecheckSignal as t };