agi_runtime.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package main
  2. import (
  3. "net/http"
  4. prout "imuslab.com/arozos/mod/prouter"
  5. "imuslab.com/arozos/mod/utils"
  6. )
  7. /*
  8. AGI Runtime Manager
  9. Registers the "AGI Runtimes" tab in System Settings > Developer Options
  10. and exposes two authenticated endpoints:
  11. GET /system/ajgi/runtime/list – list running VMs (filtered by role)
  12. POST /system/ajgi/runtime/stop – force-stop a VM by execid
  13. Regular users may list and stop their own VMs.
  14. Admins may list and stop any VM.
  15. */
  16. func AGIRuntimeManagerInit() {
  17. // Register the settings tab in the "Advance" (Developer Options) group.
  18. // RequireAdmin: false so regular users can view their own running scripts.
  19. registerSetting(settingModule{
  20. Name: "AGI Runtimes",
  21. Desc: "Monitor and force-stop running AGI script VM instances",
  22. IconPath: "SystemAO/advance/img/small_icon.png",
  23. Group: "Advance",
  24. StartDir: "SystemAO/advance/agi_runtime.html",
  25. RequireAdmin: false,
  26. })
  27. // Authenticated, non-admin router so every logged-in user can reach these
  28. // endpoints. Permission filtering is enforced inside the handler methods.
  29. authRouter := prout.NewModuleRouter(prout.RouterOption{
  30. ModuleName: "System Settings",
  31. AdminOnly: false,
  32. UserHandler: userHandler,
  33. DeniedHandler: func(w http.ResponseWriter, r *http.Request) {
  34. utils.SendErrorResponse(w, "Permission Denied")
  35. },
  36. })
  37. authRouter.HandleFunc("/system/ajgi/runtime/list", AGIGateway.HandleListRuntimes)
  38. authRouter.HandleFunc("/system/ajgi/runtime/stop", AGIGateway.HandleForceStopRuntime)
  39. }