UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 4.2 kB
import{g as readStringValue,t as hasNonEmptyString}from"./string-coerce-CpTFcSwY.mjs";import{a as asOptionalRecord}from"./record-coerce-BTbqdJ3-.mjs";import{c as normalizeToolPolicyName}from"./tool-policy-shared-KKJW93v9.mjs";import"./tool-policy-Bsc3kFBH.mjs";import{r as readToolResultDetails,t as isToolResultError}from"./tool-result-error-DAdEhHzf.mjs";import{n as isMessageToolSendActionName}from"./message-action-names-8lTam9uQ.mjs";import{o as isPluginNativeMessagingTool,r as isMessagingToolDeliveryAction,t as isMessageToolConversationCreateActionName}from"./embedded-agent-messaging-CINcI8mM.mjs";import{a as pluginEnvelopeHas,c as readEmbeddedMessageDeliveryFact,d as normalizeMessageDeliveryStatus,i as pluginBroadcastHasDelivery}from"./embedded-agent-message-delivery-Cz7gntl-.mjs"; //!src/agents/embedded-agent-message-tool-source-reply.ts const EXPLICIT_MESSAGE_ROUTE_KEYS=[`channel`,`target`,`to`,`channelId`,`provider`];function resolveMessageToolSourceReplyFinal(e,t=true){const n=(asOptionalRecord(e)??{}).final;return n===void 0?t:n!==false}function resultConfirmsCurrentSourceRoute(e){return asOptionalRecord(asOptionalRecord(e)?.details)?.sourceReplyRoute===`current-source`}function hasExplicitMessageRoute(e){return EXPLICIT_MESSAGE_ROUTE_KEYS.some(t=>hasNonEmptyString(e[t]))||Array.isArray(e.targets)&&e.targets.some(e=>hasNonEmptyString(e))}function isMessageToolSourceReplyActionName(e){return isMessageToolSendActionName(e)||[`reply`,`thread-reply`,`poll`].includes(normalizeMessageDeliveryStatus(e)??``)}function readMessageToolSourceReplyText(e){const t=asOptionalRecord(e)??{};if(!isMessageToolSourceReplyActionName(t.action))return;if(normalizeMessageDeliveryStatus(t.action)===`poll`)return readStringValue(t.pollQuestion)??readStringValue(t.poll_question);return[`content`,`message`,`text`,`body`].map(e=>readStringValue(t[e])).find(e=>e!==void 0)}function isDeliveredMessagingToolResult(e){const t=asOptionalRecord(e.args)??{};if(t.dryRun===true)return false;const n=normalizeToolPolicyName(e.toolName??`message`);if(n===`conversations_send`||n===`conversations_turn`){const t=readToolResultDetails(e.result)?.status;return t===`sent`||n===`conversations_turn`&&(t===`replied`||t===`timeout`)}if(!isPluginNativeMessagingTool(n))return false;const r=normalizeMessageDeliveryStatus(t.action);const i=[e.result,e.hookResult];const hasSignal=e=>i.some(t=>pluginEnvelopeHas(t,e));if(hasSignal(`dryRun`)||e.requirePluginDeliveryId&&!hasSignal(`deliveryId`))return false;if(hasSignal(`partial`))return true;if(r&&isMessageToolConversationCreateActionName(r)&&hasSignal(`conversation`))return true;if(r===`broadcast`&&i.some(pluginBroadcastHasDelivery))return true;if(e.isError||i.some(e=>isToolResultError(e)||pluginEnvelopeHas(e,`failure`)))return false;const a=hasSignal(`nonDelivery`);const o=hasSignal(`noOp`);return!a&&!o&&(isMessagingToolDeliveryAction(n,t)&&r!==`broadcast`&&hasSignal(`ok`)||hasSignal(`delivery`))}function isDeliveredMessageToolOnlySourceReplyResult(e){const t=readEmbeddedMessageDeliveryFact(readToolResultDetails(e.hookResult)?.messageDelivery)??readEmbeddedMessageDeliveryFact(readToolResultDetails(e.result)?.messageDelivery);const n=t?.sourceReplyDelivered===true||resultConfirmsCurrentSourceRoute(e.result)||resultConfirmsCurrentSourceRoute(e.hookResult);if(e.sourceReplyDeliveryMode!==`message_tool_only`&&!n&&e.allowExplicitSourceRoute!==true)return false;if(normalizeToolPolicyName(e.toolName)!==`message`)return false;const r=asOptionalRecord(e.args)??{};if(r.dryRun===true||e.isError&&!t?.sourceReplyDelivered||t?.partialDelivery||[e.result,e.hookResult].some(e=>pluginEnvelopeHas(e,`partial`)))return false;const i=(e.allowExplicitSourceRoute===true||n)&&isMessageToolSourceReplyActionName(r.action);if(t?.sourceReplyDelivered!==true&&!isMessageToolSendActionName(r.action)&&!i)return false;if(hasExplicitMessageRoute(r)&&e.allowExplicitSourceRoute!==true&&!n)return false;return e.deliveryConfirmed??(t?t.status===`settled`:isDeliveredMessagingToolResult(e))}export{resolveMessageToolSourceReplyFinal as i,isDeliveredMessagingToolResult as n,readMessageToolSourceReplyText as r,isDeliveredMessageToolOnlySourceReplyResult as t};