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:
scawful
2025-10-03 12:39:48 -04:00
parent 655c5547b2
commit 208b9ade51
25 changed files with 689 additions and 242 deletions

View File

@@ -37,3 +37,7 @@ set(
app/test/unit_test_suite.h
app/editor/system/proposal_drawer.cc
)
if(YAZE_WITH_GRPC)
list(APPEND YAZE_APP_EDITOR_SRC app/editor/system/agent_chat_widget.cc)
endif()

View File

@@ -8,7 +8,6 @@
#include "absl/strings/match.h"
#include "absl/strings/str_cat.h"
#include "app/core/features.h"
#include "app/gfx/performance_profiler.h"
#include "app/core/platform/file_dialog.h"
#include "app/core/project.h"
#include "app/editor/code/assembly_editor.h"
@@ -21,6 +20,7 @@
#include "app/editor/sprite/sprite_editor.h"
#include "app/emu/emulator.h"
#include "app/gfx/arena.h"
#include "app/gfx/performance_profiler.h"
#include "app/gui/background_renderer.h"
#include "app/gui/icons.h"
#include "app/gui/input.h"
@@ -38,11 +38,16 @@
#ifdef YAZE_ENABLE_GTEST
#include "app/test/unit_test_suite.h"
#endif
#include "app/editor/system/settings_editor.h"
#include "app/editor/system/toast_manager.h"
#include "app/emu/emulator.h"
#include "app/gfx/performance_dashboard.h"
#include "editor/editor.h"
#include "imgui/imgui.h"
#include "imgui/misc/cpp/imgui_stdlib.h"
#include "util/log.h"
#include "util/macro.h"
#include "yaze_config.h"
namespace yaze {
namespace editor {
@@ -706,6 +711,10 @@ void EditorManager::Initialize(const std::string& filename) {
// Agent Proposals
{absl::StrCat(ICON_MD_PREVIEW, " Agent Proposals"), "",
[&]() { proposal_drawer_.Toggle(); }},
#ifdef YAZE_WITH_GRPC
{absl::StrCat(ICON_MD_CHAT, " Agent Chat"), "",
[&]() { show_agent_chat_widget_ = !show_agent_chat_widget_; }},
#endif
{gui::kSeparator, "", nullptr, []() { return true; }},
@@ -915,6 +924,19 @@ absl::Status EditorManager::Update() {
}
}
}
if (show_performance_dashboard_) {
gfx::PerformanceDashboard::Get().Render();
}
if (show_proposal_drawer_) {
proposal_drawer_.Draw();
}
#ifdef YAZE_WITH_GRPC
if (show_agent_chat_widget_) {
agent_chat_widget_.Draw();
}
#endif
return absl::OkStatus();
}

View File

@@ -21,6 +21,9 @@
#include "app/editor/sprite/sprite_editor.h"
#include "app/editor/system/popup_manager.h"
#include "app/editor/system/proposal_drawer.h"
#ifdef YAZE_WITH_GRPC
#include "app/editor/system/agent_chat_widget.h"
#endif
#include "app/editor/system/settings_editor.h"
#include "app/editor/system/toast_manager.h"
#include "app/emu/emulator.h"
@@ -174,11 +177,17 @@ class EditorManager {
// Testing interface
bool show_test_dashboard_ = false;
bool show_performance_dashboard_ = false;
// Agent proposal drawer
ProposalDrawer proposal_drawer_;
bool show_proposal_drawer_ = false;
#ifdef YAZE_WITH_GRPC
// Agent chat widget
AgentChatWidget agent_chat_widget_;
bool show_agent_chat_widget_ = false;
#endif
std::string version_ = "";
std::string settings_filename_ = "settings.ini";
float font_global_scale_ = 1.0f;

View File

@@ -0,0 +1,42 @@
#include "app/editor/system/agent_chat_widget.h"
#include "imgui.h"
namespace yaze {
namespace editor {
AgentChatWidget::AgentChatWidget() {
title_ = "Agent Chat";
memset(input_buffer_, 0, sizeof(input_buffer_));
}
void AgentChatWidget::Draw() {
if (!active_) {
return;
}
ImGui::Begin(title_.c_str(), &active_);
// Display message history
ImGui::BeginChild("History", ImVec2(0, -ImGui::GetFrameHeightWithSpacing()));
for (const auto& msg : agent_service_.GetHistory()) {
std::string prefix =
msg.sender == cli::agent::ChatMessage::Sender::kUser ? "You: " : "Agent: ";
ImGui::TextWrapped((prefix + msg.message).c_str());
}
ImGui::EndChild();
// Display input text box
if (ImGui::InputText("Input", input_buffer_, sizeof(input_buffer_),
ImGuiInputTextFlags_EnterReturnsTrue)) {
if (strlen(input_buffer_) > 0) {
(void)agent_service_.SendMessage(input_buffer_);
memset(input_buffer_, 0, sizeof(input_buffer_));
}
ImGui::SetKeyboardFocusHere(-1); // Refocus input
}
ImGui::End();
}
} // namespace editor
} // namespace yaze

View File

@@ -0,0 +1,30 @@
#ifndef YAZE_SRC_APP_EDITOR_SYSTEM_AGENT_CHAT_WIDGET_H_
#define YAZE_SRC_APP_EDITOR_SYSTEM_AGENT_CHAT_WIDGET_H_
#include <string>
#include "cli/service/agent/conversational_agent_service.h"
namespace yaze {
namespace editor {
class AgentChatWidget {
public:
AgentChatWidget();
void Draw();
bool* active() { return &active_; }
void set_active(bool active) { active_ = active; }
private:
cli::agent::ConversationalAgentService agent_service_;
char input_buffer_[1024];
bool active_ = false;
std::string title_;
};
} // namespace editor
} // namespace yaze
#endif // YAZE_SRC_APP_EDITOR_SYSTEM_AGENT_CHAT_WIDGET_H_