Skip to content

tool add show_on#732

Open
zyqzyq wants to merge 1 commit into
langgenius:mainfrom
zyqzyq:feat/add_tool_show_on
Open

tool add show_on#732
zyqzyq wants to merge 1 commit into
langgenius:mainfrom
zyqzyq:feat/add_tool_show_on

Conversation

@zyqzyq
Copy link
Copy Markdown

@zyqzyq zyqzyq commented May 14, 2026

Description

Fixes langgenius/dify#36141

This pull request adds conditional visibility metadata for tool parameters and select options via show_on, aligned with the intent of the upstream change set

  • Introduces ToolParameterShowOnObject (variable + value) and attaches show_on to ToolParameter and ParameterOption.
  • Ensures JSON/YAML unmarshaling normalizes absent show_on to an empty slice (non-nil) for stable consumers and validation.
  • Adds unit tests covering tool-parameter and option-level show_on for both JSON and YAML (where applicable).

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

  • Files touched: pkg/entities/plugin_entities/constant.go, pkg/entities/plugin_entities/tool_declaration.go, pkg/entities/plugin_entities/tool_declaration_test.go
  • Reviewers may want to run: go test ./pkg/entities/plugin_entities/... on a toolchain satisfying go.mod.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels May 14, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds conditional visibility to tool parameters and options through a new ShowOn field and the ToolParameterShowOnObject struct. It includes custom unmarshaling logic for JSON and YAML to handle default slice initialization and adds corresponding validation tests. Review feedback identifies non-idiomatic pointer usage in the YAML decoding process and recommends increasing validation length limits for consistency with existing parameter name constraints.

Alias: (*Alias)(p),
}

if err := value.Decode(&aux); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of &aux in value.Decode(&aux) is non-idiomatic because aux is already a pointer to the target struct. Passing a pointer to a pointer (**struct) is unnecessary and inconsistent with the json.Unmarshal(data, aux) call used in the UnmarshalJSON method above.

Suggested change
if err := value.Decode(&aux); err != nil {
if err := value.Decode(aux); err != nil {

Comment on lines +125 to +126
Variable string `json:"variable" yaml:"variable" validate:"required,lt=256"`
Value string `json:"value" yaml:"value" validate:"required,lt=256"`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The length limit for Variable (lt=256) is inconsistent with the limit for ToolParameter.Name (lt=1024). Since Variable is intended to store a parameter name for conditional visibility, it should support the same maximum length. Similarly, Value should likely have a matching limit to ensure consistency when comparing against parameter values.

	Variable string `json:"variable" yaml:"variable" validate:"required,lt=1024"`\n	Value    string `json:"value" yaml:"value" validate:"required,lt=1024"`

Alias: (*Alias)(t),
}

if err := value.Decode(&aux); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of &aux in value.Decode(&aux) is non-idiomatic because aux is already a pointer to the target struct. Passing a pointer to a pointer (**struct) is unnecessary and inconsistent with the json.Unmarshal(data, aux) call used in the UnmarshalJSON method above.

Suggested change
if err := value.Decode(&aux); err != nil {
if err := value.Decode(aux); err != nil {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: tool plugin support show_on param

1 participant