Assemble interleaved message events
Reduce only AG-UI TEXT_MESSAGE_START, TEXT_MESSAGE_CONTENT, and TEXT_MESSAGE_END events. A start requires a new nonempty message ID and role assistant. Content requires an open message and a nonempty string delta. End closes an open message. Return {messageId: {text, open}}, preserving incomplete messages. Reject invalid ordering and unsupported types with ValueError. This is a strict subset for teaching, not a full AG-UI client, transport, replay protocol, or renderer.
Your task
- Complete the starter function using the contract above.
- Use the examples and visible tests to check normal inputs, boundaries, and rejected inputs.
- Run tests to record your result, then compare with the explained reference solution.
Examples
Inputstart a, content a=Hi, start b, content b=Wait, end a
Outputa contains Hi and is closed; b contains Wait and is open
Inputcontent for an unknown message
OutputValueError
Implement the function, then run the tests.
Ctrl / ⌘ + Enter to test · Shift + Tab leaves editor