validateDashCommandVariableUsage static method

Map<String, Map<String, String>>? validateDashCommandVariableUsage(
  1. Map<String, dynamic> commandJson
)

Implementation

static Map<String, Map<String, String>>? validateDashCommandVariableUsage(
    Map<String, dynamic> commandJson) {
  final registeredInputs =
      (commandJson['registered_inputs']?.cast<Map<String, dynamic>>())
          .map<String>((Map<String, dynamic> input) => input['id'] as String)
          .toList();
  final registeredOutput = (commandJson['registered_outputs']
          ?.cast<Map<String, dynamic>>())
      .map<String>((Map<String, dynamic> output) => output['id'] as String)
      .toList();

  final registeredVariables = <String>[
    ...registeredInputs,
    ...registeredOutput
  ];
  final nonRegisteredStepVariables = <String, Map<String, String>>{};
  final steps = commandJson['steps']?.cast<Map<String, dynamic>>();
  for (final step in steps) {
    final type = step['type'];
    if (step['type'] == 'search_in_sources') {
      final validationResponse =
          _validateMachingDocumentStep(step, registeredVariables);
      if (validationResponse != null) {
        if (!nonRegisteredStepVariables.containsKey(type)) {
          nonRegisteredStepVariables[type] = {};
        }
        nonRegisteredStepVariables[type]
            ?.addAll({'MachingDocumentStep': validationResponse});
      }
    } else if (step['type'] == 'search_in_workspace') {
      final validationResponse =
          _validateWorkspaceQueryStep(step, registeredVariables);
      if (validationResponse != null) {
        if (!nonRegisteredStepVariables.containsKey(type)) {
          nonRegisteredStepVariables[type] = {};
        }
        nonRegisteredStepVariables[type]
            ?.addAll({'WorkspaceQueryStep': validationResponse});
      }
    } else if (step['type'] == 'prompt_query') {
      final validationResponse =
          _validatePromptQueryStep(step, registeredVariables);
      if (validationResponse != null) {
        if (!nonRegisteredStepVariables.containsKey(type)) {
          nonRegisteredStepVariables[type] = {};
        }
        nonRegisteredStepVariables[type]
            ?.addAll({'PromptQueryStep': validationResponse});
      }
    } else if (step['type'] == 'append_to_chat') {
      final validationResponse =
          _validateAppendToChatStep(step, registeredVariables);
      if (validationResponse != null) {
        if (!nonRegisteredStepVariables.containsKey(type)) {
          nonRegisteredStepVariables[type] = {};
        }
        nonRegisteredStepVariables[type]
            ?.addAll({'AppendToChatStep': validationResponse});
      }
    }
  }

  if (nonRegisteredStepVariables.isEmpty) {
    return null;
  }
  return nonRegisteredStepVariables;
}