responsesInputItems function

List<Map<String, dynamic>> responsesInputItems(
  1. List<Message> messages
)

Converts harness history into Responses API input items (issue #705).

Wire grammar (the invariant this converter owns): assistant tool calls serialize as TOP-LEVEL function_call items and tool results as top-level function_call_output items — never as message content-part slots. The message content-part enum admits only input_text/output_text/input_image; a nested function_call is a hard 400 (Invalid value: 'function_call') that repeats on EVERY replay, bricking a session switched from another provider mid-flight.

Sanitize-on-switch: the conversion is total and runs statelessly on every request (image-registry precedent), so a history authored by any other provider re-shapes to valid responses items, and a session poisoned under the previous converter un-bricks on the first post-fix turn with no manual JSONL surgery. Unconvertible records degrade instead of emitting grammar-invalid items: an assistant record with no text and no tool calls (thinking/image-only from another provider) is skipped; a tool result with no text (image-only) degrades its output to responsesOmittedToolResultNote.

Implementation

List<Map<String, dynamic>> responsesInputItems(List<Message> messages) => [
  for (final message in messages) ..._inputItemsFor(message),
];