Skip to content

Commit 685ad5d

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

48 files changed

Lines changed: 1516 additions & 682 deletions

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/azure_devops.test.ts‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ const buildParams = (
1111
/**
1212
* On an agent call the model supplies `continuationToken`/`top`/`iterationPath`/`format` under the
1313
* tool's own names; the per-operation fields (`pipelinesContinuationToken`, `queryTop`, …) are never
14-
* rendered in the agent tool input. The handler forwards `{ ...inputs, ...mapped }`.
14+
* rendered in the agent tool input. A tool call carries the operation only in `context`, and the
15+
* handler forwards `{ ...inputs, ...mapped }`.
1516
*/
1617
describe('AzureDevOpsBlock agent tool calls', () => {
1718
const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => {
18-
const inputs = { ...args, operation, organization: 'org', project: 'proj' }
19+
const inputs = { ...args, organization: 'org', project: 'proj' }
1920
return { ...inputs, ...buildParams(inputs, { operation }) }
2021
}
2122

@@ -28,6 +29,21 @@ describe('AzureDevOpsBlock agent tool calls', () => {
2829
}
2930
)
3031

32+
it.each(['azure_devops_create_work_item', 'azure_devops_update_work_item'])(
33+
'keeps a model zero for remainingWork, completedWork and effort on %s',
34+
(operation) => {
35+
const mapped = agentCall(operation, {
36+
workItemId: 5,
37+
workItemType: 'Task',
38+
title: 't',
39+
remainingWork: 0,
40+
completedWork: 0,
41+
effort: 0,
42+
})
43+
expect([mapped.remainingWork, mapped.completedWork, mapped.effort]).toEqual([0, 0, 0])
44+
}
45+
)
46+
3147
it('keeps the model top on azure_devops_query_work_items', () => {
3248
expect(agentCall('azure_devops_query_work_items', { wiqlQuery: 'q', top: 5 }).top).toBe(5)
3349
})
@@ -45,6 +61,23 @@ describe('AzureDevOpsBlock agent tool calls', () => {
4561
expect(mapped.format).toBe('markdown')
4662
})
4763

64+
it('keeps the model ids on azure_devops_get_work_items_batch', () => {
65+
expect(agentCall('azure_devops_get_work_items_batch', { ids: '1,2' }).ids).toBe('1,2')
66+
})
67+
68+
it('keeps the model text on azure_devops_add_comment', () => {
69+
expect(agentCall('azure_devops_add_comment', { workItemId: 1, text: 'hi' }).text).toBe('hi')
70+
})
71+
72+
it('expands a bare model start date on azure_devops_create_work_item', () => {
73+
const mapped = agentCall('azure_devops_create_work_item', {
74+
workItemType: 'Epic',
75+
title: 't',
76+
startDate: '2026-01-15',
77+
})
78+
expect(mapped.startDate).toBe('2026-01-15T00:00:00Z')
79+
})
80+
4881
it('drops a List Builds token left over on the canvas under list pipelines', () => {
4982
const inputs = { operation: 'azure_devops_list_pipelines', continuationToken: 'stale' }
5083
expect({ ...inputs, ...buildParams(inputs) }.continuationToken).toBeUndefined()

‎apps/sim/blocks/blocks/azure_devops.ts‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AzureIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4-
import { toolCallArg, withSavedCredential } from '@/blocks/utils'
4+
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'
55
import type { AzureDevOpsBasicWorkItemType } from '@/tools/azure_devops/types'
66
import { AZURE_DEVOPS_BASIC_WORK_ITEM_STATES } from '@/tools/azure_devops/utils'
77
import { getTrigger } from '@/triggers'
@@ -22,6 +22,11 @@ function resolveTop(dedicated: unknown, shared: unknown): number | undefined {
2222
return value ? Number(value) : undefined
2323
}
2424

25+
/** Coerces an optional numeric field, keeping `0` (a model may send it to clear remaining work). */
26+
function optionalNumber(value: unknown): number | undefined {
27+
return value === undefined || value === null || value === '' ? undefined : Number(value)
28+
}
29+
2530
export const AzureDevOpsBlock: BlockConfig = {
2631
type: 'azure_devops',
2732
hideFromToolbar: true,
@@ -724,7 +729,7 @@ export const AzureDevOpsBlock: BlockConfig = {
724729
organization: params.organization as string,
725730
project: params.project as string,
726731
}
727-
switch (params.operation) {
732+
switch (mapperOperation(params, context)) {
728733
case 'azure_devops_list_pipelines':
729734
return {
730735
...base,
@@ -782,7 +787,10 @@ export const AzureDevOpsBlock: BlockConfig = {
782787
case 'azure_devops_get_work_item':
783788
return { ...base, workItemId: Number(params.workItemId) }
784789
case 'azure_devops_get_work_items_batch':
785-
return { ...base, ids: params.workItemIds as string }
790+
return {
791+
...base,
792+
ids: (params.workItemIds as string) || toolCallArg(context, params.ids as string),
793+
}
786794
case 'azure_devops_create_work_item':
787795
return {
788796
...base,
@@ -791,12 +799,12 @@ export const AzureDevOpsBlock: BlockConfig = {
791799
description: (params.description as string) || undefined,
792800
assignedTo: (params.assignedTo as string) || undefined,
793801
priority: params.priority ? Number(params.priority) : undefined,
794-
effort: params.effort ? Number(params.effort) : undefined,
802+
effort: optionalNumber(params.effort),
795803
startDate: normalizeDate(params.startDate),
796804
targetDate: normalizeDate(params.targetDate),
797805
activity: (params.activity as string) || undefined,
798-
remainingWork: params.remainingWork ? Number(params.remainingWork) : undefined,
799-
completedWork: params.completedWork ? Number(params.completedWork) : undefined,
806+
remainingWork: optionalNumber(params.remainingWork),
807+
completedWork: optionalNumber(params.completedWork),
800808
areaPath: (params.areaPath as string) || undefined,
801809
iterationPath: (params.iterationPath as string) || undefined,
802810
tags: (params.tags as string) || undefined,
@@ -809,12 +817,12 @@ export const AzureDevOpsBlock: BlockConfig = {
809817
state: (params.state as string) || undefined,
810818
assignedTo: (params.assignedTo as string) || undefined,
811819
priority: params.priority ? Number(params.priority) : undefined,
812-
effort: params.effort ? Number(params.effort) : undefined,
820+
effort: optionalNumber(params.effort),
813821
startDate: normalizeDate(params.startDate),
814822
targetDate: normalizeDate(params.targetDate),
815823
activity: (params.activity as string) || undefined,
816-
remainingWork: params.remainingWork ? Number(params.remainingWork) : undefined,
817-
completedWork: params.completedWork ? Number(params.completedWork) : undefined,
824+
remainingWork: optionalNumber(params.remainingWork),
825+
completedWork: optionalNumber(params.completedWork),
818826
description: (params.description as string) || undefined,
819827
areaPath: (params.areaPath as string) || undefined,
820828
iterationPath:
@@ -827,7 +835,7 @@ export const AzureDevOpsBlock: BlockConfig = {
827835
return {
828836
...base,
829837
workItemId: Number(params.workItemId),
830-
text: params.commentText as string,
838+
text: (params.commentText as string) || toolCallArg(context, params.text as string),
831839
format:
832840
(params.commentFormat as string) ||
833841
toolCallArg(context, params.format) ||
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { BitbucketBlock } from '@/blocks/blocks/bitbucket'
3+
4+
/**
5+
* On a tool call the model supplies args under the tool's param names (`refName`, `reviewerUuids`,
6+
* …) and the operation arrives only in `context`; the handler forwards `{ ...args, ...mapped }`.
7+
*/
8+
const toolCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => {
9+
const inputs = { workspaceSlug: 'ws', repoSlug: 'repo', ...args }
10+
return { ...inputs, ...BitbucketBlock.tools.config?.params?.(inputs, { operation }) }
11+
}
12+
13+
describe('BitbucketBlock tool calls', () => {
14+
it('defaults the ref type and keeps the model ref name on bitbucket_trigger_pipeline', () => {
15+
const mapped = toolCall('bitbucket_trigger_pipeline', { refName: 'main' })
16+
expect(mapped).toMatchObject({ refType: 'branch', refName: 'main' })
17+
})
18+
19+
it('splits model reviewers and keeps closeSourceBranch on bitbucket_create_pull_request', () => {
20+
const mapped = toolCall('bitbucket_create_pull_request', {
21+
title: 'PR',
22+
sourceBranch: 'feature',
23+
reviewerUuids: '{a}, {b}',
24+
closeSourceBranch: true,
25+
})
26+
expect(mapped).toMatchObject({ reviewerUuids: ['{a}', '{b}'], closeSourceBranch: true })
27+
})
28+
29+
it('keeps the model commit, path and filter on bitbucket_list_directory', () => {
30+
const mapped = toolCall('bitbucket_list_directory', { commit: 'abc', path: 'src', q: 'x' })
31+
expect(mapped).toMatchObject({ commit: 'abc', path: 'src', q: 'x' })
32+
})
33+
})

‎apps/sim/blocks/blocks/bitbucket.ts‎

Lines changed: 75 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BitbucketIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4+
import { mapperOperation, toolCallArg } from '@/blocks/utils'
45
import { getTrigger } from '@/triggers'
56

67
const WORKSPACE_FIELD = ['workspacePicker', 'workspaceSlugInput'] as const
@@ -925,10 +926,20 @@ export const BitbucketBlock: BlockConfig = {
925926
}
926927
return params.operation
927928
},
928-
params: (params) => {
929-
if (!isBitbucketOperation(params.operation)) {
930-
throw new Error(`Invalid Bitbucket operation: ${String(params.operation)}`)
929+
params: (params, context) => {
930+
const operation = mapperOperation(params, context)
931+
if (!isBitbucketOperation(operation)) {
932+
throw new Error(`Invalid Bitbucket operation: ${operation}`)
931933
}
934+
/** A tool call's model args arrive under the tool's param names, not the block field ids. */
935+
const modelArg = (key: string) => toolCallArg(context, params[key])
936+
const q = () => optionalString(params.query, 'query') ?? optionalString(modelArg('q'), 'q')
937+
const commit = () =>
938+
optionalString(params.revision, 'revision') ??
939+
optionalString(modelArg('commit'), 'commit')
940+
const branchName = () =>
941+
optionalString(params.branchName, 'branchName') ??
942+
optionalString(modelArg('name'), 'name')
932943

933944
const common = {
934945
oauthCredential: params.oauthCredential,
@@ -940,7 +951,7 @@ export const BitbucketBlock: BlockConfig = {
940951
nextUrl: optionalString(params.nextUrl, 'nextUrl'),
941952
}
942953

943-
switch (params.operation) {
954+
switch (operation) {
944955
case 'bitbucket_list_workspaces':
945956
return {
946957
oauthCredential: params.oauthCredential,
@@ -953,30 +964,41 @@ export const BitbucketBlock: BlockConfig = {
953964
oauthCredential: params.oauthCredential,
954965
workspaceSlug: optionalString(params.workspaceSlug, 'workspaceSlug'),
955966
role: optionalString(params.role, 'role'),
956-
q: optionalString(params.query, 'query'),
967+
q: q(),
957968
sort: optionalString(params.sort, 'sort'),
958969
...pagination,
959970
}
960971
case 'bitbucket_list_branches':
961972
return {
962973
...common,
963-
q: optionalString(params.query, 'query'),
974+
q: q(),
964975
sort: optionalString(params.sort, 'sort'),
965976
...pagination,
966977
}
967978
case 'bitbucket_list_pipelines':
968979
return {
969980
...common,
970-
refType: optionalString(params.pipelineRefType, 'pipelineRefType'),
971-
refName: optionalString(params.pipelineRefName, 'pipelineRefName'),
972-
commitHash: optionalString(params.pipelineCommitHash, 'pipelineCommitHash'),
973-
selectorType: optionalString(params.pipelineSelectorType, 'pipelineSelectorType'),
974-
selectorPattern: optionalString(
975-
params.pipelineSelectorPattern,
976-
'pipelineSelectorPattern'
977-
),
978-
triggerType: optionalString(params.pipelineTriggerType, 'pipelineTriggerType'),
979-
status: optionalString(params.pipelineStatus, 'pipelineStatus'),
981+
refType:
982+
optionalString(params.pipelineRefType, 'pipelineRefType') ??
983+
optionalString(modelArg('refType'), 'refType'),
984+
refName:
985+
optionalString(params.pipelineRefName, 'pipelineRefName') ??
986+
optionalString(modelArg('refName'), 'refName'),
987+
commitHash:
988+
optionalString(params.pipelineCommitHash, 'pipelineCommitHash') ??
989+
optionalString(modelArg('commitHash'), 'commitHash'),
990+
selectorType:
991+
optionalString(params.pipelineSelectorType, 'pipelineSelectorType') ??
992+
optionalString(modelArg('selectorType'), 'selectorType'),
993+
selectorPattern:
994+
optionalString(params.pipelineSelectorPattern, 'pipelineSelectorPattern') ??
995+
optionalString(modelArg('selectorPattern'), 'selectorPattern'),
996+
triggerType:
997+
optionalString(params.pipelineTriggerType, 'pipelineTriggerType') ??
998+
optionalString(modelArg('triggerType'), 'triggerType'),
999+
status:
1000+
optionalString(params.pipelineStatus, 'pipelineStatus') ??
1001+
optionalString(modelArg('status'), 'status'),
9801002
sort: optionalString(params.sort, 'sort'),
9811003
...pagination,
9821004
}
@@ -985,48 +1007,54 @@ export const BitbucketBlock: BlockConfig = {
9851007
case 'bitbucket_create_branch':
9861008
return {
9871009
...common,
988-
name: optionalString(params.branchName, 'branchName'),
1010+
name: branchName(),
9891011
target: optionalString(params.target, 'target'),
9901012
}
9911013
case 'bitbucket_delete_branch':
992-
return { ...common, name: optionalString(params.branchName, 'branchName') }
1014+
return { ...common, name: branchName() }
9931015
case 'bitbucket_list_commits':
9941016
return {
9951017
...common,
996-
include: stringList(params.commitInclude, 'commitInclude'),
997-
exclude: stringList(params.commitExclude, 'commitExclude'),
998-
path: optionalString(params.commitPath, 'commitPath'),
1018+
include:
1019+
stringList(params.commitInclude, 'commitInclude') ??
1020+
stringList(modelArg('include'), 'include'),
1021+
exclude:
1022+
stringList(params.commitExclude, 'commitExclude') ??
1023+
stringList(modelArg('exclude'), 'exclude'),
1024+
path:
1025+
optionalString(params.commitPath, 'commitPath') ??
1026+
optionalString(modelArg('path'), 'path'),
9991027
...pagination,
10001028
}
10011029
case 'bitbucket_get_commit':
1002-
return { ...common, commit: optionalString(params.revision, 'revision') }
1030+
return { ...common, commit: commit() }
10031031
case 'bitbucket_list_directory':
10041032
return {
10051033
...common,
1006-
commit: optionalString(params.revision, 'revision'),
1034+
commit: commit(),
10071035
path: optionalText(params.path, 'path'),
1008-
q: optionalString(params.query, 'query'),
1036+
q: q(),
10091037
sort: optionalString(params.sort, 'sort'),
10101038
...pagination,
10111039
}
10121040
case 'bitbucket_get_file_metadata':
10131041
return {
10141042
...common,
1015-
commit: optionalString(params.revision, 'revision'),
1043+
commit: commit(),
10161044
path: optionalText(params.path, 'path'),
10171045
}
10181046
case 'bitbucket_get_file':
10191047
return {
10201048
...common,
1021-
commit: optionalString(params.revision, 'revision'),
1049+
commit: commit(),
10221050
path: optionalText(params.path, 'path'),
10231051
maxCharacters: optionalInteger(params.maxCharacters, 'maxCharacters'),
10241052
}
10251053
case 'bitbucket_list_pull_requests':
10261054
return {
10271055
...common,
10281056
state: optionalString(params.state, 'state'),
1029-
q: optionalString(params.query, 'query'),
1057+
q: q(),
10301058
sort: optionalString(params.sort, 'sort'),
10311059
...pagination,
10321060
}
@@ -1042,11 +1070,12 @@ export const BitbucketBlock: BlockConfig = {
10421070
sourceBranch: optionalString(params.sourceBranch, 'sourceBranch'),
10431071
destinationBranch: optionalString(params.destinationBranch, 'destinationBranch'),
10441072
description: optionalText(params.description, 'description'),
1045-
reviewerUuids: stringList(params.reviewerAccountIds, 'reviewerAccountIds'),
1046-
closeSourceBranch: optionalBoolean(
1047-
params.createCloseSourceBranch,
1048-
'createCloseSourceBranch'
1049-
),
1073+
reviewerUuids:
1074+
stringList(params.reviewerAccountIds, 'reviewerAccountIds') ??
1075+
stringList(modelArg('reviewerUuids'), 'reviewerUuids'),
1076+
closeSourceBranch:
1077+
optionalBoolean(params.createCloseSourceBranch, 'createCloseSourceBranch') ??
1078+
optionalBoolean(modelArg('closeSourceBranch'), 'closeSourceBranch'),
10501079
draft: optionalBoolean(params.draft, 'draft'),
10511080
}
10521081
case 'bitbucket_merge_pull_request':
@@ -1055,10 +1084,9 @@ export const BitbucketBlock: BlockConfig = {
10551084
prId: optionalInteger(params.prId, 'prId'),
10561085
mergeStrategy: optionalString(params.mergeStrategy, 'mergeStrategy'),
10571086
message: optionalText(params.message, 'message'),
1058-
closeSourceBranch: optionalBoolean(
1059-
params.mergeCloseSourceBranch,
1060-
'mergeCloseSourceBranch'
1061-
),
1087+
closeSourceBranch:
1088+
optionalBoolean(params.mergeCloseSourceBranch, 'mergeCloseSourceBranch') ??
1089+
optionalBoolean(modelArg('closeSourceBranch'), 'closeSourceBranch'),
10621090
}
10631091
case 'bitbucket_get_pull_request_merge_task_status':
10641092
return {
@@ -1080,7 +1108,7 @@ export const BitbucketBlock: BlockConfig = {
10801108
return {
10811109
...common,
10821110
prId: optionalInteger(params.prId, 'prId'),
1083-
q: optionalString(params.query, 'query'),
1111+
q: q(),
10841112
sort: optionalString(params.sort, 'sort'),
10851113
...pagination,
10861114
}
@@ -1097,9 +1125,16 @@ export const BitbucketBlock: BlockConfig = {
10971125
case 'bitbucket_trigger_pipeline':
10981126
return {
10991127
...common,
1100-
refType: optionalString(params.targetRefType, 'targetRefType') ?? 'branch',
1101-
refName: optionalString(params.targetRef, 'targetRef'),
1102-
commitHash: optionalString(params.targetCommitHash, 'targetCommitHash'),
1128+
refType:
1129+
optionalString(params.targetRefType, 'targetRefType') ??
1130+
optionalString(modelArg('refType'), 'refType') ??
1131+
'branch',
1132+
refName:
1133+
optionalString(params.targetRef, 'targetRef') ??
1134+
optionalString(modelArg('refName'), 'refName'),
1135+
commitHash:
1136+
optionalString(params.targetCommitHash, 'targetCommitHash') ??
1137+
optionalString(modelArg('commitHash'), 'commitHash'),
11031138
}
11041139
case 'bitbucket_list_pipeline_steps':
11051140
return {

0 commit comments

Comments
 (0)