fix(mothership): fix mothership file uploads (#3640)

* Fix files

* Fix

* Fix
This commit is contained in:
Siddharth Ganesan
2026-03-17 16:19:47 -07:00
committed by GitHub
parent 25a03f1f3c
commit cdd0f75cd5
2 changed files with 15 additions and 3 deletions

View File

@@ -132,7 +132,7 @@ function toDisplayAttachment(f: TaskStoredFileAttachment): ChatMessageAttachment
media_type: f.media_type,
size: f.size,
previewUrl: f.media_type.startsWith('image/')
? `/api/files/serve/${encodeURIComponent(f.key)}?context=copilot`
? `/api/files/serve/${encodeURIComponent(f.key)}?context=mothership`
: undefined,
}
}

View File

@@ -209,8 +209,9 @@ export async function uploadWorkspaceFile(
/**
* Track a file that was already uploaded to workspace S3 as a chat-scoped upload.
* Creates a workspaceFiles record with context='mothership' and the given chatId.
* No S3 operations -- the file is already in storage from the presigned/upload step.
* Links the existing workspaceFiles metadata record (created by the storage service
* during upload) to the chat by setting chatId and context='mothership'.
* Falls back to inserting a new record if none exists for the key.
*/
export async function trackChatUpload(
workspaceId: string,
@@ -221,6 +222,17 @@ export async function trackChatUpload(
contentType: string,
size: number
): Promise<void> {
const updated = await db
.update(workspaceFiles)
.set({ chatId, context: 'mothership' })
.where(and(eq(workspaceFiles.key, s3Key), eq(workspaceFiles.workspaceId, workspaceId), isNull(workspaceFiles.deletedAt)))
.returning({ id: workspaceFiles.id })
if (updated.length > 0) {
logger.info(`Linked existing file record to chat: ${fileName} for chat ${chatId}`)
return
}
const fileId = `wf_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`
await db.insert(workspaceFiles).values({