UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.75 kB
import{i as getLoadedChannelPluginForRead}from"./registry-loaded-BEn6LBRM.mjs";import{t as normalizeAnyChannelId}from"./registry-normalize-BP0gv89S.mjs";import{o as hasReplyPayloadContent}from"./payload-B5c5LLYp.mjs";import{t as createCronExecutionId}from"./run-id-CYBVQnKU.mjs";import{t as createOutboundSendDeps}from"./outbound-send-deps-CZdlQN0d.mjs";import{t as createMessageReceiptFromOutboundResults}from"./receipt-DMUG87P5.mjs";import{l as outboundDeliveryQueueName}from"./delivery-queue-namespaces-BNCoN9F0.mjs";import{t as buildOutboundSessionContext}from"./session-context-7JncscTR.mjs";import{n as sendDurableMessageBatchCore,t as durableMessageBatchMayHaveReachedRecipient}from"./send-BGs4mM8f.mjs";import{r as createChannelReplyTransform}from"./reply-transform-DmEQ9gjo.mjs";import{t as resolveAgentOutboundIdentity}from"./identity-45hM2JZu.mjs";import"./runtime-D5cceDNw.mjs";import"./delivery-plan-BGmM1emp.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-D9hut4hx.mjs"; //!src/cron/delivery.ts 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,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:n=>{if(e.onDeliveryReceipt){const r=createMessageReceiptFromOutboundResults({results:[n]});for(const i of r.parts)e.onDeliveryReceipt({channel:i.raw?.channel??n.channel,to:i.raw?.target?.id??n.target?.id??t.to,accountId:t.accountId,threadId:i.threadId??t.threadId,messageId:i.platformMessageId})}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}}})}export{sendCronAnnouncePayloadStrict as t};