openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
41 lines (40 loc) • 1.4 kB
JavaScript
import { a as asOptionalRecord } from "./record-coerce-CVPuDqcc.mjs";
//#region src/agents/command/attempt-callbacks.ts
function resetAgentAttemptLifecycle(e) {
e.lifecycleError = void 0;
e.lifecycleErrorObservation = void 0;
e.lifecycleFinishing = false;
e.lifecycleEnded = false;
}
function emitAgentAttemptRuntimeStart(e, t) {
if (e.phase === "assistant_output_started" || e.phase === "tool_execution_started") t({
stream: "lifecycle",
data: { phase: "start" }
});
}
function createAgentAttemptLifecycleCallbacks(e, t) {
return {
onAttemptStart: () => resetAgentAttemptLifecycle(e),
onAttemptTerminalReplaced: () => {
if (!e.lifecycleEnded) resetAgentAttemptLifecycle(e);
},
onAgentEvent: (n) => {
if (n.stream !== "lifecycle" || typeof n.data?.phase !== "string") return;
if (n.data.phase === "start") {
resetAgentAttemptLifecycle(e);
return t?.();
}
if (typeof n.data.error === "string" && n.data.error.trim()) {
e.lifecycleError = n.data.error;
e.lifecycleErrorObservation = asOptionalRecord(n.data.errorObservation);
}
if (n.data.phase === "finishing") {
e.lifecycleFinishing = true;
return;
}
if (n.data.phase === "end" || n.data.phase === "error") e.lifecycleEnded = true;
}
};
}
//#endregion
export { emitAgentAttemptRuntimeStart as n, resetAgentAttemptLifecycle as r, createAgentAttemptLifecycleCallbacks as t };