actionToMessage function

Message actionToMessage(
  1. A2uiClientAction action
)

Builds the agent input message for sending a rendered surface's user action back to the agent as the next turn.

The action's name becomes a human-readable summary so the agent can react to it; the full action object is attached as an a2ui data part for richer handling by the middleware.

Implementation

Message actionToMessage(A2uiClientAction action) {
  final ctx = action.context.isNotEmpty
      ? ' with context ${jsonEncode(action.context)}'
      : '';
  final summary =
      'User interacted with the UI (surface "${action.surfaceId}"): '
      'action "${action.name}"$ctx.';
  return Message(
    role: Role.user,
    content: [
      TextPart(text: summary),
      a2uiPart([
        {'action': action.toJson()},
      ]),
    ],
  );
}