ToolUseMessage.fromJson constructor

ToolUseMessage.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory ToolUseMessage.fromJson(Map<String, dynamic> json) {
  ToolUseType type = ToolUseService.getToolUseTypeEnum(
      json["extraInfo"]?["typeDetails"]?["toolType"] ?? "",
      nativeToolType: json["extraInfo"]?["typeDetails"]?["nativeTool"]
          ?["id"]);
  bool isPipeline = type == ToolUseType.pipeline;
  bool isRemoteCall = type == ToolUseType.remoteCall;
  bool isTodoList = type == ToolUseType.nativeToolsToDoList;
  bool isWebSearch = type == ToolUseType.nativeToolsWebSearch;
  bool isKnowledgeBase = type == ToolUseType.nativeToolsKnowledgeBase;
  bool isDocument = type == ToolUseType.nativeToolsDocument;
  bool isSMTP = type == ToolUseType.nativeToolsSMTP;
  bool isImageGeneration = type == ToolUseType.nativeToolsImageGeneration;
  bool isBrowserUse = type == ToolUseType.nativeToolsBrowserUse;
  bool isAskUser = type == ToolUseType.nativeToolsAskUser;
  bool isWebReader = type == ToolUseType.nativeToolsWebReader;
  Map<String, dynamic> answer = getMessage(json, false);

  return ToolUseMessage(
    id: json["id"] ?? "",
    assistantName: json["assistantName"] ?? "",
    imageUuid: json["imageUuid"],
    chatBotId: json["chatBotId"],
    marketPlaceId: json["marketPlaceId"],
    type: type,
    toolName: json["extraInfo"]?["typeDetails"]?["toolName"] ?? "tool",
    queryGroupId: json["queryGroupId"] ?? "",
    showTool: json["extraInfo"]?["typeDetails"]?["showTool"] ?? true,
    toolMessage: json["extraInfo"]?["typeDetails"]?["toolMessage"] ?? "",
    nativeToolData: ToolUseService.isNativeTool(type)
        ? getNativeToolData(json, false)
        : null,
    pipelineData: isPipeline ? ToolUsePipelineData.fromJson(answer) : null,
    remoteCallData: isRemoteCall ? answer : null,
    toDoListData: isTodoList ? ToolUseToDoListData.fromJson(answer, json["extraInfo"]?["typeDetails"]) : null,
    webSearchData: isWebSearch ? ToolUseWebSearchData.fromJson(answer) : null,
    knowledgeBaseData:
        isKnowledgeBase ? ToolUseKnowledgeBaseData.fromJson(answer) : null,
    documentData: isDocument
        ? ToolUseDocumentData.fromJson(
            answer, json["extraInfo"]?["typeDetails"])
        : null,
    smtpData: isSMTP ? ToolUseSMTPData.fromJson(answer) : null,
    imageGenerationData: isImageGeneration
        ? ToolUseImageGenerationData.fromJson(answer)
        : null,
    browserUseData: isBrowserUse
        ? ToolUseBrowserUseData.fromJson(
            answer, json["extraInfo"]?["typeDetails"])
        : null,
    askUserData: isAskUser
        ? ToolUseAskUserData.fromJson(json["extraInfo"]?["typeDetails"])
        : null,
    webReaderData: isWebReader ? ToolUseWebReaderData.fromJson(answer) : null,
  );
}