UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

81 lines (80 loc) • 2.93 kB
import { r as defaultRuntime } from "./runtime-B-SLYP-m.mjs"; import { r as terminalText } from "./safe-text-C80HAQ2e.mjs"; import { r as theme } from "./theme-BOI0xyRZ.mjs"; import { t as createChannelIngressQueue } from "./ingress-queue-CSJ9I3-y.mjs"; import { n as formatDurationHuman } from "./format-duration-iMnO_MN6.mjs"; import { t as parseLogsPositiveInt } from "./logs-cli.options-DAFf8S0V.mjs"; //#region src/commands/channels/dead-letters.ts function resolveScope(e) { const t = e.channel?.trim(); if (!t) throw new Error("--channel is required."); const n = e.account?.trim() ?? "default"; if (!n) throw new Error("--account must not be blank"); return { channelId: t, accountId: n }; } async function channelsDeadLettersListCommand(e) { const { channelId: t, accountId: n } = resolveScope(e); const r = createChannelIngressQueue({ channelId: t, accountId: n }); if (!r.listFailed) throw new Error("This runtime does not support channel ingress dead-letter inspection."); const i = await r.listFailed({ limit: parseLogsPositiveInt(e.limit, 100, "--limit") }); if (e.json) { defaultRuntime.writeJson({ channelId: t, accountId: n, deadLetters: i }); return; } defaultRuntime.log(theme.heading(terminalText`Channel ingress dead letters (${t}/${n})`)); if (i.length === 0) { defaultRuntime.log(theme.muted("No dead-lettered ingress events.")); return; } const a = Date.now(); for (const e of i) { const t = formatDurationHuman(Math.max(0, a - e.failedAt)); defaultRuntime.log(terminalText`- ${e.id}: ${e.reason}; attempts=${e.attempts}; failed ${t} ago`); } } /** Atomically return one retained ingress failure to its channel/account queue. */ async function channelsDeadLettersResubmitCommand(e, t) { const { channelId: n, accountId: r } = resolveScope(t); const i = createChannelIngressQueue({ channelId: n, accountId: r }); if (!i.resubmit) throw new Error("This runtime does not support channel ingress dead-letter resubmission."); const a = await i.resubmit(e); if (a.kind === "resubmitted") { if (t.json) defaultRuntime.writeJson({ channelId: n, accountId: r, eventId: e, result: a }); else defaultRuntime.log(`${theme.success("Resubmitted")} ${terminalText`channel ingress event ${e} (${n}/${r}). The running channel retries it within 5 minutes by default (longer if configured).`}`); return; } let o; switch (a.kind) { case "completed": o = `Ingress event ${e} is completed and cannot be resubmitted.`; break; case "active": o = `Ingress event ${e} is already ${a.status}.`; break; case "unrecoverable": o = `Ingress event ${e} has no retained payload and cannot be resubmitted.`; break; default: o = `Ingress event ${e} was not found for ${n}/${r}.`; } throw new Error(t.json ? o : terminalText`${o}`); } //#endregion export { channelsDeadLettersListCommand, channelsDeadLettersResubmitCommand };