pub fn push_message_block(
messages: &mut Vec<BetaMessageParam>,
role: BetaMessageRole,
block: BetaContentBlockParam,
)Expand description
Append a single content block to a Claude messages list, building a
well-formed conversation as we go:
- Consecutive blocks for the same role are merged into one message, instead of producing two adjacent same-role messages (which the Claude API rejects).
- Whenever a
tool_resultblock is appended to ausermessage, we make sure the immediately preceding assistant message contains a matchingtool_useblock. If none exists (for example, when a client uses the OpenAI Responses API withprevious_response_idand only sends newfunction_call_outputitems), we synthesize a placeholdertool_useso the request still satisfies the API’s pairing rule: “Eachtool_resultblock must have a correspondingtool_useblock in the previous message.”
Use this helper from every transform that produces Claude messages from a non-Claude source. It centralises the invariants so each converter can stay focused on its own input format.