copilotInitiatorFor function

String copilotInitiatorFor(
  1. List<Message> messages
)

The X-Initiator value for messages: agent when the LAST message is an assistant or tool result (a continuation of the model's own turn), user otherwise (goal: copilot-proxy-go requestHeaders).

Implementation

String copilotInitiatorFor(List<Message> messages) {
  final role = messages.isEmpty ? '' : messages.last.role;
  return role == 'assistant' || role == 'toolResult' ? 'agent' : 'user';
}