Skip to content

Commit ed1af53

Browse files
committed
fix(integrations): resolve the operation from the tool-call context in the ClickUp, Airtable, Asana, monday, SAP S/4HANA, and Workday mappers
1 parent 69bfb1b commit ed1af53

12 files changed

Lines changed: 232 additions & 55 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ describe('Airtable pagination offsets', () => {
116116
})
117117

118118
it('keeps the model offset on a List Records tool call', () => {
119-
const mapped = mapParams(
120-
{ ...baseParams, operation: 'list', offset: 'itrModel' },
121-
{ operation: 'list' }
122-
)
119+
const mapped = mapParams({ ...baseParams, offset: 'itrModel' }, { operation: 'list' })
123120
expect(mapped.offset).toBe('itrModel')
124121
})
122+
123+
it('maps an offset the user set on the tool when the operation arrives only on the context', () => {
124+
const mapped = mapParams({ ...baseParams, recordsOffset: 'itrUser' }, { operation: 'list' })
125+
expect(mapped.offset).toBe('itrUser')
126+
})
125127
})

‎apps/sim/blocks/blocks/airtable.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ Return ONLY the valid JSON array of record ID strings - no explanations, no mark
428428
basesOffset,
429429
...rest
430430
} = params
431+
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
432+
const operation = params.operation ?? context?.operation
431433
let parsedRecords: unknown
432434
let parsedFields: unknown
433435
let parsedFieldsToMergeOn: unknown
@@ -440,24 +442,22 @@ Return ONLY the valid JSON array of record ID strings - no explanations, no mark
440442
try {
441443
if (
442444
records &&
443-
(params.operation === 'create' ||
444-
params.operation === 'updateMultiple' ||
445-
params.operation === 'upsert')
445+
(operation === 'create' || operation === 'updateMultiple' || operation === 'upsert')
446446
) {
447447
parsedRecords = parseJsonInput(records)
448448
}
449-
if (fields && params.operation === 'update') {
449+
if (fields && operation === 'update') {
450450
parsedFields = parseJsonInput(fields)
451451
}
452-
if (fieldsToMergeOn && params.operation === 'upsert') {
452+
if (fieldsToMergeOn && operation === 'upsert') {
453453
parsedFieldsToMergeOn = parseJsonInput(fieldsToMergeOn)
454454
}
455-
if (recordIds && params.operation === 'delete') {
455+
if (recordIds && operation === 'delete') {
456456
parsedRecordIds = parseJsonInput(recordIds)
457457
}
458458
} catch (error) {
459459
throw new Error(
460-
`Invalid JSON input for ${params.operation} operation: ${getErrorMessage(error)}`
460+
`Invalid JSON input for ${operation} operation: ${getErrorMessage(error)}`
461461
)
462462
}
463463

@@ -469,7 +469,7 @@ Return ONLY the valid JSON array of record ID strings - no explanations, no mark
469469
const typecastParams =
470470
typecast != null ? { typecast: typecast === true || typecast === 'true' } : {}
471471

472-
switch (params.operation) {
472+
switch (operation) {
473473
case 'list':
474474
return {
475475
...baseParams,

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ const buildParams = (
1010

1111
/**
1212
* On an agent call the model supplies args under the tool's own param names (`workspace`, `text`,
13-
* `taskGid`, array `projects`/`followers`); the per-operation canvas fields are never rendered.
14-
* The handler forwards `{ ...inputs, ...mapped }`.
13+
* `taskGid`, array `projects`/`followers`), and the stored operation reaches the mapper only on
14+
* `context` (never in the args). The handler forwards `{ ...inputs, ...mapped }`.
1515
*/
1616
describe('AsanaBlock agent tool calls', () => {
1717
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => {
18-
const inputs = { ...args, operation }
19-
return { ...inputs, ...buildParams(inputs, { operation }) }
18+
return { ...args, ...buildParams(args, { operation }) }
2019
}
2120

2221
it('keeps the model workspace, project, limit, and offset on get_task', () => {
@@ -81,3 +80,13 @@ describe('AsanaBlock canvas inputs', () => {
8180
).toMatchObject({ limit: 25 })
8281
})
8382
})
83+
84+
describe('AsanaBlock agent tool calls with a configured field', () => {
85+
it('maps a workspace the user set on the tool to the get_task workspace param', () => {
86+
const mapped = buildParams(
87+
{ getTasks_workspace: 'ws-1', assignee: 'me' },
88+
{ operation: 'get_task' }
89+
)
90+
expect(mapped.workspace).toBe('ws-1')
91+
})
92+
})

‎apps/sim/blocks/blocks/asana.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
519519
}
520520
},
521521
params: (params, context) => {
522-
const { oauthCredential, operation } = params
522+
const { oauthCredential } = params
523+
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
524+
const operation = params.operation ?? context?.operation
523525

524526
const splitGids = (value: unknown): string[] | undefined => {
525527
if (Array.isArray(value)) return value.map(String)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { triggersMock } from '@sim/testing/mocks/triggers.mock'
2+
import { describe, expect, it, vi } from 'vitest'
3+
4+
vi.mock('@/triggers', () => triggersMock)
5+
6+
import { ClickUpBlock } from '@/blocks/blocks/clickup'
7+
import type { BlockToolParamsContext } from '@/blocks/types'
8+
9+
const mapParams = (
10+
inputs: Record<string, unknown>,
11+
context?: BlockToolParamsContext
12+
): Record<string, unknown> => ClickUpBlock.tools.config?.params?.(inputs, context) ?? {}
13+
14+
/** On an agent call the stored operation reaches the mapper only on `context`, never in the args. */
15+
describe('ClickUp agent tool calls', () => {
16+
it('maps the workspace picked on the tool to workspaceId', () => {
17+
expect(mapParams({ teamId: 'team-1' }, { operation: 'search_tasks' }).workspaceId).toBe(
18+
'team-1'
19+
)
20+
})
21+
22+
it('keeps the model workspaceId when no workspace is picked', () => {
23+
expect(mapParams({ workspaceId: 'team-2' }, { operation: 'get_spaces' }).workspaceId).toBe(
24+
'team-2'
25+
)
26+
})
27+
28+
it('maps the picked workspace on the canvas exactly as before', () => {
29+
expect(mapParams({ operation: 'search_tasks', teamId: 'team-1' }).workspaceId).toBe('team-1')
30+
})
31+
})

‎apps/sim/blocks/blocks/clickup.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,9 @@ Return ONLY the value (plain string, number, or JSON) - no explanations, no extr
14771477
config: {
14781478
tool: (params) => `clickup_${params.operation}`,
14791479
params: (params, context) => {
1480-
const { oauthCredential, operation } = params
1480+
const { oauthCredential } = params
1481+
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
1482+
const operation = params.operation ?? context?.operation
14811483

14821484
const baseParams = {
14831485
accessToken: oauthCredential?.accessToken,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { triggersMock } from '@sim/testing/mocks/triggers.mock'
2+
import { describe, expect, it, vi } from 'vitest'
3+
4+
vi.mock('@/triggers', () => triggersMock)
5+
6+
import { MondayBlock } from '@/blocks/blocks/monday'
7+
import type { BlockToolParamsContext } from '@/blocks/types'
8+
9+
const mapParams = (
10+
inputs: Record<string, unknown>,
11+
context?: BlockToolParamsContext
12+
): Record<string, unknown> => MondayBlock.tools.config?.params?.(inputs, context) ?? {}
13+
14+
/** On an agent call the stored operation reaches the mapper only on `context`, never in the args. */
15+
describe('monday agent tool calls', () => {
16+
it('maps the update body set on the tool to the create_update body param', () => {
17+
expect(
18+
mapParams({ itemId: '1', updateBody: 'Shipped' }, { operation: 'create_update' }).body
19+
).toBe('Shipped')
20+
})
21+
22+
it('keeps the model body and column value when the tool fields are blank', () => {
23+
expect(mapParams({ itemId: '1', body: 'Hi' }, { operation: 'create_update' }).body).toBe('Hi')
24+
expect(
25+
mapParams(
26+
{ boardId: '1', itemId: '2', columnId: 'status', value: '{"label":"Done"}' },
27+
{ operation: 'change_column_value' }
28+
).value
29+
).toBe('{"label":"Done"}')
30+
})
31+
32+
it('maps the canvas update body exactly as before', () => {
33+
expect(mapParams({ operation: 'create_update', itemId: '1', updateBody: 'Shipped' }).body).toBe(
34+
'Shipped'
35+
)
36+
})
37+
})

‎apps/sim/blocks/blocks/monday.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ export const MondayBlock: BlockConfig = {
525525
const baseParams: Record<string, unknown> = {
526526
oauthCredential: params.oauthCredential,
527527
}
528-
const op = typeof params.operation === 'string' ? params.operation.trim() : 'list_boards'
528+
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
529+
const rawOperation = params.operation ?? context?.operation
530+
const op = typeof rawOperation === 'string' ? rawOperation.trim() : 'list_boards'
529531

530532
switch (op) {
531533
case 'list_boards':
@@ -550,7 +552,7 @@ export const MondayBlock: BlockConfig = {
550552
return {
551553
...baseParams,
552554
boardId: params.boardId,
553-
columns: params.searchColumns,
555+
columns: params.searchColumns || toolCallArg(context, params.columns),
554556
limit: params.limit ? Number(params.limit) : undefined,
555557
cursor: params.cursor || undefined,
556558
}
@@ -575,7 +577,7 @@ export const MondayBlock: BlockConfig = {
575577
boardId: params.boardId,
576578
itemId: params.itemId,
577579
columnId: params.columnId,
578-
value: params.columnValue,
580+
value: params.columnValue ?? toolCallArg(context, params.value),
579581
createLabelsIfMissing: Boolean(params.createLabelsIfMissing),
580582
}
581583
case 'duplicate_item':
@@ -590,7 +592,8 @@ export const MondayBlock: BlockConfig = {
590592
...baseParams,
591593
boardName: params.boardName,
592594
boardKind: params.boardKind || 'public',
593-
description: params.boardDescription || undefined,
595+
description:
596+
params.boardDescription || toolCallArg(context, params.description) || undefined,
594597
workspaceId: params.workspaceId || undefined,
595598
folderId: params.folderId || undefined,
596599
}
@@ -626,7 +629,7 @@ export const MondayBlock: BlockConfig = {
626629
return {
627630
...baseParams,
628631
itemId: params.itemId,
629-
body: params.updateBody,
632+
body: params.updateBody || toolCallArg(context, params.body),
630633
}
631634
case 'create_group':
632635
return {
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 { SapS4HanaBlock } from '@/blocks/blocks/sap_s4hana'
3+
import type { BlockToolParamsContext } from '@/blocks/types'
4+
5+
const mapParams = (
6+
inputs: Record<string, unknown>,
7+
context?: BlockToolParamsContext
8+
): Record<string, unknown> => SapS4HanaBlock.tools.config?.params?.(inputs, context) ?? {}
9+
10+
const items = [{ Material: 'M-1', RequestedQuantity: '1' }]
11+
12+
/** On an agent call the stored operation reaches the mapper only on `context`, never in the args. */
13+
describe('SAP S/4HANA agent tool calls', () => {
14+
it('maps sales order items set on the tool to the items param', () => {
15+
expect(
16+
mapParams({ salesOrderItems: items }, { operation: 'sap_s4hana_create_sales_order' }).items
17+
).toEqual(items)
18+
})
19+
20+
it('keeps the model OData service, path and body when the tool fields are blank', () => {
21+
const mapped = mapParams(
22+
{ service: 'API_PRODUCT_SRV', path: '/A_Product', method: 'POST', body: { Product: 'P1' } },
23+
{ operation: 'sap_s4hana_odata_query' }
24+
)
25+
expect(mapped).toMatchObject({
26+
service: 'API_PRODUCT_SRV',
27+
path: '/A_Product',
28+
method: 'POST',
29+
body: { Product: 'P1' },
30+
})
31+
})
32+
33+
it('maps canvas OData fields exactly as before', () => {
34+
const mapped = mapParams({
35+
operation: 'sap_s4hana_odata_query',
36+
odataService: 'API_PRODUCT_SRV',
37+
odataPath: '/A_Product',
38+
})
39+
expect(mapped).toMatchObject({ service: 'API_PRODUCT_SRV', path: '/A_Product', method: 'GET' })
40+
})
41+
})

0 commit comments

Comments
 (0)