RequestAnalysisContextCommand.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. using LLM.Editor.Helper;
  3. using JetBrains.Annotations;
  4. namespace LLM.Editor.Commands
  5. {
  6. /// <summary>
  7. /// A command that does not act on the scene directly, but instead signals the UI
  8. /// to prompt the user for the objects needed for an analysis.
  9. /// </summary>
  10. [UsedImplicitly]
  11. public class RequestAnalysisContextCommand : ICommand
  12. {
  13. // This event can be subscribed to by the MCPWindow to update its UI.
  14. public static event System.Action<RequestAnalysisContextParams> OnAnalysisContextRequested;
  15. private readonly RequestAnalysisContextParams _params;
  16. public RequestAnalysisContextCommand(string jsonParams)
  17. {
  18. _params = jsonParams?.FromJson<RequestAnalysisContextParams>();
  19. }
  20. public CommandOutcome Execute(Data.CommandContext context)
  21. {
  22. if (_params?.subjectRoles == null || _params.subjectRoles.Length == 0)
  23. {
  24. Debug.LogError("[RequestAnalysisContextCommand] Invalid parameters. Subject roles are required.");
  25. return CommandOutcome.Error;
  26. }
  27. // The command's job is to simply invoke the event.
  28. // The UI is responsible for handling it and showing the staging area.
  29. OnAnalysisContextRequested?.Invoke(_params);
  30. Debug.Log($"[RequestAnalysisContextCommand] Fired event to request context for roles: {string.Join(", ", _params.subjectRoles)}");
  31. return CommandOutcome.Success;
  32. }
  33. }
  34. }