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"
21#ifdef YAZE_WITH_GRPC
23#endif
24
25namespace yaze {
26
27class Rom;
28namespace cli {
29class AIService;
30} // namespace cli
31
32namespace editor {
33
34class ToastManager;
35class ProposalDrawer;
36class AgentChat;
37class AgentCollaborationCoordinator;
38class AgentConfigPanel;
39class FeatureFlagEditorPanel;
40class ManifestPanel;
41class MesenDebugPanel;
42class MesenScreenshotPanel;
43class OracleStateLibraryPanel;
44class SramViewerPanel;
45
46#ifdef YAZE_WITH_GRPC
47class NetworkCollaborationCoordinator;
48#endif
49
69class AgentEditor : public Editor {
70 public:
72 ~AgentEditor() override;
73
74 // Editor interface implementation
75 void Initialize() override;
76 absl::Status Load() override;
77 absl::Status Save() override;
78 absl::Status Update() override;
79 absl::Status Cut() override {
80 return absl::UnimplementedError("Not applicable");
81 }
82 absl::Status Copy() override {
83 return absl::UnimplementedError("Not applicable");
84 }
85 absl::Status Paste() override {
86 return absl::UnimplementedError("Not applicable");
87 }
88 absl::Status Undo() override {
89 return absl::UnimplementedError("Not applicable");
90 }
91 absl::Status Redo() override {
92 return absl::UnimplementedError("Not applicable");
93 }
94 absl::Status Find() override {
95 return absl::UnimplementedError("Not applicable");
96 }
97
98 // Initialization with dependencies
99 void InitializeWithDependencies(ToastManager* toast_manager,
100 ProposalDrawer* proposal_drawer, Rom* rom);
101 void SetRomContext(Rom* rom);
103
104 // Main rendering (called by Update())
105 void DrawDashboard();
106
107 // Bot Configuration & Profile Management
108 struct BotProfile {
109 std::string name = "Default Bot";
110 std::string description;
112 std::string host_id;
113 std::string model;
114 std::string ollama_host = "http://localhost:11434";
115 std::string gemini_api_key;
116 std::string anthropic_api_key;
117 std::string openai_api_key;
118 std::string openai_base_url = "https://api.openai.com";
119 std::string system_prompt;
120 bool verbose = false;
121 bool show_reasoning = true;
124 float temperature = 0.25f;
125 float top_p = 0.95f;
127 bool stream_responses = false;
128 std::vector<std::string> tags;
129 absl::Time created_at = absl::Now();
130 absl::Time modified_at = absl::Now();
131 };
132
133 // Profile accessor for external sync (used by AgentUiController)
136
137 // Legacy support
138 struct AgentConfig {
140 std::string model;
141 std::string ollama_host = "http://localhost:11434";
142 std::string gemini_api_key;
143 std::string anthropic_api_key;
144 std::string openai_api_key;
145 std::string openai_base_url = "https://api.openai.com";
146 bool verbose = false;
147 bool show_reasoning = true;
150 float temperature = 0.25f;
151 float top_p = 0.95f;
153 bool stream_responses = false;
154 };
155
157 struct Stage {
158 std::string name;
159 std::string summary;
160 bool completed = false;
161 };
162 std::vector<Stage> stages;
164 std::vector<std::string> goals;
165 std::string persona_notes;
166 struct ToolPlan {
167 bool resources = true;
168 bool dungeon = true;
169 bool overworld = true;
170 bool dialogue = true;
171 bool gui = false;
172 bool music = false;
173 bool sprite = false;
174 bool emulator = false;
175 bool memory_inspector = false;
177 bool auto_run_tests = false;
178 bool auto_sync_rom = true;
180 std::string blueprint_path;
181 bool ready_for_e2e = false;
182 };
183
184 // Retro hacker animation state
185 float pulse_animation_ = 0.0f;
186 float scanline_offset_ = 0.0f;
187 float glitch_timer_ = 0.0f;
189
191 void ApplyConfig(const AgentConfig& config);
192 void ApplyUserSettingsDefaults(bool force = false);
193
194 // Bot Profile Management
195 absl::Status SaveBotProfile(const BotProfile& profile);
196 absl::Status LoadBotProfile(const std::string& name);
197 absl::Status DeleteBotProfile(const std::string& name);
198 std::vector<BotProfile> GetAllProfiles() const;
199 void SetCurrentProfile(const BotProfile& profile);
200 absl::Status ExportProfile(const BotProfile& profile,
201 const std::filesystem::path& path);
202 absl::Status ImportProfile(const std::filesystem::path& path);
203
204 // Chat widget access (for EditorManager)
205 AgentChat* GetAgentChat() { return agent_chat_.get(); }
206 bool IsChatActive() const;
207 void SetChatActive(bool active);
208 void ToggleChat();
209 void OpenChatWindow();
210
211 // Knowledge panel callback (set by AgentUiController)
212 using KnowledgePanelCallback = std::function<void()>;
214 knowledge_panel_callback_ = std::move(callback);
215 }
216
217 // Collaboration and session management
218 enum class CollaborationMode {
219 kLocal, // Filesystem-based collaboration
220 kNetwork // WebSocket-based collaboration
221 };
222
223 struct SessionInfo {
224 std::string session_id;
225 std::string session_name;
226 std::vector<std::string> participants;
227 };
228
229 absl::StatusOr<SessionInfo> HostSession(
230 const std::string& session_name,
232 absl::StatusOr<SessionInfo> JoinSession(
233 const std::string& session_code,
235 absl::Status LeaveSession();
236 absl::StatusOr<SessionInfo> RefreshSession();
237
243
244 absl::Status CaptureSnapshot(std::filesystem::path* output_path,
245 const CaptureConfig& config);
246 absl::Status SendToGemini(const std::filesystem::path& image_path,
247 const std::string& prompt);
248
249#ifdef YAZE_WITH_GRPC
250 absl::Status ConnectToServer(const std::string& server_url);
251 void DisconnectFromServer();
252 bool IsConnectedToServer() const;
253#endif
254
255 bool IsInSession() const;
257 std::optional<SessionInfo> GetCurrentSession() const;
258
259 // Access to underlying components
263#ifdef YAZE_WITH_GRPC
264 NetworkCollaborationCoordinator* GetNetworkCoordinator() {
265 return network_coordinator_.get();
266 }
267#endif
268
269 private:
270 // Dashboard panel rendering
272 void DrawStatusPanel();
273 void DrawMetricsPanel();
282 void DrawManifestPanel();
283 void DrawMesenDebugPanel();
286 void DrawSramViewerPanel();
289 void ApplyConfigFromContext(const AgentConfigState& config);
291 void RefreshModelCache(bool force);
292 void ApplyModelPreset(const ModelPreset& preset);
294
295 // Setup callbacks
298
299 // Bot profile helpers
300 std::filesystem::path GetProfilesDirectory() const;
301 absl::Status EnsureProfilesDirectory();
302 std::string ProfileToJson(const BotProfile& profile) const;
303 absl::StatusOr<BotProfile> JsonToProfile(const std::string& json) const;
304 absl::Status SaveBuilderBlueprint(const std::filesystem::path& path);
305 absl::Status LoadBuilderBlueprint(const std::filesystem::path& path);
306
307 // Profile UI state
308 void MarkProfileUiDirty();
309 void SyncProfileUiState();
310
311 // Internal state
312 std::unique_ptr<AgentChat> agent_chat_; // Owned by AgentEditor
313 std::unique_ptr<AgentCollaborationCoordinator> local_coordinator_;
314 std::unique_ptr<AgentConfigPanel> config_panel_;
315 std::unique_ptr<FeatureFlagEditorPanel> feature_flag_panel_;
316 std::unique_ptr<ManifestPanel> manifest_panel_;
317 std::unique_ptr<MesenDebugPanel> mesen_debug_panel_;
318 std::unique_ptr<MesenScreenshotPanel> mesen_screenshot_panel_;
319 std::unique_ptr<OracleStateLibraryPanel> oracle_state_panel_;
320 std::unique_ptr<SramViewerPanel> sram_viewer_panel_;
321#ifdef YAZE_WITH_GRPC
322 std::unique_ptr<NetworkCollaborationCoordinator> network_coordinator_;
323 AutomationBridge harness_telemetry_bridge_;
324#endif
325
328 Rom* rom_ = nullptr;
330 // Note: Config syncing is managed by AgentUiController
331
332 // Configuration state (legacy)
334
336 std::string provider;
337 std::string model;
338 std::string ollama_host;
339 std::string gemini_api_key;
340 std::string anthropic_api_key;
341 std::string openai_api_key;
342 std::string openai_base_url;
343 bool verbose = false;
344 };
346 std::unique_ptr<cli::AIService> model_service_;
347 std::vector<std::string> last_local_model_paths_;
348 absl::Time last_local_model_scan_ = absl::InfinitePast();
349
350 // Bot Profile System
352 std::vector<BotProfile> loaded_profiles_;
354
356 bool dirty = true;
357 char model_buf[128] = {};
358 char ollama_host_buf[256] = {};
359 char gemini_key_buf[256] = {};
360 char anthropic_key_buf[256] = {};
361 char openai_key_buf[256] = {};
362 char openai_base_buf[256] = {};
363 char name_buf[128] = {};
364 char desc_buf[256] = {};
365 char tags_buf[256] = {};
366 };
368
369 // System Prompt Editor
370 std::unique_ptr<TextEditor> prompt_editor_;
371 std::unique_ptr<TextEditor> common_tiles_editor_;
374 std::string active_prompt_file_ = "system_prompt_v3.txt";
375 char new_prompt_name_[128] = {};
376
377 // Collaboration state
379 bool in_session_ = false;
382 std::vector<std::string> current_participants_;
383
384 // UI state (legacy)
387 bool show_bot_profiles_ = false;
388 bool show_chat_history_ = false;
390 int selected_tab_ = 0; // 0=Config, 1=Prompts, 2=Bots, 3=History, 4=Metrics
391
392 // Panel-based UI visibility flags
393 bool show_config_card_ = true;
394 bool show_status_card_ = true;
397 bool show_history_card_ = false;
398 bool show_metrics_card_ = false;
399 bool show_builder_card_ = false;
400 bool show_chat_card_ = true;
401 bool auto_probe_done_ = false;
402
403 // Panel registration helper
404 void RegisterPanels();
405
406 // Chat history viewer state
407 std::vector<cli::agent::ChatMessage> cached_history_;
409
410 // Knowledge panel callback (set by AgentUiController)
412};
413
414} // namespace editor
415} // namespace yaze
416
417#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.
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_
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:240
EditorContext context() const
Definition editor.h:310
Rom * rom() const
Definition editor.h:306
ImGui drawer for displaying and managing agent proposals.
constexpr char kProviderMock[]
Definition provider_ids.h:7
struct yaze::editor::AgentEditor::AgentBuilderState::ToolPlan tools
std::vector< std::string > tags
std::vector< std::string > participants