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 // Edit-menu actions do not apply to the agent editor.
98 bool CanUndo() const override { return false; }
99 bool CanRedo() const override { return false; }
100 bool CanCut() const override { return false; }
101 bool CanCopy() const override { return false; }
102 bool CanPaste() const override { return false; }
103
104 // Initialization with dependencies
105 void InitializeWithDependencies(ToastManager* toast_manager,
106 ProposalDrawer* proposal_drawer, Rom* rom);
107 void SetRomContext(Rom* rom);
109
110 // Main rendering (called by Update())
111 void DrawDashboard();
112
113 // Bot Configuration & Profile Management
114 struct BotProfile {
115 std::string name = "Default Bot";
116 std::string description;
118 std::string host_id;
119 std::string model;
120 std::string ollama_host = "http://localhost:11434";
121 std::string gemini_api_key;
122 std::string anthropic_api_key;
123 std::string openai_api_key;
124 std::string openai_base_url = "https://api.openai.com";
125 std::string system_prompt;
126 bool verbose = false;
127 bool show_reasoning = true;
130 float temperature = 0.25f;
131 float top_p = 0.95f;
133 bool stream_responses = false;
134 std::vector<std::string> tags;
135 absl::Time created_at = absl::Now();
136 absl::Time modified_at = absl::Now();
137 };
138
139 // Profile accessor for external sync (used by AgentUiController)
142
143 // Legacy support
144 struct AgentConfig {
146 std::string model;
147 std::string ollama_host = "http://localhost:11434";
148 std::string gemini_api_key;
149 std::string anthropic_api_key;
150 std::string openai_api_key;
151 std::string openai_base_url = "https://api.openai.com";
152 bool verbose = false;
153 bool show_reasoning = true;
156 float temperature = 0.25f;
157 float top_p = 0.95f;
159 bool stream_responses = false;
160 };
161
163 struct Stage {
164 std::string name;
165 std::string summary;
166 bool completed = false;
167 };
168 std::vector<Stage> stages;
170 std::vector<std::string> goals;
171 std::string persona_notes;
172 struct ToolPlan {
173 bool resources = true;
174 bool dungeon = true;
175 bool overworld = true;
176 bool dialogue = true;
177 bool gui = false;
178 bool music = false;
179 bool sprite = false;
180 bool emulator = false;
181 bool memory_inspector = false;
183 bool auto_run_tests = false;
184 bool auto_sync_rom = true;
186 std::string blueprint_path;
187 bool ready_for_e2e = false;
188 };
189
190 // Retro hacker animation state
191 float pulse_animation_ = 0.0f;
192 float scanline_offset_ = 0.0f;
193 float glitch_timer_ = 0.0f;
195
197 void ApplyConfig(const AgentConfig& config);
198 void ApplyUserSettingsDefaults(bool force = false);
199
200 // Bot Profile Management
201 absl::Status SaveBotProfile(const BotProfile& profile);
202 absl::Status LoadBotProfile(const std::string& name);
203 absl::Status DeleteBotProfile(const std::string& name);
204 std::vector<BotProfile> GetAllProfiles() const;
205 void SetCurrentProfile(const BotProfile& profile);
206 absl::Status ExportProfile(const BotProfile& profile,
207 const std::filesystem::path& path);
208 absl::Status ImportProfile(const std::filesystem::path& path);
209
210 // Chat widget access (for EditorManager)
211 AgentChat* GetAgentChat() { return agent_chat_.get(); }
212 bool IsChatActive() const;
213 void SetChatActive(bool active);
214 void ToggleChat();
215 void OpenChatWindow();
216
217 // Knowledge panel callback (set by AgentUiController)
218 using KnowledgePanelCallback = std::function<void()>;
220 knowledge_panel_callback_ = std::move(callback);
221 }
222
223 // Collaboration and session management
224 enum class CollaborationMode {
225 kLocal, // Filesystem-based collaboration
226 kNetwork // WebSocket-based collaboration
227 };
228
229 struct SessionInfo {
230 std::string session_id;
231 std::string session_name;
232 std::vector<std::string> participants;
233 };
234
235 absl::StatusOr<SessionInfo> HostSession(
236 const std::string& session_name,
238 absl::StatusOr<SessionInfo> JoinSession(
239 const std::string& session_code,
241 absl::Status LeaveSession();
242 absl::StatusOr<SessionInfo> RefreshSession();
243
249
250 absl::Status CaptureSnapshot(std::filesystem::path* output_path,
251 const CaptureConfig& config);
252 absl::Status SendToGemini(const std::filesystem::path& image_path,
253 const std::string& prompt);
254
255#ifdef YAZE_WITH_GRPC
256 absl::Status ConnectToServer(const std::string& server_url);
257 void DisconnectFromServer();
258 bool IsConnectedToServer() const;
259#endif
260
261 bool IsInSession() const;
263 std::optional<SessionInfo> GetCurrentSession() const;
264
265 // Access to underlying components
269#ifdef YAZE_WITH_GRPC
270 NetworkCollaborationCoordinator* GetNetworkCoordinator() {
271 return network_coordinator_.get();
272 }
273#endif
274
275 private:
276 // Dashboard panel rendering
278 void DrawStatusPanel();
279 void DrawMetricsPanel();
288 void DrawManifestPanel();
289 void DrawMesenDebugPanel();
292 void DrawSramViewerPanel();
295 void ApplyConfigFromContext(const AgentConfigState& config);
297 void RefreshModelCache(bool force);
298 void ApplyModelPreset(const ModelPreset& preset);
300
301 // Setup callbacks
304
305 // Bot profile helpers
306 std::filesystem::path GetProfilesDirectory() const;
307 absl::Status EnsureProfilesDirectory();
308 std::string ProfileToJson(const BotProfile& profile) const;
309 absl::StatusOr<BotProfile> JsonToProfile(const std::string& json) const;
310 absl::Status SaveBuilderBlueprint(const std::filesystem::path& path);
311 absl::Status LoadBuilderBlueprint(const std::filesystem::path& path);
312
313 // Profile UI state
314 void MarkProfileUiDirty();
315 void SyncProfileUiState();
316
317 // Internal state
318 std::unique_ptr<AgentChat> agent_chat_; // Owned by AgentEditor
319 std::unique_ptr<AgentCollaborationCoordinator> local_coordinator_;
320 std::unique_ptr<AgentConfigPanel> config_panel_;
321 std::unique_ptr<FeatureFlagEditorPanel> feature_flag_panel_;
322 std::unique_ptr<ManifestPanel> manifest_panel_;
323 std::unique_ptr<MesenDebugPanel> mesen_debug_panel_;
324 std::unique_ptr<MesenScreenshotPanel> mesen_screenshot_panel_;
325 std::unique_ptr<OracleStateLibraryPanel> oracle_state_panel_;
326 std::unique_ptr<SramViewerPanel> sram_viewer_panel_;
327#ifdef YAZE_WITH_GRPC
328 std::unique_ptr<NetworkCollaborationCoordinator> network_coordinator_;
329 std::shared_ptr<AutomationBridge> harness_telemetry_bridge_ =
330 std::make_shared<AutomationBridge>();
331#endif
332
335 Rom* rom_ = nullptr;
337 // Note: Config syncing is managed by AgentUiController
338
339 // Configuration state (legacy)
341
343 std::string provider;
344 std::string model;
345 std::string ollama_host;
346 std::string gemini_api_key;
347 std::string anthropic_api_key;
348 std::string openai_api_key;
349 std::string openai_base_url;
350 bool verbose = false;
351 };
353 std::unique_ptr<cli::AIService> model_service_;
354 std::vector<std::string> last_local_model_paths_;
355 absl::Time last_local_model_scan_ = absl::InfinitePast();
356
357 // Bot Profile System
359 std::vector<BotProfile> loaded_profiles_;
361
363 bool dirty = true;
364 char model_buf[128] = {};
365 char ollama_host_buf[256] = {};
366 char gemini_key_buf[256] = {};
367 char anthropic_key_buf[256] = {};
368 char openai_key_buf[256] = {};
369 char openai_base_buf[256] = {};
370 char name_buf[128] = {};
371 char desc_buf[256] = {};
372 char tags_buf[256] = {};
373 };
375
376 // System Prompt Editor
377 std::unique_ptr<TextEditor> prompt_editor_;
378 std::unique_ptr<TextEditor> common_tiles_editor_;
381 std::string active_prompt_file_ = "system_prompt_v3.txt";
382 char new_prompt_name_[128] = {};
383
384 // Collaboration state
386 bool in_session_ = false;
389 std::vector<std::string> current_participants_;
390
391 // UI state (legacy)
394 bool show_bot_profiles_ = false;
395 bool show_chat_history_ = false;
397 int selected_tab_ = 0; // 0=Config, 1=Prompts, 2=Bots, 3=History, 4=Metrics
398
399 // Panel-based UI visibility flags
400 bool show_config_card_ = true;
401 bool show_status_card_ = true;
404 bool show_history_card_ = false;
405 bool show_metrics_card_ = false;
406 bool show_builder_card_ = false;
407 bool show_chat_card_ = true;
408 bool auto_probe_done_ = false;
409
410 // Panel registration helper
411 void RegisterPanels();
412
413 // Chat history viewer state
414 std::vector<cli::agent::ChatMessage> cached_history_;
416
417 // Knowledge panel callback (set by AgentUiController)
419};
420
421} // namespace editor
422} // namespace yaze
423
424#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:49
Unified Agent Chat Component.
Definition agent_chat.h:32
Comprehensive AI Agent Platform & Bot Creator.
bool CanUndo() const override
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)
bool CanRedo() const override
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_
bool CanCut() const override
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_
bool CanCopy() const override
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
bool CanPaste() const 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:249
EditorContext context() const
Definition editor.h:364
Rom * rom() const
Definition editor.h:356
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