Agent.secas.xml 1.53 KB
<?xml version="1.0" encoding="UTF-8"?>
<secas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-eca-3.xsd">
    <seca id="AgentTriggerOnCommunication" service="create#mantle.party.communication.CommunicationEvent" when="post-service">
        <condition>
            <expression>toPartyId == 'AGENT_CLAUDE_PARTY'</expression>
        </condition>
        <actions>
            <!-- Ensure rootCommEventId is set (thread tracking) -->
            <script><![CDATA[
                def rootId = rootCommEventId ?: communicationEventId
                if (!rootCommEventId) {
                    ec.service.sync().name("update#mantle.party.communication.CommunicationEvent")
                        .parameters([communicationEventId: communicationEventId, rootCommEventId: rootId])
                        .call()
                }
                
                // Trigger Agent Turn
                ec.service.sync().name("create#moqui.service.message.SystemMessage").parameters([
                    systemMessageTypeId: 'SmtyAgentTask',
                    statusId: 'SmsgReceived',
                    requestedByPartyId: fromPartyId,
                    effectiveUserId: ec.user.userId, // Use the actual human user ID for RBAC
                    productStoreId: 'POPC_DEFAULT',
                    aiConfigId: 'DEFAULT',
                    rootCommEventId: rootId,
                    isOutgoing: 'N'
                ]).call()
            ]]></script>
        </actions>
    </seca>
</secas>