Skip to content
Prev Previous commit
Next Next commit
Handle writing to same file name gracefully
  • Loading branch information
Theodore Li committed Mar 30, 2026
commit d5352a7bfbfc69e86040df65c426be18a6e40154
8 changes: 0 additions & 8 deletions apps/sim/app/api/tools/file/manage/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ export async function POST(request: NextRequest) {
)
}

const existing = await getWorkspaceFileByName(workspaceId, fileName)
if (existing) {
return NextResponse.json(
{ success: false, error: `File already exists: "${fileName}"` },
{ status: 409 }
)
}

const mimeType = contentType || getMimeTypeFromExtension(getFileExtension(fileName))
const fileBuffer = Buffer.from(content ?? '', 'utf-8')
const result = await uploadWorkspaceFile(
Expand Down
6 changes: 4 additions & 2 deletions apps/sim/tools/file/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ interface FileWriteParams {
export const fileWriteTool: ToolConfig<FileWriteParams, ToolResponse> = {
id: 'file_write',
name: 'File Write',
description: 'Create a new workspace file. Fails if a file with the same name already exists.',
description:
'Create a new workspace file. If a file with the same name already exists, a numeric suffix is added (e.g., "data (1).csv").',
version: '1.0.0',

params: {
fileName: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'File name (e.g., "data.csv"). Fails if a file with this name already exists.',
description:
'File name (e.g., "data.csv"). If a file with this name exists, a numeric suffix is added automatically.',
},
content: {
type: 'string',
Expand Down
Loading