cancel method
Implementation
Future<void> cancel(String path, MeshDocument thread, {bool useAgentMessages = false, String? turnId, String? participantName}) async {
if (hasPendingSendWait(path)) {
cancelPendingSend(path);
return;
}
if (useAgentMessages) {
final room = _requireRoom('Canceling an agent turn');
if (turnId == null || turnId.trim().isEmpty) {
return;
}
await Future.wait([
for (final participant in getAgentParticipants(thread, participantName: participantName))
room.messaging.sendMessage(
to: participant,
type: agentRoomMessageType,
message: {"type": agentTurnInterruptType, "thread_id": path, "turn_id": turnId},
),
]);
return;
}
final room = _requireRoom('Canceling a thread');
for (final participant in getOnlineParticipants(thread).whereType<RemoteParticipant>()) {
final normalizedParticipantName = participantName?.trim();
if (normalizedParticipantName != null &&
normalizedParticipantName.isNotEmpty &&
participant.getAttribute("name") != normalizedParticipantName) {
continue;
}
if (participant.role == "agent") {
await room.messaging.sendMessage(to: participant, type: "cancel", message: {"path": path});
}
}
}