Skip to content
Merged
10 changes: 10 additions & 0 deletions apps/sim/blocks/blocks/jotform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@ describe('JotformBlock', () => {

expect({ ...inputs, ...buildParams(inputs) }.questions).toBe(inputs.bulkQuestions)
})

/**
* An agent tool call passes the operation only in `context`; a report title filled
* on the tool row must still reach the tool's `title` param.
*/
it('maps tool-row fields on an agent tool call', () => {
const args: Record<string, unknown> = { apiKey: 'key', formId: '2315', reportTitle: 'Weekly' }

expect({ ...args, ...buildParams(args, { operation: 'create_report' }) }.title).toBe('Weekly')
})
})
6 changes: 3 additions & 3 deletions apps/sim/blocks/blocks/jotform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JotformIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, withSavedCredential } from '@/blocks/utils'
import { getTrigger } from '@/triggers'

/**
Expand Down Expand Up @@ -730,10 +730,10 @@ export const JotformBlock: BlockConfig = {
* Everything else — formId, submissionId, answers, the pagination fields — is
* named after its param and reaches the tool unchanged.
*/
params: (params) => {
params: (params, context) => {
const result: Record<string, unknown> = {}

switch (params.operation) {
switch (mapperOperation(params, context)) {
case 'create_form':
if (params.newFormQuestions) result.questions = params.newFormQuestions
if (params.newFormProperties) result.properties = params.newFormProperties
Expand Down
17 changes: 17 additions & 0 deletions apps/sim/blocks/blocks/kalshi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, expect, it } from 'vitest'
import { KalshiBlock } from '@/blocks/blocks/kalshi'

const buildParams = KalshiBlock.tools.config?.params
if (!buildParams) throw new Error('KalshiBlock has no params mapper')

describe('KalshiBlock', () => {
/**
* An agent tool call passes the operation only in `context`; the order ID filled
* on the tool row must still reach the tool's `orderId` param.
*/
it('maps the order ID field on an agent tool call', () => {
const args: Record<string, unknown> = { keyId: 'key', privateKey: 'pem', orderIdParam: 'ord-1' }

expect({ ...args, ...buildParams(args, { operation: 'cancel_order' }) }.orderId).toBe('ord-1')
})
})
6 changes: 3 additions & 3 deletions apps/sim/blocks/blocks/kalshi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KalshiIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { createVersionedToolSelector, withSavedCredential } from '@/blocks/utils'
import { createVersionedToolSelector, mapperOperation, withSavedCredential } from '@/blocks/utils'

/*
* Mutually exclusive alternates, not canonical pairs — an order carries either
Expand Down Expand Up @@ -695,9 +695,9 @@ Return ONLY the numeric timestamp (seconds since Unix epoch) - no explanations,
return 'kalshi_get_markets'
}
},
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const {
operation,
orderStatus,
tickerFilter,
tickerFills,
Expand Down
25 changes: 25 additions & 0 deletions apps/sim/blocks/blocks/ketch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { describe, expect, it } from 'vitest'
import { KetchBlock } from '@/blocks/blocks/ketch'

const buildParams = KetchBlock.tools.config?.params
if (!buildParams) throw new Error('KetchBlock has no params mapper')

describe('KetchBlock', () => {
/**
* An agent tool call passes the operation only in `context`; a purposes map the
* model sends as JSON text must reach the tool as an object, like the canvas sends it.
*/
it('parses a JSON-text purposes map on an agent tool call', () => {
const args = {
organizationCode: 'org',
propertyCode: 'web',
environmentCode: 'production',
identities: { email: 'a@example.com' },
purposes: '{"analytics":{"allowed":"granted"}}',
}

expect({ ...args, ...buildParams(args, { operation: 'set_consent' }) }.purposes).toEqual({
analytics: { allowed: 'granted' },
})
})
})
12 changes: 7 additions & 5 deletions apps/sim/blocks/blocks/ketch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { KetchIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { IntegrationType } from '@/blocks/types'
import { mapperOperation } from '@/blocks/utils'

export const KetchBlock: BlockConfig = {
type: 'ketch',
Expand Down Expand Up @@ -186,7 +187,8 @@ export const KetchBlock: BlockConfig = {
],
config: {
tool: (params) => `ketch_${params.operation}`,
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const result: Record<string, unknown> = {
organizationCode: params.organizationCode,
propertyCode: params.propertyCode,
Expand All @@ -203,20 +205,20 @@ export const KetchBlock: BlockConfig = {
: params.identities
}

if (params.operation === 'get_consent' && params.purposesFilter) {
if (operation === 'get_consent' && params.purposesFilter) {
result.purposes =
typeof params.purposesFilter === 'string'
? JSON.parse(params.purposesFilter)
: params.purposesFilter
}

if (params.operation === 'set_consent' && params.purposes) {
if (operation === 'set_consent' && params.purposes) {
result.purposes =
typeof params.purposes === 'string' ? JSON.parse(params.purposes) : params.purposes
if (params.collectedAt) result.collectedAt = Number(params.collectedAt)
}

if (params.operation === 'set_subscriptions') {
if (operation === 'set_subscriptions') {
if (params.topics) {
result.topics =
typeof params.topics === 'string' ? JSON.parse(params.topics) : params.topics
Expand All @@ -227,7 +229,7 @@ export const KetchBlock: BlockConfig = {
}
}

if (params.operation === 'invoke_right') {
if (operation === 'invoke_right') {
if (params.rightCode) result.rightCode = params.rightCode
if (params.userData) {
result.userData =
Expand Down
19 changes: 19 additions & 0 deletions apps/sim/blocks/blocks/langsmith.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'
import { LangsmithBlock } from '@/blocks/blocks/langsmith'

const buildParams = LangsmithBlock.tools.config?.params
if (!buildParams) throw new Error('LangsmithBlock has no params mapper')

describe('LangsmithBlock', () => {
/**
* The model names the create-run outputs after the tool's `run_outputs` param, not the
* block's `outputs` field; the mapper must not overwrite them with the empty field.
*/
it('keeps model run outputs on an agent create-run call', () => {
const args = { apiKey: 'key', name: 'run', run_type: 'chain', run_outputs: { answer: 42 } }

expect(
{ ...args, ...buildParams(args, { operation: 'langsmith_create_run' }) }.run_outputs
).toEqual({ answer: 42 })
})
})
18 changes: 11 additions & 7 deletions apps/sim/blocks/blocks/langsmith.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toError } from '@sim/utils/errors'
import { LangsmithIcon } from '@/components/icons'
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
import { withSavedCredential } from '@/blocks/utils'
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'

export const LangsmithBlock: BlockConfig = {
type: 'langsmith',
Expand Down Expand Up @@ -315,7 +315,8 @@ Common patch fields: outputs, end_time, status, error`,
],
config: {
tool: (params) => params.operation,
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const parseJsonValue = (value: unknown, label: string) => {
if (value === undefined || value === null || value === '') {
return undefined
Expand All @@ -332,7 +333,7 @@ Common patch fields: outputs, end_time, status, error`,

const emptyToUndefined = (value: unknown) => (value === '' ? undefined : value)

if (params.operation === 'langsmith_create_runs_batch') {
if (operation === 'langsmith_create_runs_batch') {
const post = parseJsonValue(params.post, 'post runs')
const patch = parseJsonValue(params.patch, 'patch runs')

Expand All @@ -347,7 +348,7 @@ Common patch fields: outputs, end_time, status, error`,
}
}

if (params.operation === 'langsmith_update_run') {
if (operation === 'langsmith_update_run') {
const name = emptyToUndefined(params.name)
const end_time = emptyToUndefined(params.end_time)
const outputs = parseJsonValue(params.outputs, 'outputs')
Expand Down Expand Up @@ -379,14 +380,14 @@ Common patch fields: outputs, end_time, status, error`,
}
}

if (params.operation === 'langsmith_get_run') {
if (operation === 'langsmith_get_run') {
return {
apiKey: params.apiKey,
runId: params.runId,
}
}

if (params.operation === 'langsmith_create_feedback') {
if (operation === 'langsmith_create_feedback') {
const parseScore = (value: unknown) => {
if (value === undefined || value === null || value === '') {
return undefined
Expand Down Expand Up @@ -418,7 +419,10 @@ Common patch fields: outputs, end_time, status, error`,
start_time: params.start_time,
end_time: params.end_time,
inputs: parseJsonValue(params.inputs, 'inputs'),
run_outputs: parseJsonValue(params.outputs, 'outputs'),
run_outputs: parseJsonValue(
params.outputs || toolCallArg(context, params.run_outputs),
'outputs'
),
extra: parseJsonValue(params.extra, 'metadata'),
tags: parseJsonValue(params.tags, 'tags'),
parent_run_id: params.parent_run_id,
Expand Down
23 changes: 23 additions & 0 deletions apps/sim/blocks/blocks/launchdarkly.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { describe, expect, it } from 'vitest'
import { LaunchDarklyBlock } from '@/blocks/blocks/launchdarkly'

type Params = Record<string, unknown>

const toolCall = (args: Params, operation: string): Params =>
LaunchDarklyBlock.tools.config?.params?.(args as never, { operation }) as Params

describe('LaunchDarkly agent tool calls', () => {
it('keeps the model name, key and boolean temporary flag on create_flag', () => {
const mapped = toolCall(
{ projectKey: 'default', name: 'New checkout', key: 'new-checkout', temporary: true },
'create_flag'
)
expect(mapped).toMatchObject({ name: 'New checkout', key: 'new-checkout', temporary: true })
})

it('keeps a boolean archive on update_flag', () => {
expect(
toolCall({ projectKey: 'default', flagKey: 'old-flag', archive: true }, 'update_flag').archive
).toBe(true)
})
})
17 changes: 9 additions & 8 deletions apps/sim/blocks/blocks/launchdarkly.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LaunchDarklyIcon } 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 LaunchDarklyBlock: BlockConfig = {
type: 'launchdarkly',
Expand Down Expand Up @@ -329,23 +329,24 @@ Return ONLY the resource specifier string - no explanations, no extra text.`,
const operation = params.operation || 'list_flags'
return `launchdarkly_${operation}`
},
params: (params) => {
const { operation, flagName, newFlagKey, ...rest } = params
params: (params, context) => {
const operation = mapperOperation(params, context)
const { flagName, newFlagKey, ...rest } = params

if (operation === 'create_flag') {
rest.name = flagName
rest.key = newFlagKey
rest.name = flagName ?? toolCallArg(context, params.name)
rest.key = newFlagKey ?? toolCallArg(context, params.key)
}

if (operation === 'toggle_flag') {
rest.enabled = rest.enabled === 'true'
rest.enabled = rest.enabled === true || rest.enabled === 'true'
}

if (rest.temporary !== undefined) {
rest.temporary = rest.temporary === 'true'
rest.temporary = rest.temporary === true || rest.temporary === 'true'
}

if (rest.archive !== undefined) {
if (rest.archive !== undefined && typeof rest.archive !== 'boolean') {
if (rest.archive === 'true') rest.archive = true
else if (rest.archive === 'false') rest.archive = false
else rest.archive = undefined
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/blocks/blocks/linkedin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LinkedInIcon } from '@/components/icons'
import { getScopesForService } from '@/lib/oauth/utils'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { mapperOperation } from '@/blocks/utils'

export const LinkedInBlock: BlockConfig = {
type: 'linkedin',
Expand Down Expand Up @@ -103,8 +104,8 @@ export const LinkedInBlock: BlockConfig = {

return 'linkedin_share_post'
},
params: (inputs) => {
const operation = inputs.operation || 'share_post'
params: (inputs, context) => {
const operation = mapperOperation(inputs, context) || 'share_post'
const { oauthCredential, ...rest } = inputs

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

type Params = Record<string, unknown>

const toolCall = (args: Params, operation: string): Params =>
LinqBlock.tools.config?.params?.(args as never, { operation }) as Params

describe('Linq agent tool calls', () => {
it('unwraps a single picked file on create_attachment', () => {
const file = {
id: 'f1',
name: 'card.png',
key: 'workspace/ws/card.png',
size: 10,
type: 'image/png',
}
expect(toolCall({ file: [file] }, 'create_attachment').file).toEqual(file)
})
})
12 changes: 8 additions & 4 deletions apps/sim/blocks/blocks/linq.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LinqIcon } from '@/components/icons'
import type { BlockConfig, BlockMeta } from '@/blocks/types'
import { AuthMode, IntegrationType } from '@/blocks/types'
import { normalizeFileInput, withSavedCredential } from '@/blocks/utils'
import { mapperOperation, normalizeFileInput, withSavedCredential } from '@/blocks/utils'
import { getTrigger } from '@/triggers'

const CHAT_ID_OPS = [
Expand Down Expand Up @@ -781,9 +781,9 @@ export const LinqBlock: BlockConfig = {
],
config: {
tool: (params) => `linq_${params.operation || 'send_message'}`,
params: (params) => {
params: (params, context) => {
const operation = mapperOperation(params, context)
const {
operation,
senderFrom,
recipients,
messageText,
Expand Down Expand Up @@ -881,7 +881,6 @@ export const LinqBlock: BlockConfig = {
}

if (operation === 'react_to_message') {
if (reactionOperation) rest.operation = reactionOperation
if (reactionType) rest.type = reactionType
if (reactionCustomEmoji) rest.customEmoji = reactionCustomEmoji
if (reactionPartIndex !== undefined && reactionPartIndex !== '') {
Expand Down Expand Up @@ -940,6 +939,11 @@ export const LinqBlock: BlockConfig = {
rest.limit = toFiniteNumber(limit, 'Limit')
}

// The react tool declares its own `operation` param: add or remove.
if (operation === 'react_to_message' && reactionOperation) {
return { ...rest, operation: reactionOperation }
}

return rest
},
},
Expand Down
Loading
Loading