This commit is contained in:
Lakee Sivaraya
2026-01-16 15:08:31 -08:00
parent 94c6795efc
commit 3d81c1cc14
4 changed files with 5 additions and 57 deletions

View File

@@ -43,58 +43,6 @@ function normalizeToolId(toolId: string): string {
*/
const MAX_REQUEST_BODY_SIZE_BYTES = 10 * 1024 * 1024 // 10MB
/**
* Parameter aliases that LLMs commonly use as synonyms.
* Maps alternative parameter names to their canonical names.
* Key: toolId, Value: map of alias -> canonical parameter name
*/
const PARAMETER_ALIASES: Record<string, Record<string, string>> = {
table_update_row: {
values: 'data',
row: 'data',
fields: 'data',
update: 'data',
updates: 'data',
changes: 'data',
newData: 'data',
rowData: 'data',
},
table_insert_row: {
values: 'data',
row: 'data',
fields: 'data',
rowData: 'data',
},
table_upsert_row: {
values: 'data',
row: 'data',
fields: 'data',
rowData: 'data',
},
}
/**
* Applies parameter aliases to normalize LLM-provided parameters.
* If the LLM uses an alias (e.g., "values" instead of "data"),
* this function maps it to the canonical parameter name.
*/
function applyParameterAliases(toolId: string, params: Record<string, any>): Record<string, any> {
const aliases = PARAMETER_ALIASES[toolId]
if (!aliases) return params
const normalizedParams = { ...params }
for (const [alias, canonical] of Object.entries(aliases)) {
// If the alias is present and the canonical name is not, copy the value
if (alias in normalizedParams && !(canonical in normalizedParams)) {
normalizedParams[canonical] = normalizedParams[alias]
delete normalizedParams[alias]
}
}
return normalizedParams
}
/**
* User-friendly error message for body size limit exceeded
*/
@@ -287,8 +235,7 @@ export async function executeTool(
}
// Ensure context is preserved if it exists
// Apply parameter aliases to handle common LLM synonym usage (e.g., "values" -> "data")
const contextParams = applyParameterAliases(normalizedToolId, { ...params })
const contextParams = { ...params }
// Validate the tool and its parameters
validateRequiredParametersAfterMerge(toolId, tool, contextParams)

View File

@@ -4,7 +4,8 @@ import type { TableRowInsertParams, TableRowResponse } from './types'
export const tableInsertRowTool: ToolConfig<TableRowInsertParams, TableRowResponse> = {
id: 'table_insert_row',
name: 'Insert Row',
description: 'Insert a new row into a table',
description:
'Insert a new row into a table. IMPORTANT: You must use the "data" parameter (not "values", "row", "fields", or other variations) to specify the row contents.',
version: '1.0.0',
params: {

View File

@@ -5,7 +5,7 @@ export const tableUpdateRowTool: ToolConfig<TableRowUpdateParams, TableRowRespon
id: 'table_update_row',
name: 'Update Row',
description:
'Update an existing row in a table. Supports partial updates - only include the fields you want to change.',
'Update an existing row in a table. Supports partial updates - only include the fields you want to change. IMPORTANT: You must use the "data" parameter (not "values", "row", "fields", or other variations) to specify the fields to update.',
version: '1.0.0',
params: {

View File

@@ -14,7 +14,7 @@ export const tableUpsertRowTool: ToolConfig<TableRowInsertParams, TableUpsertRes
id: 'table_upsert_row',
name: 'Upsert Row',
description:
'Insert or update a row based on unique column constraints. If a row with matching unique field exists, update it; otherwise insert a new row.',
'Insert or update a row based on unique column constraints. If a row with matching unique field exists, update it; otherwise insert a new row. IMPORTANT: You must use the "data" parameter (not "values", "row", "fields", or other variations) to specify the row contents.',
version: '1.0.0',
params: {