Skip to content

Commit cdd0f75

Browse files
authored
fix(mothership): fix mothership file uploads (#3640)
* Fix files * Fix * Fix
1 parent 25a03f1 commit cdd0f75

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function toDisplayAttachment(f: TaskStoredFileAttachment): ChatMessageAttachment
132132
media_type: f.media_type,
133133
size: f.size,
134134
previewUrl: f.media_type.startsWith('image/')
135-
? `/api/files/serve/${encodeURIComponent(f.key)}?context=copilot`
135+
? `/api/files/serve/${encodeURIComponent(f.key)}?context=mothership`
136136
: undefined,
137137
}
138138
}

apps/sim/lib/uploads/contexts/workspace/workspace-file-manager.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,9 @@ export async function uploadWorkspaceFile(
209209

210210
/**
211211
* Track a file that was already uploaded to workspace S3 as a chat-scoped upload.
212-
* Creates a workspaceFiles record with context='mothership' and the given chatId.
213-
* No S3 operations -- the file is already in storage from the presigned/upload step.
212+
* Links the existing workspaceFiles metadata record (created by the storage service
213+
* during upload) to the chat by setting chatId and context='mothership'.
214+
* Falls back to inserting a new record if none exists for the key.
214215
*/
215216
export async function trackChatUpload(
216217
workspaceId: string,
@@ -221,6 +222,17 @@ export async function trackChatUpload(
221222
contentType: string,
222223
size: number
223224
): Promise<void> {
225+
const updated = await db
226+
.update(workspaceFiles)
227+
.set({ chatId, context: 'mothership' })
228+
.where(and(eq(workspaceFiles.key, s3Key), eq(workspaceFiles.workspaceId, workspaceId), isNull(workspaceFiles.deletedAt)))
229+
.returning({ id: workspaceFiles.id })
230+
231+
if (updated.length > 0) {
232+
logger.info(`Linked existing file record to chat: ${fileName} for chat ${chatId}`)
233+
return
234+
}
235+
224236
const fileId = `wf_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`
225237

226238
await db.insert(workspaceFiles).values({

0 commit comments

Comments
 (0)