moduleManager.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package agi
  2. import (
  3. "errors"
  4. "imuslab.com/arozos/mod/agi/static"
  5. apt "imuslab.com/arozos/mod/apt"
  6. "imuslab.com/arozos/mod/info/logger"
  7. )
  8. /*
  9. AGI Module Manager
  10. This interface handles the agi function module registartions
  11. and make sure the structures of all modules fits the pre-defined
  12. interface to be used by ArozOS Core system
  13. */
  14. // Lib interface, require vm, user, target system file handler and the vpath of the running script
  15. // This interface is called during injection (in user's term, require / import)
  16. // When called, the required agi function module will be injected into the virtual machine
  17. // which provide the function required for the vm code to interact with the real-systems
  18. type AgiLibInjectionIntergface func(*static.AgiLibInjectionPayload)
  19. type AgiLibInterface interface {
  20. GetLibraryID() string //Get the module unique name for import
  21. GetInjectFunction() AgiLibInjectionIntergface //Get the module injection point
  22. }
  23. // Register a library's identification name and its injection interface to the VM environment
  24. func (g *Gateway) RegisterLib(libname string, entryPoint AgiLibInjectionIntergface) error {
  25. _, ok := g.LoadedAGILibrary[libname]
  26. if ok {
  27. //This lib already registered. Return error
  28. return errors.New("This library name already registered")
  29. } else {
  30. g.LoadedAGILibrary[libname] = entryPoint
  31. }
  32. return nil
  33. }
  34. /*
  35. AGI Library Register List
  36. Add more library here if required
  37. */
  38. func (g *Gateway) LoadAllFunctionalModules() {
  39. g.ImageLibRegister()
  40. g.FileLibRegister()
  41. g.HTTPLibRegister()
  42. g.ShareLibRegister()
  43. g.AppdataLibRegister()
  44. g.SysinfoLibRegister()
  45. //g.AudioLibRegister() //work in progress
  46. g.ZipLibRegister()
  47. g.LLMLibRegister()
  48. g.CNNLibRegister()
  49. g.SQLiteLibRegister()
  50. g.OfficeLibRegister()
  51. //Shared collaboration spaces + MeetRoom control, only when the host
  52. //system wired the managers in (see src/agi.go)
  53. if g.Option.SharedSpaceManager != nil {
  54. g.SharedSpaceLibRegister()
  55. }
  56. if g.Option.MeetRoomManager != nil {
  57. g.MeetRoomLibRegister()
  58. }
  59. if g.Option.NotificationSender != nil {
  60. g.NotificationLibRegister()
  61. }
  62. if g.Option.GitManager != nil {
  63. g.GitLibRegister()
  64. }
  65. if g.Option.EmailManager != nil {
  66. g.EmailLibRegister()
  67. }
  68. if g.Option.ClusterProvider != nil {
  69. g.ClusterLibRegister()
  70. }
  71. //Only register ffmpeg lib if host OS have ffmpeg installed
  72. ffmpegExists, _ := apt.PackageExists("ffmpeg")
  73. if ffmpegExists {
  74. g.FFmpegLibRegister()
  75. } else {
  76. logger.PrintAndLog("Agi", "[AGI] ffmpeg not installed on host OS. Bypassing module.", nil)
  77. }
  78. }