From e35303d52f9da8724a8e90b623ea5d59d10ccc90 Mon Sep 17 00:00:00 2001 From: Theodore Li Date: Wed, 5 Aug 2026 19:15:39 -0700 Subject: [PATCH] fix(tables): pass enriched query schema to agents --- .../handlers/agent/agent-handler.test.ts | 19 ++++ .../executor/handlers/agent/agent-handler.ts | 9 +- .../executor/handlers/pi/sim-tools.test.ts | 15 +++ apps/sim/executor/handlers/pi/sim-tools.ts | 8 ++ apps/sim/providers/utils.test.ts | 72 ++++++++++++ apps/sim/providers/utils.ts | 25 +++-- apps/sim/tools/params.test.ts | 22 ++++ apps/sim/tools/params.ts | 27 ++++- apps/sim/tools/schema-enrichers.test.ts | 104 ++++++++++++++++++ apps/sim/tools/schema-enrichers.ts | 73 +++++++----- apps/sim/tools/table/batch_insert_rows.ts | 4 +- apps/sim/tools/table/delete_rows_by_filter.ts | 4 +- apps/sim/tools/table/insert_row.ts | 4 +- apps/sim/tools/table/query_rows.ts | 4 +- apps/sim/tools/table/update_row.ts | 4 +- apps/sim/tools/table/update_rows_by_filter.ts | 4 +- apps/sim/tools/table/upsert_row.ts | 4 +- apps/sim/tools/types.ts | 3 +- 18 files changed, 349 insertions(+), 56 deletions(-) create mode 100644 apps/sim/tools/schema-enrichers.test.ts diff --git a/apps/sim/executor/handlers/agent/agent-handler.test.ts b/apps/sim/executor/handlers/agent/agent-handler.test.ts index 0d3e61bd4c3..602dc20342e 100644 --- a/apps/sim/executor/handlers/agent/agent-handler.test.ts +++ b/apps/sim/executor/handlers/agent/agent-handler.test.ts @@ -29,6 +29,7 @@ import { SIM_AUTO_MODEL_ID } from '@/providers/models' import { getProviderFromModel, transformBlockTool } from '@/providers/utils' import type { SerializedBlock, SerializedWorkflow } from '@/serializer/types' import { executeTool } from '@/tools' +import { ToolSchemaEnrichmentError } from '@/tools/params' process.env.NEXT_PUBLIC_APP_URL = 'http://localhost:3000' @@ -289,6 +290,24 @@ describe('AgentBlockHandler', () => { expect(result).toEqual(expectedOutput) }) + it('fails fast when a configured tool schema cannot be enriched', async () => { + const error = new ToolSchemaEnrichmentError( + 'table_query_rows', + new Error('table metadata unavailable') + ) + mockTransformBlockTool.mockRejectedValueOnce(error) + + await expect( + handler.execute(mockContext, mockBlock, { + model: 'gpt-4o', + userPrompt: 'Query the table', + apiKey: 'test-api-key', + tools: [{ type: 'table', operation: 'query_rows', usageControl: 'auto' }], + }) + ).rejects.toBe(error) + expect(mockExecuteProviderRequest).not.toHaveBeenCalled() + }) + it('reports a sim-auto run under the sim-auto identity, not the model that served it', async () => { mockExecuteProviderRequest.mockResolvedValue({ content: 'Mocked response content', diff --git a/apps/sim/executor/handlers/agent/agent-handler.ts b/apps/sim/executor/handlers/agent/agent-handler.ts index 801a4fd6f41..a567d899c30 100644 --- a/apps/sim/executor/handlers/agent/agent-handler.ts +++ b/apps/sim/executor/handlers/agent/agent-handler.ts @@ -67,7 +67,7 @@ import { import { isAutoModel, SIM_AUTO_MODEL_ID } from '@/providers/models' import { getProviderFromModel, transformBlockTool } from '@/providers/utils' import type { SerializedBlock } from '@/serializer/types' -import { filterSchemaForLLM, type ToolSchema } from '@/tools/params' +import { filterSchemaForLLM, type ToolSchema, ToolSchemaEnrichmentError } from '@/tools/params' import { getTool } from '@/tools/utils' import { getToolAsync } from '@/tools/utils.server' @@ -526,6 +526,7 @@ export class AgentBlockHandler implements BlockHandler { } return this.transformBlockTool(ctx, tool, canonicalModes, toolIndex) } catch (error) { + if (error instanceof ToolSchemaEnrichmentError) throw error logger.error( '[AgentHandler] Error creating tool', projectAgentDiagnosticMetadata( @@ -952,6 +953,12 @@ export class AgentBlockHandler implements BlockHandler { }), getTool, canonicalModes, + enrichmentContext: { + workflowId: ctx.workflowId, + workspaceId: ctx.workspaceId, + executionId: ctx.executionId, + userId: ctx.userId, + }, toolIndex, resolveCustomBlockBinding: (blockType: string) => resolveCustomBlockToolBinding(blockType, ctx.workspaceId), diff --git a/apps/sim/executor/handlers/pi/sim-tools.test.ts b/apps/sim/executor/handlers/pi/sim-tools.test.ts index dd49cdd7d38..2e1760cfbcc 100644 --- a/apps/sim/executor/handlers/pi/sim-tools.test.ts +++ b/apps/sim/executor/handlers/pi/sim-tools.test.ts @@ -16,6 +16,7 @@ vi.mock('@/tools/utils.server', () => ({ getToolAsync: vi.fn() })) import { buildSimToolSpecs } from '@/executor/handlers/pi/sim-tools' import type { ExecutionContext } from '@/executor/types' import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' +import { ToolSchemaEnrichmentError } from '@/tools/params' function executionContext(registry: ResolvedSecretTraceRegistry | undefined): ExecutionContext { return { @@ -76,6 +77,20 @@ describe('buildSimToolSpecs', () => { expect(mockTransformBlockTool).not.toHaveBeenCalled() }) + it('fails fast when a tool schema cannot be enriched', async () => { + const error = new ToolSchemaEnrichmentError( + 'table_query_rows', + new Error('table metadata unavailable') + ) + mockTransformBlockTool.mockRejectedValueOnce(error) + + await expect( + buildSimToolSpecs(completeExecutionContext(), [ + { type: 'table', operation: 'query_rows', usageControl: 'auto' }, + ]) + ).rejects.toBe(error) + }) + it('forwards a trusted _context that an LLM-supplied _context cannot override', async () => { mockTransformBlockTool.mockResolvedValue({ id: 'exa_search', diff --git a/apps/sim/executor/handlers/pi/sim-tools.ts b/apps/sim/executor/handlers/pi/sim-tools.ts index 61ca951483c..f49c511ce48 100644 --- a/apps/sim/executor/handlers/pi/sim-tools.ts +++ b/apps/sim/executor/handlers/pi/sim-tools.ts @@ -22,6 +22,7 @@ import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secr import { transformBlockTool } from '@/providers/utils' import { executeTool } from '@/tools' import { mergeToolParameters } from '@/tools/merge-params' +import { ToolSchemaEnrichmentError } from '@/tools/params' import type { ToolResponse } from '@/tools/types' import { getTool } from '@/tools/utils' import { getToolAsync } from '@/tools/utils.server' @@ -97,6 +98,12 @@ export async function buildSimToolSpecs( getAllBlocks, getTool, getToolAsync, + enrichmentContext: { + workflowId: ctx.workflowId, + workspaceId: ctx.workspaceId, + executionId: ctx.executionId, + userId: ctx.userId, + }, resolveCustomBlockBinding: (blockType: string) => resolveCustomBlockToolBinding(blockType, ctx.workspaceId), }) @@ -171,6 +178,7 @@ export async function buildSimToolSpecs( }, }) } catch (error) { + if (error instanceof ToolSchemaEnrichmentError) throw error logger.warn('Failed to adapt Sim tool for Pi', { type: tool.type, error: getErrorMessage(error), diff --git a/apps/sim/providers/utils.test.ts b/apps/sim/providers/utils.test.ts index 980839059da..c550b19dbcf 100644 --- a/apps/sim/providers/utils.test.ts +++ b/apps/sim/providers/utils.test.ts @@ -1622,6 +1622,78 @@ describe('transformBlockTool multi-instance unique IDs', () => { expect(result?.id).toBe('table_query_rows_tbl_abc') }) + it('resolves the canonical table id before enriching the LLM tool schema', async () => { + const enrichTool = vi.fn( + async ( + tableId: string, + schema: { + type: 'object' + properties: Record + required: string[] + } + ) => ({ + description: `Query rows from ${tableId}`, + parameters: { + ...schema, + properties: { + ...schema.properties, + customer_name: { type: 'string' }, + }, + }, + }) + ) + const result = await transformBlockTool( + { + type: 'table', + operation: 'query_rows', + params: { tableSelector: 'tbl_abc' }, + }, + { + selectedOperation: 'query_rows', + getAllBlocks, + enrichmentContext: { + workspaceId: 'workspace-1', + userId: 'user-1', + }, + getTool: (id: string) => ({ + id, + name: 'Query Rows', + description: 'Query table rows', + params: { + tableId: { type: 'string', required: true, visibility: 'user-only' }, + filter: { type: 'object', visibility: 'user-or-llm' }, + }, + toolEnrichment: { + dependsOn: 'tableId', + enrichTool, + }, + }), + } + ) + + expect(enrichTool).toHaveBeenCalledWith( + 'tbl_abc', + expect.objectContaining({ + properties: expect.objectContaining({ filter: expect.any(Object) }), + }), + 'Query table rows', + { + workspaceId: 'workspace-1', + userId: 'user-1', + } + ) + expect(result).toMatchObject({ + id: 'table_query_rows_tbl_abc', + description: 'Query rows from tbl_abc', + params: { tableSelector: 'tbl_abc' }, + parameters: { + properties: { + customer_name: { type: 'string' }, + }, + }, + }) + }) + it('appends the table id resolved from the advanced manual input', async () => { const result = await transformTable( { manualTableId: 'tbl_xyz' }, diff --git a/apps/sim/providers/utils.ts b/apps/sim/providers/utils.ts index e4e8931aaca..7d805394ea8 100644 --- a/apps/sim/providers/utils.ts +++ b/apps/sim/providers/utils.ts @@ -53,6 +53,7 @@ import { import type { ProviderId, ProviderToolConfig } from '@/providers/types' import { useProvidersStore } from '@/stores/providers/store' import { mergeToolParameters } from '@/tools/merge-params' +import type { WorkflowToolExecutionContext } from '@/tools/types' const logger = createLogger('ProviderUtils') @@ -629,6 +630,7 @@ export async function transformBlockTool( getTool: (toolId: string) => any getToolAsync?: (toolId: string) => Promise canonicalModes?: Record + enrichmentContext?: WorkflowToolExecutionContext /** * Server-only resolver for a custom (deploy-as-block) tool's binding (bound * workflow + input schema), org-scoped to the consumer. Injected as a dependency @@ -646,8 +648,15 @@ export async function transformBlockTool( toolIndex?: number } ): Promise { - const { selectedOperation, getAllBlocks, getTool, getToolAsync, canonicalModes, toolIndex } = - options + const { + selectedOperation, + getAllBlocks, + getTool, + getToolAsync, + canonicalModes, + enrichmentContext, + toolIndex, + } = options const scopedCanonicalModes = scopeCanonicalModesForTool(canonicalModes, toolIndex, block.type) const blockDef = getAllBlocks().find((b: any) => b.type === block.type) @@ -755,12 +764,6 @@ export async function transformBlockTool( const userProvidedParams = block.params || {} - const { - schema: llmSchema, - enrichedDescription, - modelBlockedParams, - } = await createLLMToolSchema(toolConfig, userProvidedParams) - const canonicalGroups: CanonicalGroup[] = blockDef?.subBlocks ? Object.values(buildCanonicalIndex(blockDef.subBlocks).groupsById).filter(isCanonicalPair) : [] @@ -771,6 +774,12 @@ export async function transformBlockTool( scopedCanonicalModes ) + const { + schema: llmSchema, + enrichedDescription, + modelBlockedParams, + } = await createLLMToolSchema(toolConfig, resolvedResourceParams, enrichmentContext) + let uniqueToolId = toolConfig.id let toolName = toolConfig.name let toolDescription = enrichedDescription || toolConfig.description diff --git a/apps/sim/tools/params.test.ts b/apps/sim/tools/params.test.ts index b7fd6a7ee00..85f515345a6 100644 --- a/apps/sim/tools/params.test.ts +++ b/apps/sim/tools/params.test.ts @@ -12,6 +12,7 @@ import { isPasswordParameter, type ToolParameterConfig, type ToolSchema, + ToolSchemaEnrichmentError, type ValidationResult, validateToolParameters, } from '@/tools/params' @@ -130,6 +131,27 @@ describe('Tool Parameters Utils', () => { expect(schema.required).not.toContain('apiKey') // user-only, never required for LLM expect(schema.required).toContain('message') // user-or-llm + required: true }) + + it('wraps tool enrichment failures so execution boundaries can fail fast', async () => { + const cause = new Error('table metadata unavailable') + const toolConfig = { + ...mockToolConfig, + toolEnrichment: { + dependsOn: 'tableId', + enrichTool: vi.fn().mockRejectedValue(cause), + }, + } + + const error = await createLLMToolSchema(toolConfig, { tableId: 'tbl_123' }).catch( + (caught) => caught + ) + + expect(error).toBeInstanceOf(ToolSchemaEnrichmentError) + expect(error).toMatchObject({ + message: 'Failed to enrich schema for tool "test_tool"', + cause, + }) + }) }) describe('createUserToolSchema', () => { diff --git a/apps/sim/tools/params.ts b/apps/sim/tools/params.ts index 8f5fb3e55d1..fb4fed18287 100644 --- a/apps/sim/tools/params.ts +++ b/apps/sim/tools/params.ts @@ -25,6 +25,7 @@ import type { ParameterVisibility, ToolConfig, ToolParameterItemSchema, + WorkflowToolExecutionContext, } from '@/tools/types' const logger = createLogger('ToolsParams') @@ -155,6 +156,13 @@ export interface LLMToolSchemaResult { modelBlockedParams?: string[] } +export class ToolSchemaEnrichmentError extends Error { + constructor(toolId: string, cause: unknown) { + super(`Failed to enrich schema for tool "${toolId}"`, { cause }) + this.name = 'ToolSchemaEnrichmentError' + } +} + export interface ValidationResult { valid: boolean missingParams: string[] @@ -630,7 +638,8 @@ export function createUserToolSchema( export async function createLLMToolSchema( toolConfig: ToolConfig, - userProvidedParams: Record + userProvidedParams: Record, + enrichmentContext: WorkflowToolExecutionContext = {} ): Promise { const schema: ToolSchema = { type: 'object', @@ -704,11 +713,17 @@ export async function createLLMToolSchema( if (toolConfig.toolEnrichment) { const dependencyValue = userProvidedParams[toolConfig.toolEnrichment.dependsOn] as string if (dependencyValue) { - const enriched = await toolConfig.toolEnrichment.enrichTool( - dependencyValue, - schema, - toolConfig.description - ) + let enriched + try { + enriched = await toolConfig.toolEnrichment.enrichTool( + dependencyValue, + schema, + toolConfig.description, + enrichmentContext + ) + } catch (error) { + throw new ToolSchemaEnrichmentError(toolConfig.id, error) + } if (enriched) { return { schema: enriched.parameters as ToolSchema, diff --git a/apps/sim/tools/schema-enrichers.test.ts b/apps/sim/tools/schema-enrichers.test.ts new file mode 100644 index 00000000000..655507ab514 --- /dev/null +++ b/apps/sim/tools/schema-enrichers.test.ts @@ -0,0 +1,104 @@ +/** + * @vitest-environment node + */ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' + +const { mockBuildAPIUrl, mockBuildAuthHeaders, mockExtractAPIErrorMessage } = vi.hoisted(() => ({ + mockBuildAPIUrl: vi.fn((path: string, params?: Record) => { + const url = new URL(path, 'http://localhost:3000') + for (const [key, value] of Object.entries(params ?? {})) { + url.searchParams.set(key, value) + } + return url + }), + mockBuildAuthHeaders: vi.fn(), + mockExtractAPIErrorMessage: vi.fn(), +})) + +vi.mock('@/executor/utils/http', () => ({ + buildAPIUrl: mockBuildAPIUrl, + buildAuthHeaders: mockBuildAuthHeaders, + extractAPIErrorMessage: mockExtractAPIErrorMessage, +})) + +import { enrichTableToolSchema } from '@/tools/schema-enrichers' + +const ORIGINAL_SCHEMA = { + type: 'object' as const, + properties: { + filter: { type: 'object' }, + sort: { type: 'object' }, + }, + required: [], +} + +describe('enrichTableToolSchema', () => { + beforeEach(() => { + vi.clearAllMocks() + mockBuildAuthHeaders.mockResolvedValue({ Authorization: 'Bearer internal-token' }) + }) + + afterEach(() => { + vi.unstubAllGlobals() + }) + + it('fetches the table through the authenticated detail route and enriches the schema', async () => { + const mockFetch = vi.fn().mockResolvedValue( + new Response( + JSON.stringify({ + success: true, + data: { + table: { + name: 'Customers', + schema: { + columns: [ + { name: 'email', type: 'string' }, + { name: 'score', type: 'number' }, + ], + }, + }, + }, + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ) + ) + vi.stubGlobal('fetch', mockFetch) + + const result = await enrichTableToolSchema( + 'table-1', + 'table_query_rows', + ORIGINAL_SCHEMA, + 'Query rows', + { workspaceId: 'workspace-1', userId: 'user-1' } + ) + + expect(mockBuildAuthHeaders).toHaveBeenCalledWith('user-1') + expect(mockFetch).toHaveBeenCalledWith( + 'http://localhost:3000/api/table/table-1?workspaceId=workspace-1', + { headers: { Authorization: 'Bearer internal-token' } } + ) + expect(result.description).toContain('Table "Customers" columns:') + expect(result.parameters.required).toContain('filter') + expect(result.parameters.properties.filter).toMatchObject({ + description: expect.stringContaining('email, score'), + }) + }) + + it('fails when the table detail request fails', async () => { + vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(null, { status: 404 }))) + mockExtractAPIErrorMessage.mockResolvedValue('Table not found') + + await expect( + enrichTableToolSchema('missing-table', 'table_query_rows', ORIGINAL_SCHEMA, 'Query rows', { + workspaceId: 'workspace-1', + userId: 'user-1', + }) + ).rejects.toThrow('Failed to fetch table schema for missing-table: Table not found') + }) + + it('fails when trusted execution identity is missing', async () => { + await expect( + enrichTableToolSchema('table-1', 'table_query_rows', ORIGINAL_SCHEMA, 'Query rows', {}) + ).rejects.toThrow('Workspace ID is required to enrich table tool schema for table-1') + }) +}) diff --git a/apps/sim/tools/schema-enrichers.ts b/apps/sim/tools/schema-enrichers.ts index 08bc43468ff..a0132aa6da7 100644 --- a/apps/sim/tools/schema-enrichers.ts +++ b/apps/sim/tools/schema-enrichers.ts @@ -1,33 +1,57 @@ import { createLogger } from '@sim/logger' +import { isRecordLike } from '@sim/utils/object' +import { isColumnType } from '@/lib/table/column-types' import { enrichTableToolDescription, enrichTableToolParameters } from '@/lib/table/llm/enrichment' import type { TableSummary } from '@/lib/table/types' +import type { WorkflowToolExecutionContext } from '@/tools/types' const logger = createLogger('SchemaEnrichers') -async function fetchTableSchema(tableId: string): Promise { - try { - const { buildAuthHeaders, buildAPIUrl } = await import('@/executor/utils/http') +async function fetchTableSchema( + tableId: string, + context: WorkflowToolExecutionContext +): Promise { + if (!context.workspaceId) { + throw new Error(`Workspace ID is required to enrich table tool schema for ${tableId}`) + } + if (!context.userId) { + throw new Error(`User ID is required to enrich table tool schema for ${tableId}`) + } - const headers = await buildAuthHeaders() - const url = buildAPIUrl(`/api/table/${tableId}/schema`) + const { buildAuthHeaders, buildAPIUrl, extractAPIErrorMessage } = await import( + '@/executor/utils/http' + ) - const response = await fetch(url.toString(), { headers }) - if (!response.ok) { - logger.warn(`Failed to fetch table schema for ${tableId}: ${response.status}`) - return null - } + const headers = await buildAuthHeaders(context.userId) + const url = buildAPIUrl(`/api/table/${tableId}`, { workspaceId: context.workspaceId }) + const response = await fetch(url.toString(), { headers }) - const result = await response.json() - const data = result.data || result + if (!response.ok) { + const message = await extractAPIErrorMessage(response) + throw new Error(`Failed to fetch table schema for ${tableId}: ${message}`) + } - return { - name: data.name || 'Table', - columns: data.columns || [], - } - } catch (error) { - logger.error('Failed to fetch table schema:', error) - return null + const result: unknown = await response.json() + if (!isRecordLike(result) || !isRecordLike(result.data) || !isRecordLike(result.data.table)) { + throw new Error(`Invalid table response while enriching schema for ${tableId}`) + } + + const table = result.data.table + if (typeof table.name !== 'string' || !isRecordLike(table.schema)) { + throw new Error(`Invalid table metadata while enriching schema for ${tableId}`) + } + if (!Array.isArray(table.schema.columns)) { + throw new Error(`Invalid table columns while enriching schema for ${tableId}`) } + + const columns = table.schema.columns.map((column, index) => { + if (!isRecordLike(column) || typeof column.name !== 'string' || !isColumnType(column.type)) { + throw new Error(`Invalid table column ${index} while enriching schema for ${tableId}`) + } + return { name: column.name, type: column.type } + }) + + return { name: table.name, columns } } export async function enrichTableToolSchema( @@ -38,7 +62,8 @@ export async function enrichTableToolSchema( properties: Record required: string[] }, - originalDescription: string + originalDescription: string, + context: WorkflowToolExecutionContext ): Promise<{ description: string parameters: { @@ -46,12 +71,8 @@ export async function enrichTableToolSchema( properties: Record required: string[] } -} | null> { - const tableSchema = await fetchTableSchema(tableId) - - if (!tableSchema) { - return null - } +}> { + const tableSchema = await fetchTableSchema(tableId, context) const enrichedDescription = enrichTableToolDescription(originalDescription, tableSchema, toolId) const enrichedParams = enrichTableToolParameters( diff --git a/apps/sim/tools/table/batch_insert_rows.ts b/apps/sim/tools/table/batch_insert_rows.ts index e12d2920b6d..39fdb2f228d 100644 --- a/apps/sim/tools/table/batch_insert_rows.ts +++ b/apps/sim/tools/table/batch_insert_rows.ts @@ -15,8 +15,8 @@ export const tableBatchInsertRowsTool: ToolConfig< toolEnrichment: { dependsOn: 'tableId', - enrichTool: (tableId, schema, desc) => - enrichTableToolSchema(tableId, 'table_batch_insert_rows', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_batch_insert_rows', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/delete_rows_by_filter.ts b/apps/sim/tools/table/delete_rows_by_filter.ts index 64fbcc35de5..cad82ba66aa 100644 --- a/apps/sim/tools/table/delete_rows_by_filter.ts +++ b/apps/sim/tools/table/delete_rows_by_filter.ts @@ -15,8 +15,8 @@ export const tableDeleteRowsByFilterTool: ToolConfig< toolEnrichment: { dependsOn: 'tableId', - enrichTool: (tableId, schema, desc) => - enrichTableToolSchema(tableId, 'table_delete_rows_by_filter', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_delete_rows_by_filter', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/insert_row.ts b/apps/sim/tools/table/insert_row.ts index 4573d6fec7e..b8751610019 100644 --- a/apps/sim/tools/table/insert_row.ts +++ b/apps/sim/tools/table/insert_row.ts @@ -12,8 +12,8 @@ export const tableInsertRowTool: ToolConfig - enrichTableToolSchema(tableId, 'table_insert_row', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_insert_row', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/query_rows.ts b/apps/sim/tools/table/query_rows.ts index ddc743b0322..828c9f775b5 100644 --- a/apps/sim/tools/table/query_rows.ts +++ b/apps/sim/tools/table/query_rows.ts @@ -11,8 +11,8 @@ export const tableQueryRowsTool: ToolConfig - enrichTableToolSchema(tableId, 'table_query_rows', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_query_rows', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/update_row.ts b/apps/sim/tools/table/update_row.ts index 0305ea3301a..c9792f95680 100644 --- a/apps/sim/tools/table/update_row.ts +++ b/apps/sim/tools/table/update_row.ts @@ -12,8 +12,8 @@ export const tableUpdateRowTool: ToolConfig - enrichTableToolSchema(tableId, 'table_update_row', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_update_row', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/update_rows_by_filter.ts b/apps/sim/tools/table/update_rows_by_filter.ts index 05deda6791c..d1f2b759eba 100644 --- a/apps/sim/tools/table/update_rows_by_filter.ts +++ b/apps/sim/tools/table/update_rows_by_filter.ts @@ -16,8 +16,8 @@ export const tableUpdateRowsByFilterTool: ToolConfig< toolEnrichment: { dependsOn: 'tableId', - enrichTool: (tableId, schema, desc) => - enrichTableToolSchema(tableId, 'table_update_rows_by_filter', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_update_rows_by_filter', schema, desc, context), }, params: { diff --git a/apps/sim/tools/table/upsert_row.ts b/apps/sim/tools/table/upsert_row.ts index 88af9342291..70afc179872 100644 --- a/apps/sim/tools/table/upsert_row.ts +++ b/apps/sim/tools/table/upsert_row.ts @@ -12,8 +12,8 @@ export const tableUpsertRowTool: ToolConfig - enrichTableToolSchema(tableId, 'table_upsert_row', schema, desc), + enrichTool: (tableId, schema, desc, context) => + enrichTableToolSchema(tableId, 'table_upsert_row', schema, desc, context), }, params: { diff --git a/apps/sim/tools/types.ts b/apps/sim/tools/types.ts index 9db38f022b7..fc2e25436c7 100644 --- a/apps/sim/tools/types.ts +++ b/apps/sim/tools/types.ts @@ -339,7 +339,8 @@ interface ToolEnrichmentConfig { properties: Record required: string[] }, - originalDescription: string + originalDescription: string, + context: WorkflowToolExecutionContext ) => Promise<{ description: string parameters: {