Skip to content

Commit 84c7072

Browse files
committed
fix(integrations): sweep2 v1 — read the mapper operation from the tool-call context and validate integrations against vendor specs
1 parent 41a5f38 commit 84c7072

226 files changed

Lines changed: 5074 additions & 1940 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/sim/blocks/blocks/datadog.test.ts‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,48 @@ describe('datadog numeric coercion', () => {
9999
expect(params[key]).toBe(0)
100100
})
101101
})
102+
103+
/**
104+
* On a tool call (Agent tool row, Pi, Human-in-the-loop) the operation arrives only in
105+
* `context`, and the model's args are keyed by the tool's param names. The mapper's result is
106+
* spread over those args, so a branch that renames a block field onto a tool param must keep
107+
* the model's value when the block field is blank.
108+
*/
109+
function toolCallParams(
110+
operation: string,
111+
modelArgs: Record<string, unknown>
112+
): Record<string, unknown> {
113+
const params = { ...baseInputs, ...modelArgs }
114+
return { ...params, ...(mapParams?.(params, { operation }) as Record<string, unknown>) }
115+
}
116+
117+
describe('datadog tool-call params', () => {
118+
it.each([
119+
['datadog_create_monitor', { query: 'avg:cpu{*} > 90', tags: 'team:a', priority: 2 }],
120+
['datadog_mute_monitor', { monitorId: '123' }],
121+
['datadog_query_logs', { query: 'status:error', from: 'now-1h', to: 'now', limit: 20 }],
122+
['datadog_create_incident', { title: 'DB down', customerImpacted: true }],
123+
['datadog_update_security_signal_state', { signalId: 's1', state: 'archived' }],
124+
['datadog_trigger_synthetics_tests', { publicIds: 'abc-def-ghi' }],
125+
['datadog_list_monitors', { name: 'cpu', monitorTags: 'env:prod', page: 0 }],
126+
])('keeps the model args for %s', (operation, modelArgs) => {
127+
const params = toolCallParams(operation, modelArgs)
128+
129+
expect(params).toMatchObject(modelArgs)
130+
})
131+
132+
it('drops a non-numeric model page size instead of sending it to Datadog', () => {
133+
const params = toolCallParams('datadog_list_monitors', { pageSize: 'fifty' })
134+
135+
expect(params.pageSize).toBeUndefined()
136+
})
137+
138+
it('reads a model switch value sent as a string', () => {
139+
const params = toolCallParams('datadog_unmute_monitor', {
140+
monitorId: '123',
141+
allScopes: 'false',
142+
})
143+
144+
expect(params.allScopes).toBe(false)
145+
})
146+
})

‎apps/sim/blocks/blocks/datadog.ts‎

Lines changed: 195 additions & 135 deletions
Large diffs are not rendered by default.

‎apps/sim/blocks/blocks/github.ts‎

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Calendar } from '@sim/emcn/icons'
22
import { GithubIcon } from '@/components/icons'
33
import type { BlockConfig, BlockMeta } from '@/blocks/types'
44
import { AuthMode, IntegrationType } from '@/blocks/types'
5-
import { createVersionedToolSelector, withSavedCredential } from '@/blocks/utils'
5+
import { createVersionedToolSelector, mapperOperation, withSavedCredential } from '@/blocks/utils'
66
import { 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
*/
2123
const 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

4989
export 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

Comments
 (0)