tool.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package tool_entities
  2. import (
  3. "github.com/go-playground/validator/v10"
  4. "github.com/langgenius/dify-plugin-daemon/pkg/entities/plugin_entities"
  5. "github.com/langgenius/dify-plugin-daemon/pkg/validators"
  6. )
  7. type ToolResponseChunkType string
  8. const (
  9. ToolResponseChunkTypeText ToolResponseChunkType = "text"
  10. ToolResponseChunkTypeFile ToolResponseChunkType = "file"
  11. ToolResponseChunkTypeBlob ToolResponseChunkType = "blob"
  12. ToolResponseChunkTypeBlobChunk ToolResponseChunkType = "blob_chunk"
  13. ToolResponseChunkTypeJson ToolResponseChunkType = "json"
  14. ToolResponseChunkTypeLink ToolResponseChunkType = "link"
  15. ToolResponseChunkTypeImage ToolResponseChunkType = "image"
  16. ToolResponseChunkTypeImageLink ToolResponseChunkType = "image_link"
  17. ToolResponseChunkTypeVariable ToolResponseChunkType = "variable"
  18. ToolResponseChunkTypeLog ToolResponseChunkType = "log"
  19. )
  20. func IsValidToolResponseChunkType(fl validator.FieldLevel) bool {
  21. t := fl.Field().String()
  22. switch ToolResponseChunkType(t) {
  23. case ToolResponseChunkTypeText,
  24. ToolResponseChunkTypeFile,
  25. ToolResponseChunkTypeBlob,
  26. ToolResponseChunkTypeBlobChunk,
  27. ToolResponseChunkTypeJson,
  28. ToolResponseChunkTypeLink,
  29. ToolResponseChunkTypeImage,
  30. ToolResponseChunkTypeImageLink,
  31. ToolResponseChunkTypeVariable,
  32. ToolResponseChunkTypeLog:
  33. return true
  34. default:
  35. return false
  36. }
  37. }
  38. func init() {
  39. validators.GlobalEntitiesValidator.RegisterValidation(
  40. "is_valid_tool_response_chunk_type",
  41. IsValidToolResponseChunkType,
  42. )
  43. }
  44. type ToolResponseChunk struct {
  45. Type ToolResponseChunkType `json:"type" validate:"required,is_valid_tool_response_chunk_type"`
  46. Message map[string]any `json:"message"`
  47. Meta map[string]any `json:"meta"`
  48. }
  49. type GetToolRuntimeParametersResponse struct {
  50. Parameters []plugin_entities.ToolParameter `json:"parameters"`
  51. }