-
Notifications
You must be signed in to change notification settings - Fork 396
Refactor dispatch/call workflow duplication with shared input, tool, and resolver helpers #33947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package workflow | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sort" | ||
|
|
||
| "github.com/github/gh-aw/pkg/stringutil" | ||
| ) | ||
|
|
||
| type workflowToolDefinitionOptions struct { | ||
| workflowName string | ||
| workflowInputs map[string]any | ||
| descriptionFormat string | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [/zoom-out] Exported function lacks documentation. 💡 Suggested documentation// generateWorkflowToolDefinition creates an MCP tool definition for workflow
// dispatch or call operations. The returned tool schema includes normalized
// naming, input parameter validation, and metadata for handler routing.
//
// The metadataKey parameter determines which internal field is used for routing
// (e.g., "_workflow_name" for dispatch, "_call_workflow_name" for call).
func generateWorkflowToolDefinition(opts workflowToolDefinitionOptions) map[string]any {This function is central to the refactoring — documenting its purpose and the significance of |
||
| metadataKey string | ||
| } | ||
|
|
||
| func generateWorkflowToolDefinition(opts workflowToolDefinitionOptions) map[string]any { | ||
| toolName := stringutil.NormalizeSafeOutputIdentifier(opts.workflowName) | ||
| description := fmt.Sprintf(opts.descriptionFormat, opts.workflowName) | ||
| properties, required := buildInputSchema(opts.workflowInputs, func(inputName string) string { | ||
| return fmt.Sprintf("Input parameter '%s' for workflow %s", inputName, opts.workflowName) | ||
| }) | ||
|
|
||
| tool := map[string]any{ | ||
| "name": toolName, | ||
| "description": description, | ||
| opts.metadataKey: opts.workflowName, | ||
| "inputSchema": map[string]any{ | ||
| "type": "object", | ||
| "properties": properties, | ||
| "additionalProperties": false, | ||
| }, | ||
| } | ||
|
|
||
| if len(required) > 0 { | ||
| sort.Strings(required) | ||
| tool["inputSchema"].(map[string]any)["required"] = required | ||
| } | ||
|
|
||
| return tool | ||
| } | ||
|
|
||
| func resolveWorkflowExtension(fileResult *findWorkflowFileResult) (string, bool) { | ||
| if fileResult.lockExists { | ||
| return ".lock.yml", true | ||
| } | ||
| if fileResult.ymlExists { | ||
| return ".yml", true | ||
| } | ||
| if fileResult.mdExists { | ||
| // .md-only: the workflow is a same-batch compilation target that will produce a .lock.yml | ||
| return ".lock.yml", true | ||
| } | ||
|
|
||
| return "", false | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[/improve-codebase-architecture] Type name lacks domain context —
workflowToolDefinitionOptionsis too generic.💡 Suggested naming
Consider one of these domain-specific names:
The current name "options" suggests configuration, but this is actually the definition of an MCP tool for workflow triggers. Using "options" for a struct that produces a tool schema can be confusing — consider
Configor drop the suffix entirely.