Integrate AI Agent Services and Chat Interface
- Added support for AI agent services, including `ConversationalAgentService`, to facilitate user interactions through a chat interface. - Implemented `ChatTUI` for a terminal-based chat experience, allowing users to send messages and receive responses from the AI agent. - Updated `EditorManager` to include options for displaying the agent chat widget and performance dashboard. - Enhanced CMake configurations to include new source files for AI services and chat interface components. This commit significantly expands the functionality of the z3ed system, paving the way for a more interactive and user-friendly experience in ROM hacking.
This commit is contained in:
52
src/cli/service/agent/conversational_agent_service.cc
Normal file
52
src/cli/service/agent/conversational_agent_service.cc
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "cli/service/agent/conversational_agent_service.h"
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_join.h"
|
||||
#include "absl/time/clock.h"
|
||||
#include "cli/service/ai/service_factory.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
namespace agent {
|
||||
|
||||
ConversationalAgentService::ConversationalAgentService() {
|
||||
ai_service_ = CreateAIService();
|
||||
}
|
||||
|
||||
absl::StatusOr<ChatMessage> ConversationalAgentService::SendMessage(
|
||||
const std::string& message) {
|
||||
// 1. Add user message to history.
|
||||
history_.push_back({ChatMessage::Sender::kUser, message, absl::Now()});
|
||||
|
||||
// 2. Get response from the AI service using the full history.
|
||||
auto response_or = ai_service_->GenerateResponse(history_);
|
||||
if (!response_or.ok()) {
|
||||
return absl::InternalError(absl::StrCat("Failed to get AI response: ",
|
||||
response_or.status().message()));
|
||||
}
|
||||
|
||||
const auto& agent_response = response_or.value();
|
||||
|
||||
// For now, combine text and commands for display.
|
||||
// In the future, the TUI/GUI will handle these differently.
|
||||
std::string response_text = agent_response.text_response;
|
||||
if (!agent_response.commands.empty()) {
|
||||
response_text += "\n\nCommands:\n" + absl::StrJoin(agent_response.commands, "\n");
|
||||
}
|
||||
|
||||
ChatMessage chat_response = {ChatMessage::Sender::kAgent, response_text,
|
||||
absl::Now()};
|
||||
|
||||
// 3. Add agent response to history.
|
||||
history_.push_back(chat_response);
|
||||
|
||||
return chat_response;
|
||||
}
|
||||
|
||||
const std::vector<ChatMessage>& ConversationalAgentService::GetHistory() const {
|
||||
return history_;
|
||||
}
|
||||
|
||||
} // namespace agent
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
40
src/cli/service/agent/conversational_agent_service.h
Normal file
40
src/cli/service/agent/conversational_agent_service.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_H_
|
||||
#define YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/status/statusor.h"
|
||||
#include "cli/service/ai/ai_service.h"
|
||||
|
||||
namespace yaze {
|
||||
namespace cli {
|
||||
namespace agent {
|
||||
|
||||
struct ChatMessage {
|
||||
enum class Sender { kUser, kAgent };
|
||||
Sender sender;
|
||||
std::string message;
|
||||
absl::Time timestamp;
|
||||
};
|
||||
|
||||
class ConversationalAgentService {
|
||||
public:
|
||||
ConversationalAgentService();
|
||||
|
||||
// Send a message from the user and get the agent's response.
|
||||
absl::StatusOr<ChatMessage> SendMessage(const std::string& message);
|
||||
|
||||
// Get the full chat history.
|
||||
const std::vector<ChatMessage>& GetHistory() const;
|
||||
|
||||
private:
|
||||
std::vector<ChatMessage> history_;
|
||||
std::unique_ptr<AIService> ai_service_;
|
||||
};
|
||||
|
||||
} // namespace agent
|
||||
} // namespace cli
|
||||
} // namespace yaze
|
||||
|
||||
#endif // YAZE_SRC_CLI_SERVICE_AGENT_CONVERSATIONAL_AGENT_SERVICE_H_
|
||||
Reference in New Issue
Block a user