authorizeTool static method

Future<Stream<SSEModel>?> authorizeTool(
  1. String messageId,
  2. String toolId
)

Implementation

static Future<Stream<SSEModel>?> authorizeTool(
  String messageId,
  String toolId,
) async {
  ChatController chatController = Get.find();
  String? assistantId = chatController.assistant.value?.id;
  Conversation? conversation = chatController.conversation.value;
  if (assistantId == null || conversation == null) return null;

  PupauMessage message = chatController.messages.firstWhere(
    (element) => element.id == messageId,
  );
  bool isMarketplace = chatController.isMarketplace;

  final Map<String, String>? authParams = chatController.pupauConfig?.authHeaders;
  if (authParams == null) return null;

  String queryParams = "";
  List<String> params = [];
  if (params.isNotEmpty) {
    queryParams = "&${params.join('&')}";
  }
  String? authCode = await GoogleDriveService.requestGoogleDriveAuth();
  if (authCode == null) return null;
  String url =
      "${ApiUrls.toolAuthUrl(assistantId, conversation.id, message.id, toolId, authCode, isMarketplace: isMarketplace)}$queryParams";
  Stream<SSEModel> messageSendStream = SSEClient.subscribeToSSE(
    method: SSERequestType.POST,
    url: url,
    header: {
      ...authParams,
      "Conversation-Token": conversation.token,
      "Content-type": "Application/json",
    },
    body: {"request": message.answer},
  );
  return messageSendStream;
}