feat: Add AI action parser for natural language command processing
- Introduced `AIActionParser` class to parse natural language commands into structured GUI actions, supporting commands like placing tiles and opening editors. - Implemented helper functions for extracting coordinates and parsing hex/decimal values. - Added action types for various AI actions, including selecting and placing tiles, saving changes, and clicking buttons. - Created header file `ai_action_parser.h` to define the action types and parser interface. - Added implementation file `ai_action_parser.cc` with command parsing logic and pattern matching for different action types.
This commit is contained in:
86
src/cli/service/ai/ai_action_parser.h
Normal file
86
src/cli/service/ai/ai_action_parser.h
Normal file
@@ -0,0 +1,86 @@
|
||||
#ifndef YAZE_CLI_SERVICE_AI_AI_ACTION_PARSER_H_
|
||||
#define YAZE_CLI_SERVICE_AI_AI_ACTION_PARSER_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/statusor.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
namespace ai {
|
||||
|
||||
/**
|
||||
* @enum AIActionType
|
||||
* @brief Types of actions the AI can request
|
||||
*/
|
||||
enum class AIActionType {
|
||||
kOpenEditor, // Open a specific editor window
|
||||
kSelectTile, // Select a tile from the tile16 selector
|
||||
kPlaceTile, // Place a tile at a specific position
|
||||
kSaveTile, // Save tile changes to ROM
|
||||
kVerifyTile, // Verify a tile was placed correctly
|
||||
kClickButton, // Click a specific button
|
||||
kWait, // Wait for a duration or condition
|
||||
kScreenshot, // Take a screenshot for verification
|
||||
kInvalidAction
|
||||
};
|
||||
|
||||
/**
|
||||
* @struct AIAction
|
||||
* @brief Represents a single action to be performed in the GUI
|
||||
*/
|
||||
struct AIAction {
|
||||
AIActionType type;
|
||||
std::map<std::string, std::string> parameters;
|
||||
|
||||
AIAction() : type(AIActionType::kInvalidAction) {}
|
||||
AIAction(AIActionType t) : type(t) {}
|
||||
AIAction(AIActionType t, const std::map<std::string, std::string>& params)
|
||||
: type(t), parameters(params) {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class AIActionParser
|
||||
* @brief Parses natural language commands into structured GUI actions
|
||||
*
|
||||
* Understands commands like:
|
||||
* - "Place tile 0x42 at overworld position (5, 7)"
|
||||
* - "Open the overworld editor"
|
||||
* - "Select tile 100 from the tile selector"
|
||||
*/
|
||||
class AIActionParser {
|
||||
public:
|
||||
/**
|
||||
* Parse a natural language command into a sequence of AI actions
|
||||
* @param command The command to parse
|
||||
* @return Vector of actions, or error status
|
||||
*/
|
||||
static absl::StatusOr<std::vector<AIAction>> ParseCommand(
|
||||
const std::string& command);
|
||||
|
||||
/**
|
||||
* Convert an action back to a human-readable string
|
||||
*/
|
||||
static std::string ActionToString(const AIAction& action);
|
||||
|
||||
private:
|
||||
static AIActionType ParseActionType(const std::string& verb);
|
||||
static std::map<std::string, std::string> ExtractParameters(
|
||||
const std::string& command, AIActionType type);
|
||||
|
||||
// Pattern matchers for different command types
|
||||
static bool MatchesPlaceTilePattern(const std::string& command,
|
||||
std::map<std::string, std::string>* params);
|
||||
static bool MatchesSelectTilePattern(const std::string& command,
|
||||
std::map<std::string, std::string>* params);
|
||||
static bool MatchesOpenEditorPattern(const std::string& command,
|
||||
std::map<std::string, std::string>* params);
|
||||
};
|
||||
|
||||
} // namespace ai
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_CLI_SERVICE_AI_AI_ACTION_PARSER_H_
|
||||
Reference in New Issue
Block a user