@@ -2,7 +2,7 @@ import { Calendar } from '@sim/emcn/icons'
22import { GithubIcon } from '@/components/icons'
33import type { BlockConfig , BlockMeta } from '@/blocks/types'
44import { AuthMode , IntegrationType } from '@/blocks/types'
5- import { createVersionedToolSelector , withSavedCredential } from '@/blocks/utils'
5+ import { createVersionedToolSelector , mapperOperation , withSavedCredential } from '@/blocks/utils'
66import { getTrigger } from '@/triggers'
77
88/** Reviewers can be named individually or by team slug; either identifies the request. */
@@ -16,7 +16,9 @@ const REVIEWER_FIELD = ['reviewers', 'team_reviewers'] as const
1616 *
1717 * `toBoolean` marks a dropdown feeding a boolean tool param: a dropdown stores
1818 * its option id, so the value arrives as the string 'true'/'false' and the
19- * generic handler only JSON-parses `json`/`array` inputs.
19+ * generic handler only JSON-parses `json`/`array` inputs. An entry whose
20+ * `from` equals `to` only coerces; scoping it to the operation whose subBlock
21+ * owns the field keeps a stale value left from another operation raw.
2022 */
2123const GITHUB_PARAM_ALIASES : ReadonlyArray < {
2224 from : string
@@ -44,6 +46,44 @@ const GITHUB_PARAM_ALIASES: ReadonlyArray<{
4446 { from : 'fork_name' , to : 'name' , operations : [ 'github_fork_repo' ] } ,
4547 { from : 'fork_sort' , to : 'sort' , operations : [ 'github_list_forks' ] } ,
4648 { from : 'gist_public' , to : 'public' , operations : [ 'github_create_gist' ] , toBoolean : true } ,
49+ {
50+ from : 'draft' ,
51+ to : 'draft' ,
52+ operations : [ 'github_create_pr' , 'github_create_release' ] ,
53+ toBoolean : true ,
54+ } ,
55+ { from : 'prerelease' , to : 'prerelease' , operations : [ 'github_create_release' ] , toBoolean : true } ,
56+ {
57+ from : 'default_branch_only' ,
58+ to : 'default_branch_only' ,
59+ operations : [ 'github_fork_repo' ] ,
60+ toBoolean : true ,
61+ } ,
62+ ]
63+
64+ /**
65+ * Operations whose tools take no `owner`/`repo`: projects are addressed by owner
66+ * login or node ID, gists by gist ID, and searches by query alone.
67+ */
68+ const OPERATIONS_WITHOUT_REPOSITORY = [
69+ 'github_list_projects' ,
70+ 'github_get_project' ,
71+ 'github_create_project' ,
72+ 'github_update_project' ,
73+ 'github_delete_project' ,
74+ 'github_search_code' ,
75+ 'github_search_commits' ,
76+ 'github_search_issues' ,
77+ 'github_search_repos' ,
78+ 'github_search_users' ,
79+ 'github_create_gist' ,
80+ 'github_get_gist' ,
81+ 'github_list_gists' ,
82+ 'github_update_gist' ,
83+ 'github_delete_gist' ,
84+ 'github_fork_gist' ,
85+ 'github_star_gist' ,
86+ 'github_unstar_gist' ,
4787]
4888
4989export const GitHubBlock : BlockConfig = {
@@ -472,13 +512,15 @@ export const GitHubBlock: BlockConfig = {
472512 type : 'short-input' ,
473513 placeholder : 'e.g., microsoft' ,
474514 required : true ,
515+ condition : { field : 'operation' , value : OPERATIONS_WITHOUT_REPOSITORY , not : true } ,
475516 } ,
476517 {
477518 id : 'repo' ,
478519 title : 'Repository Name' ,
479520 type : 'short-input' ,
480521 placeholder : 'e.g., vscode' ,
481522 required : true ,
523+ condition : { field : 'operation' , value : OPERATIONS_WITHOUT_REPOSITORY , not : true } ,
482524 } ,
483525 {
484526 id : 'pullNumber' ,
@@ -656,6 +698,7 @@ export const GitHubBlock: BlockConfig = {
656698 title : 'State' ,
657699 type : 'dropdown' ,
658700 options : [
701+ { label : 'No change' , id : '' } ,
659702 { label : 'Open' , id : 'open' } ,
660703 { label : 'Closed' , id : 'closed' } ,
661704 ] ,
@@ -740,7 +783,6 @@ export const GitHubBlock: BlockConfig = {
740783 type : 'short-input' ,
741784 placeholder : 'Comma-separated: user1,user2' ,
742785 condition : { field : 'operation' , value : 'github_request_reviewers' } ,
743- mode : 'advanced' ,
744786 } ,
745787 {
746788 id : 'team_reviewers' ,
@@ -1042,6 +1084,7 @@ export const GitHubBlock: BlockConfig = {
10421084 title : 'State' ,
10431085 type : 'dropdown' ,
10441086 options : [
1087+ { label : 'No change' , id : '' } ,
10451088 { label : 'Open' , id : 'open' } ,
10461089 { label : 'Closed' , id : 'closed' } ,
10471090 ] ,
@@ -1410,6 +1453,7 @@ export const GitHubBlock: BlockConfig = {
14101453 title : 'Public' ,
14111454 type : 'dropdown' ,
14121455 options : [
1456+ { label : 'No change' , id : '' } ,
14131457 { label : 'Private' , id : 'false' } ,
14141458 { label : 'Public' , id : 'true' } ,
14151459 ] ,
@@ -1867,6 +1911,8 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
18671911 'github_list_forks' ,
18681912 'github_list_milestones' ,
18691913 'github_list_stargazers' ,
1914+ 'github_list_branches' ,
1915+ 'github_get_pr_files' ,
18701916 ] ,
18711917 } ,
18721918 mode : 'advanced' ,
@@ -1987,7 +2033,31 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
19872033 title : 'Page Number' ,
19882034 type : 'short-input' ,
19892035 placeholder : 'e.g., 1' ,
1990- condition : { field : 'operation' , value : 'github_list_tags' } ,
2036+ condition : {
2037+ field : 'operation' ,
2038+ value : [
2039+ 'github_list_tags' ,
2040+ 'github_list_branches' ,
2041+ 'github_list_commits' ,
2042+ 'github_list_forks' ,
2043+ 'github_list_gists' ,
2044+ 'github_list_issue_comments' ,
2045+ 'github_list_issues' ,
2046+ 'github_list_milestones' ,
2047+ 'github_list_pr_comments' ,
2048+ 'github_list_prs' ,
2049+ 'github_list_releases' ,
2050+ 'github_list_stargazers' ,
2051+ 'github_list_workflow_runs' ,
2052+ 'github_list_workflows' ,
2053+ 'github_get_pr_files' ,
2054+ 'github_search_code' ,
2055+ 'github_search_commits' ,
2056+ 'github_search_issues' ,
2057+ 'github_search_repos' ,
2058+ 'github_search_users' ,
2059+ ] ,
2060+ } ,
19912061 mode : 'advanced' ,
19922062 } ,
19932063 ] ,
@@ -2289,19 +2359,14 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
22892359 * block did not supply would clobber a model-supplied value on the agent
22902360 * path.
22912361 *
2292- * On the agent tool-calling path `operation` is not part of the params
2293- * this receives: `providers/utils.ts` spreads it in for the tool-selection
2294- * call (`:736-739`) but builds the transform's input from `block.params`
2295- * alone (`:776`). Every alias therefore skips there, which is the same
2296- * behaviour as before this mapper existed - the agent path already works
2297- * because a model supplies `content`/`title`/`sort` by their real names.
2298- * That gap is shared by every block whose mapper branches on
2299- * `params.operation`, so closing it belongs in the provider layer rather
2300- * than here.
2362+ * On a tool call (Agent tool row, Pi, Human-in-the-loop) the operation
2363+ * arrives only in `context`, so it is read through `mapperOperation`. A
2364+ * value the user stored under a block-only id then reaches its tool param,
2365+ * and an unset one emits nothing, leaving the model's own argument intact.
23012366 */
2302- params : ( params ) => {
2367+ params : ( params , context ) => {
23032368 const result : Record < string , unknown > = { }
2304- const operation = typeof params . operation === 'string' ? params . operation : ''
2369+ const operation = mapperOperation ( params , context )
23052370
23062371 const isSet = ( value : unknown ) => value !== undefined && value !== null && value !== ''
23072372
0 commit comments