Skip to content

Commit 5729416

Browse files
authored
fix(blocks): read the mapper operation from the tool-call context in j–z blocks (#10078)
* fix(integrations): sweep2 m4 — read the mapper operation from the tool-call context and validate integrations against vendor specs * chore: regenerate tool metadata, docs and ratchet baselines * refactor: simplify and clean up the sweep changes * fix(blocks): type the sweep2 m4 mapper tests and stripe JSON spreads for test-types * fix(rocketlane): send only the saved time source when a tool call also names another * chore: regenerate tool metadata and mapper baseline after merging staging
1 parent a86f4c2 commit 5729416

63 files changed

Lines changed: 1546 additions & 865 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/sim/blocks/blocks/jotform.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ describe('JotformBlock', () => {
2525

2626
expect({ ...inputs, ...buildParams(inputs) }.questions).toBe(inputs.bulkQuestions)
2727
})
28+
29+
/**
30+
* An agent tool call passes the operation only in `context`; a report title filled
31+
* on the tool row must still reach the tool's `title` param.
32+
*/
33+
it('maps tool-row fields on an agent tool call', () => {
34+
const args: Record<string, unknown> = { apiKey: 'key', formId: '2315', reportTitle: 'Weekly' }
35+
36+
expect({ ...args, ...buildParams(args, { operation: 'create_report' }) }.title).toBe('Weekly')
37+
})
2838
})

‎apps/sim/blocks/blocks/jotform.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { JotformIcon } from '@/components/icons'
22
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
3-
import { withSavedCredential } from '@/blocks/utils'
3+
import { mapperOperation, withSavedCredential } from '@/blocks/utils'
44
import { getTrigger } from '@/triggers'
55

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

736-
switch (params.operation) {
736+
switch (mapperOperation(params, context)) {
737737
case 'create_form':
738738
if (params.newFormQuestions) result.questions = params.newFormQuestions
739739
if (params.newFormProperties) result.properties = params.newFormProperties
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { KalshiBlock } from '@/blocks/blocks/kalshi'
3+
4+
const buildParams = KalshiBlock.tools.config?.params
5+
if (!buildParams) throw new Error('KalshiBlock has no params mapper')
6+
7+
describe('KalshiBlock', () => {
8+
/**
9+
* An agent tool call passes the operation only in `context`; the order ID filled
10+
* on the tool row must still reach the tool's `orderId` param.
11+
*/
12+
it('maps the order ID field on an agent tool call', () => {
13+
const args: Record<string, unknown> = { keyId: 'key', privateKey: 'pem', orderIdParam: 'ord-1' }
14+
15+
expect({ ...args, ...buildParams(args, { operation: 'cancel_order' }) }.orderId).toBe('ord-1')
16+
})
17+
})

‎apps/sim/blocks/blocks/kalshi.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { KalshiIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4-
import { createVersionedToolSelector, withSavedCredential } from '@/blocks/utils'
4+
import { createVersionedToolSelector, mapperOperation, withSavedCredential } from '@/blocks/utils'
55

66
/*
77
* Mutually exclusive alternates, not canonical pairs — an order carries either
@@ -695,9 +695,9 @@ Return ONLY the numeric timestamp (seconds since Unix epoch) - no explanations,
695695
return 'kalshi_get_markets'
696696
}
697697
},
698-
params: (params) => {
698+
params: (params, context) => {
699+
const operation = mapperOperation(params, context)
699700
const {
700-
operation,
701701
orderStatus,
702702
tickerFilter,
703703
tickerFills,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { KetchBlock } from '@/blocks/blocks/ketch'
3+
4+
const buildParams = KetchBlock.tools.config?.params
5+
if (!buildParams) throw new Error('KetchBlock has no params mapper')
6+
7+
describe('KetchBlock', () => {
8+
/**
9+
* An agent tool call passes the operation only in `context`; a purposes map the
10+
* model sends as JSON text must reach the tool as an object, like the canvas sends it.
11+
*/
12+
it('parses a JSON-text purposes map on an agent tool call', () => {
13+
const args = {
14+
organizationCode: 'org',
15+
propertyCode: 'web',
16+
environmentCode: 'production',
17+
identities: { email: 'a@example.com' },
18+
purposes: '{"analytics":{"allowed":"granted"}}',
19+
}
20+
21+
expect({ ...args, ...buildParams(args, { operation: 'set_consent' }) }.purposes).toEqual({
22+
analytics: { allowed: 'granted' },
23+
})
24+
})
25+
})

‎apps/sim/blocks/blocks/ketch.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { KetchIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { IntegrationType } from '@/blocks/types'
4+
import { mapperOperation } from '@/blocks/utils'
45

56
export const KetchBlock: BlockConfig = {
67
type: 'ketch',
@@ -186,7 +187,8 @@ export const KetchBlock: BlockConfig = {
186187
],
187188
config: {
188189
tool: (params) => `ketch_${params.operation}`,
189-
params: (params) => {
190+
params: (params, context) => {
191+
const operation = mapperOperation(params, context)
190192
const result: Record<string, unknown> = {
191193
organizationCode: params.organizationCode,
192194
propertyCode: params.propertyCode,
@@ -203,20 +205,20 @@ export const KetchBlock: BlockConfig = {
203205
: params.identities
204206
}
205207

206-
if (params.operation === 'get_consent' && params.purposesFilter) {
208+
if (operation === 'get_consent' && params.purposesFilter) {
207209
result.purposes =
208210
typeof params.purposesFilter === 'string'
209211
? JSON.parse(params.purposesFilter)
210212
: params.purposesFilter
211213
}
212214

213-
if (params.operation === 'set_consent' && params.purposes) {
215+
if (operation === 'set_consent' && params.purposes) {
214216
result.purposes =
215217
typeof params.purposes === 'string' ? JSON.parse(params.purposes) : params.purposes
216218
if (params.collectedAt) result.collectedAt = Number(params.collectedAt)
217219
}
218220

219-
if (params.operation === 'set_subscriptions') {
221+
if (operation === 'set_subscriptions') {
220222
if (params.topics) {
221223
result.topics =
222224
typeof params.topics === 'string' ? JSON.parse(params.topics) : params.topics
@@ -227,7 +229,7 @@ export const KetchBlock: BlockConfig = {
227229
}
228230
}
229231

230-
if (params.operation === 'invoke_right') {
232+
if (operation === 'invoke_right') {
231233
if (params.rightCode) result.rightCode = params.rightCode
232234
if (params.userData) {
233235
result.userData =
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { LangsmithBlock } from '@/blocks/blocks/langsmith'
3+
4+
const buildParams = LangsmithBlock.tools.config?.params
5+
if (!buildParams) throw new Error('LangsmithBlock has no params mapper')
6+
7+
describe('LangsmithBlock', () => {
8+
/**
9+
* The model names the create-run outputs after the tool's `run_outputs` param, not the
10+
* block's `outputs` field; the mapper must not overwrite them with the empty field.
11+
*/
12+
it('keeps model run outputs on an agent create-run call', () => {
13+
const args = { apiKey: 'key', name: 'run', run_type: 'chain', run_outputs: { answer: 42 } }
14+
15+
expect(
16+
{ ...args, ...buildParams(args, { operation: 'langsmith_create_run' }) }.run_outputs
17+
).toEqual({ answer: 42 })
18+
})
19+
})

‎apps/sim/blocks/blocks/langsmith.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { toError } from '@sim/utils/errors'
22
import { LangsmithIcon } from '@/components/icons'
33
import { AuthMode, type BlockConfig, type BlockMeta, IntegrationType } from '@/blocks/types'
4-
import { withSavedCredential } from '@/blocks/utils'
4+
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'
55

66
export const LangsmithBlock: BlockConfig = {
77
type: 'langsmith',
@@ -315,7 +315,8 @@ Common patch fields: outputs, end_time, status, error`,
315315
],
316316
config: {
317317
tool: (params) => params.operation,
318-
params: (params) => {
318+
params: (params, context) => {
319+
const operation = mapperOperation(params, context)
319320
const parseJsonValue = (value: unknown, label: string) => {
320321
if (value === undefined || value === null || value === '') {
321322
return undefined
@@ -332,7 +333,7 @@ Common patch fields: outputs, end_time, status, error`,
332333

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

335-
if (params.operation === 'langsmith_create_runs_batch') {
336+
if (operation === 'langsmith_create_runs_batch') {
336337
const post = parseJsonValue(params.post, 'post runs')
337338
const patch = parseJsonValue(params.patch, 'patch runs')
338339

@@ -347,7 +348,7 @@ Common patch fields: outputs, end_time, status, error`,
347348
}
348349
}
349350

350-
if (params.operation === 'langsmith_update_run') {
351+
if (operation === 'langsmith_update_run') {
351352
const name = emptyToUndefined(params.name)
352353
const end_time = emptyToUndefined(params.end_time)
353354
const outputs = parseJsonValue(params.outputs, 'outputs')
@@ -379,14 +380,14 @@ Common patch fields: outputs, end_time, status, error`,
379380
}
380381
}
381382

382-
if (params.operation === 'langsmith_get_run') {
383+
if (operation === 'langsmith_get_run') {
383384
return {
384385
apiKey: params.apiKey,
385386
runId: params.runId,
386387
}
387388
}
388389

389-
if (params.operation === 'langsmith_create_feedback') {
390+
if (operation === 'langsmith_create_feedback') {
390391
const parseScore = (value: unknown) => {
391392
if (value === undefined || value === null || value === '') {
392393
return undefined
@@ -418,7 +419,10 @@ Common patch fields: outputs, end_time, status, error`,
418419
start_time: params.start_time,
419420
end_time: params.end_time,
420421
inputs: parseJsonValue(params.inputs, 'inputs'),
421-
run_outputs: parseJsonValue(params.outputs, 'outputs'),
422+
run_outputs: parseJsonValue(
423+
params.outputs || toolCallArg(context, params.run_outputs),
424+
'outputs'
425+
),
422426
extra: parseJsonValue(params.extra, 'metadata'),
423427
tags: parseJsonValue(params.tags, 'tags'),
424428
parent_run_id: params.parent_run_id,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { LaunchDarklyBlock } from '@/blocks/blocks/launchdarkly'
3+
4+
type Params = Record<string, unknown>
5+
6+
const toolCall = (args: Params, operation: string): Params =>
7+
LaunchDarklyBlock.tools.config?.params?.(args as never, { operation }) as Params
8+
9+
describe('LaunchDarkly agent tool calls', () => {
10+
it('keeps the model name, key and boolean temporary flag on create_flag', () => {
11+
const mapped = toolCall(
12+
{ projectKey: 'default', name: 'New checkout', key: 'new-checkout', temporary: true },
13+
'create_flag'
14+
)
15+
expect(mapped).toMatchObject({ name: 'New checkout', key: 'new-checkout', temporary: true })
16+
})
17+
18+
it('keeps a boolean archive on update_flag', () => {
19+
expect(
20+
toolCall({ projectKey: 'default', flagKey: 'old-flag', archive: true }, 'update_flag').archive
21+
).toBe(true)
22+
})
23+
})

‎apps/sim/blocks/blocks/launchdarkly.ts‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { LaunchDarklyIcon } from '@/components/icons'
22
import type { BlockConfig, BlockMeta } from '@/blocks/types'
33
import { AuthMode, IntegrationType } from '@/blocks/types'
4-
import { withSavedCredential } from '@/blocks/utils'
4+
import { mapperOperation, toolCallArg, withSavedCredential } from '@/blocks/utils'
55

66
export const LaunchDarklyBlock: BlockConfig = {
77
type: 'launchdarkly',
@@ -329,23 +329,24 @@ Return ONLY the resource specifier string - no explanations, no extra text.`,
329329
const operation = params.operation || 'list_flags'
330330
return `launchdarkly_${operation}`
331331
},
332-
params: (params) => {
333-
const { operation, flagName, newFlagKey, ...rest } = params
332+
params: (params, context) => {
333+
const operation = mapperOperation(params, context)
334+
const { flagName, newFlagKey, ...rest } = params
334335

335336
if (operation === 'create_flag') {
336-
rest.name = flagName
337-
rest.key = newFlagKey
337+
rest.name = flagName ?? toolCallArg(context, params.name)
338+
rest.key = newFlagKey ?? toolCallArg(context, params.key)
338339
}
339340

340341
if (operation === 'toggle_flag') {
341-
rest.enabled = rest.enabled === 'true'
342+
rest.enabled = rest.enabled === true || rest.enabled === 'true'
342343
}
343344

344345
if (rest.temporary !== undefined) {
345-
rest.temporary = rest.temporary === 'true'
346+
rest.temporary = rest.temporary === true || rest.temporary === 'true'
346347
}
347348

348-
if (rest.archive !== undefined) {
349+
if (rest.archive !== undefined && typeof rest.archive !== 'boolean') {
349350
if (rest.archive === 'true') rest.archive = true
350351
else if (rest.archive === 'false') rest.archive = false
351352
else rest.archive = undefined

0 commit comments

Comments
 (0)