Skip to content

Commit 8d84c30

Browse files
authored
feat(copilot): add rename operation to user_table tool (#3691)
* feat(copilot): add rename operation to user_table tool * fix(copilot): use newName instead of name for table rename operation
1 parent e796dfe commit 8d84c30

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

apps/sim/lib/copilot/tools/server/table/user-table.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
insertRow,
1919
queryRows,
2020
renameColumn,
21+
renameTable,
2122
updateColumnConstraints,
2223
updateColumnType,
2324
updateRow,
@@ -878,6 +879,36 @@ export const userTableServerTool: BaseServerTool<UserTableArgs, UserTableResult>
878879
}
879880
}
880881

882+
case 'rename': {
883+
if (!args.tableId) {
884+
return { success: false, message: 'Table ID is required' }
885+
}
886+
const newName = (args as Record<string, unknown>).newName as string | undefined
887+
if (!newName) {
888+
return { success: false, message: 'newName is required for renaming a table' }
889+
}
890+
if (!workspaceId) {
891+
return { success: false, message: 'Workspace ID is required' }
892+
}
893+
894+
const table = await getTableById(args.tableId)
895+
if (!table) {
896+
return { success: false, message: `Table not found: ${args.tableId}` }
897+
}
898+
if (table.workspaceId !== workspaceId) {
899+
return { success: false, message: 'Table not found' }
900+
}
901+
902+
const requestId = crypto.randomUUID().slice(0, 8)
903+
const renamed = await renameTable(args.tableId, newName, requestId)
904+
905+
return {
906+
success: true,
907+
message: `Renamed table to "${renamed.name}"`,
908+
data: { table: { id: renamed.id, name: renamed.name } },
909+
}
910+
}
911+
881912
default:
882913
return { success: false, message: `Unknown operation: ${operation}` }
883914
}

apps/sim/lib/copilot/tools/shared/schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export const UserTableArgsSchema = z.object({
127127
'rename_column',
128128
'delete_column',
129129
'update_column',
130+
'rename',
130131
]),
131132
args: z
132133
.object({

0 commit comments

Comments
 (0)