fromJevChoice static method

List<DeciderOption> fromJevChoice(
  1. Map<String, Object?> question
)

The options of a Jev Choice question (TypeSafe AI's wire format): one option per criteria entry, its key the id.

question is one question object of a Jev request, e.g. {"type": "choice", "instructions": "...", "criteria": {"returns": "Exchanges, wrong or damaged items", "billing": null}}. A string criterion becomes the description; an object or array is JSON-encoded into it; null or an empty string uses the key itself as the description, as Jev reads the option name. instructions is not part of an option and is not used by an embedding decider.

Choice questions only: throws ArgumentError for any other type (noul, score), and for a missing or empty criteria map.

Implementation

static List<DeciderOption> fromJevChoice(Map<String, Object?> question) {
  final type = question['type'];
  if (type != 'choice') {
    throw ArgumentError.value(
      type,
      'question.type',
      'only Jev Choice questions ("choice") become decider options',
    );
  }
  final criteria = question['criteria'];
  if (criteria is! Map || criteria.isEmpty) {
    throw ArgumentError.value(
      criteria,
      'question.criteria',
      'a Choice question needs a non-empty criteria map',
    );
  }
  return [
    for (final MapEntry(:key, :value) in criteria.entries)
      DeciderOption(
        '$key',
        description: switch (value) {
          null => '$key',
          final String text when text.isNotEmpty => text,
          final String _ => '$key',
          _ => jsonEncode(value),
        },
      ),
  ];
}