#ifndef YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_ #define YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_ #include #include #include #include #include #include "absl/status/status.h" #include "absl/status/statusor.h" #include "app/editor/editor.h" #include "app/gui/widgets/text_editor.h" #include "cli/service/agent/conversational_agent_service.h" namespace yaze { class Rom; namespace editor { class ToastManager; class ProposalDrawer; class AgentChatWidget; class AgentCollaborationCoordinator; #ifdef YAZE_WITH_GRPC class NetworkCollaborationCoordinator; #endif /** * @class AgentEditor * @brief Comprehensive AI Agent Platform & Bot Creator * * A full-featured bot creation and management platform: * - Agent provider configuration (Ollama, Gemini, Mock) * - Model selection and parameters * - System prompt editing with live syntax highlighting * - Bot profile management (create, save, load custom bots) * - Chat history viewer and management * - Session metrics and analytics dashboard * - Collaboration settings (Local/Network) * - Z3ED command automation presets * - Multimodal/vision configuration * - Export/Import bot configurations * * The chat widget is separate and managed by EditorManager, with * a dense/compact mode for focused conversations. */ class AgentEditor : public Editor { public: AgentEditor(); ~AgentEditor() override; // Editor interface implementation void Initialize() override; absl::Status Load() override; absl::Status Save() override; absl::Status Update() override; absl::Status Cut() override { return absl::UnimplementedError("Not applicable"); } absl::Status Copy() override { return absl::UnimplementedError("Not applicable"); } absl::Status Paste() override { return absl::UnimplementedError("Not applicable"); } absl::Status Undo() override { return absl::UnimplementedError("Not applicable"); } absl::Status Redo() override { return absl::UnimplementedError("Not applicable"); } absl::Status Find() override { return absl::UnimplementedError("Not applicable"); } // Initialization with dependencies void InitializeWithDependencies(ToastManager* toast_manager, ProposalDrawer* proposal_drawer, Rom* rom); void SetRomContext(Rom* rom); // Main rendering (called by Update()) void DrawDashboard(); // Bot Configuration & Profile Management struct BotProfile { std::string name = "Default Bot"; std::string description; std::string provider = "mock"; std::string model; std::string ollama_host = "http://localhost:11434"; std::string gemini_api_key; std::string system_prompt; bool verbose = false; bool show_reasoning = true; int max_tool_iterations = 4; int max_retry_attempts = 3; std::vector tags; absl::Time created_at = absl::Now(); absl::Time modified_at = absl::Now(); }; // Legacy support struct AgentConfig { std::string provider = "mock"; std::string model; std::string ollama_host = "http://localhost:11434"; std::string gemini_api_key; bool verbose = false; bool show_reasoning = true; int max_tool_iterations = 4; }; struct AgentBuilderState { struct Stage { std::string name; std::string summary; bool completed = false; }; std::vector stages; int active_stage = 0; std::vector goals; std::string persona_notes; struct ToolPlan { bool resources = true; bool dungeon = true; bool overworld = true; bool dialogue = true; bool gui = false; bool music = false; bool sprite = false; bool emulator = false; } tools; bool auto_run_tests = false; bool auto_sync_rom = true; bool auto_focus_proposals = true; std::string blueprint_path; bool ready_for_e2e = false; }; // Retro hacker animation state float pulse_animation_ = 0.0f; float scanline_offset_ = 0.0f; float glitch_timer_ = 0.0f; int blink_counter_ = 0; AgentConfig GetCurrentConfig() const; void ApplyConfig(const AgentConfig& config); // Bot Profile Management absl::Status SaveBotProfile(const BotProfile& profile); absl::Status LoadBotProfile(const std::string& name); absl::Status DeleteBotProfile(const std::string& name); std::vector GetAllProfiles() const; BotProfile GetCurrentProfile() const { return current_profile_; } void SetCurrentProfile(const BotProfile& profile); absl::Status ExportProfile(const BotProfile& profile, const std::filesystem::path& path); absl::Status ImportProfile(const std::filesystem::path& path); // Chat widget access (for EditorManager) AgentChatWidget* GetChatWidget() { return chat_widget_.get(); } bool IsChatActive() const; void SetChatActive(bool active); void ToggleChat(); void OpenChatWindow(); // Collaboration and session management enum class CollaborationMode { kLocal, // Filesystem-based collaboration kNetwork // WebSocket-based collaboration }; struct SessionInfo { std::string session_id; std::string session_name; std::vector participants; }; absl::StatusOr HostSession(const std::string& session_name, CollaborationMode mode = CollaborationMode::kLocal); absl::StatusOr JoinSession(const std::string& session_code, CollaborationMode mode = CollaborationMode::kLocal); absl::Status LeaveSession(); absl::StatusOr RefreshSession(); struct CaptureConfig { enum class CaptureMode { kFullWindow, kActiveEditor, kSpecificWindow }; CaptureMode mode = CaptureMode::kActiveEditor; std::string specific_window_name; }; absl::Status CaptureSnapshot(std::filesystem::path* output_path, const CaptureConfig& config); absl::Status SendToGemini(const std::filesystem::path& image_path, const std::string& prompt); #ifdef YAZE_WITH_GRPC absl::Status ConnectToServer(const std::string& server_url); void DisconnectFromServer(); bool IsConnectedToServer() const; #endif bool IsInSession() const; CollaborationMode GetCurrentMode() const; std::optional GetCurrentSession() const; // Access to underlying components AgentCollaborationCoordinator* GetLocalCoordinator() { return local_coordinator_.get(); } #ifdef YAZE_WITH_GRPC NetworkCollaborationCoordinator* GetNetworkCoordinator() { return network_coordinator_.get(); } #endif private: // Dashboard panel rendering void DrawConfigurationPanel(); void DrawStatusPanel(); void DrawMetricsPanel(); void DrawPromptEditorPanel(); void DrawBotProfilesPanel(); void DrawChatHistoryViewer(); void DrawAdvancedMetricsPanel(); void DrawCommonTilesEditor(); void DrawNewPromptCreator(); void DrawAgentBuilderPanel(); // Setup callbacks void SetupChatWidgetCallbacks(); void SetupMultimodalCallbacks(); // Bot profile helpers std::filesystem::path GetProfilesDirectory() const; absl::Status EnsureProfilesDirectory(); std::string ProfileToJson(const BotProfile& profile) const; absl::StatusOr JsonToProfile(const std::string& json) const; absl::Status SaveBuilderBlueprint(const std::filesystem::path& path); absl::Status LoadBuilderBlueprint(const std::filesystem::path& path); // Internal state std::unique_ptr chat_widget_; // Owned by AgentEditor std::unique_ptr local_coordinator_; #ifdef YAZE_WITH_GRPC std::unique_ptr network_coordinator_; #endif ToastManager* toast_manager_ = nullptr; ProposalDrawer* proposal_drawer_ = nullptr; Rom* rom_ = nullptr; // Configuration state (legacy) AgentConfig current_config_; // Bot Profile System BotProfile current_profile_; std::vector loaded_profiles_; AgentBuilderState builder_state_; // System Prompt Editor std::unique_ptr prompt_editor_; std::unique_ptr common_tiles_editor_; bool prompt_editor_initialized_ = false; bool common_tiles_initialized_ = false; std::string active_prompt_file_ = "system_prompt_v3.txt"; char new_prompt_name_[128] = {}; // Collaboration state CollaborationMode current_mode_ = CollaborationMode::kLocal; bool in_session_ = false; std::string current_session_id_; std::string current_session_name_; std::vector current_participants_; // UI state bool show_advanced_settings_ = false; bool show_prompt_editor_ = false; bool show_bot_profiles_ = false; bool show_chat_history_ = false; bool show_metrics_dashboard_ = false; int selected_tab_ = 0; // 0=Config, 1=Prompts, 2=Bots, 3=History, 4=Metrics // Chat history viewer state std::vector cached_history_; bool history_needs_refresh_ = true; }; } // namespace editor } // namespace yaze #endif // YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_