import '../../../core/api_gateway.dart'; import 'chat_commands.dart'; /// The session's harness commands from a `chat_commands` reply list: each /// entry's `name`, `description` and `argument_hint`. Entries without a usable /// single-word name are skipped and duplicates keep their first entry, in the /// server's order. A harness without commands yields an empty list. List chatHarnessCommandsFromWire(List entries) { final seen = {}; final commands = []; for (final entry in entries) { var name = '${entry['name'] ?? ''}'.trim(); if (name.startsWith('/')) name = name.substring(1); if (name.isEmpty || name.contains(RegExp(r'\s'))) continue; if (!seen.add(name.toLowerCase())) continue; final description = '${entry['description'] ?? ''}'.trim(); final hint = '${entry['argument_hint'] ?? ''}'.trim(); commands.add( ChatCommand.harness( name: name, summary: description, usage: hint.isEmpty ? '/$name' : '/$name $hint', ), ); } return commands; }