Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions apps/sim/blocks/blocks/athena.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, it } from 'vitest'
import { AthenaBlock } from '@/blocks/blocks/athena'

/**
* An agent tool call sends model args under the tool's param names (`workGroup`, `queryStatement`,
* `name`) with the operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
*/
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => ({
...args,
...(AthenaBlock.tools.config?.params?.(args, { operation }) ?? {}),
})

const CREDENTIALS = { awsRegion: 'us-east-1', awsAccessKeyId: 'AKIA', awsSecretAccessKey: 'secret' }

describe('AthenaBlock agent tool calls', () => {
it('keeps the model prepared statement workgroup and statement instead of throwing', () => {
expect(
agentCall('create_prepared_statement', {
...CREDENTIALS,
statementName: 'by_day',
workGroup: 'primary',
queryStatement: 'SELECT * FROM t WHERE d = ?',
description: 'Daily rows',
})
).toMatchObject({
statementName: 'by_day',
workGroup: 'primary',
queryStatement: 'SELECT * FROM t WHERE d = ?',
description: 'Daily rows',
})
})

it('keeps the model catalog name and coerces maxResults on list calls', () => {
expect(agentCall('get_data_catalog', { ...CREDENTIALS, name: 'AwsDataCatalog' })).toMatchObject(
{ name: 'AwsDataCatalog' }
)
expect(agentCall('list_named_queries', { ...CREDENTIALS, maxResults: '5' })).toMatchObject({
maxResults: 5,
})
})
})
60 changes: 34 additions & 26 deletions apps/sim/blocks/blocks/athena.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AthenaIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'

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

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

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

case 'create_named_query': {
if (!rest.queryName) {
if (!queryName) {
throw new Error('Query name is required')
}
if (!rest.database) {
Expand All @@ -779,10 +783,10 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
awsRegion,
awsAccessKeyId,
awsSecretAccessKey,
name: rest.queryName,
name: queryName,
database: rest.database,
queryString: rest.queryString,
...(rest.queryDescription && { description: rest.queryDescription }),
...(queryDescription && { description: queryDescription }),
...(rest.workGroup && { workGroup: rest.workGroup }),
}
}
Expand Down Expand Up @@ -879,7 +883,7 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
if (!rest.namedQueryId) {
throw new Error('Named query ID is required')
}
if (!rest.queryName) {
if (!queryName) {
throw new Error('Query name is required')
}
if (!rest.queryString) {
Expand All @@ -888,64 +892,66 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
return {
...connection,
namedQueryId: rest.namedQueryId,
name: rest.queryName,
name: queryName,
queryString: rest.queryString,
...(rest.queryDescription && { description: rest.queryDescription }),
...(queryDescription && { description: queryDescription }),
}

case 'create_prepared_statement':
case 'update_prepared_statement':
case 'update_prepared_statement': {
const queryStatement = rest.queryString || toolCallArg(context, rest.queryStatement)
if (!rest.statementName) {
throw new Error('Statement name is required')
}
if (!rest.workGroupName) {
if (!workGroupName) {
throw new Error('Workgroup is required')
}
if (!rest.queryString) {
if (!queryStatement) {
throw new Error('SQL query statement is required')
}
return {
...connection,
statementName: rest.statementName,
workGroup: rest.workGroupName,
queryStatement: rest.queryString,
...(rest.queryDescription && { description: rest.queryDescription }),
workGroup: workGroupName,
queryStatement,
...(queryDescription && { description: queryDescription }),
}
}

case 'get_prepared_statement':
case 'delete_prepared_statement':
if (!rest.statementName) {
throw new Error('Statement name is required')
}
if (!rest.workGroupName) {
if (!workGroupName) {
throw new Error('Workgroup is required')
}
return {
...connection,
statementName: rest.statementName,
workGroup: rest.workGroupName,
workGroup: workGroupName,
}

case 'batch_get_prepared_statement':
if (!rest.preparedStatementNames) {
throw new Error('Statement names are required')
}
if (!rest.workGroupName) {
if (!workGroupName) {
throw new Error('Workgroup is required')
}
return {
...connection,
preparedStatementNames: rest.preparedStatementNames,
workGroup: rest.workGroupName,
workGroup: workGroupName,
}

case 'list_prepared_statements':
if (!rest.workGroupName) {
if (!workGroupName) {
throw new Error('Workgroup is required')
}
return {
...connection,
workGroup: rest.workGroupName,
workGroup: workGroupName,
...(parsedMaxResults !== undefined && { maxResults: parsedMaxResults }),
...(rest.nextToken && { nextToken: rest.nextToken }),
}
Expand All @@ -958,15 +964,17 @@ Return ONLY a JSON array of strings — no explanations, no markdown code blocks
...(rest.nextToken && { nextToken: rest.nextToken }),
}

case 'get_data_catalog':
if (!rest.catalogName) {
case 'get_data_catalog': {
const catalogName = rest.catalogName || toolCallArg(context, rest.name)
if (!catalogName) {
throw new Error('Data catalog name is required')
}
return {
...connection,
name: rest.catalogName,
name: catalogName,
...(rest.workGroup && { workGroup: rest.workGroup }),
}
}

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

case 'get_work_group':
if (!rest.workGroupName) {
if (!workGroupName) {
throw new Error('Workgroup is required')
}
return { ...connection, workGroup: rest.workGroupName }
return { ...connection, workGroup: workGroupName }

default:
throw new Error(`Invalid Athena operation: ${operation}`)
Expand Down
14 changes: 9 additions & 5 deletions apps/sim/blocks/blocks/azure_data_explorer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AzureDataExplorerIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'

/** Every operation except the cluster-level database listing runs in a database. */
const DATABASE_SCOPED_OPERATIONS = [
Expand Down Expand Up @@ -423,7 +423,7 @@ export const AzureDataExplorerBlock: BlockConfig = {
],
config: {
tool: (params) => params.operation,
params: (params) => {
params: (params, context) => {
const auth = {
clusterUri: params.clusterUri,
tenantId: params.tenantId,
Expand All @@ -432,7 +432,7 @@ export const AzureDataExplorerBlock: BlockConfig = {
resource: params.resource || undefined,
}

switch (params.operation) {
switch (mapperOperation(params, context)) {
case 'azure_data_explorer_query':
return {
...auth,
Expand Down Expand Up @@ -467,9 +467,13 @@ export const AzureDataExplorerBlock: BlockConfig = {
...auth,
database: params.database,
table: params.table,
mode: params.ingestMode || undefined,
mode: params.ingestMode || toolCallArg(context, params.mode) || undefined,
sourceQuery: params.sourceQuery,
async: toBoolean(params.ingestAsync),
async:
params.ingestAsync === false || params.ingestAsync === 'false'
? undefined
: (toBoolean(params.ingestAsync) ??
toBoolean(toolCallArg(context, params.async))),
ingestionProperties: params.ingestionProperties || undefined,
}
case 'azure_data_explorer_create_table':
Expand Down
37 changes: 37 additions & 0 deletions apps/sim/blocks/blocks/cloudflare.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,40 @@ describe('Cloudflare migration convergence', () => {
expect(second.blocks['block-1'].subBlocks.recordProxied?.value).toBe('true')
})
})

/**
* An agent tool call sends model args under the tool's param names (`type`, `files`) with the
* operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
*/
describe('Cloudflare agent tool calls', () => {
const agentCall = (
operation: string,
args: Record<string, unknown>
): Record<string, unknown> => ({
...args,
...CloudflareBlock.tools.config?.params?.(args, { operation }),
})

it('keeps the model record type that the canvas reads from an alias subBlock', () => {
expect(
agentCall('create_dns_record', {
...CREDENTIALS,
zoneId: 'zone-1',
type: 'CNAME',
name: 'app.example.com',
content: 'origin.example.com',
})
).toMatchObject({ type: 'CNAME' })
})

it('drops file targets when the model purges everything', () => {
expect(
agentCall('purge_cache', {
...CREDENTIALS,
zoneId: 'zone-1',
purge_everything: true,
files: 'https://example.com/a.css',
}).files
).toBeUndefined()
})
})
17 changes: 11 additions & 6 deletions apps/sim/blocks/blocks/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CloudflareIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { isToolCall, mapperOperation, withSavedCredential } from '@/blocks/utils'

/** Advanced inputs serialize before conditions; separate aliases prevent hidden values crossing operations. */
const SUBBLOCK_ALIASES: Record<string, Record<string, string>> = {
Expand Down Expand Up @@ -4521,11 +4521,16 @@ export const CloudflareBlock: BlockConfig = {
],
config: {
tool: (params) => `cloudflare_${params.operation}`,
params: (params) => {
params: (params, context) => {
const result = { ...params }
const operation = typeof result.operation === 'string' ? result.operation : ''
for (const [toolParam, aliasId] of Object.entries(SUBBLOCK_ALIASES[operation] ?? {}))
result[toolParam] = result[aliasId]
const operation = mapperOperation(params, context)
const toolCall = isToolCall(context)
for (const [toolParam, aliasId] of Object.entries(SUBBLOCK_ALIASES[operation] ?? {})) {
const aliasValue = result[aliasId]
const aliasBlank = aliasValue === undefined || aliasValue === null || aliasValue === ''
// A tool call carries the model's value under the tool's own param name.
if (!(toolCall && aliasBlank)) result[toolParam] = aliasValue
}
for (const aliasId of ALIASED_SUBBLOCK_IDS) result[aliasId] = void 0
if (result.proxied === 'true') result.proxied = !0
else if (result.proxied === 'false') result.proxied = !1
Expand All @@ -4545,7 +4550,7 @@ export const CloudflareBlock: BlockConfig = {
if (result.match === '') result.match = void 0
if (result.tag_match === '') result.tag_match = void 0
if (result.deploy === '') result.deploy = void 0
if (result.operation === 'update_dns_record') {
if (operation === 'update_dns_record') {
if (result.content === '') result.content = void 0
if (result.name === '') result.name = void 0
if (result.comment === '') result.comment = void 0
Expand Down
32 changes: 32 additions & 0 deletions apps/sim/blocks/blocks/cloudformation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import { CloudFormationBlock } from '@/blocks/blocks/cloudformation'

/**
* An agent tool call sends model args under the tool's param names (`description`, `tags`) with
* the operation only on `context`; the handler forwards `{ ...args, ...mapped }`.
*/
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => ({
...args,
...(CloudFormationBlock.tools.config?.params?.(args, { operation }) ?? {}),
})

describe('CloudFormationBlock agent tool calls', () => {
it('keeps the model change set description and tags', () => {
expect(
agentCall('create_change_set', {
awsRegion: 'us-east-1',
awsAccessKeyId: 'AKIA',
awsSecretAccessKey: 'secret',
stackName: 'app',
changeSetName: 'cs-1',
usePreviousTemplate: true,
description: 'Bump instance size',
tags: [{ Key: 'team', Value: 'infra' }],
})
).toMatchObject({
usePreviousTemplate: true,
description: 'Bump instance size',
tags: [{ Key: 'team', Value: 'infra' }],
})
})
})
Loading
Loading