* Build a GEP-A2A protocol envelope around a payload. * * Strict hub endpoints (/a2a/hello, /a2a/fetch, /a2a/validate, ...) run * isValidProtocolMessage server-side and reject bare bodies with * 400 invalid_protocol_message. Lenient endpoints such as * /a2a/assets/search accept raw bodies and m
(messageType, payload, senderId)
| 19 | * @returns {object} Full protocol envelope |
| 20 | */ |
| 21 | function buildEnvelope(messageType, payload, senderId) { |
| 22 | if (!messageType || typeof messageType !== 'string') { |
| 23 | throw new Error('buildEnvelope: messageType is required'); |
| 24 | } |
| 25 | return { |
| 26 | protocol: PROTOCOL_NAME, |
| 27 | protocol_version: PROTOCOL_VERSION, |
| 28 | message_type: messageType, |
| 29 | message_id: 'msg_' + Date.now() + '_' + crypto.randomBytes(4).toString('hex'), |
| 30 | sender_id: senderId || null, |
| 31 | timestamp: new Date().toISOString(), |
| 32 | payload: payload || {}, |
| 33 | }; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Wrap `body` in a GEP-A2A envelope unless it already is one. |
no outgoing calls
no test coverage detected