MCPcopy Index your code
hub / github.com/simstudioai/sim / execute

Function execute

apps/sim/lib/copilot/tools/server/files/delete-file.ts:32–106  ·  view source on GitHub ↗
(params: DeleteFileArgs, context?: ServerToolContext)

Source from the content-addressed store, hash-verified

30export const deleteFileServerTool: BaseServerTool<DeleteFileArgs, DeleteFileResult> = {
31 name: DeleteFile.id,
32 async execute(params: DeleteFileArgs, context?: ServerToolContext): Promise<DeleteFileResult> {
33 if (!context?.userId) {
34 throw new Error('Authentication required')
35 }
36 const workspaceId = context.workspaceId
37 if (!workspaceId) {
38 return { success: false, message: 'Workspace ID is required' }
39 }
40 await ensureWorkspaceAccess(workspaceId, context.userId, 'write')
41
42 const nested = params.args
43 const paths: string[] =
44 params.paths ??
45 (nested?.paths as string[] | undefined) ??
46 [params.path || (nested?.path as string) || ''].filter(Boolean)
47 const legacyFileIds: string[] =
48 params.fileIds ??
49 (nested?.fileIds as string[] | undefined) ??
50 [params.fileId || (nested?.fileId as string) || ''].filter(Boolean)
51
52 if (paths.length === 0 && legacyFileIds.length === 0) {
53 return { success: false, message: 'paths is required' }
54 }
55
56 const deletable: { id: string; name: string }[] = []
57 const failed: string[] = []
58
59 for (const path of paths) {
60 const existingFile = await resolveWorkspaceFileReference(workspaceId, path)
61 if (!existingFile) {
62 failed.push(path)
63 continue
64 }
65 deletable.push({ id: existingFile.id, name: existingFile.name })
66 }
67
68 for (const fileId of legacyFileIds) {
69 const existingFile = await getWorkspaceFile(workspaceId, fileId)
70 if (!existingFile) {
71 failed.push(fileId)
72 continue
73 }
74 deletable.push({ id: fileId, name: existingFile.name })
75 }
76
77 if (deletable.length > 0) {
78 assertServerToolNotAborted(context)
79 const result = await performDeleteWorkspaceFileItems({
80 workspaceId,
81 userId: context.userId,
82 fileIds: deletable.map((file) => file.id),
83 })
84 if (!result.success) {
85 return { success: false, message: result.error || 'Failed to delete files' }
86 }
87 }
88
89 for (const file of deletable) {

Callers

nothing calls this directly

Calls 8

ensureWorkspaceAccessFunction · 0.90
getWorkspaceFileFunction · 0.90
infoMethod · 0.80
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected