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
57 changes: 56 additions & 1 deletion apps/sim/blocks/blocks/affinity.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'

vi.mock('@/lib/internal/workflows/read-tool-enrichment', () => ({
readWorkflowInputFieldsForTool: vi.fn(),
readWorkflowMetadataForTool: vi.fn(),
}))

import { AffinityBlock } from '@/blocks/blocks/affinity'
import { ToolCallParamsError } from '@/providers/tool-params-error'
import { prepareToolExecution, transformBlockTool } from '@/providers/utils'
import { affinityCreateListFieldDropdownOptionTool } from '@/tools/affinity/create_list_field_dropdown_option'

/** 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) {
Expand All @@ -22,3 +31,49 @@ describe('AffinityBlock agent tool calls', () => {
).toMatchObject({ name: 'Deals', type: 'company', isPublic: true })
})
})

describe('AffinityBlock dropdown option rank and win rate on a tool call', () => {
const operation = 'create_list_field_dropdown_option'

async function prepare(stored: Record<string, string>, modelArgs: Record<string, unknown>) {
const providerTool = await transformBlockTool(
{ type: AffinityBlock.type, operation, params: { apiKey: 'key', ...stored } },
{
selectedOperation: operation,
getAllBlocks: () => [AffinityBlock],
getTool: () => affinityCreateListFieldDropdownOptionTool,
}
)
if (!providerTool) throw new Error('Affinity agent tool was not created')
return prepareToolExecution(providerTool, modelArgs, {}, undefined).executionParams
}

const pinnedStatusOption = {
listId: 'l1',
fieldId: 'f1',
optionType: 'status-dropdown',
optionText: 'Won',
optionColor: 'green',
optionStatusCategory: 'won',
}

it('fails the call instead of sending the model fields over the pinned option', async () => {
await expect(
prepare(pinnedStatusOption, { rank: 2, winRate: 150, type: 'ranked-dropdown', text: 'X' })
).rejects.toThrow(ToolCallParamsError)
})

it.each([
['Option Rank', { optionRank: ' ' }, { rank: 2.5 }],
['Win Rate', { optionWinRate: ' ' }, { rank: 1, winRate: 250 }],
])('validates the model value behind a blank %s', async (_label, stored, modelArgs) => {
await expect(prepare({ ...pinnedStatusOption, ...stored }, modelArgs)).rejects.toThrow(
ToolCallParamsError
)
})

it('sends a valid model rank behind a blank Option Rank', async () => {
const params = await prepare({ ...pinnedStatusOption, optionRank: ' ' }, { rank: 3 })
expect(params).toMatchObject({ type: 'status-dropdown', text: 'Won', rank: 3 })
})
})
343 changes: 171 additions & 172 deletions apps/sim/blocks/blocks/affinity.ts

Large diffs are not rendered by default.

29 changes: 28 additions & 1 deletion apps/sim/blocks/blocks/mailgun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*/
import { describe, expect, it } from 'vitest'
import { MailgunV2Block } from '@/blocks/blocks/mailgun'
import type { BlockToolParamsContext } from '@/blocks/types'
import { mailgunAddListMemberTool } from '@/tools/mailgun/add_list_member'
import { mailgunGetMailingListTool } from '@/tools/mailgun/get_mailing_list'
import type { ToolConfig } from '@/tools/types'
import { validateRequiredParametersAfterMerge } from '@/tools/utils'

function mapParams(
inputs: Record<string, unknown>,
context?: { operation: string }
context?: BlockToolParamsContext
): Record<string, unknown> {
const mapped = MailgunV2Block.tools.config?.params?.(inputs, context) ?? {}
return { ...inputs, ...mapped }
Expand Down Expand Up @@ -59,6 +61,31 @@ describe('Mailgun block add_list_member mapping', () => {
expect(formFields(params)).toMatchObject({ address: 'bob@example.com', name: 'Bob' })
})

it('adds the member even when the model names the list address as the member', () => {
const params = mapParams(
{ apiKey: 'key', listAddress: 'news@mg.example.com', address: 'news@mg.example.com' },
{ operation: 'add_list_member', pinnedParams: new Set(['apiKey']) }
)
expect(formFields(params).address).toBe('news@mg.example.com')
})

it('never adds the row-saved List Address to its own list as a member', () => {
const params = mapParams(
{ apiKey: 'key', address: 'news@mg.example.com' },
{ operation: 'add_list_member', pinnedParams: new Set(['apiKey', 'address']) }
)
expect(requestUrl(mailgunAddListMemberTool, params)).toBe(
'https://api.mailgun.net/v3/lists/news@mg.example.com/members'
)
expect(() =>
validateRequiredParametersAfterMerge(
'mailgun_add_list_member',
mailgunAddListMemberTool,
params
)
).toThrow('Address is required')
})

it.each([
['a stored string', 'false', 'no'],
['a model boolean', false, 'no'],
Expand Down
13 changes: 9 additions & 4 deletions apps/sim/blocks/blocks/mailgun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,17 @@ Return ONLY the JSON object - no explanations or markdown.`,
const { memberAddress, memberName, ...rest } = params

if (mapperOperation(params, context) === 'add_list_member') {
const modelMemberAddress =
params.address !== params.listAddress ? params.address : undefined
/**
* The block's List Address field is stored under `address`, the tool's member param.
* On the canvas, and on a tool call whose row saved that field, `address` is the list;
* otherwise it is the member the model named.
*/
const addressIsList =
!isToolCall(context) || Boolean(context?.pinnedParams?.has('address'))
return {
...rest,
listAddress: toolCallArg(context, params.listAddress) || params.address,
address: memberAddress || toolCallArg(context, modelMemberAddress),
listAddress: addressIsList ? params.address : params.listAddress,
address: memberAddress || (addressIsList ? undefined : params.address),
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
name: memberName || toolCallArg(context, params.name),
subscribed: isToolCall(context)
? parseOptionalBooleanInput(params.subscribed)
Expand Down
12 changes: 12 additions & 0 deletions apps/sim/blocks/blocks/perplexity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ describe('Perplexity tool calls', () => {
expect(result.search_domain_filter).toEqual(['nature.com', 'science.org'])
})
})

describe('Perplexity canvas', () => {
it('sends a Temperature of 0 on Chat', () => {
const result = mapParams({
operation: 'perplexity_chat',
apiKey: 'k',
content: 'q',
temperature: 0,
})
expect(result.temperature).toBe(0)
})
})
13 changes: 7 additions & 6 deletions apps/sim/blocks/blocks/perplexity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PerplexityIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
import { mapperOperation, toolCallArg } from '@/blocks/utils'
import { mapperOperation } from '@/blocks/utils'

export const PerplexityBlock: BlockConfig = {
type: 'perplexity',
Expand Down Expand Up @@ -238,11 +238,12 @@ Return ONLY the date string in MM/DD/YYYY format - no explanations, no quotes, n
content: params.content,
systemPrompt: params.systemPrompt,
max_tokens: params.max_tokens ? Number.parseInt(params.max_tokens) : undefined,
temperature: params.temperature
? Number.parseFloat(params.temperature)
: params.temperature === 0
? toolCallArg(context, 0)
: undefined,
temperature:
params.temperature === 0
? 0
: params.temperature
? Number.parseFloat(params.temperature)
: undefined,
}

return chatParams
Expand Down
61 changes: 58 additions & 3 deletions apps/sim/blocks/blocks/resend.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, it } from 'vitest'
import { ResendV2Block } from '@/blocks/blocks/resend'
import type { BlockToolParamsContext } from '@/blocks/types'
import { describe, expect, it, vi } from 'vitest'
import { ResendBlock, ResendV2Block } from '@/blocks/blocks/resend'
import type { BlockConfig, BlockToolParamsContext } from '@/blocks/types'
import { collectBlockFieldIssues } from '@/serializer/index'

/** Lint checks fields against the real tool params, which vitest.setup.ts mocks empty. */
vi.unmock('@/tools/metadata')

function mapParams(params: Record<string, unknown>, context?: BlockToolParamsContext) {
const mapper = ResendV2Block.tools.config?.params
Expand Down Expand Up @@ -40,3 +44,54 @@ describe('Resend list pagination limit', () => {
expect(mapParams({ operation: 'list_domains', limit: '' }).limit).toBeUndefined()
})
})

describe('Resend Create Broadcast recipient', () => {
function missingFields(config: BlockConfig, values: Record<string, string>) {
const params = {
operation: 'create_broadcast',
broadcastFrom: 'news@example.com',
broadcastSubject: 'Hi',
...values,
}
const subBlocks = Object.fromEntries(
Object.entries(params).map(([id, value]) => [id, { id, type: 'short-input' as const, value }])
)
const block = {
id: 'b1',
type: config.type,
name: 'Resend',
enabled: true,
position: { x: 0, y: 0 },
subBlocks,
outputs: {},
data: {},
}
return collectBlockFieldIssues(block, config, params, { mode: 'lint' }).missingRequiredFields
}

it.each([ResendBlock, ResendV2Block])(
'flags Audience ID only when no segment is given',
(config) => {
expect(missingFields(config, { segmentId: '', audienceId: '' })).toContain('Audience ID')
expect(missingFields(config, { segmentId: 'seg_1', audienceId: '' })).not.toContain(
'Audience ID'
)
expect(missingFields(config, { segmentId: '', audienceId: 'aud_1' })).not.toContain(
'Audience ID'
)
}
)

it.each([ResendBlock, ResendV2Block])(
'publishes Audience ID as required only for the audience operations when no values are known',
(config) => {
const audienceId = config.subBlocks.find((subBlock) => subBlock.id === 'audienceId')
const required = audienceId?.required
if (typeof required !== 'function') throw new Error('Audience ID requirement is not dynamic')
expect(required()).toEqual({
field: 'operation',
value: ['get_audience', 'delete_audience'],
})
}
)
})
14 changes: 11 additions & 3 deletions apps/sim/blocks/blocks/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,18 @@ Return ONLY the email body - no explanations, no extra text.`,
field: 'operation',
value: ['get_audience', 'delete_audience', 'create_broadcast'],
},
required: {
/**
* Create Broadcast needs an audience only when no segment is set. Without block values (the
* public catalog, Copilot validation) a segment may still be given, so only the audience
* operations require it.
*/
required: (values) => ({
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
field: 'operation',
value: ['get_audience', 'delete_audience'],
},
value:
values && !String(values.segmentId ?? '').trim()
? ['get_audience', 'delete_audience', 'create_broadcast']
: ['get_audience', 'delete_audience'],
}),
},

{
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/blocks/blocks/sailpoint.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest'
import { SailPointV2Block } from '@/blocks/blocks/sailpoint'
import type { BlockToolParamsContext } from '@/blocks/types'
import { sailpointSearchTool } from '@/tools/sailpoint/definitions'

function mapParams(params: Record<string, unknown>, context?: BlockToolParamsContext) {
const mapper = SailPointV2Block.tools.config?.params
Expand Down Expand Up @@ -63,6 +64,24 @@ describe('SailPoint search list fields', () => {
'displayName,-id'
)
})

it.each([
[
'a canvas JSON number',
canvasToolInput({ operation: 'sailpoint_search', searchAfter: '12345' }),
],
['a model number', toolCallInput({ searchAfter: 12345 }, 'sailpoint_search')],
])('sends a lone searchAfter given as %s as a one-entry string list', (_label, input) => {
const operationInput = sailpointSearchTool.operation?.input
if (!operationInput) throw new Error('SailPoint search has no operation input')
const request = operationInput({
...input,
tenant: 't',
accessToken: 'token',
query: { query: '*' },
})
expect(request).toMatchObject({ searchAfter: ['12345'] })
})
})

describe('SailPoint canvas selector gates', () => {
Expand Down
4 changes: 0 additions & 4 deletions apps/sim/lib/workflows/search-replace/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ const DISPLAY_ONLY_SUBBLOCK_TYPES = new Set<SubBlockType>([
'webhook-config',
])

const TEXT_VALUE_ONLY_SUBBLOCK_TYPES = new Set<SubBlockType>(['filter-builder', 'variables-input'])
const DISPLAY_LABEL_READONLY_REASON = 'Display labels cannot be replaced'

const TOOL_INPUT_TEXT_EXCLUDED_LEAF_KEYS = new Set([
Expand Down Expand Up @@ -227,9 +226,6 @@ function isSearchableLeafPath(
return false
}
}
if (mode === 'text' && subBlockType && TEXT_VALUE_ONLY_SUBBLOCK_TYPES.has(subBlockType)) {
return lastSegment === 'value'
}
if (
mode === 'text' &&
(subBlockType === 'input-format' ||
Expand Down
8 changes: 6 additions & 2 deletions apps/sim/lib/workflows/search-replace/json-value-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const SEARCHABLE_JSON_ARRAY_VALUE_FIELDS: Partial<Record<SubBlockType, Record<st
'variables-input': {
value: 'Value',
},
'filter-builder': {
value: 'Value',
},
}

const SEARCHABLE_JSON_OBJECT_VALUE_FIELDS: Partial<Record<SubBlockType, string>> = {
Expand Down Expand Up @@ -99,6 +102,7 @@ export function isSearchableJsonValueSubBlock(
| 'knowledge-tag-filters'
| 'document-tag-entry'
| 'variables-input'
| 'filter-builder'
| 'input-mapping'
| 'workflow-input-mapper'
| 'table' {
Expand All @@ -111,8 +115,8 @@ export function isSearchableJsonValueSubBlock(
}

/**
* Rule builders stay as their stored JSON text in a tool row: the replacer edits a tool param's
* raw text, and has no path into a builder's rule array the way it does for `table` cells.
* Rule builders stay as their stored JSON text in a tool row so a replacement writes the param
* back as text. A filter rule's `value` is still reached through the JSON leaf replacer above.
*/
const RAW_TEXT_TOOL_PARAM_SUBBLOCK_TYPES = new Set<SubBlockType>(['filter-builder', 'sort-builder'])

Expand Down
Loading
Loading