openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
77 lines (76 loc) • 3.34 kB
JavaScript
import { w as parseStrictPositiveInteger } from "./number-coercion-CLj0HTDM.js";
import { a as writeRuntimeJson, r as defaultRuntime } from "./runtime-CF2WjnNZ.js";
import { n as sanitizeTerminalText } from "./safe-text-BGBqp1a4.js";
import { r as theme } from "./theme-vjDs9tao.js";
import { t as createChannelIngressQueue } from "./ingress-queue-DrsU80Sd.js";
import { n as formatDurationHuman } from "./format-duration-CeDWULoS.js";
//#region src/commands/channels/dead-letters.ts
function resolveScope(options) {
const channelId = options.channel?.trim();
if (!channelId) throw new Error("--channel is required.");
const accountId = options.account?.trim() ?? "default";
if (!accountId) throw new Error("--account must not be blank");
return {
channelId,
accountId
};
}
function parseLimit(value) {
const parsed = parseStrictPositiveInteger(value ?? "100");
if (parsed === void 0) throw new Error("--limit must be a positive integer.");
return parsed;
}
/** List retained ingress failures for one channel account. */
async function channelsDeadLettersListCommand(options, runtime = defaultRuntime) {
const { channelId, accountId } = resolveScope(options);
const queue = createChannelIngressQueue({
channelId,
accountId
});
if (!queue.listFailed) throw new Error("This runtime does not support channel ingress dead-letter inspection.");
const deadLetters = await queue.listFailed({ limit: parseLimit(options.limit) });
if (options.json) {
writeRuntimeJson(runtime, {
channelId,
accountId,
deadLetters
});
return;
}
runtime.log(theme.heading(`Channel ingress dead letters (${channelId}/${accountId})`));
if (deadLetters.length === 0) {
runtime.log(theme.muted("No dead-lettered ingress events."));
return;
}
const now = Date.now();
for (const entry of deadLetters) {
const age = formatDurationHuman(Math.max(0, now - entry.failedAt));
runtime.log(`- ${sanitizeTerminalText(entry.id)}: ${sanitizeTerminalText(entry.reason)}; attempts=${entry.attempts}; failed ${age} ago`);
}
}
/** Atomically return one retained ingress failure to its channel/account queue. */
async function channelsDeadLettersResubmitCommand(eventId, options, runtime = defaultRuntime) {
const { channelId, accountId } = resolveScope(options);
const queue = createChannelIngressQueue({
channelId,
accountId
});
if (!queue.resubmit) throw new Error("This runtime does not support channel ingress dead-letter resubmission.");
const result = await queue.resubmit(eventId);
if (result.kind === "resubmitted") {
if (options.json) writeRuntimeJson(runtime, {
channelId,
accountId,
eventId,
result
});
else runtime.log(`${theme.success("Resubmitted")} channel ingress event ${sanitizeTerminalText(eventId)} (${channelId}/${accountId}).`);
return;
}
if (result.kind === "completed") throw new Error(`Ingress event ${eventId} is completed and cannot be resubmitted.`);
if (result.kind === "active") throw new Error(`Ingress event ${eventId} is already ${result.status}.`);
if (result.kind === "unrecoverable") throw new Error(`Ingress event ${eventId} has no retained payload and cannot be resubmitted.`);
throw new Error(`Ingress event ${eventId} was not found for ${channelId}/${accountId}.`);
}
//#endregion
export { channelsDeadLettersListCommand, channelsDeadLettersResubmitCommand };