openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
126 lines (125 loc) • 4.92 kB
JavaScript
import { a as extractErrorCode } from "./error-coercion-hDrHOSGy.mjs";
import { n as formatErrorMessageWithCode } from "./errors-BKzCeTYb.mjs";
import { t as classifyGatewayStorageFailure } from "./sqlite-error-diagnostics-6_hREUnq.mjs";
import { C as isCronTimeoutErrorText, b as CRON_PRE_EXECUTION_TIMEOUT_ERROR, x as CRON_SETUP_TIMEOUT_ERROR, y as CRON_JOB_EXECUTION_TIMEOUT_ERROR } from "./run-history-detail-rOrjKG4Z.mjs";
import { u as renderStorageFailureSummary } from "./assistant-request-failure-copy-CDAkRIru.mjs";
//#region src/agents/embedded-agent-runner/execution-phase.ts
const EMBEDDED_AGENT_EXECUTION_PHASES = {
runner_entered: {
label: "runner-entered",
startupPhase: "preparing_workspace"
},
workspace: {
label: "workspace",
startupPhase: "preparing_workspace"
},
runtime_plugins: {
label: "runtime-plugins",
startupPhase: "preparing_workspace"
},
before_agent_reply: {
label: "before-agent-reply",
startupPhase: "preparing_context"
},
model_resolution: {
label: "model-resolution",
startupPhase: "preparing_context"
},
auth: {
label: "auth",
startupPhase: "preparing_context"
},
context_engine: {
label: "context-engine",
startupPhase: "preparing_context"
},
attempt_dispatch: {
label: "attempt-dispatch",
startupPhase: "preparing_context"
},
context_assembled: {
label: "context-assembled",
startupPhase: "preparing_context"
},
turn_accepted: {
label: "turn-accepted",
startupPhase: "starting_model"
},
process_spawned: {
label: "process-spawned",
startupPhase: "starting_model"
},
tool_execution_started: {
label: "tool-execution-started",
startupPhase: void 0
},
assistant_output_started: {
label: "assistant-output-started",
startupPhase: void 0
},
model_call_started: {
label: "model-call-started",
startupPhase: "starting_model"
}
};
function formatEmbeddedAgentExecutionPhase(e) {
return e ? EMBEDDED_AGENT_EXECUTION_PHASES[e].label : void 0;
}
function resolveRunStartupPhase(e) {
return EMBEDDED_AGENT_EXECUTION_PHASES[e].startupPhase;
}
//#endregion
//#region src/cron/service/execution-errors.ts
/** Formats stable cron timeout and execution error messages. */
function formatCronTimeoutMessage(e, t) {
const n = formatEmbeddedAgentExecutionPhase(t?.phase);
return n ? `${e} (last phase: ${n})` : e;
}
function isCronTerminalAbortReasonText(e) {
return isCronTimeoutErrorText(e);
}
/** Formats the generic cron execution timeout message with last-known phase context when available. */
function timeoutErrorMessage(e) {
return formatCronTimeoutMessage(CRON_JOB_EXECUTION_TIMEOUT_ERROR, e);
}
/** Formats timeout text for runs that stalled before the isolated runner started. */
function setupTimeoutErrorMessage(e) {
return formatCronTimeoutMessage(CRON_SETUP_TIMEOUT_ERROR, e);
}
/** Returns true for the setup-timeout class that fires before the isolated runner starts. */
function isSetupTimeoutErrorText(e) {
return e === "cron: isolated agent setup timed out before runner start" || e.startsWith("cron: isolated agent setup timed out before runner start" + " ");
}
/** Formats timeout text for runs that stalled after setup but before execution start. */
function preExecutionTimeoutErrorMessage(e) {
return formatCronTimeoutMessage(CRON_PRE_EXECUTION_TIMEOUT_ERROR, e);
}
/** Extracts a human timeout/abort reason, falling back to the canonical cron timeout text. */
function resolveCronAbortReasonText(e) {
if (typeof e === "string" && e.trim()) return e.trim();
if (e instanceof Error) {
const t = e.message.trim();
if (extractErrorCode(e) === void 0 && (!t || t === timeoutErrorMessage())) return;
return formatErrorMessageWithCode(e);
}
}
/** Extracts a human timeout/abort reason, falling back to the canonical cron timeout text. */
function abortErrorMessage(e) {
return resolveCronAbortReasonText(e?.reason) ?? timeoutErrorMessage();
}
/** The controller owns whether an interruption was a watchdog timeout or a cancellation. */
function cronAbortErrorClassification(e) {
return !e || e.reason instanceof Error && e.reason.name === "TimeoutError" ? {
kind: "reason",
reason: "timeout"
} : { kind: "aborted" };
}
/** Normalizes thrown cron run failures into stable log/run-history text. */
function normalizeCronRunErrorText(e) {
const t = renderStorageFailureSummary(classifyGatewayStorageFailure(e));
if (t) return t;
if (e instanceof Error && (e.name === "AbortError" || e.message.trim() === timeoutErrorMessage())) return resolveCronAbortReasonText(e) ?? timeoutErrorMessage();
return formatErrorMessageWithCode(e);
}
//#endregion
export { normalizeCronRunErrorText as a, setupTimeoutErrorMessage as c, isSetupTimeoutErrorText as i, timeoutErrorMessage as l, cronAbortErrorClassification as n, preExecutionTimeoutErrorMessage as o, isCronTerminalAbortReasonText as r, resolveCronAbortReasonText as s, abortErrorMessage as t, resolveRunStartupPhase as u };