Skip to content

Commit 41a5f38

Browse files
authored
fix(blocks): read the mapper operation from the tool-call context and ratchet raw reads (#10070)
* fix(blocks): read the mapper operation from the tool-call context and ratchet raw reads A block's tools.config.params mapper gets the operation only as context.operation on a tool call (Agent tool rows, Pi, Human v2), so branches on params.operation take the no-operation path there. Add mapperOperation(params, context), move the mappers that already fell back to context onto it, and add check:mapper-operation, a per-file ratchet over the remaining raw reads (505 in 173 files) so they can only shrink. * fix(blocks): return an empty string from mapperOperation when no operation is set * fix(audits): track helper argument positions, destructured rests, helper results, and shadowed names in check:mapper-operation; drop _operation strips * fix(audits): refuse to raise the mapper-operation baseline and alias only helper results that carry their input * fix(audits): follow local copies when deciding whether a helper returns its params
1 parent 6d6c14c commit 41a5f38

23 files changed

Lines changed: 790 additions & 47 deletions

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AirtableIcon } from '@/components/icons'
33
import { getScopesForService } from '@/lib/oauth/utils'
44
import type { BlockConfig, BlockMeta } from '@/blocks/types'
55
import { AuthMode, IntegrationType } from '@/blocks/types'
6-
import { toolCallArg } from '@/blocks/utils'
6+
import { mapperOperation, toolCallArg } from '@/blocks/utils'
77
import { getTrigger } from '@/triggers'
88

99
/** Canonical account pair — an advanced-mode card only fills `manualCredential`. */
@@ -429,7 +429,7 @@ Return ONLY the valid JSON array of record ID strings - no explanations, no mark
429429
...rest
430430
} = params
431431
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
432-
const operation = params.operation ?? context?.operation
432+
const operation = mapperOperation(params, context)
433433
let parsedRecords: unknown
434434
let parsedFields: unknown
435435
let parsedFieldsToMergeOn: unknown

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AsanaIcon } from '@/components/icons'
22
import { getScopesForService } from '@/lib/oauth/utils'
33
import type { BlockConfig, BlockMeta } from '@/blocks/types'
44
import { AuthMode, IntegrationType } from '@/blocks/types'
5-
import { toolCallArg } from '@/blocks/utils'
5+
import { mapperOperation, toolCallArg } from '@/blocks/utils'
66

77
const WORKSPACE_FIELD = ['workspaceSelector', 'workspace'] as const
88
const GET_TASKS_WORKSPACE_FIELD = ['getTasksWorkspaceSelector', 'getTasks_workspace'] as const
@@ -521,7 +521,7 @@ Return ONLY the date string in YYYY-MM-DD format - no explanations, no quotes, n
521521
params: (params, context) => {
522522
const { oauthCredential } = params
523523
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
524-
const operation = params.operation ?? context?.operation
524+
const operation = mapperOperation(params, context)
525525

526526
const splitGids = (value: unknown): string[] | undefined => {
527527
if (Array.isArray(value)) return value.map(String)

‎apps/sim/blocks/blocks/attio.ts‎

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

67
/*
@@ -1613,7 +1614,7 @@ Record reference: {"allowed_objects": ["people", "companies"]}`,
16131614
const cleanParams: Record<string, unknown> = {
16141615
oauthCredential: params.oauthCredential,
16151616
}
1616-
const op = params.operation ?? context?.operation
1617+
const op = mapperOperation(params, context)
16171618

16181619
// Record params — each field is only sent for the operations whose subBlock condition
16191620
// actually exposes it, so a stale value left over from switching operations never leaks

‎apps/sim/blocks/blocks/box.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BoxCompanyIcon } from '@/components/icons'
33
import { getScopesForService } from '@/lib/oauth/utils'
44
import type { BlockConfig, BlockMeta } from '@/blocks/types'
55
import { AuthMode, IntegrationType } from '@/blocks/types'
6-
import { normalizeFileInput, toolCallArg } from '@/blocks/utils'
6+
import { mapperOperation, normalizeFileInput, toolCallArg } from '@/blocks/utils'
77

88
/** Canonical pair for the upload payload: file picker in basic mode, file reference in advanced. */
99
const UPLOAD_FILE_FIELD = ['uploadFile', 'fileRef'] as const
@@ -534,8 +534,8 @@ export const BoxBlock = {
534534
if (normalizedFile) {
535535
params.file = normalizedFile
536536
}
537-
const { credential, operation: storedOperation, ...rest } = params
538-
const operation = storedOperation ?? context?.operation
537+
const { credential, ...rest } = params
538+
const operation = mapperOperation(params, context)
539539

540540
const baseParams: Record<string, unknown> = {
541541
accessToken: credential,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { BlockConfig, BlockMeta } from '@/blocks/types'
44
import { AuthMode, IntegrationType } from '@/blocks/types'
55
import {
66
isToolCall,
7+
mapperOperation,
78
normalizeFileInput,
89
parseOptionalBooleanInput,
910
toolCallArg,
@@ -1479,7 +1480,7 @@ Return ONLY the value (plain string, number, or JSON) - no explanations, no extr
14791480
params: (params, context) => {
14801481
const { oauthCredential } = params
14811482
/** Agent tool calls carry the stored operation only on `context`, not in `params`. */
1482-
const operation = params.operation ?? context?.operation
1483+
const operation = mapperOperation(params, context)
14831484

14841485
const baseParams = {
14851486
accessToken: oauthCredential?.accessToken,

‎apps/sim/blocks/blocks/dropbox.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DropboxIcon } from '@/components/icons'
33
import { getScopesForService } from '@/lib/oauth/utils'
44
import type { BlockConfig, BlockMeta } from '@/blocks/types'
55
import { AuthMode, IntegrationType } from '@/blocks/types'
6-
import { normalizeFileInput, toolCallArg } from '@/blocks/utils'
6+
import { mapperOperation, normalizeFileInput, toolCallArg } from '@/blocks/utils'
77

88
/*
99
* Canonical basic/advanced pair for the upload source, shared by the card
@@ -483,7 +483,7 @@ Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
483483
},
484484
params: (params, context) => {
485485
const result: Record<string, unknown> = {}
486-
const operation = params.operation ?? context?.operation
486+
const operation = mapperOperation(params, context)
487487
// `cursor` is List Shared Links' field; List Folder and Search page with their own
488488
if (operation === 'dropbox_list_folder') {
489489
result.cursor = params.listFolderCursor || toolCallArg(context, params.cursor)

‎apps/sim/blocks/blocks/gauge.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GaugeIcon } from '@/components/icons'
22
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
3+
import { mapperOperation } from '@/blocks/utils'
34

45
export const GaugeBlock: BlockConfig = {
56
type: 'gauge',
@@ -972,7 +973,7 @@ export const GaugeBlock: BlockConfig = {
972973
config: {
973974
tool: (params) => params.operation,
974975
params: (params, context) => {
975-
const operation = context?.operation ?? params.operation
976+
const operation = mapperOperation(params, context)
976977
const patch = ['gauge_bulk_update_prompts', 'gauge_update_prompt'].includes(operation)
977978
return {
978979
...params,

‎apps/sim/blocks/blocks/higgsfield.ts‎

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

55
const GENERATE_OPERATIONS = ['higgsfield_generate', 'higgsfield_generate_soul_image']
66
const REQUEST_OPERATIONS = [
@@ -315,7 +315,7 @@ export const HiggsfieldBlock: BlockConfig = {
315315
config: {
316316
tool: (params) => params.operation,
317317
params: (params, context) => {
318-
const operation = context?.operation ?? params.operation
318+
const operation = mapperOperation(params, context)
319319
const isSoul = operation === SOUL
320320
const isGenerate = GENERATE_OPERATIONS.includes(operation)
321321
const isList = operation === 'higgsfield_list_characters'

‎apps/sim/blocks/blocks/hubspot.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { HubspotIcon } from '@/components/icons'
22
import { getScopesForService } from '@/lib/oauth/utils'
33
import type { BlockConfig, BlockMeta } from '@/blocks/types'
44
import { AuthMode, IntegrationType } from '@/blocks/types'
5-
import { toolCallArg } from '@/blocks/utils'
5+
import { mapperOperation, toolCallArg } from '@/blocks/utils'
66
import { getTrigger } from '@/triggers'
77

88
export const HubSpotBlock: BlockConfig = {
@@ -1635,7 +1635,6 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
16351635
params: (params, context) => {
16361636
const {
16371637
oauthCredential,
1638-
operation: storedOperation,
16391638
propertiesToSet,
16401639
properties,
16411640
searchProperties,
@@ -1647,7 +1646,7 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
16471646
archived,
16481647
...rest
16491648
} = params
1650-
const operation = storedOperation ?? context?.operation
1649+
const operation = mapperOperation(params, context)
16511650

16521651
const cleanParams: Record<string, any> = {
16531652
oauthCredential,

‎apps/sim/blocks/blocks/intercom.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { toBooleanFromInput } from '@sim/utils/coerce'
22
import { IntercomIcon } from '@/components/icons'
33
import type { BlockConfig, BlockMeta } from '@/blocks/types'
44
import { AuthMode, IntegrationType } from '@/blocks/types'
5-
import { createVersionedToolSelector, toolCallArg, withSavedCredential } from '@/blocks/utils'
5+
import {
6+
createVersionedToolSelector,
7+
mapperOperation,
8+
toolCallArg,
9+
withSavedCredential,
10+
} from '@/blocks/utils'
611
import { getTrigger } from '@/triggers'
712

813
/**
@@ -38,7 +43,6 @@ type IntercomParamsMapper = NonNullable<NonNullable<BlockConfig['tools']['config
3843
/** Maps Intercom block fields to tool params; shared by every Intercom block version. */
3944
const mapIntercomParams: IntercomParamsMapper = (params, context) => {
4045
const {
41-
operation: storedOperation,
4246
message_type_msg,
4347
company_name,
4448
contact_company_id,
@@ -68,7 +72,7 @@ const mapIntercomParams: IntercomParamsMapper = (params, context) => {
6872
event_created_at,
6973
...rest
7074
} = params
71-
const operation = storedOperation ?? context?.operation
75+
const operation = mapperOperation(params, context)
7276
const cleanParams: Record<string, any> = {}
7377

7478
if (operation === 'create_message' && message_type_msg) {

0 commit comments

Comments
 (0)