diff --git a/apps/sim/lib/copilot/tools/server/table/user-table.ts b/apps/sim/lib/copilot/tools/server/table/user-table.ts index ec64397ea0..733e10ca41 100644 --- a/apps/sim/lib/copilot/tools/server/table/user-table.ts +++ b/apps/sim/lib/copilot/tools/server/table/user-table.ts @@ -18,6 +18,7 @@ import { insertRow, queryRows, renameColumn, + renameTable, updateColumnConstraints, updateColumnType, updateRow, @@ -878,6 +879,36 @@ export const userTableServerTool: BaseServerTool } } + case 'rename': { + if (!args.tableId) { + return { success: false, message: 'Table ID is required' } + } + const newName = (args as Record).newName as string | undefined + if (!newName) { + return { success: false, message: 'newName is required for renaming a table' } + } + if (!workspaceId) { + return { success: false, message: 'Workspace ID is required' } + } + + const table = await getTableById(args.tableId) + if (!table) { + return { success: false, message: `Table not found: ${args.tableId}` } + } + if (table.workspaceId !== workspaceId) { + return { success: false, message: 'Table not found' } + } + + const requestId = crypto.randomUUID().slice(0, 8) + const renamed = await renameTable(args.tableId, newName, requestId) + + return { + success: true, + message: `Renamed table to "${renamed.name}"`, + data: { table: { id: renamed.id, name: renamed.name } }, + } + } + default: return { success: false, message: `Unknown operation: ${operation}` } } diff --git a/apps/sim/lib/copilot/tools/shared/schemas.ts b/apps/sim/lib/copilot/tools/shared/schemas.ts index addf280c05..26a2f39113 100644 --- a/apps/sim/lib/copilot/tools/shared/schemas.ts +++ b/apps/sim/lib/copilot/tools/shared/schemas.ts @@ -127,6 +127,7 @@ export const UserTableArgsSchema = z.object({ 'rename_column', 'delete_column', 'update_column', + 'rename', ]), args: z .object({