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
24 changes: 24 additions & 0 deletions apps/sim/blocks/blocks/affinity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from 'vitest'
import { AffinityBlock } from '@/blocks/blocks/affinity'

/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
function toolCall(args: Record<string, unknown>, operation: string) {
const mapParams = AffinityBlock.tools.config?.params
if (!mapParams) throw new Error('Affinity block has no params mapper')
return { ...args, ...mapParams(args, { operation }) }
}

describe('AffinityBlock agent tool calls', () => {
it('maps block-field keys and keeps model args instead of dropping them', () => {
const result = toolCall(
{ apiKey: 'key', noteEntityType: 'company', entityId: '42', limit: '10' },
'list_entity_notes'
)
expect(result).toMatchObject({ entityType: 'company', entityId: '42', limit: 10 })
expect(result.noteEntityType).toBeUndefined()

expect(
toolCall({ apiKey: 'key', name: 'Deals', type: 'company', isPublic: true }, 'create_list')
).toMatchObject({ name: 'Deals', type: 'company', isPublic: true })
})
})
43 changes: 34 additions & 9 deletions apps/sim/blocks/blocks/affinity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { AffinityIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import {
isToolCall,
mapperOperation,
parseOptionalBooleanInput,
parseOptionalNumberInput,
toolCallArg,
withSavedCredential,
} from '@/blocks/utils'

Expand Down Expand Up @@ -1337,9 +1340,13 @@ export const AffinityBlock: BlockConfig = {
* omitting a key leaves the previous operation's value on the wire — an
* advanced field is serialized on non-emptiness alone, even while the UI
* hides it. `undefined` is what actually drops one.
*
* On a tool call the model's args arrive under the tool's own param names,
* so a tool param the selected operation does not fill from a block field
* keeps the model's value instead of being dropped.
*/
params: (params) => {
const operation = String(params.operation ?? '')
params: (params, context) => {
const operation = mapperOperation(params, context)
const isIn = (group: readonly string[]) => group.includes(operation)

const isKeywordSearch = isIn(KEYWORD_SEARCH_OPERATIONS)
Expand Down Expand Up @@ -1380,7 +1387,7 @@ export const AffinityBlock: BlockConfig = {
else if (isKeywordSearch) ids = params.searchIds
else if (isFieldValueSelection) ids = params.valueFieldIds

return {
const toolParams: Record<string, unknown> = {
apiKey: params.apiKey,
entityType,
type,
Expand Down Expand Up @@ -1429,16 +1436,24 @@ export const AffinityBlock: BlockConfig = {
isPublic: isCreateList ? parseOptionalBooleanInput(params.isPublic) : undefined,
text: isDropdownWrite ? params.optionText : undefined,
rank: isDropdownWrite
? parseOptionalNumberInput(params.optionRank, 'Option Rank', { integer: true, min: 0 })
? parseOptionalNumberInput(
params.optionRank ?? toolCallArg(context, params.rank),
'Option Rank',
{ integer: true, min: 0 }
)
: undefined,
color: isDropdownWrite ? params.optionColor : undefined,
statusCategory: isDropdownWrite ? params.optionStatusCategory : undefined,
winRate: isDropdownWrite
? parseOptionalNumberInput(params.optionWinRate, 'Win Rate', {
integer: true,
min: 0,
max: 100,
})
? parseOptionalNumberInput(
params.optionWinRate ?? toolCallArg(context, params.winRate),
'Win Rate',
{
integer: true,
min: 0,
max: 100,
}
)
: undefined,
value: isIn(FIELD_VALUE_WRITE_OPERATIONS) ? params.fieldValue : undefined,
updates: isIn(FIELD_BATCH_WRITE_OPERATIONS) ? params.fieldUpdates : undefined,
Expand Down Expand Up @@ -1470,6 +1485,16 @@ export const AffinityBlock: BlockConfig = {
totalCount: isIn(TOTAL_COUNT_OPERATIONS)
? parseOptionalBooleanInput(params.totalCount)
: undefined,
}

if (isToolCall(context)) {
for (const [key, value] of Object.entries(toolParams)) {
if (value === undefined) toolParams[key] = params[key]
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
}
}

return {
...toolParams,
fieldEntityType: undefined,
noteEntityType: undefined,
mergeEntityType: undefined,
Expand Down
38 changes: 38 additions & 0 deletions apps/sim/blocks/blocks/agentmail.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, expect, it } from 'vitest'
import { AgentMailBlock } from '@/blocks/blocks/agentmail'

/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
function toolCall(args: Record<string, unknown>, operation: string) {
const mapParams = AgentMailBlock.tools.config?.params
if (!mapParams) throw new Error('AgentMail block has no params mapper')
return { ...args, ...mapParams(args, { operation }) }
}

describe('AgentMailBlock agent tool calls', () => {
it('maps the block-field reply message key and keeps the model recipients and flags', () => {
expect(
toolCall(
{ inboxId: 'inbox', replyMessageId: 'msg-1', to: 'a@example.com', replyAll: true },
'reply_message'
)
).toMatchObject({ messageId: 'msg-1', to: 'a@example.com', replyAll: true })
})

it('keeps a boolean permanent flag from the model', () => {
expect(
toolCall({ inboxId: 'inbox', threadId: 't-1', permanent: true }, 'delete_thread')
).toMatchObject({ permanent: true })
})

it('treats a stored "false" permanent dropdown as a trash move, not a permanent delete', () => {
expect(
toolCall({ inboxId: 'inbox', threadId: 't-1', permanent: 'false' }, 'delete_thread')
).toMatchObject({ permanent: false })
})

it('treats a stored "false" reply-all dropdown as a reply to the sender only', () => {
expect(
toolCall({ inboxId: 'inbox', replyMessageId: 'msg-1', replyAll: 'false' }, 'reply_message')
).toMatchObject({ replyAll: false })
})
})
12 changes: 6 additions & 6 deletions apps/sim/blocks/blocks/agentmail.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AgentMailIcon } 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'

export const AgentMailBlock: BlockConfig = {
type: 'agentmail',
Expand Down Expand Up @@ -567,9 +567,9 @@ export const AgentMailBlock: BlockConfig = {
],
config: {
tool: (params) => `agentmail_${params.operation || 'send_message'}`,
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const {
operation,
inboxIdParam,
permanent,
replyMessageId,
Expand All @@ -590,11 +590,11 @@ export const AgentMailBlock: BlockConfig = {
}

if (operation === 'delete_thread' && permanent !== undefined) {
rest.permanent = permanent === 'true'
rest.permanent = permanent === true || permanent === 'true'
}

if (operation === 'reply_message' && replyAll !== undefined) {
rest.replyAll = replyAll === 'true'
rest.replyAll = replyAll === true || replyAll === 'true'
}

if (operation === 'reply_message' && replyMessageId) {
Expand All @@ -604,7 +604,7 @@ export const AgentMailBlock: BlockConfig = {
if (operation === 'reply_message' && replyTo) {
rest.to = replyTo
} else if (operation === 'reply_message') {
rest.to = undefined
rest.to = toolCallArg(context, rest.to)
}

if (operation === 'forward_message' && forwardMessageId) {
Expand Down
17 changes: 17 additions & 0 deletions apps/sim/blocks/blocks/agentphone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { AgentPhoneBlock } from '@/blocks/blocks/agentphone'

/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
function toolCall(args: Record<string, unknown>, operation: string) {
const mapParams = AgentPhoneBlock.tools.config?.params
if (!mapParams) throw new Error('AgentPhone block has no params mapper')
return { ...args, ...mapParams(args, { operation }) }
}

describe('AgentPhoneBlock agent tool calls', () => {
it('maps block-field filters and coerces limits for an operation passed only in context', () => {
expect(
toolCall({ apiKey: 'key', callsStatus: 'completed', limit: '25' }, 'list_calls')
).toMatchObject({ status: 'completed', limit: 25 })
})
})
8 changes: 4 additions & 4 deletions apps/sim/blocks/blocks/agentphone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { toError } from '@sim/utils/errors'
import { AgentPhoneIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, withSavedCredential } from '@/blocks/utils'

const CONVERSATION_OPS = [
'get_conversation',
Expand Down Expand Up @@ -588,9 +588,9 @@ export const AgentPhoneBlock: BlockConfig = {
],
config: {
tool: (params) => `agentphone_${params.operation || 'create_number'}`,
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const {
operation,
attachAgentId,
callAgentId,
toNumberCall,
Expand Down Expand Up @@ -633,7 +633,7 @@ export const AgentPhoneBlock: BlockConfig = {
if (messageBody !== undefined) rest.body = messageBody
}

if (['create_contact', 'update_contact'].includes(operation as string)) {
if (['create_contact', 'update_contact'].includes(operation)) {
if (contactPhoneNumber) rest.phoneNumber = contactPhoneNumber
if (contactName) rest.name = contactName
if (contactEmail) rest.email = contactEmail
Expand Down
29 changes: 29 additions & 0 deletions apps/sim/blocks/blocks/algolia.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest'
import { AlgoliaBlock } from '@/blocks/blocks/algolia'

/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
function toolCall(args: Record<string, unknown>, operation: string) {
const mapParams = AlgoliaBlock.tools.config?.params
if (!mapParams) throw new Error('Algolia block has no params mapper')
return { ...args, ...mapParams(args, { operation }) }
}

describe('AlgoliaBlock agent tool calls', () => {
it('maps the block-field requests key on a tool call', () => {
expect(
toolCall({ indexName: 'products', getRecordsRequests: '[{"objectID":"1"}]' }, 'get_records')
).toMatchObject({ requests: '[{"objectID":"1"}]' })
})

it('keeps the model filters, requests, and copy-or-move operation', () => {
expect(toolCall({ indexName: 'p', filters: 'brand:x' }, 'delete_by_filter')).toMatchObject({
filters: 'brand:x',
})
expect(
toolCall({ indexName: 'p', requests: [{ objectID: '1' }] }, 'get_records')
).toMatchObject({ requests: [{ objectID: '1' }] })
expect(
toolCall({ indexName: 'p', destination: 'q', operation: 'move' }, 'copy_move_index')
).toMatchObject({ operation: 'move' })
})
})
19 changes: 11 additions & 8 deletions apps/sim/blocks/blocks/algolia.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AlgoliaIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import type { BlockConfig, BlockMeta, BlockToolParamsContext } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { isToolCall, mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'

export const AlgoliaBlock: BlockConfig = {
type: 'algolia',
Expand Down Expand Up @@ -593,11 +593,11 @@ Return ONLY the JSON array.`,
],
config: {
tool: (params: Record<string, unknown>) => `algolia_${params.operation}`,
params: (params: Record<string, unknown>) => {
const { operation, ...rest } = params
params: (params: Record<string, unknown>, context?: BlockToolParamsContext) => {
const operation = mapperOperation(params, context)
const result: Record<string, unknown> = {}

for (const [key, value] of Object.entries(rest)) {
for (const [key, value] of Object.entries(params)) {
if (value === undefined || value === null || value === '') continue
result[key] = value
}
Expand All @@ -618,15 +618,18 @@ Return ONLY the JSON array.`,
result.getRankingInfo = toBool(result.getRankingInfo, false)
}
if (operation === 'copy_move_index') {
result.operation = result.copyMoveOperation
// A tool call carries the tool's own copy-or-move `operation` as a model arg.
if (!isToolCall(context) || result.copyMoveOperation !== undefined) {
result.operation = result.copyMoveOperation
}
result.copyMoveOperation = undefined
}
if (operation === 'delete_by_filter') {
result.filters = result.deleteFilters
result.filters = result.deleteFilters ?? toolCallArg(context, result.filters)
result.deleteFilters = undefined
}
if (operation === 'get_records') {
result.requests = result.getRecordsRequests
result.requests = result.getRecordsRequests ?? toolCallArg(context, result.requests)
result.getRecordsRequests = undefined
}

Expand Down
20 changes: 20 additions & 0 deletions apps/sim/blocks/blocks/amplitude.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest'
import { AmplitudeBlock } from '@/blocks/blocks/amplitude'

/** Runs the mapper the way an Agent tool call does: its result is spread over the merged args. */
function toolCall(args: Record<string, unknown>, operation: string) {
const mapParams = AmplitudeBlock.tools.config?.params
if (!mapParams) throw new Error('Amplitude block has no params mapper')
return { ...args, ...mapParams(args, { operation }) }
}

describe('AmplitudeBlock agent tool calls', () => {
it('maps the block-field event key for an operation passed only in context', () => {
expect(
toolCall(
{ apiKey: 'k', secretKey: 's', segmentationEventType: 'signup', start: '20260101' },
'event_segmentation'
)
).toMatchObject({ eventType: 'signup', start: '20260101' })
})
})
6 changes: 3 additions & 3 deletions apps/sim/blocks/blocks/amplitude.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AmplitudeIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, withSavedCredential } from '@/blocks/utils'

/*
* Amplitude identifies a person by user id or device id — either one alone is
Expand Down Expand Up @@ -1012,10 +1012,10 @@ export const AmplitudeBlock: BlockConfig = {
],
config: {
tool: (params) => `amplitude_${params.operation}`,
params: (params) => {
params: (params, context) => {
const result: Record<string, unknown> = {}

switch (params.operation) {
switch (mapperOperation(params, context)) {
case 'send_event':
if (params.sendEventUserProperties)
result.userProperties = params.sendEventUserProperties
Expand Down
Loading
Loading