moduleManager.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.IoTLibRegister()
  44. g.AppdataLibRegister()
  45. g.SysinfoLibRegister()
  46. //g.AudioLibRegister() //work in progress
  47. g.ZipLibRegister()
  48. g.LLMLibRegister()
  49. g.CNNLibRegister()
  50. g.SQLiteLibRegister()
  51. g.OfficeLibRegister()
  52. //Shared collaboration spaces + MeetRoom control, only when the host
  53. //system wired the managers in (see src/agi.go)
  54. if g.Option.SharedSpaceManager != nil {
  55. g.SharedSpaceLibRegister()
  56. }
  57. if g.Option.MeetRoomManager != nil {
  58. g.MeetRoomLibRegister()
  59. }
  60. if g.Option.NotificationSender != nil {
  61. g.NotificationLibRegister()
  62. }
  63. if g.Option.GitManager != nil {
  64. g.GitLibRegister()
  65. }
  66. //Only register ffmpeg lib if host OS have ffmpeg installed
  67. ffmpegExists, _ := apt.PackageExists("ffmpeg")
  68. if ffmpegExists {
  69. g.FFmpegLibRegister()
  70. } else {
  71. logger.PrintAndLog("Agi", "[AGI] ffmpeg not installed on host OS. Bypassing module.", nil)
  72. }
  73. }