From a31dc733cf027a9e251e7456882b5c152b938fce Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com> Date: Fri, 7 Nov 2025 11:40:13 -0800 Subject: [PATCH] fix(copilot): fix image auth (#1841) * Fix copilot image auth * Lint * Remove extra loggign * Update apps/sim/app/api/copilot/chat/route.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- apps/sim/app/api/copilot/chat/route.ts | 1 + apps/sim/app/api/files/authorization.ts | 2 +- apps/sim/app/api/files/upload/route.ts | 9 ++++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/sim/app/api/copilot/chat/route.ts b/apps/sim/app/api/copilot/chat/route.ts index 5a90b167b..71f8981dc 100644 --- a/apps/sim/app/api/copilot/chat/route.ts +++ b/apps/sim/app/api/copilot/chat/route.ts @@ -325,6 +325,7 @@ export async function POST(req: NextRequest) { ...(processedFileContents.length > 0 && { fileAttachments: processedFileContents }), } + try { logger.info(`[${tracker.requestId}] About to call Sim Agent`, { hasContext: agentContexts.length > 0, diff --git a/apps/sim/app/api/files/authorization.ts b/apps/sim/app/api/files/authorization.ts index f2cb2673b..3291eda56 100644 --- a/apps/sim/app/api/files/authorization.ts +++ b/apps/sim/app/api/files/authorization.ts @@ -122,7 +122,7 @@ export async function verifyFileAccess( } // 2. Execution files: workspace_id/workflow_id/execution_id/filename - if (inferredContext === 'execution' || isExecutionFile(cloudKey, bucketType)) { + if (inferredContext === 'execution' || (!context && isExecutionFile(cloudKey, bucketType))) { return await verifyExecutionFileAccess(cloudKey, userId, customConfig) } diff --git a/apps/sim/app/api/files/upload/route.ts b/apps/sim/app/api/files/upload/route.ts index 663164ebb..ce0b96cff 100644 --- a/apps/sim/app/api/files/upload/route.ts +++ b/apps/sim/app/api/files/upload/route.ts @@ -245,6 +245,11 @@ export async function POST(request: NextRequest) { logger.info(`Uploading ${context} file: ${originalName}`) + // Generate storage key with context prefix and timestamp to ensure uniqueness + const timestamp = Date.now() + const safeFileName = originalName.replace(/\s+/g, '-') + const storageKey = `${context}/${timestamp}-${safeFileName}` + const metadata: Record = { originalName: originalName, uploadedAt: new Date().toISOString(), @@ -258,9 +263,11 @@ export async function POST(request: NextRequest) { const fileInfo = await storageService.uploadFile({ file: buffer, - fileName: originalName, + fileName: storageKey, contentType: file.type, context, + preserveKey: true, + customKey: storageKey, metadata, })