openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
55 lines (54 loc) • 2.98 kB
JavaScript
//#region src/infra/outbound/deliver-types.ts
/** Count platform sends without double-counting equivalent receipt representations. */
function countPhysicalOutboundSends(e) {
return e.reduce((e, t) => {
if (t.outcome === "not_sent") return e;
const n = t.receipt;
const r = n ? n.parts.length || n.platformMessageIds.length : 0;
return e + Math.max(1, r);
}, 0);
}
const PLATFORM_MESSAGE_NOT_DISPATCHED_ERROR_CODE = "OPENCLAW_PLATFORM_MESSAGE_NOT_DISPATCHED";
/**
* Provider assertion that no recipient-visible send began. Set retryable=false
* for permanent payload/policy rejection; never use after an ambiguous send.
*/
var PlatformMessageNotDispatchedError = class extends Error {
constructor(e, t) {
const n = t.retryable !== false;
super(n ? e : e.trim() || "Platform rejected the message before dispatch", { cause: t.cause });
this.code = PLATFORM_MESSAGE_NOT_DISPATCHED_ERROR_CODE;
this.name = "PlatformMessageNotDispatchedError";
this.retryable = n;
}
};
function isPlatformMessageNotDispatchedError(e) {
return e instanceof PlatformMessageNotDispatchedError;
}
function isPlatformMessageRejectedError(e) {
return e instanceof PlatformMessageNotDispatchedError && !e.retryable;
}
/** Every reported payload intentionally omitted delivery; missing evidence stays unknown. */
function areOutboundPayloadsIntentionallySuppressed(e) {
return e.length > 0 && e.every((e) => e.status === "suppressed" && e.reason !== "adapter_returned_no_identity");
}
/** Error carrying partial delivery results when an outbound send fails mid-batch. */
var OutboundDeliveryError = class extends Error {
constructor(e, t) {
super(e, { cause: t.cause });
this.name = "OutboundDeliveryError";
this.results = [...t.results ?? []];
this.payloadOutcomes = [...t.payloadOutcomes ?? []];
this.sentBeforeError = t.sentBeforeError === true || this.results.length > 0 || this.payloadOutcomes.some((e) => e.status === "failed" ? e.sentBeforeError : e.status === "suppressed" && e.reason === "adapter_returned_no_identity");
this.stage = t.stage ?? "unknown";
}
};
/** Internal control flow for lifecycle closure before recipient-visible dispatch. */
var OutboundDeliveryAdmissionClosedError = class extends Error {};
const isOutboundDeliveryAdmissionClosedError = (e) => e instanceof OutboundDeliveryAdmissionClosedError || e instanceof OutboundDeliveryError && e.cause instanceof OutboundDeliveryAdmissionClosedError;
/** Narrows unknown failures to outbound delivery errors with partial-send metadata. */
function isOutboundDeliveryError(e) {
return e instanceof OutboundDeliveryError;
}
//#endregion
export { countPhysicalOutboundSends as a, isPlatformMessageNotDispatchedError as c, areOutboundPayloadsIntentionallySuppressed as i, isPlatformMessageRejectedError as l, OutboundDeliveryError as n, isOutboundDeliveryAdmissionClosedError as o, PlatformMessageNotDispatchedError as r, isOutboundDeliveryError as s, OutboundDeliveryAdmissionClosedError as t };