getMessageIdFromLastStep method
Implementation
Future<String?> getMessageIdFromLastStep({
required String runId,
required String threadId,
}) async {
final result = await _repository.getListRunSteps(runId, threadId);
return await result.fold(
(l) => null,
(r) async {
if (r.isEmpty) {
await Future.delayed(const Duration(seconds: 1));
return getMessageIdFromLastStep(runId: runId, threadId: threadId);
}
final lastStep = r.first;
if (lastStep.status != 'completed') {
await Future.delayed(const Duration(seconds: 1));
return getMessageIdFromLastStep(runId: runId, threadId: threadId);
}
return lastStep.stepDetails?.messageCreation?.messageId == null
? null
: lastStep.stepDetails!.messageCreation!.messageId!;
},
);
}