Skip to content

Commit a335383

Browse files
fix(tables): resolve active selector before schema enrichment
1 parent 0ae09c1 commit a335383

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

apps/sim/providers/utils.test.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ describe('transformBlockTool multi-instance unique IDs', () => {
16221622
expect(result?.id).toBe('table_query_rows_tbl_abc')
16231623
})
16241624

1625-
it('resolves the canonical table id before enriching the LLM tool schema', async () => {
1625+
it('resolves the active table selector before enriching the LLM tool schema', async () => {
16261626
const enrichTool = vi.fn(
16271627
async (
16281628
tableId: string,
@@ -1646,7 +1646,7 @@ describe('transformBlockTool multi-instance unique IDs', () => {
16461646
{
16471647
type: 'table',
16481648
operation: 'query_rows',
1649-
params: { tableSelector: 'tbl_abc' },
1649+
params: { tableId: 'tbl_stale', tableSelector: 'tbl_active' },
16501650
},
16511651
{
16521652
selectedOperation: 'query_rows',
@@ -1672,7 +1672,7 @@ describe('transformBlockTool multi-instance unique IDs', () => {
16721672
)
16731673

16741674
expect(enrichTool).toHaveBeenCalledWith(
1675-
'tbl_abc',
1675+
'tbl_active',
16761676
expect.objectContaining({
16771677
properties: expect.objectContaining({ filter: expect.any(Object) }),
16781678
}),
@@ -1683,15 +1683,16 @@ describe('transformBlockTool multi-instance unique IDs', () => {
16831683
}
16841684
)
16851685
expect(result).toMatchObject({
1686-
id: 'table_query_rows_tbl_abc',
1687-
description: 'Query rows from tbl_abc',
1688-
params: { tableSelector: 'tbl_abc' },
1686+
id: 'table_query_rows_tbl_active',
1687+
description: 'Query rows from tbl_active',
1688+
params: { tableId: 'tbl_stale', tableSelector: 'tbl_active' },
16891689
parameters: {
16901690
properties: {
16911691
customer_name: { type: 'string' },
16921692
},
16931693
},
16941694
})
1695+
expect(result?.paramsTransform?.(result.params)).toEqual({ tableId: 'tbl_active' })
16951696
})
16961697

16971698
it('appends the table id resolved from the advanced manual input', async () => {
@@ -1715,6 +1716,16 @@ describe('transformBlockTool multi-instance unique IDs', () => {
17151716
expect(result?.id).toBe('table_query_rows_tbl_direct')
17161717
})
17171718

1719+
it('preserves the canonical table id when advanced mode is active', async () => {
1720+
const result = await transformTable(
1721+
{ tableId: 'tbl_advanced', tableSelector: 'tbl_basic' },
1722+
{ '0:tableId': 'advanced' },
1723+
0
1724+
)
1725+
expect(result?.id).toBe('table_query_rows_tbl_advanced')
1726+
expect(result?.paramsTransform?.(result.params)).toEqual({ tableId: 'tbl_advanced' })
1727+
})
1728+
17181729
it('falls back to the base tool id when no table is selected', async () => {
17191730
const result = await transformTable({})
17201731
expect(result?.id).toBe('table_query_rows')

apps/sim/providers/utils.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,15 +487,16 @@ export function extractAndParseJSON(content: string): any {
487487

488488
/**
489489
* Resolves canonical pair ids (e.g. `tableId`, `knowledgeBaseId`) from a tool's
490-
* raw params, filling them in from their basic/advanced selector subblock source
491-
* values when the canonical key isn't already present.
490+
* raw params, preferring the active basic/advanced selector subblock source over
491+
* a previously resolved canonical value.
492492
*
493493
* Selector subblocks persist their value under the subblock id (e.g.
494494
* `tableSelector`), not the canonical id, so any lookup that keys off the
495495
* canonical id — like the unique-tool-id suffix below — must resolve it first.
496496
* Mode selection mirrors {@link transformBlockTool}'s execution-time
497497
* `paramsTransform` so the resolved id matches the params the tool actually runs
498-
* with.
498+
* with. When the active selector has no value, the original canonical value is
499+
* preserved for direct-id callers and nested tools in advanced mode.
499500
*
500501
* @returns The params with canonical resource ids resolved (non-destructive)
501502
*/
@@ -507,8 +508,6 @@ function resolveCanonicalResourceParams(
507508
if (canonicalGroups.length === 0) return params
508509
const resolved = { ...params }
509510
for (const group of canonicalGroups) {
510-
const existing = resolved[group.canonicalId]
511-
if (existing !== undefined && existing !== null && existing !== '') continue
512511
// Route through the canonical SOT: an explicit scoped override wins, else the value heuristic -
513512
// no `?? 'basic'` (which ignored an advanced-only value when basic was empty).
514513
const explicitMode = scopedCanonicalModes?.[group.canonicalId]

0 commit comments

Comments
 (0)