From 0510aed97c1cca47834c5954f95888a483f28222 Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 16 Nov 2026 13:40:28 -0800 Subject: [PATCH 1/2] fix(integrations): address release review findings on the sweep --- apps/sim/blocks/blocks/affinity.test.ts | 57 ++- apps/sim/blocks/blocks/affinity.ts | 343 +++++++++--------- apps/sim/blocks/blocks/mailgun.test.ts | 29 +- apps/sim/blocks/blocks/mailgun.ts | 13 +- apps/sim/blocks/blocks/perplexity.test.ts | 12 + apps/sim/blocks/blocks/perplexity.ts | 13 +- apps/sim/blocks/blocks/resend.test.ts | 48 ++- apps/sim/blocks/blocks/resend.ts | 8 +- apps/sim/blocks/blocks/sailpoint.test.ts | 19 + .../lib/workflows/search-replace/indexer.ts | 4 - .../search-replace/json-value-fields.ts | 8 +- .../search-replace/replacements.test.ts | 63 ++++ apps/sim/tools/sailpoint/common.ts | 25 +- 13 files changed, 436 insertions(+), 206 deletions(-) diff --git a/apps/sim/blocks/blocks/affinity.test.ts b/apps/sim/blocks/blocks/affinity.test.ts index 51992e239ad..19b372a3933 100644 --- a/apps/sim/blocks/blocks/affinity.test.ts +++ b/apps/sim/blocks/blocks/affinity.test.ts @@ -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, operation: string) { @@ -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, modelArgs: Record) { + 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 }) + }) +}) diff --git a/apps/sim/blocks/blocks/affinity.ts b/apps/sim/blocks/blocks/affinity.ts index 8c6a160be84..dadff8f1d3c 100644 --- a/apps/sim/blocks/blocks/affinity.ts +++ b/apps/sim/blocks/blocks/affinity.ts @@ -2,6 +2,7 @@ import { AffinityIcon } from '@/components/icons' import type { BlockConfig, BlockMeta } from '@/blocks/types' import { AuthMode, IntegrationType } from '@/blocks/types' import { + failToolCallOnError, isToolCall, mapperOperation, parseOptionalBooleanInput, @@ -1345,193 +1346,191 @@ export const AffinityBlock: BlockConfig = { * 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, context) => { - const operation = mapperOperation(params, context) - const isIn = (group: readonly string[]) => group.includes(operation) + params: (params, context) => + failToolCallOnError(context, () => { + const operation = mapperOperation(params, context) + const isIn = (group: readonly string[]) => group.includes(operation) - const isKeywordSearch = isIn(KEYWORD_SEARCH_OPERATIONS) - const isDropdownWrite = isIn(DROPDOWN_OPTION_WRITE_OPERATIONS) - const isEntitySearch = isIn(ENTITY_SEARCH_OPERATIONS) - const isFieldValueSelection = isIn(FIELD_VALUE_SELECTION_OPERATIONS) - const isNoteWrite = isIn(NOTE_WRITE_OPERATIONS) - const isCreateNote = operation === 'create_note' - const isCreateList = operation === 'create_list' - const isCreateReminder = operation === 'create_reminder' + const isKeywordSearch = isIn(KEYWORD_SEARCH_OPERATIONS) + const isDropdownWrite = isIn(DROPDOWN_OPTION_WRITE_OPERATIONS) + const isEntitySearch = isIn(ENTITY_SEARCH_OPERATIONS) + const isFieldValueSelection = isIn(FIELD_VALUE_SELECTION_OPERATIONS) + const isNoteWrite = isIn(NOTE_WRITE_OPERATIONS) + const isCreateNote = operation === 'create_note' + const isCreateList = operation === 'create_list' + const isCreateReminder = operation === 'create_reminder' - let entityType: unknown - if (isIn(FIELD_ENTITY_OPERATIONS)) entityType = params.fieldEntityType - else if (operation === 'list_entity_notes') entityType = params.noteEntityType - else if (isIn(MERGE_OPERATIONS)) entityType = params.mergeEntityType - else if (isCreateReminder) entityType = params.reminderEntityType + let entityType: unknown + if (isIn(FIELD_ENTITY_OPERATIONS)) entityType = params.fieldEntityType + else if (operation === 'list_entity_notes') entityType = params.noteEntityType + else if (isIn(MERGE_OPERATIONS)) entityType = params.mergeEntityType + else if (isCreateReminder) entityType = params.reminderEntityType - let type: unknown - if (isCreateList) type = params.listType - else if (operation === 'create_list_field_dropdown_option') type = params.optionType - else if (isCreateNote) type = params.noteType - else if (isCreateReminder) type = params.reminderType + let type: unknown + if (isCreateList) type = params.listType + else if (operation === 'create_list_field_dropdown_option') type = params.optionType + else if (isCreateNote) type = params.noteType + else if (isCreateReminder) type = params.reminderType - let filter: unknown - if (isIn(CONNECTION_OPERATIONS)) filter = params.connectionFilter - else if (isIn(FILTER_OPERATIONS)) filter = params.filter + let filter: unknown + if (isIn(CONNECTION_OPERATIONS)) filter = params.connectionFilter + else if (isIn(FILTER_OPERATIONS)) filter = params.filter - let orderBy: unknown - if (operation === 'list_entity_relationships') orderBy = params.relationshipOrderBy - else if (operation === 'list_field_value_changes') orderBy = params.changeOrderBy + let orderBy: unknown + if (operation === 'list_entity_relationships') orderBy = params.relationshipOrderBy + else if (operation === 'list_field_value_changes') orderBy = params.changeOrderBy - let includes: unknown - if (isIn(NOTE_INCLUDES_OPERATIONS)) includes = params.noteIncludes - else if (isIn(FIELD_INCLUDES_OPERATIONS)) includes = params.fieldIncludes + let includes: unknown + if (isIn(NOTE_INCLUDES_OPERATIONS)) includes = params.noteIncludes + else if (isIn(FIELD_INCLUDES_OPERATIONS)) includes = params.fieldIncludes - let ids: unknown - if (isIn(ID_FILTER_OPERATIONS)) ids = params.entityIds - else if (isKeywordSearch) ids = params.searchIds - else if (isFieldValueSelection) ids = params.valueFieldIds + let ids: unknown + if (isIn(ID_FILTER_OPERATIONS)) ids = params.entityIds + else if (isKeywordSearch) ids = params.searchIds + else if (isFieldValueSelection) ids = params.valueFieldIds - const toolParams: Record = { - apiKey: params.apiKey, - entityType, - type, - filter, - orderBy, - includes, - ids, - entityId: isIn(ENTITY_ID_OPERATIONS) ? params.entityId : undefined, - companyId: - operation === 'get_company' - ? params.companyId - : isKeywordSearch - ? params.scopeCompanyId + /** A blank block field falls through to the model's value, which is validated too. */ + const parseOptionRank = (value: unknown) => + parseOptionalNumberInput(value, 'Option Rank', { integer: true, min: 0 }) + const parseWinRate = (value: unknown) => + parseOptionalNumberInput(value, 'Win Rate', { integer: true, min: 0, max: 100 }) + + const toolParams: Record = { + apiKey: params.apiKey, + entityType, + type, + filter, + orderBy, + includes, + ids, + entityId: isIn(ENTITY_ID_OPERATIONS) ? params.entityId : undefined, + companyId: + operation === 'get_company' + ? params.companyId + : isKeywordSearch + ? params.scopeCompanyId + : undefined, + personId: operation === 'get_person' ? params.personId : undefined, + opportunityId: operation === 'get_opportunity' ? params.opportunityId : undefined, + listId: isIn(LIST_ID_OPERATIONS) ? params.listId : undefined, + listEntryId: isIn(LIST_ENTRY_ID_OPERATIONS) ? params.listEntryId : undefined, + viewId: + operation === 'get_saved_view' || operation === 'list_saved_view_entries' + ? params.viewId + : undefined, + fieldId: isIn(FIELD_ID_OPERATIONS) ? params.fieldId : undefined, + dropdownOptionId: isIn(DROPDOWN_OPTION_ID_OPERATIONS) + ? params.dropdownOptionId + : undefined, + noteId: isIn(NOTE_ID_OPERATIONS) ? params.noteId : undefined, + transcriptId: + operation === 'get_transcript' || operation === 'list_transcript_fragments' + ? params.transcriptId : undefined, - personId: operation === 'get_person' ? params.personId : undefined, - opportunityId: operation === 'get_opportunity' ? params.opportunityId : undefined, - listId: isIn(LIST_ID_OPERATIONS) ? params.listId : undefined, - listEntryId: isIn(LIST_ENTRY_ID_OPERATIONS) ? params.listEntryId : undefined, - viewId: - operation === 'get_saved_view' || operation === 'list_saved_view_entries' - ? params.viewId + userId: operation === 'get_user' ? params.userId : undefined, + mergeId: operation === 'get_merge' ? params.mergeId : undefined, + taskId: operation === 'get_merge_task' ? params.taskId : undefined, + types: isFieldValueSelection ? params.valueFieldTypes : undefined, + fieldIds: isIn(FIELD_SELECTION_OPERATIONS) ? params.fieldIds : undefined, + fieldTypes: isIn(FIELD_SELECTION_OPERATIONS) ? params.fieldTypes : undefined, + filters: isEntitySearch ? params.searchFilters : undefined, + sorts: isEntitySearch ? params.searchSorts : undefined, + searchTerm: isEntitySearch ? params.searchTerm : undefined, + searchFieldIds: isEntitySearch ? params.searchTermFieldIds : undefined, + prompt: isIn(PROMPT_OPERATIONS) ? params.prompt : undefined, + listIds: operation === 'semantic_search' ? params.listIds : undefined, + term: + operation === 'list_lists' || operation === 'list_users' ? params.term : undefined, + name: isCreateList ? params.listName : undefined, + isPublic: isCreateList ? parseOptionalBooleanInput(params.isPublic) : undefined, + text: isDropdownWrite ? params.optionText : undefined, + rank: isDropdownWrite + ? (parseOptionRank(params.optionRank) ?? + parseOptionRank(toolCallArg(context, params.rank))) : undefined, - fieldId: isIn(FIELD_ID_OPERATIONS) ? params.fieldId : undefined, - dropdownOptionId: isIn(DROPDOWN_OPTION_ID_OPERATIONS) - ? params.dropdownOptionId - : undefined, - noteId: isIn(NOTE_ID_OPERATIONS) ? params.noteId : undefined, - transcriptId: - operation === 'get_transcript' || operation === 'list_transcript_fragments' - ? params.transcriptId + color: isDropdownWrite ? params.optionColor : undefined, + statusCategory: isDropdownWrite ? params.optionStatusCategory : undefined, + winRate: isDropdownWrite + ? (parseWinRate(params.optionWinRate) ?? + parseWinRate(toolCallArg(context, params.winRate))) : undefined, - userId: operation === 'get_user' ? params.userId : undefined, - mergeId: operation === 'get_merge' ? params.mergeId : undefined, - taskId: operation === 'get_merge_task' ? params.taskId : undefined, - types: isFieldValueSelection ? params.valueFieldTypes : undefined, - fieldIds: isIn(FIELD_SELECTION_OPERATIONS) ? params.fieldIds : undefined, - fieldTypes: isIn(FIELD_SELECTION_OPERATIONS) ? params.fieldTypes : undefined, - filters: isEntitySearch ? params.searchFilters : undefined, - sorts: isEntitySearch ? params.searchSorts : undefined, - searchTerm: isEntitySearch ? params.searchTerm : undefined, - searchFieldIds: isEntitySearch ? params.searchTermFieldIds : undefined, - prompt: isIn(PROMPT_OPERATIONS) ? params.prompt : undefined, - listIds: operation === 'semantic_search' ? params.listIds : undefined, - term: operation === 'list_lists' || operation === 'list_users' ? params.term : undefined, - name: isCreateList ? params.listName : undefined, - isPublic: isCreateList ? parseOptionalBooleanInput(params.isPublic) : undefined, - text: isDropdownWrite ? params.optionText : undefined, - rank: isDropdownWrite - ? 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 ?? toolCallArg(context, params.winRate), - 'Win Rate', - { + value: isIn(FIELD_VALUE_WRITE_OPERATIONS) ? params.fieldValue : undefined, + updates: isIn(FIELD_BATCH_WRITE_OPERATIONS) ? params.fieldUpdates : undefined, + html: isNoteWrite ? params.noteHtml : undefined, + companyIds: isNoteWrite ? params.noteCompanyIds : undefined, + personIds: isNoteWrite ? params.notePersonIds : undefined, + opportunityIds: isNoteWrite ? params.noteOpportunityIds : undefined, + interactionId: isCreateNote ? params.interactionId : undefined, + interactionType: isCreateNote ? params.interactionType : undefined, + parentId: isCreateNote ? params.parentId : undefined, + creatorId: isCreateNote ? params.creatorId : undefined, + createdAt: isCreateNote ? params.noteCreatedAt : undefined, + primaryId: operation === 'create_merge' ? params.primaryId : undefined, + duplicateId: operation === 'create_merge' ? params.duplicateId : undefined, + dueDate: isCreateReminder ? params.dueDate : undefined, + content: isCreateReminder ? params.reminderContent : undefined, + ownerId: isCreateReminder ? params.ownerId : undefined, + resetTrigger: isCreateReminder ? params.resetTrigger : undefined, + periodDays: isCreateReminder + ? parseOptionalNumberInput(params.periodDays, 'Period In Days', { 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, - html: isNoteWrite ? params.noteHtml : undefined, - companyIds: isNoteWrite ? params.noteCompanyIds : undefined, - personIds: isNoteWrite ? params.notePersonIds : undefined, - opportunityIds: isNoteWrite ? params.noteOpportunityIds : undefined, - interactionId: isCreateNote ? params.interactionId : undefined, - interactionType: isCreateNote ? params.interactionType : undefined, - parentId: isCreateNote ? params.parentId : undefined, - creatorId: isCreateNote ? params.creatorId : undefined, - createdAt: isCreateNote ? params.noteCreatedAt : undefined, - primaryId: operation === 'create_merge' ? params.primaryId : undefined, - duplicateId: operation === 'create_merge' ? params.duplicateId : undefined, - dueDate: isCreateReminder ? params.dueDate : undefined, - content: isCreateReminder ? params.reminderContent : undefined, - ownerId: isCreateReminder ? params.ownerId : undefined, - resetTrigger: isCreateReminder ? params.resetTrigger : undefined, - periodDays: isCreateReminder - ? parseOptionalNumberInput(params.periodDays, 'Period In Days', { - integer: true, - min: 1, - }) - : undefined, - cursor: isIn(CURSOR_OPERATIONS) ? params.cursor : undefined, - limit: isIn(LIMIT_OPERATIONS) - ? parseOptionalNumberInput(params.limit, 'Limit', { integer: true, min: 1 }) - : undefined, - totalCount: isIn(TOTAL_COUNT_OPERATIONS) - ? parseOptionalBooleanInput(params.totalCount) - : undefined, - } + min: 1, + }) + : undefined, + cursor: isIn(CURSOR_OPERATIONS) ? params.cursor : undefined, + limit: isIn(LIMIT_OPERATIONS) + ? parseOptionalNumberInput(params.limit, 'Limit', { integer: true, min: 1 }) + : undefined, + 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] + if (isToolCall(context)) { + for (const [key, value] of Object.entries(toolParams)) { + if (value === undefined) toolParams[key] = params[key] + } } - } - return { - ...toolParams, - fieldEntityType: undefined, - noteEntityType: undefined, - mergeEntityType: undefined, - reminderEntityType: undefined, - listName: undefined, - listType: undefined, - optionType: undefined, - optionText: undefined, - optionRank: undefined, - optionColor: undefined, - optionStatusCategory: undefined, - optionWinRate: undefined, - fieldValue: undefined, - fieldUpdates: undefined, - searchFilters: undefined, - searchSorts: undefined, - searchTermFieldIds: undefined, - searchIds: undefined, - scopeCompanyId: undefined, - entityIds: undefined, - valueFieldIds: undefined, - valueFieldTypes: undefined, - noteType: undefined, - noteHtml: undefined, - noteCompanyIds: undefined, - notePersonIds: undefined, - noteOpportunityIds: undefined, - noteCreatedAt: undefined, - reminderType: undefined, - reminderContent: undefined, - connectionFilter: undefined, - relationshipOrderBy: undefined, - changeOrderBy: undefined, - noteIncludes: undefined, - fieldIncludes: undefined, - } - }, + return { + ...toolParams, + fieldEntityType: undefined, + noteEntityType: undefined, + mergeEntityType: undefined, + reminderEntityType: undefined, + listName: undefined, + listType: undefined, + optionType: undefined, + optionText: undefined, + optionRank: undefined, + optionColor: undefined, + optionStatusCategory: undefined, + optionWinRate: undefined, + fieldValue: undefined, + fieldUpdates: undefined, + searchFilters: undefined, + searchSorts: undefined, + searchTermFieldIds: undefined, + searchIds: undefined, + scopeCompanyId: undefined, + entityIds: undefined, + valueFieldIds: undefined, + valueFieldTypes: undefined, + noteType: undefined, + noteHtml: undefined, + noteCompanyIds: undefined, + notePersonIds: undefined, + noteOpportunityIds: undefined, + noteCreatedAt: undefined, + reminderType: undefined, + reminderContent: undefined, + connectionFilter: undefined, + relationshipOrderBy: undefined, + changeOrderBy: undefined, + noteIncludes: undefined, + fieldIncludes: undefined, + } + }), }, }, diff --git a/apps/sim/blocks/blocks/mailgun.test.ts b/apps/sim/blocks/blocks/mailgun.test.ts index 2e54d51c60c..93f46b9ed03 100644 --- a/apps/sim/blocks/blocks/mailgun.test.ts +++ b/apps/sim/blocks/blocks/mailgun.test.ts @@ -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, - context?: { operation: string } + context?: BlockToolParamsContext ): Record { const mapped = MailgunV2Block.tools.config?.params?.(inputs, context) ?? {} return { ...inputs, ...mapped } @@ -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'], diff --git a/apps/sim/blocks/blocks/mailgun.ts b/apps/sim/blocks/blocks/mailgun.ts index 6424151dab0..7c4f64ea5f7 100644 --- a/apps/sim/blocks/blocks/mailgun.ts +++ b/apps/sim/blocks/blocks/mailgun.ts @@ -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), name: memberName || toolCallArg(context, params.name), subscribed: isToolCall(context) ? parseOptionalBooleanInput(params.subscribed) diff --git a/apps/sim/blocks/blocks/perplexity.test.ts b/apps/sim/blocks/blocks/perplexity.test.ts index 67f984f3afa..5fb993d7ce3 100644 --- a/apps/sim/blocks/blocks/perplexity.test.ts +++ b/apps/sim/blocks/blocks/perplexity.test.ts @@ -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) + }) +}) diff --git a/apps/sim/blocks/blocks/perplexity.ts b/apps/sim/blocks/blocks/perplexity.ts index 5e35b3e2711..175bbcc45c3 100644 --- a/apps/sim/blocks/blocks/perplexity.ts +++ b/apps/sim/blocks/blocks/perplexity.ts @@ -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', @@ -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 diff --git a/apps/sim/blocks/blocks/resend.test.ts b/apps/sim/blocks/blocks/resend.test.ts index 50a66016116..0033441ffd9 100644 --- a/apps/sim/blocks/blocks/resend.test.ts +++ b/apps/sim/blocks/blocks/resend.test.ts @@ -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, context?: BlockToolParamsContext) { const mapper = ResendV2Block.tools.config?.params @@ -40,3 +44,41 @@ describe('Resend list pagination limit', () => { expect(mapParams({ operation: 'list_domains', limit: '' }).limit).toBeUndefined() }) }) + +describe('Resend Create Broadcast recipient', () => { + function missingFields(config: BlockConfig, values: Record) { + 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', 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' + ) + } + ) +}) diff --git a/apps/sim/blocks/blocks/resend.ts b/apps/sim/blocks/blocks/resend.ts index 2d27059693a..1a475147492 100644 --- a/apps/sim/blocks/blocks/resend.ts +++ b/apps/sim/blocks/blocks/resend.ts @@ -317,10 +317,12 @@ Return ONLY the email body - no explanations, no extra text.`, field: 'operation', value: ['get_audience', 'delete_audience', 'create_broadcast'], }, - required: { + required: (values) => ({ field: 'operation', - value: ['get_audience', 'delete_audience'], - }, + value: String(values?.segmentId ?? '').trim() + ? ['get_audience', 'delete_audience'] + : ['get_audience', 'delete_audience', 'create_broadcast'], + }), }, { diff --git a/apps/sim/blocks/blocks/sailpoint.test.ts b/apps/sim/blocks/blocks/sailpoint.test.ts index 924c465817d..2d5dc603c2a 100644 --- a/apps/sim/blocks/blocks/sailpoint.test.ts +++ b/apps/sim/blocks/blocks/sailpoint.test.ts @@ -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, context?: BlockToolParamsContext) { const mapper = SailPointV2Block.tools.config?.params @@ -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.searchAfter).toEqual(['12345']) + }) }) describe('SailPoint canvas selector gates', () => { diff --git a/apps/sim/lib/workflows/search-replace/indexer.ts b/apps/sim/lib/workflows/search-replace/indexer.ts index c2f6880c816..cccaa00e5b5 100644 --- a/apps/sim/lib/workflows/search-replace/indexer.ts +++ b/apps/sim/lib/workflows/search-replace/indexer.ts @@ -137,7 +137,6 @@ const DISPLAY_ONLY_SUBBLOCK_TYPES = new Set([ 'webhook-config', ]) -const TEXT_VALUE_ONLY_SUBBLOCK_TYPES = new Set(['filter-builder', 'variables-input']) const DISPLAY_LABEL_READONLY_REASON = 'Display labels cannot be replaced' const TOOL_INPUT_TEXT_EXCLUDED_LEAF_KEYS = new Set([ @@ -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' || diff --git a/apps/sim/lib/workflows/search-replace/json-value-fields.ts b/apps/sim/lib/workflows/search-replace/json-value-fields.ts index 05c36473544..6f478dfac9f 100644 --- a/apps/sim/lib/workflows/search-replace/json-value-fields.ts +++ b/apps/sim/lib/workflows/search-replace/json-value-fields.ts @@ -23,6 +23,9 @@ const SEARCHABLE_JSON_ARRAY_VALUE_FIELDS: Partial> = { @@ -99,6 +102,7 @@ export function isSearchableJsonValueSubBlock( | 'knowledge-tag-filters' | 'document-tag-entry' | 'variables-input' + | 'filter-builder' | 'input-mapping' | 'workflow-input-mapper' | 'table' { @@ -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(['filter-builder', 'sort-builder']) diff --git a/apps/sim/lib/workflows/search-replace/replacements.test.ts b/apps/sim/lib/workflows/search-replace/replacements.test.ts index bd8c99c7d62..6ffd1518a80 100644 --- a/apps/sim/lib/workflows/search-replace/replacements.test.ts +++ b/apps/sim/lib/workflows/search-replace/replacements.test.ts @@ -476,6 +476,69 @@ describe('buildWorkflowSearchReplacePlan', () => { ]) }) + it('edits only rule values, never rule keys, in a tool input filter builder', () => { + const workflow = createSearchReplaceWorkflowFixture() + const rule = { id: 'r1', logicalOperator: 'and', column: 'status', operator: 'eq' } + workflow.blocks['tool-input-1'] = { + id: 'tool-input-1', + type: 'custom', + name: 'Tool Input Block', + position: { x: 0, y: 0 }, + enabled: true, + outputs: {}, + subBlocks: { + tools: { + id: 'tools', + type: 'tool-input', + value: [ + { + type: 'table_v2', + toolId: 'table_query_rows_v2', + operation: 'query_rows', + title: 'Table', + params: { + tableId: 'tbl_1', + filterBuilder: JSON.stringify([{ ...rule, value: 'operator and status' }]), + }, + }, + ], + }, + }, + } + const findEditable = (query: string) => + indexWorkflowSearchMatches({ + workflow, + query, + mode: 'text', + blockConfigs: { + ...SEARCH_REPLACE_BLOCK_CONFIGS, + custom: { subBlocks: [{ id: 'tools', title: 'Tools', type: 'tool-input' }] }, + table_v2: TableV2Block, + }, + }).filter((match) => match.blockId === 'tool-input-1' && match.editable) + + expect(findEditable('logicalOperator')).toEqual([]) + expect(findEditable('eq')).toEqual([]) + + const matches = findEditable('operator') + const plan = buildWorkflowSearchReplacePlan({ + blocks: workflow.blocks, + matches, + selectedMatchIds: new Set(matches.map((match) => match.id)), + defaultReplacement: 'owner', + }) + + expect(plan.conflicts).toEqual([]) + expect(plan.updates).toHaveLength(1) + expect(plan.updates[0].nextValue).toEqual([ + expect.objectContaining({ + params: expect.objectContaining({ + filterBuilder: JSON.stringify([{ ...rule, value: 'owner and status' }]), + }), + }), + ]) + }) + it('conflicts when a selected duplicate file occurrence is removed', () => { const workflow = createSearchReplaceWorkflowFixture() const files = [ diff --git a/apps/sim/tools/sailpoint/common.ts b/apps/sim/tools/sailpoint/common.ts index 0fb72cd517e..1fedf7d56b3 100644 --- a/apps/sim/tools/sailpoint/common.ts +++ b/apps/sim/tools/sailpoint/common.ts @@ -1,5 +1,5 @@ import { toError } from '@sim/utils/errors' -import { filterUndefined } from '@sim/utils/object' +import { filterUndefined, toArray } from '@sim/utils/object' import { STANDARD_LIMIT_MAX } from '@/lib/internal/sailpoint/schema' import type { SailPointCredentials } from '@/tools/sailpoint/types' import { savedCredentialTokenParam } from '@/tools/shared/saved-credentials' @@ -119,33 +119,38 @@ export function parseJsonValue(value: T | string | undefined, label: string): } } -/** Normalizes an array, JSON array, or comma-separated string to non-empty strings. */ +/** + * Normalizes an array, JSON array, comma-separated string, or lone number or boolean (what a + * JSON-parsed field or a model sends for a one-entry list) to non-empty strings. + */ export function normalizeStringList( - value: string[] | string | undefined, + value: unknown, label: string, options: { required?: boolean; maxItems?: number } = {} ): string[] | undefined { - if (value === undefined) { + if (value === undefined || value === null) { if (options.required) throw new Error(`${label} is required`) return undefined } - let values: unknown + let values: unknown[] if (Array.isArray(value)) { values = value - } else { + } else if (typeof value === 'string') { const trimmed = value.trim() if (!trimmed) values = [] - else if (trimmed.startsWith('[')) values = parseJsonValue(trimmed, label) + else if (trimmed.startsWith('[')) values = toArray(parseJsonValue(trimmed, label)) else values = trimmed.split(',') + } else { + values = [value] } - if (!Array.isArray(values)) throw new Error(`${label} must be an array of strings`) const normalized = values.map((entry) => { - if (typeof entry !== 'string' || !entry.trim()) { + const text = typeof entry === 'number' || typeof entry === 'boolean' ? String(entry) : entry + if (typeof text !== 'string' || !text.trim()) { throw new Error(`${label} must contain only non-empty strings`) } - return entry.trim() + return text.trim() }) if (options.required && normalized.length === 0) throw new Error(`${label} is required`) if (options.maxItems !== undefined && normalized.length > options.maxItems) { From 39a4fdac439703be630c8403847c9d944229fdee Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 16 Nov 2026 13:53:39 -0800 Subject: [PATCH 2/2] fix(resend): keep the catalog's audience requirement static and type the new tests --- apps/sim/blocks/blocks/resend.test.ts | 15 ++++++++++++++- apps/sim/blocks/blocks/resend.ts | 12 +++++++++--- apps/sim/blocks/blocks/sailpoint.test.ts | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/apps/sim/blocks/blocks/resend.test.ts b/apps/sim/blocks/blocks/resend.test.ts index 0033441ffd9..ccd59529e31 100644 --- a/apps/sim/blocks/blocks/resend.test.ts +++ b/apps/sim/blocks/blocks/resend.test.ts @@ -54,7 +54,7 @@ describe('Resend Create Broadcast recipient', () => { ...values, } const subBlocks = Object.fromEntries( - Object.entries(params).map(([id, value]) => [id, { id, type: 'short-input', value }]) + Object.entries(params).map(([id, value]) => [id, { id, type: 'short-input' as const, value }]) ) const block = { id: 'b1', @@ -81,4 +81,17 @@ describe('Resend Create Broadcast recipient', () => { ) } ) + + 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'], + }) + } + ) }) diff --git a/apps/sim/blocks/blocks/resend.ts b/apps/sim/blocks/blocks/resend.ts index 1a475147492..80387b437ad 100644 --- a/apps/sim/blocks/blocks/resend.ts +++ b/apps/sim/blocks/blocks/resend.ts @@ -317,11 +317,17 @@ Return ONLY the email body - no explanations, no extra text.`, field: 'operation', value: ['get_audience', 'delete_audience', 'create_broadcast'], }, + /** + * 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) => ({ field: 'operation', - value: String(values?.segmentId ?? '').trim() - ? ['get_audience', 'delete_audience'] - : ['get_audience', 'delete_audience', 'create_broadcast'], + value: + values && !String(values.segmentId ?? '').trim() + ? ['get_audience', 'delete_audience', 'create_broadcast'] + : ['get_audience', 'delete_audience'], }), }, diff --git a/apps/sim/blocks/blocks/sailpoint.test.ts b/apps/sim/blocks/blocks/sailpoint.test.ts index 2d5dc603c2a..d4157f5bfbb 100644 --- a/apps/sim/blocks/blocks/sailpoint.test.ts +++ b/apps/sim/blocks/blocks/sailpoint.test.ts @@ -80,7 +80,7 @@ describe('SailPoint search list fields', () => { accessToken: 'token', query: { query: '*' }, }) - expect(request.searchAfter).toEqual(['12345']) + expect(request).toMatchObject({ searchAfter: ['12345'] }) }) })