Skip to content

Commit 43aac92

Browse files
authored
fix(blocks): read the mapper operation from the tool-call context in aws and infra blocks (#10075)
* fix(integrations): sweep2 m1 — read the mapper operation from the tool-call context and validate integrations against vendor specs * chore: regenerate tool metadata, docs and ratchet baselines * refactor: simplify and clean up the sweep changes * fix(blocks): keep model format, recursive and extended statistics on tool calls - tinybird append: fall back to the model's format before the csv default - sftp mkdir: fall back to the model's recursive before the default - cloudwatch get_metric_statistics: accept and normalize extendedStatistics from either source - azure data explorer ingest: an explicitly disabled Run in background stays off - cloudwatch/codepipeline tests: narrow the mapper so test-types passes
1 parent 41a5f38 commit 43aac92

80 files changed

Lines changed: 1961 additions & 693 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { AthenaBlock } from '@/blocks/blocks/athena'
3+
4+
/**
5+
* An agent tool call sends model args under the tool's param names (`workGroup`, `queryStatement`,
6+
* `name`) with the operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
7+
*/
8+
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => ({
9+
...args,
10+
...(AthenaBlock.tools.config?.params?.(args, { operation }) ?? {}),
11+
})
12+
13+
const CREDENTIALS = { awsRegion: 'us-east-1', awsAccessKeyId: 'AKIA', awsSecretAccessKey: 'secret' }
14+
15+
describe('AthenaBlock agent tool calls', () => {
16+
it('keeps the model prepared statement workgroup and statement instead of throwing', () => {
17+
expect(
18+
agentCall('create_prepared_statement', {
19+
...CREDENTIALS,
20+
statementName: 'by_day',
21+
workGroup: 'primary',
22+
queryStatement: 'SELECT * FROM t WHERE d = ?',
23+
description: 'Daily rows',
24+
})
25+
).toMatchObject({
26+
statementName: 'by_day',
27+
workGroup: 'primary',
28+
queryStatement: 'SELECT * FROM t WHERE d = ?',
29+
description: 'Daily rows',
30+
})
31+
})
32+
33+
it('keeps the model catalog name and coerces maxResults on list calls', () => {
34+
expect(agentCall('get_data_catalog', { ...CREDENTIALS, name: 'AwsDataCatalog' })).toMatchObject(
35+
{ name: 'AwsDataCatalog' }
36+
)
37+
expect(agentCall('list_named_queries', { ...CREDENTIALS, maxResults: '5' })).toMatchObject({
38+
maxResults: 5,
39+
})
40+
})
41+
})

‎apps/sim/blocks/blocks/athena.ts‎

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AthenaIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4-
import { withSavedCredential } from '@/blocks/utils'
4+
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'
55

66
/**
77
* Normalizes a switch value that may arrive as a boolean or as the strings 'true' / 'false'.
@@ -681,8 +681,9 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
681681
throw new Error(`Invalid Athena operation: ${params.operation}`)
682682
}
683683
},
684-
params: (params) => {
685-
const { operation, maxResults, ...rest } = params
684+
params: (params, context) => {
685+
const { maxResults, ...rest } = params
686+
const operation = mapperOperation(params, context)
686687

687688
const awsRegion = rest.awsRegion
688689
const awsAccessKeyId = rest.awsAccessKeyId
@@ -696,6 +697,9 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
696697
rest.resultReuseMaxAgeInMinutes !== ''
697698
? Number.parseInt(String(rest.resultReuseMaxAgeInMinutes), 10)
698699
: undefined
700+
const queryName = rest.queryName || toolCallArg(context, rest.name)
701+
const queryDescription = rest.queryDescription || toolCallArg(context, rest.description)
702+
const workGroupName = rest.workGroupName || toolCallArg(context, rest.workGroup)
699703

700704
switch (operation) {
701705
case 'start_query':
@@ -766,7 +770,7 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
766770
}
767771

768772
case 'create_named_query': {
769-
if (!rest.queryName) {
773+
if (!queryName) {
770774
throw new Error('Query name is required')
771775
}
772776
if (!rest.database) {
@@ -779,10 +783,10 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
779783
awsRegion,
780784
awsAccessKeyId,
781785
awsSecretAccessKey,
782-
name: rest.queryName,
786+
name: queryName,
783787
database: rest.database,
784788
queryString: rest.queryString,
785-
...(rest.queryDescription && { description: rest.queryDescription }),
789+
...(queryDescription && { description: queryDescription }),
786790
...(rest.workGroup && { workGroup: rest.workGroup }),
787791
}
788792
}
@@ -879,7 +883,7 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
879883
if (!rest.namedQueryId) {
880884
throw new Error('Named query ID is required')
881885
}
882-
if (!rest.queryName) {
886+
if (!queryName) {
883887
throw new Error('Query name is required')
884888
}
885889
if (!rest.queryString) {
@@ -888,64 +892,66 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
888892
return {
889893
...connection,
890894
namedQueryId: rest.namedQueryId,
891-
name: rest.queryName,
895+
name: queryName,
892896
queryString: rest.queryString,
893-
...(rest.queryDescription && { description: rest.queryDescription }),
897+
...(queryDescription && { description: queryDescription }),
894898
}
895899

896900
case 'create_prepared_statement':
897-
case 'update_prepared_statement':
901+
case 'update_prepared_statement': {
902+
const queryStatement = rest.queryString || toolCallArg(context, rest.queryStatement)
898903
if (!rest.statementName) {
899904
throw new Error('Statement name is required')
900905
}
901-
if (!rest.workGroupName) {
906+
if (!workGroupName) {
902907
throw new Error('Workgroup is required')
903908
}
904-
if (!rest.queryString) {
909+
if (!queryStatement) {
905910
throw new Error('SQL query statement is required')
906911
}
907912
return {
908913
...connection,
909914
statementName: rest.statementName,
910-
workGroup: rest.workGroupName,
911-
queryStatement: rest.queryString,
912-
...(rest.queryDescription && { description: rest.queryDescription }),
915+
workGroup: workGroupName,
916+
queryStatement,
917+
...(queryDescription && { description: queryDescription }),
913918
}
919+
}
914920

915921
case 'get_prepared_statement':
916922
case 'delete_prepared_statement':
917923
if (!rest.statementName) {
918924
throw new Error('Statement name is required')
919925
}
920-
if (!rest.workGroupName) {
926+
if (!workGroupName) {
921927
throw new Error('Workgroup is required')
922928
}
923929
return {
924930
...connection,
925931
statementName: rest.statementName,
926-
workGroup: rest.workGroupName,
932+
workGroup: workGroupName,
927933
}
928934

929935
case 'batch_get_prepared_statement':
930936
if (!rest.preparedStatementNames) {
931937
throw new Error('Statement names are required')
932938
}
933-
if (!rest.workGroupName) {
939+
if (!workGroupName) {
934940
throw new Error('Workgroup is required')
935941
}
936942
return {
937943
...connection,
938944
preparedStatementNames: rest.preparedStatementNames,
939-
workGroup: rest.workGroupName,
945+
workGroup: workGroupName,
940946
}
941947

942948
case 'list_prepared_statements':
943-
if (!rest.workGroupName) {
949+
if (!workGroupName) {
944950
throw new Error('Workgroup is required')
945951
}
946952
return {
947953
...connection,
948-
workGroup: rest.workGroupName,
954+
workGroup: workGroupName,
949955
...(parsedMaxResults !== undefined && { maxResults: parsedMaxResults }),
950956
...(rest.nextToken && { nextToken: rest.nextToken }),
951957
}
@@ -958,15 +964,17 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
958964
...(rest.nextToken && { nextToken: rest.nextToken }),
959965
}
960966

961-
case 'get_data_catalog':
962-
if (!rest.catalogName) {
967+
case 'get_data_catalog': {
968+
const catalogName = rest.catalogName || toolCallArg(context, rest.name)
969+
if (!catalogName) {
963970
throw new Error('Data catalog name is required')
964971
}
965972
return {
966973
...connection,
967-
name: rest.catalogName,
974+
name: catalogName,
968975
...(rest.workGroup && { workGroup: rest.workGroup }),
969976
}
977+
}
970978

971979
case 'get_database':
972980
if (!rest.catalogName) {
@@ -1008,10 +1016,10 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
10081016
}
10091017

10101018
case 'get_work_group':
1011-
if (!rest.workGroupName) {
1019+
if (!workGroupName) {
10121020
throw new Error('Workgroup is required')
10131021
}
1014-
return { ...connection, workGroup: rest.workGroupName }
1022+
return { ...connection, workGroup: workGroupName }
10151023

10161024
default:
10171025
throw new Error(`Invalid Athena operation: ${operation}`)

‎apps/sim/blocks/blocks/azure_data_explorer.ts‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AzureDataExplorerIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4-
import { withSavedCredential } from '@/blocks/utils'
4+
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'
55

66
/** Every operation except the cluster-level database listing runs in a database. */
77
const DATABASE_SCOPED_OPERATIONS = [
@@ -423,7 +423,7 @@ export const AzureDataExplorerBlock: BlockConfig = {
423423
],
424424
config: {
425425
tool: (params) => params.operation,
426-
params: (params) => {
426+
params: (params, context) => {
427427
const auth = {
428428
clusterUri: params.clusterUri,
429429
tenantId: params.tenantId,
@@ -432,7 +432,7 @@ export const AzureDataExplorerBlock: BlockConfig = {
432432
resource: params.resource || undefined,
433433
}
434434

435-
switch (params.operation) {
435+
switch (mapperOperation(params, context)) {
436436
case 'azure_data_explorer_query':
437437
return {
438438
...auth,
@@ -467,9 +467,13 @@ export const AzureDataExplorerBlock: BlockConfig = {
467467
...auth,
468468
database: params.database,
469469
table: params.table,
470-
mode: params.ingestMode || undefined,
470+
mode: params.ingestMode || toolCallArg(context, params.mode) || undefined,
471471
sourceQuery: params.sourceQuery,
472-
async: toBoolean(params.ingestAsync),
472+
async:
473+
params.ingestAsync === false || params.ingestAsync === 'false'
474+
? undefined
475+
: (toBoolean(params.ingestAsync) ??
476+
toBoolean(toolCallArg(context, params.async))),
473477
ingestionProperties: params.ingestionProperties || undefined,
474478
}
475479
case 'azure_data_explorer_create_table':

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,3 +233,40 @@ describe('Cloudflare migration convergence', () => {
233233
expect(second.blocks['block-1'].subBlocks.recordProxied?.value).toBe('true')
234234
})
235235
})
236+
237+
/**
238+
* An agent tool call sends model args under the tool's param names (`type`, `files`) with the
239+
* operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
240+
*/
241+
describe('Cloudflare agent tool calls', () => {
242+
const agentCall = (
243+
operation: string,
244+
args: Record<string, unknown>
245+
): Record<string, unknown> => ({
246+
...args,
247+
...CloudflareBlock.tools.config?.params?.(args, { operation }),
248+
})
249+
250+
it('keeps the model record type that the canvas reads from an alias subBlock', () => {
251+
expect(
252+
agentCall('create_dns_record', {
253+
...CREDENTIALS,
254+
zoneId: 'zone-1',
255+
type: 'CNAME',
256+
name: 'app.example.com',
257+
content: 'origin.example.com',
258+
})
259+
).toMatchObject({ type: 'CNAME' })
260+
})
261+
262+
it('drops file targets when the model purges everything', () => {
263+
expect(
264+
agentCall('purge_cache', {
265+
...CREDENTIALS,
266+
zoneId: 'zone-1',
267+
purge_everything: true,
268+
files: 'https://example.com/a.css',
269+
}).files
270+
).toBeUndefined()
271+
})
272+
})

‎apps/sim/blocks/blocks/cloudflare.ts‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CloudflareIcon } from '@/components/icons'
22
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
3-
import { withSavedCredential } from '@/blocks/utils'
3+
import { isToolCall, mapperOperation, withSavedCredential } from '@/blocks/utils'
44

55
/** Advanced inputs serialize before conditions; separate aliases prevent hidden values crossing operations. */
66
const SUBBLOCK_ALIASES: Record<string, Record<string, string>> = {
@@ -4521,11 +4521,16 @@ export const CloudflareBlock: BlockConfig = {
45214521
],
45224522
config: {
45234523
tool: (params) => `cloudflare_${params.operation}`,
4524-
params: (params) => {
4524+
params: (params, context) => {
45254525
const result = { ...params }
4526-
const operation = typeof result.operation === 'string' ? result.operation : ''
4527-
for (const [toolParam, aliasId] of Object.entries(SUBBLOCK_ALIASES[operation] ?? {}))
4528-
result[toolParam] = result[aliasId]
4526+
const operation = mapperOperation(params, context)
4527+
const toolCall = isToolCall(context)
4528+
for (const [toolParam, aliasId] of Object.entries(SUBBLOCK_ALIASES[operation] ?? {})) {
4529+
const aliasValue = result[aliasId]
4530+
const aliasBlank = aliasValue === undefined || aliasValue === null || aliasValue === ''
4531+
// A tool call carries the model's value under the tool's own param name.
4532+
if (!(toolCall && aliasBlank)) result[toolParam] = aliasValue
4533+
}
45294534
for (const aliasId of ALIASED_SUBBLOCK_IDS) result[aliasId] = void 0
45304535
if (result.proxied === 'true') result.proxied = !0
45314536
else if (result.proxied === 'false') result.proxied = !1
@@ -4545,7 +4550,7 @@ export const CloudflareBlock: BlockConfig = {
45454550
if (result.match === '') result.match = void 0
45464551
if (result.tag_match === '') result.tag_match = void 0
45474552
if (result.deploy === '') result.deploy = void 0
4548-
if (result.operation === 'update_dns_record') {
4553+
if (operation === 'update_dns_record') {
45494554
if (result.content === '') result.content = void 0
45504555
if (result.name === '') result.name = void 0
45514556
if (result.comment === '') result.comment = void 0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { CloudFormationBlock } from '@/blocks/blocks/cloudformation'
3+
4+
/**
5+
* An agent tool call sends model args under the tool's param names (`description`, `tags`) with
6+
* the operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
7+
*/
8+
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => ({
9+
...args,
10+
...(CloudFormationBlock.tools.config?.params?.(args, { operation }) ?? {}),
11+
})
12+
13+
describe('CloudFormationBlock agent tool calls', () => {
14+
it('keeps the model change set description and tags', () => {
15+
expect(
16+
agentCall('create_change_set', {
17+
awsRegion: 'us-east-1',
18+
awsAccessKeyId: 'AKIA',
19+
awsSecretAccessKey: 'secret',
20+
stackName: 'app',
21+
changeSetName: 'cs-1',
22+
usePreviousTemplate: true,
23+
description: 'Bump instance size',
24+
tags: [{ Key: 'team', Value: 'infra' }],
25+
})
26+
).toMatchObject({
27+
usePreviousTemplate: true,
28+
description: 'Bump instance size',
29+
tags: [{ Key: 'team', Value: 'infra' }],
30+
})
31+
})
32+
})

0 commit comments

Comments
 (0)