downgradeUnsupportedImages function

List<Message> downgradeUnsupportedImages(
  1. List<Message> messages,
  2. Model model
)

Replaces image blocks with explicit placeholder text when model has no image input, so nothing is dropped silently at request time.

Ported from the downgradeUnsupportedImages half of pi's transformMessages pre-pass (transform-messages.ts): user messages and tool results get distinct placeholders; the image bytes stay in the session transcript, only the request payload is rewritten. Each adapter runs this at the top of its message conversion.

Implementation

List<Message> downgradeUnsupportedImages(List<Message> messages, Model model) {
  if (model.input.contains('image')) {
    return messages;
  }
  var dropped = 0;
  final out = _replaceImages(
    messages,
    nonVisionUserImagePlaceholder,
    nonVisionToolImagePlaceholder,
    onImage: () => dropped++,
  );
  if (dropped > 0) textOnlyImageDropNotice?.call(dropped);
  return out;
}