yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
agent_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_
2#define YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_
3
4#include <filesystem>
5#include <functional>
6#include <memory>
7#include <optional>
8#include <string>
9#include <vector>
10
11#include "absl/status/status.h"
12#include "absl/status/statusor.h"
13#include "absl/time/clock.h"
14#include "absl/time/time.h"
17#include "app/editor/editor.h"
20#ifdef YAZE_WITH_GRPC
22#endif
23
24namespace yaze {
25
26class Rom;
27namespace cli {
28class AIService;
29} // namespace cli
30
31namespace editor {
32
33class ToastManager;
34class ProposalDrawer;
35class AgentChat;
36class AgentCollaborationCoordinator;
37class AgentConfigPanel;
38class FeatureFlagEditorPanel;
39class ManifestPanel;
40class MesenDebugPanel;
41class MesenScreenshotPanel;
42class OracleStateLibraryPanel;
43class SramViewerPanel;
44
45#ifdef YAZE_WITH_GRPC
46class NetworkCollaborationCoordinator;
47#endif
48
68class AgentEditor : public Editor {
69 public:
71 ~AgentEditor() override;
72
73 // Editor interface implementation
74 void Initialize() override;
75 absl::Status Load() override;
76 absl::Status Save() override;
77 absl::Status Update() override;
78 absl::Status Cut() override {
79 return absl::UnimplementedError("Not applicable");
80 }
81 absl::Status Copy() override {
82 return absl::UnimplementedError("Not applicable");
83 }
84 absl::Status Paste() override {
85 return absl::UnimplementedError("Not applicable");
86 }
87 absl::Status Undo() override {
88 return absl::UnimplementedError("Not applicable");
89 }
90 absl::Status Redo() override {
91 return absl::UnimplementedError("Not applicable");
92 }
93 absl::Status Find() override {
94 return absl::UnimplementedError("Not applicable");
95 }
96
97 // Initialization with dependencies
98 void InitializeWithDependencies(ToastManager* toast_manager,
99 ProposalDrawer* proposal_drawer, Rom* rom);
100 void SetRomContext(Rom* rom);
102
103 // Main rendering (called by Update())
104 void DrawDashboard();
105
106 // Bot Configuration & Profile Management
107 struct BotProfile {
108 std::string name = "Default Bot";
109 std::string description;
110 std::string provider = "mock";
111 std::string host_id;
112 std::string model;
113 std::string ollama_host = "http://localhost:11434";
114 std::string gemini_api_key;
115 std::string anthropic_api_key;
116 std::string openai_api_key;
117 std::string openai_base_url = "https://api.openai.com";
118 std::string system_prompt;
119 bool verbose = false;
120 bool show_reasoning = true;
123 float temperature = 0.25f;
124 float top_p = 0.95f;
126 bool stream_responses = false;
127 std::vector<std::string> tags;
128 absl::Time created_at = absl::Now();
129 absl::Time modified_at = absl::Now();
130 };
131
132 // Profile accessor for external sync (used by AgentUiController)
135
136 // Legacy support
137 struct AgentConfig {
138 std::string provider = "mock";
139 std::string model;
140 std::string ollama_host = "http://localhost:11434";
141 std::string gemini_api_key;
142 std::string anthropic_api_key;
143 std::string openai_api_key;
144 std::string openai_base_url = "https://api.openai.com";
145 bool verbose = false;
146 bool show_reasoning = true;
149 float temperature = 0.25f;
150 float top_p = 0.95f;
152 bool stream_responses = false;
153 };
154
156 struct Stage {
157 std::string name;
158 std::string summary;
159 bool completed = false;
160 };
161 std::vector<Stage> stages;
163 std::vector<std::string> goals;
164 std::string persona_notes;
165 struct ToolPlan {
166 bool resources = true;
167 bool dungeon = true;
168 bool overworld = true;
169 bool dialogue = true;
170 bool gui = false;
171 bool music = false;
172 bool sprite = false;
173 bool emulator = false;
174 bool memory_inspector = false;
176 bool auto_run_tests = false;
177 bool auto_sync_rom = true;
179 std::string blueprint_path;
180 bool ready_for_e2e = false;
181 };
182
183 // Retro hacker animation state
184 float pulse_animation_ = 0.0f;
185 float scanline_offset_ = 0.0f;
186 float glitch_timer_ = 0.0f;
188
190 void ApplyConfig(const AgentConfig& config);
191 void ApplyUserSettingsDefaults(bool force = false);
192
193 // Bot Profile Management
194 absl::Status SaveBotProfile(const BotProfile& profile);
195 absl::Status LoadBotProfile(const std::string& name);
196 absl::Status DeleteBotProfile(const std::string& name);
197 std::vector<BotProfile> GetAllProfiles() const;
198 void SetCurrentProfile(const BotProfile& profile);
199 absl::Status ExportProfile(const BotProfile& profile,
200 const std::filesystem::path& path);
201 absl::Status ImportProfile(const std::filesystem::path& path);
202
203 // Chat widget access (for EditorManager)
204 AgentChat* GetAgentChat() { return agent_chat_.get(); }
205 bool IsChatActive() const;
206 void SetChatActive(bool active);
207 void ToggleChat();
208 void OpenChatWindow();
209
210 // Knowledge panel callback (set by AgentUiController)
211 using KnowledgePanelCallback = std::function<void()>;
213 knowledge_panel_callback_ = std::move(callback);
214 }
215
216 // Collaboration and session management
217 enum class CollaborationMode {
218 kLocal, // Filesystem-based collaboration
219 kNetwork // WebSocket-based collaboration
220 };
221
222 struct SessionInfo {
223 std::string session_id;
224 std::string session_name;
225 std::vector<std::string> participants;
226 };
227
228 absl::StatusOr<SessionInfo> HostSession(
229 const std::string& session_name,
231 absl::StatusOr<SessionInfo> JoinSession(
232 const std::string& session_code,
234 absl::Status LeaveSession();
235 absl::StatusOr<SessionInfo> RefreshSession();
236
242
243 absl::Status CaptureSnapshot(std::filesystem::path* output_path,
244 const CaptureConfig& config);
245 absl::Status SendToGemini(const std::filesystem::path& image_path,
246 const std::string& prompt);
247
248#ifdef YAZE_WITH_GRPC
249 absl::Status ConnectToServer(const std::string& server_url);
250 void DisconnectFromServer();
251 bool IsConnectedToServer() const;
252#endif
253
254 bool IsInSession() const;
256 std::optional<SessionInfo> GetCurrentSession() const;
257
258 // Access to underlying components
262#ifdef YAZE_WITH_GRPC
263 NetworkCollaborationCoordinator* GetNetworkCoordinator() {
264 return network_coordinator_.get();
265 }
266#endif
267
268 private:
269 // Dashboard panel rendering
271 void DrawStatusPanel();
272 void DrawMetricsPanel();
281 void DrawManifestPanel();
282 void DrawMesenDebugPanel();
285 void DrawSramViewerPanel();
288 void ApplyConfigFromContext(const AgentConfigState& config);
290 void RefreshModelCache(bool force);
291 void ApplyModelPreset(const ModelPreset& preset);
293
294 // Setup callbacks
297
298 // Bot profile helpers
299 std::filesystem::path GetProfilesDirectory() const;
300 absl::Status EnsureProfilesDirectory();
301 std::string ProfileToJson(const BotProfile& profile) const;
302 absl::StatusOr<BotProfile> JsonToProfile(const std::string& json) const;
303 absl::Status SaveBuilderBlueprint(const std::filesystem::path& path);
304 absl::Status LoadBuilderBlueprint(const std::filesystem::path& path);
305
306 // Profile UI state
307 void MarkProfileUiDirty();
308 void SyncProfileUiState();
309
310 // Internal state
311 std::unique_ptr<AgentChat> agent_chat_; // Owned by AgentEditor
312 std::unique_ptr<AgentCollaborationCoordinator> local_coordinator_;
313 std::unique_ptr<AgentConfigPanel> config_panel_;
314 std::unique_ptr<FeatureFlagEditorPanel> feature_flag_panel_;
315 std::unique_ptr<ManifestPanel> manifest_panel_;
316 std::unique_ptr<MesenDebugPanel> mesen_debug_panel_;
317 std::unique_ptr<MesenScreenshotPanel> mesen_screenshot_panel_;
318 std::unique_ptr<OracleStateLibraryPanel> oracle_state_panel_;
319 std::unique_ptr<SramViewerPanel> sram_viewer_panel_;
320#ifdef YAZE_WITH_GRPC
321 std::unique_ptr<NetworkCollaborationCoordinator> network_coordinator_;
322 AutomationBridge harness_telemetry_bridge_;
323#endif
324
327 Rom* rom_ = nullptr;
329 // Note: Config syncing is managed by AgentUiController
330
331 // Configuration state (legacy)
333
335 std::string provider;
336 std::string model;
337 std::string ollama_host;
338 std::string gemini_api_key;
339 std::string anthropic_api_key;
340 std::string openai_api_key;
341 std::string openai_base_url;
342 bool verbose = false;
343 };
345 std::unique_ptr<cli::AIService> model_service_;
346 std::vector<std::string> last_local_model_paths_;
347 absl::Time last_local_model_scan_ = absl::InfinitePast();
348
349 // Bot Profile System
351 std::vector<BotProfile> loaded_profiles_;
353
355 bool dirty = true;
356 char model_buf[128] = {};
357 char ollama_host_buf[256] = {};
358 char gemini_key_buf[256] = {};
359 char anthropic_key_buf[256] = {};
360 char openai_key_buf[256] = {};
361 char openai_base_buf[256] = {};
362 char name_buf[128] = {};
363 char desc_buf[256] = {};
364 char tags_buf[256] = {};
365 };
367
368 // System Prompt Editor
369 std::unique_ptr<TextEditor> prompt_editor_;
370 std::unique_ptr<TextEditor> common_tiles_editor_;
373 std::string active_prompt_file_ = "system_prompt_v3.txt";
374 char new_prompt_name_[128] = {};
375
376 // Collaboration state
378 bool in_session_ = false;
381 std::vector<std::string> current_participants_;
382
383 // UI state (legacy)
386 bool show_bot_profiles_ = false;
387 bool show_chat_history_ = false;
389 int selected_tab_ = 0; // 0=Config, 1=Prompts, 2=Bots, 3=History, 4=Metrics
390
391 // Panel-based UI visibility flags
392 bool show_config_card_ = true;
393 bool show_status_card_ = true;
396 bool show_history_card_ = false;
397 bool show_metrics_card_ = false;
398 bool show_builder_card_ = false;
399 bool show_chat_card_ = true;
400 bool auto_probe_done_ = false;
401
402 // Panel registration helper
403 void RegisterPanels();
404
405 // Chat history viewer state
406 std::vector<cli::agent::ChatMessage> cached_history_;
408
409 // Knowledge panel callback (set by AgentUiController)
411};
412
413} // namespace editor
414} // namespace yaze
415
416#endif // YAZE_APP_EDITOR_AGENT_AGENT_EDITOR_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Unified Agent Chat Component.
Definition agent_chat.h:32
Comprehensive AI Agent Platform & Bot Creator.
void RefreshModelCache(bool force)
std::unique_ptr< cli::AIService > model_service_
void SetKnowledgePanelCallback(KnowledgePanelCallback callback)
void SetCurrentProfile(const BotProfile &profile)
void ApplyConfig(const AgentConfig &config)
void InitializeWithDependencies(ToastManager *toast_manager, ProposalDrawer *proposal_drawer, Rom *rom)
absl::Status SaveBuilderBlueprint(const std::filesystem::path &path)
absl::StatusOr< SessionInfo > JoinSession(const std::string &session_code, CollaborationMode mode=CollaborationMode::kLocal)
BotProfile & GetCurrentProfile()
void SetChatActive(bool active)
std::unique_ptr< MesenScreenshotPanel > mesen_screenshot_panel_
KnowledgePanelCallback knowledge_panel_callback_
absl::StatusOr< BotProfile > JsonToProfile(const std::string &json) const
absl::Status Find() override
std::unique_ptr< OracleStateLibraryPanel > oracle_state_panel_
absl::StatusOr< SessionInfo > RefreshSession()
absl::Status ImportProfile(const std::filesystem::path &path)
absl::Status Copy() override
void ApplyModelPreset(const ModelPreset &preset)
ProposalDrawer * proposal_drawer_
absl::Status Redo() override
std::vector< cli::agent::ChatMessage > cached_history_
AgentBuilderState builder_state_
ModelServiceKey last_model_service_key_
absl::Status Save() override
std::string current_session_name_
CollaborationMode GetCurrentMode() const
const BotProfile & GetCurrentProfile() const
std::unique_ptr< FeatureFlagEditorPanel > feature_flag_panel_
absl::Status SendToGemini(const std::filesystem::path &image_path, const std::string &prompt)
AgentCollaborationCoordinator * GetLocalCoordinator()
std::unique_ptr< AgentConfigPanel > config_panel_
absl::Status EnsureProfilesDirectory()
void SetContext(AgentUIContext *context)
std::unique_ptr< MesenDebugPanel > mesen_debug_panel_
AgentUIContext * context_
absl::Status Undo() override
absl::Status LoadBuilderBlueprint(const std::filesystem::path &path)
std::function< void()> KnowledgePanelCallback
absl::Status Paste() override
ProfileUiState profile_ui_state_
absl::Status ExportProfile(const BotProfile &profile, const std::filesystem::path &path)
CollaborationMode current_mode_
absl::Status SaveBotProfile(const BotProfile &profile)
absl::Status DeleteBotProfile(const std::string &name)
std::filesystem::path GetProfilesDirectory() const
ToastManager * toast_manager_
AgentConfig GetCurrentConfig() const
std::unique_ptr< TextEditor > common_tiles_editor_
absl::StatusOr< SessionInfo > HostSession(const std::string &session_name, CollaborationMode mode=CollaborationMode::kLocal)
std::string ProfileToJson(const BotProfile &profile) const
std::unique_ptr< TextEditor > prompt_editor_
std::unique_ptr< AgentCollaborationCoordinator > local_coordinator_
std::unique_ptr< SramViewerPanel > sram_viewer_panel_
absl::Status CaptureSnapshot(std::filesystem::path *output_path, const CaptureConfig &config)
absl::Status Load() override
absl::Status LoadBotProfile(const std::string &name)
std::vector< BotProfile > GetAllProfiles() const
std::vector< std::string > current_participants_
std::vector< std::string > last_local_model_paths_
void ApplyConfigFromContext(const AgentConfigState &config)
std::unique_ptr< AgentChat > agent_chat_
absl::Status Update() override
void ApplyUserSettingsDefaults(bool force=false)
std::unique_ptr< ManifestPanel > manifest_panel_
std::vector< BotProfile > loaded_profiles_
absl::Status Cut() override
std::optional< SessionInfo > GetCurrentSession() const
Unified context for agent UI components.
Interface for editor classes.
Definition editor.h:236
EditorContext context() const
Definition editor.h:300
Rom * rom() const
Definition editor.h:296
ImGui drawer for displaying and managing agent proposals.
struct yaze::editor::AgentEditor::AgentBuilderState::ToolPlan tools
std::vector< std::string > tags
std::vector< std::string > participants