aws_transaction.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package service
  2. import (
  3. "net/http"
  4. "github.com/gin-gonic/gin"
  5. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_daemon/backwards_invocation/transaction"
  6. "github.com/langgenius/dify-plugin-daemon/internal/core/plugin_manager/aws_manager"
  7. "github.com/langgenius/dify-plugin-daemon/internal/core/session_manager"
  8. )
  9. func HandleAWSPluginTransaction(handler *transaction.AWSTransactionHandler) gin.HandlerFunc {
  10. return func(c *gin.Context) {
  11. // get session id from the context
  12. session_id := c.GetString("session_id")
  13. session := session_manager.GetSession(session_id)
  14. if session == nil {
  15. c.JSON(http.StatusBadRequest, gin.H{"error": "session not found"})
  16. return
  17. }
  18. // get runtime from the session
  19. runtime := session.Runtime()
  20. if runtime == nil {
  21. c.JSON(http.StatusBadRequest, gin.H{"error": "runtime not found"})
  22. return
  23. }
  24. aws_runtime, ok := runtime.(*aws_manager.AWSPluginRuntime)
  25. if !ok {
  26. c.JSON(http.StatusBadRequest, gin.H{"error": "runtime is not aws plugin runtime"})
  27. return
  28. }
  29. handler.Handle(c, session_id, aws_runtime)
  30. }
  31. }