UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

149 lines (148 loc) • 5.36 kB
import { i as getLoadedChannelPluginForRead } from "./registry-loaded-NYWUyLLC.mjs"; import { t as normalizeAnyChannelId } from "./registry-normalize-guW5_4yo.mjs"; import { o as hasReplyPayloadContent } from "./payload-Cab4FCxl.mjs"; import { t as createCronExecutionId } from "./run-id-Be9gQ-r9.mjs"; import { t as createOutboundSendDeps } from "./outbound-send-deps-BV7tqdFC.mjs"; import { l as outboundDeliveryQueueName } from "./delivery-queue-namespaces-HQn65gG8.mjs"; import { n as sendDurableMessageBatchCore, t as durableMessageBatchMayHaveReachedRecipient } from "./send-C6MWAmk5.mjs"; import "./runtime-BgdHhvEU.mjs"; import { t as buildOutboundSessionContext } from "./session-context-CCVPkFMh.mjs"; import { r as createChannelReplyTransform } from "./reply-transform-VMjxflBU.mjs"; import { t as resolveAgentOutboundIdentity } from "./identity-DpbdIy02.mjs"; import "./delivery-plan-BMeGAb9T.mjs"; import { c as maybeApplyTtsToCronPayloads, f as retryTransientDirectCronDelivery, i as buildDirectCronDeliveryIdempotencyKey, n as normalizeDirectCronDeliveryPayloads, o as isCompletedDirectCronDelivery, p as waitForCompletedDirectCronDelivery, r as DIRECT_CRON_DELIVERY_COMPLETION_RETENTION, s as logCronDeliveryWarn, t as appendCronRunInspectionLink } from "./delivery-payload-normalization--V8NjrG-.mjs"; //#region src/cron/delivery.ts /** Sends the configured notification through the outbound conversation owner. */ async function sendCronAnnouncePayloadStrict(e) { const t = e.target; e.abortSignal.throwIfAborted(); const n = normalizeAnyChannelId(t.channel) ?? t.channel; const r = createChannelReplyTransform({ cfg: e.cfg, accountId: t.accountId, messaging: getLoadedChannelPluginForRead(n)?.messaging }); const i = normalizeDirectCronDeliveryPayloads({ deliveryPayloads: Array.isArray(e.payload) ? e.payload : [e.payload], channelTransform: r ? { apply: r } : void 0 }); if (i.kind === "suppress") return { status: "suppressed", reason: i.reason, skipReason: i.reason }; const a = e.completion?.deliveryAttemptFence; const o = e.completion ? buildDirectCronDeliveryIdempotencyKey({ jobId: e.jobId, runStartedAt: e.completion.runStartedAt, delivery: t }) : void 0; const s = outboundDeliveryQueueName({ sessionGeneration: e.sessionGeneration }); if (o) try { if (await isCompletedDirectCronDelivery(o, s)) { a?.assertCurrent(); e.onDeliveryAttempt?.(true); return { status: "sent", payloads: [] }; } } catch (t) { if (!e.bestEffort) throw t; await logCronDeliveryWarn(`[cron:${e.jobId}] delivery receipt unavailable; continuing best-effort notification`); } const c = e.tts ? await maybeApplyTtsToCronPayloads({ cfg: e.cfg, payloads: i.payload, delivery: t, agentId: e.agentId, ttsAuto: e.tts.auto }) : i.payload; const l = appendCronRunInspectionLink(c.filter((e) => hasReplyPayloadContent(e, { trimText: true })), e.inspectionUrl, n); if (l.length === 0) return { status: "suppressed", reason: "empty_after_tts" }; const u = buildOutboundSessionContext({ cfg: e.cfg, agentId: e.agentId, sessionKey: e.target.sessionKey }); const d = resolveAgentOutboundIdentity(e.cfg, e.agentId); let f = false; return await retryTransientDirectCronDelivery({ jobId: e.jobId, signal: e.abortSignal, shouldRetryError: () => !f, run: async () => { const n = []; await a?.beforeAttempt(); e.abortSignal.throwIfAborted(); a?.assertCurrent(); const r = await sendDurableMessageBatchCore({ cfg: e.cfg, channel: t.channel, to: t.to, accountId: t.accountId, threadId: t.threadId, payloads: l, session: u, transcriptRoute: e.transcriptRoute, transcriptExpectedGeneration: e.transcriptExpectedGeneration, onTranscriptDiagnostic: e.onTranscriptDiagnostic, ...e.completion ? { transcriptProvenance: { kind: "cron", jobId: e.jobId, runId: createCronExecutionId(e.jobId, e.completion.runStartedAt) } } : {}, assertTranscriptCurrent: a?.assertCurrent, identity: d, bestEffort: e.bestEffort === true, durability: e.bestEffort === true ? "best_effort" : "required", ...o ? { deliveryIntentId: o, reusePendingDeliveryIntent: true, completionRetention: DIRECT_CRON_DELIVERY_COMPLETION_RETENTION } : {}, deps: createOutboundSendDeps(e.deps), signal: e.abortSignal, assertDirectAdapterHandoff: a?.assertCurrent, onDeliveredPayload: ({ hookContent: e, ...t }) => n.push({ ...t, spokenText: e }), onDeliveryResult: () => { if (!f) { f = true; e.onDeliveryAttempt?.(true); } } }, void 0, void 0, e.sessionGeneration, e.admittedReasoning); if (!f) { f = durableMessageBatchMayHaveReachedRecipient(r); e.onDeliveryAttempt?.(f); } if (r.status === "failed" && o && await waitForCompletedDirectCronDelivery({ id: o, queueName: s, signal: e.abortSignal })) { a?.assertCurrent(); return { status: "sent", payloads: n }; } if (r.status === "failed" || r.status === "partial_failed") throw r.error; return r.status === "sent" ? { status: "sent", payloads: n } : { status: "suppressed", reason: f ? "adapter_returned_no_identity" : r.reason }; } }); } //#endregion export { sendCronAnnouncePayloadStrict as t };