* Wrap `body` in a GEP-A2A envelope unless it already is one. * * When the caller hands us a pre-built envelope, sender_id is still forced * to the proxy's own node_id: callers must not be able to impersonate * another node through the proxy (same rule as the ATP passthrough routes). * * @para
(messageType, body, senderId)
| 46 | * @returns {object} Full protocol envelope |
| 47 | */ |
| 48 | function ensureEnvelope(messageType, body, senderId) { |
| 49 | const b = body || {}; |
| 50 | const isEnvelope = b.protocol === PROTOCOL_NAME |
| 51 | && typeof b.message_type === 'string' |
| 52 | && b.payload && typeof b.payload === 'object'; |
| 53 | if (isEnvelope) { |
| 54 | return { ...b, sender_id: senderId || b.sender_id || null }; |
| 55 | } |
| 56 | return buildEnvelope(messageType, b, senderId); |
| 57 | } |
| 58 | |
| 59 | module.exports = { buildEnvelope, ensureEnvelope, PROTOCOL_NAME, PROTOCOL_VERSION }; |
no test coverage detected