openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
121 lines (120 loc) • 4.46 kB
JavaScript
import { l as isRecord } from "./record-coerce-CVPuDqcc.mjs";
import { a as resolveSendableOutboundReplyParts } from "./reply-payload-parts-0Tn7wkpR.mjs";
import { l as outboundDeliveryQueueName, s as OUTBOUND_EXECUTABLE_QUEUE_NAMES, t as COMMAND_OWNER_OUTBOUND_DELIVERY_QUEUE_NAME } from "./delivery-queue-namespaces-HQn65gG8.mjs";
//#region src/infra/outbound/prepared-batch.ts
const PREPARED_OUTBOUND_BATCH_SCHEMA_VERSION = 1;
/** Captures already-owned content without invoking modifying policy. */
function createUnmodifiedPreparedOutboundBatch(e) {
return {
schemaVersion: 1,
sourcePayloadCount: e.length,
entries: e.map((e, t) => ({
sourceIndex: t,
status: "accepted",
payload: e,
replyHookChanged: false,
messageHookChanged: false,
preparedMediaCount: resolveSendableOutboundReplyParts(e).mediaCount
}))
};
}
/** Retains terminal legacy cardinality without copying unavailable pre-policy content. */
function createUnavailablePreparedOutboundBatch(e) {
return {
schemaVersion: 1,
sourcePayloadCount: e,
entries: []
};
}
function acceptedPreparedOutboundEntries(e) {
return e.entries.filter((e) => e.status === "accepted");
}
function preparedOutboundPayloads(e) {
return acceptedPreparedOutboundEntries(e).map((e) => e.payload);
}
function preparedOutboundSuppressionOutcomes(e) {
return e.entries.flatMap((e) => e.status === "suppressed" ? [{
index: e.sourceIndex,
status: "suppressed",
reason: e.reason,
...e.hookEffect ? { hookEffect: e.hookEffect } : {}
}] : []);
}
/** Removes process-local hook details before a prepared batch enters durable custody. */
function projectPreparedOutboundBatchForStorage(e) {
return {
...e,
entries: e.entries.map((e) => {
if (e.status !== "suppressed" || !e.hookEffect) return e;
const { hookEffect: t, ...n } = e;
return n;
})
};
}
function mapPreparedOutboundAcceptedPayloads(e, t) {
let n = 0;
const r = {
...e,
entries: e.entries.map((e) => {
if (e.status !== "accepted") return e;
const r = t[n++];
if (!r) throw new Error("Prepared outbound payload map lost an accepted entry");
return {
...e,
payload: r
};
})
};
if (n !== t.length) throw new Error("Prepared outbound payload map received an extra payload");
return r;
}
//#endregion
//#region src/infra/outbound/delivery-queue-projection.ts
/** Copies shared send options without transferring queue custody or process-local callbacks. */
function projectQueuedDeliveryOptions(e) {
return {
channel: e.channel,
to: e.to,
accountId: e.accountId,
renderedBatchPlan: e.renderedBatchPlan,
threadId: e.threadId,
formatting: e.formatting,
identity: e.identity,
bestEffort: e.bestEffort,
gifPlayback: e.gifPlayback,
forceDocument: e.forceDocument,
silent: e.silent,
session: e.session,
transcriptProvenance: e.transcriptProvenance,
gatewayClientScopes: e.gatewayClientScopes,
preparedMessageId: e.preparedMessageId
};
}
function projectOutboundDelivery(e, t) {
if (!OUTBOUND_EXECUTABLE_QUEUE_NAMES.some((t) => t === e)) throw new Error(`Unsupported outbound delivery format: ${e}`);
const n = t;
if (e === "outbound-command-owner-v1") {
if (n.deliveryCompletion?.kind !== "pending-final") throw new Error(`Missing command-owner delivery completion: ${t.id}`);
n.deliveryCompletion.commandOwnerReference ??= null;
}
if (e !== outboundDeliveryQueueName(n)) throw new Error(`Outbound delivery authority does not match its format: ${t.id}`);
return n;
}
function encodeOutboundDeliverySnapshot(e) {
return {
queueName: outboundDeliveryQueueName(e),
entryJson: JSON.stringify(e)
};
}
function decodeOutboundDeliverySnapshot(e) {
const t = JSON.parse(e.entryJson);
if (!isRecord(t) || typeof t.id !== "string" || typeof t.enqueuedAt !== "number" || typeof t.retryCount !== "number") throw new Error("Invalid outbound delivery storage snapshot");
return projectOutboundDelivery(e.queueName, {
...t,
id: t.id,
enqueuedAt: t.enqueuedAt,
retryCount: t.retryCount
});
}
//#endregion
export { acceptedPreparedOutboundEntries as a, mapPreparedOutboundAcceptedPayloads as c, projectPreparedOutboundBatchForStorage as d, projectQueuedDeliveryOptions as i, preparedOutboundPayloads as l, encodeOutboundDeliverySnapshot as n, createUnavailablePreparedOutboundBatch as o, projectOutboundDelivery as r, createUnmodifiedPreparedOutboundBatch as s, decodeOutboundDeliverySnapshot as t, preparedOutboundSuppressionOutcomes as u };