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
21 changes: 21 additions & 0 deletions apps/sim/blocks/blocks/google_forms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@ describe('GoogleFormsBlock agent tool calls', () => {
const mapped = GoogleFormsBlock.tools.config?.params?.(inputs, { operation: 'get_responses' })
expect(mapped).toMatchObject({ formId: 'form-1', pageSize: 5 })
})

it.each([
{ operation: 'create_form', inputs: { documentTitle: 'd' }, missing: 'title' },
{ operation: 'create_watch', inputs: { formId: 'f', topicName: 't' }, missing: 'eventType' },
{
operation: 'create_watch',
inputs: { formId: 'f', eventType: 'RESPONSES' },
missing: 'topicName',
},
{ operation: 'delete_watch', inputs: { formId: 'f' }, missing: 'watchId' },
{ operation: 'renew_watch', inputs: { formId: 'f' }, missing: 'watchId' },
])(
'leaves a $missing the model omitted on $operation for the required-param check',
({ operation, inputs, missing }) => {
const mapped = GoogleFormsBlock.tools.config?.params?.(
{ oauthCredential: 'cred-1', ...inputs },
{ operation }
)
expect(mapped?.[missing]).toBeUndefined()
}
)
})
8 changes: 4 additions & 4 deletions apps/sim/blocks/blocks/google_forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ Example for "Add a required multiple choice question about favorite color":
case 'create_form':
return {
...baseParams,
title: String(title).trim(),
title: title == null ? undefined : String(title).trim(),
documentTitle: documentTitle ? String(documentTitle).trim() : undefined,
unpublished: unpublished ?? false,
}
Expand All @@ -377,16 +377,16 @@ Example for "Add a required multiple choice question about favorite color":
return {
...baseParams,
formId: effectiveFormId,
eventType: String(eventType),
topicName: String(topicName).trim(),
eventType: eventType == null ? undefined : String(eventType),
topicName: topicName == null ? undefined : String(topicName).trim(),
watchId: watchId ? String(watchId).trim() : undefined,
}
case 'delete_watch':
case 'renew_watch':
return {
...baseParams,
formId: effectiveFormId,
watchId: String(watchId).trim(),
watchId: watchId == null ? undefined : String(watchId).trim(),
}
default:
throw new Error(`Invalid Google Forms operation: ${operation}`)
Expand Down
22 changes: 22 additions & 0 deletions apps/sim/blocks/blocks/hubspot.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'
import { HubSpotBlock } from '@/blocks/blocks/hubspot'

function mapParams(params: Record<string, unknown>, operation: string) {
const mapper = HubSpotBlock.tools.config?.params
if (!mapper) throw new Error('HubSpot block has no params mapper')
return mapper(params, { operation })
}

describe('HubSpot create_list name on a tool call', () => {
const list = { oauthCredential: 'cred-1', objectTypeId: '0-1', processingType: 'MANUAL' }

it('keeps the List Name pinned on the tool row over the model name', () => {
expect(
mapParams({ ...list, listName: 'My List', name: 'Model Name' }, 'create_list').name
).toBe('My List')
})

it('uses the model name when the row leaves List Name empty', () => {
expect(mapParams({ ...list, name: 'Model Name' }, 'create_list').name).toBe('Model Name')
})
})
9 changes: 5 additions & 4 deletions apps/sim/blocks/blocks/hubspot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1726,10 +1726,6 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
cleanParams.associations = associations
}

if (listName && operation === 'create_list') {
cleanParams.name = listName
}

if (
operation === 'create_association' &&
associationTypeId !== undefined &&
Expand Down Expand Up @@ -1768,6 +1764,11 @@ Return ONLY the JSON array of property names - no explanations, no markdown, no
}
})

// After the copy so the row's List Name beats a model `name` on a tool call.
if (listName && operation === 'create_list') {
cleanParams.name = listName
}

return cleanParams
},
},
Expand Down
32 changes: 32 additions & 0 deletions apps/sim/blocks/blocks/intercom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,35 @@ describe('Intercom role defaults', () => {
expect(options()[0]?.id).toBe('lead')
})
})

describe('Intercom tool-row fields on a tool call', () => {
it.each([
{ operation: 'update_ticket', field: 'ticket_assignee_id', param: 'assignee_id' },
{ operation: 'create_contact', field: 'contact_company_id', param: 'company_id' },
{ operation: 'close_conversation', field: 'close_body', param: 'body' },
{ operation: 'assign_conversation', field: 'assign_body', param: 'body' },
{ operation: 'create_note', field: 'note_body', param: 'body' },
{ operation: 'create_note', field: 'tag_contact_id', param: 'contactId' },
{ operation: 'attach_contact_to_company', field: 'attach_company_id', param: 'companyId' },
{ operation: 'create_tag', field: 'tag_name', param: 'name' },
{ operation: 'create_tag', field: 'tag_id_update', param: 'id' },
{ operation: 'create_event', field: 'event_user_id', param: 'user_id' },
{ operation: 'create_event', field: 'event_email', param: 'email' },
{ operation: 'create_event', field: 'event_contact_id', param: 'id' },
{ operation: 'create_event', field: 'event_metadata', param: 'metadata' },
{ operation: 'create_message', field: 'message_type_msg', param: 'message_type' },
{ operation: 'create_company', field: 'company_name', param: 'name' },
])(
'keeps the pinned $field over the model $param on $operation',
({ operation, field, param }) => {
const mapped = mapParams({ [field]: 'pinned', [param]: 'model' }, { operation })
expect(mapped[param]).toBe('pinned')
}
)

it('fills a param from the model when the row leaves its field empty', () => {
expect(mapParams({ assignee_id: 'model' }, { operation: 'update_ticket' }).assignee_id).toBe(
'model'
)
})
})
3 changes: 2 additions & 1 deletion apps/sim/blocks/blocks/intercom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ const mapIntercomParams: IntercomParamsMapper = (params, context) => {
if (event_created_at) cleanParams.created_at = Number(event_created_at)
}

// A block field mapped above (pinned on a tool row) beats the model's arg under the tool's name.
Object.entries(rest).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
if (hasInput(value) && cleanParams[key] === undefined) {
cleanParams[key] = value
}
})
Expand Down
47 changes: 47 additions & 0 deletions apps/sim/blocks/blocks/kalshi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,51 @@ describe('KalshiBlock', () => {

expect({ ...args, ...buildParams(args, { operation: 'cancel_order' }) }.orderId).toBe('ord-1')
})

it.each([
{ operation: 'cancel_order', stale: { orderId: 'O-STALE' }, field: { orderIdParam: 'O-NEW' } },
{ operation: 'get_order', stale: { orderId: 'O-STALE' }, field: { orderIdParam: 'O-NEW' } },
{
operation: 'amend_order',
stale: { clientOrderId: 'C-STALE' },
field: { clientOrderIdAmend: 'C-NEW' },
},
{ operation: 'get_orders', stale: { status: 'open' }, field: { orderStatus: 'resting' } },
])(
'sends the $operation field over a stale canvas value under the tool param name',
({ operation, stale, field }) => {
const canvas: Record<string, unknown> = {
operation,
keyId: 'key',
privateKey: 'pem',
...stale,
...field,
}
const sent: Record<string, unknown> = { ...canvas, ...buildParams(canvas) }
expect(sent[Object.keys(stale)[0]]).toBe(Object.values(field)[0])
}
)

it('drops a stale canvas order ID when the operation field is empty', () => {
const canvas = { operation: 'get_order', orderId: 'O-STALE', orderIdParam: '' }
expect({ ...canvas, ...buildParams(canvas) }.orderId).toBeUndefined()
})

it.each([
{ operation: 'cancel_order', param: 'orderId', field: 'orderIdParam' },
{ operation: 'get_orders', param: 'status', field: 'orderStatus' },
{ operation: 'create_order', param: 'type', field: 'orderType' },
{ operation: 'create_order', param: 'ticker', field: 'tickerOrder' },
])(
'keeps the row-pinned $field over the model $param on a $operation tool call',
({ operation, param, field }) => {
const args = { [field]: 'pinned', [param]: 'model' }
expect({ ...args, ...buildParams(args, { operation }) }[param]).toBe('pinned')
}
)

it('keeps the model order ID on a tool call when the row leaves the field empty', () => {
const args = { orderId: 'model' }
expect({ ...args, ...buildParams(args, { operation: 'cancel_order' }) }.orderId).toBe('model')
})
})
84 changes: 46 additions & 38 deletions apps/sim/blocks/blocks/kalshi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { KalshiIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { createVersionedToolSelector, mapperOperation, withSavedCredential } from '@/blocks/utils'
import {
createVersionedToolSelector,
mapperOperation,
toolCallArg,
withSavedCredential,
} from '@/blocks/utils'

/*
* Mutually exclusive alternates, not canonical pairs — an order carries either
Expand Down Expand Up @@ -712,69 +717,72 @@ Return ONLY the numeric timestamp (seconds since Unix epoch) - no explanations,
...rest
} = params
const cleanParams: Record<string, any> = {}
Object.entries(rest).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
cleanParams[key] = value
}
})

/**
* The operation's own field wins over a value under the tool's param name: on the canvas
* that value is stale from another operation, and on a tool call the row's field is pinned.
* The model's value fills the param only on a tool call with the field empty.
*/
const mapField = (key: string, field: unknown) => {
cleanParams[key] = field || toolCallArg(context, cleanParams[key])
}

if (operation === 'get_orders' && orderStatus) {
cleanParams.status = orderStatus
if (operation === 'get_orders') {
mapField('status', orderStatus)
}

if (
(operation === 'get_orders' ||
operation === 'get_positions' ||
operation === 'get_settlements') &&
tickerFilter
operation === 'get_orders' ||
operation === 'get_positions' ||
operation === 'get_settlements'
) {
cleanParams.ticker = tickerFilter
mapField('ticker', tickerFilter)
}

if (operation === 'get_fills' && tickerFills) {
cleanParams.ticker = tickerFills
if (operation === 'get_fills') {
mapField('ticker', tickerFills)
}

if (operation === 'get_candlesticks') {
if (seriesTickerCandlesticks) cleanParams.seriesTicker = seriesTickerCandlesticks
if (tickerCandlesticks) cleanParams.ticker = tickerCandlesticks
mapField('seriesTicker', seriesTickerCandlesticks)
mapField('ticker', tickerCandlesticks)
}

// Map series ticker for get_event_candlesticks (event ticker flows through eventTicker)
if (operation === 'get_event_candlesticks' && seriesTickerCandlesticks) {
cleanParams.seriesTicker = seriesTickerCandlesticks
// Event candlesticks take the event ticker through eventTicker
if (operation === 'get_event_candlesticks') {
mapField('seriesTicker', seriesTickerCandlesticks)
}

if (operation === 'get_series_by_ticker' && seriesTickerGet) {
cleanParams.seriesTicker = seriesTickerGet
if (operation === 'get_series_by_ticker') {
mapField('seriesTicker', seriesTickerGet)
}

if (
(operation === 'get_order' ||
operation === 'cancel_order' ||
operation === 'amend_order') &&
orderIdParam
operation === 'get_order' ||
operation === 'cancel_order' ||
operation === 'amend_order'
) {
cleanParams.orderId = orderIdParam
mapField('orderId', orderIdParam)
}

if ((operation === 'create_order' || operation === 'amend_order') && tickerOrder) {
cleanParams.ticker = tickerOrder
if (operation === 'create_order' || operation === 'amend_order') {
mapField('ticker', tickerOrder)
}

if (operation === 'create_order' && orderType) {
cleanParams.type = orderType
if (operation === 'create_order') {
mapField('type', orderType)
}

if (operation === 'amend_order' && countAmend) {
cleanParams.count = countAmend
if (operation === 'amend_order') {
mapField('count', countAmend)
mapField('clientOrderId', clientOrderIdAmend)
}

if (operation === 'amend_order' && clientOrderIdAmend) {
cleanParams.clientOrderId = clientOrderIdAmend
}

Object.entries(rest).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
cleanParams[key] = value
}
})

return cleanParams
},
},
Expand Down
7 changes: 6 additions & 1 deletion apps/sim/blocks/blocks/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,16 @@ Return ONLY the email body - no explanations, no extra text.`,
if (operation === 'send_email') return 'resend_send'
return `resend_${operation}`
},
params: (params) => {
params: (params, context) => {
const { operation, ...rest } = params

rest.unsubscribed = toBooleanFromInput(rest.unsubscribed)

// The tool prefers a segment, so a model's segmentId would retarget a row's pinned audience.
if (context?.pinnedParams?.has('audienceId') && !context.pinnedParams.has('segmentId')) {
rest.segmentId = undefined
}

if (typeof rest.limit === 'string') {
const limit = rest.limit.trim()
rest.limit = limit ? Number(limit) : undefined
Expand Down
Loading
Loading