Skip to content

Commit d2074e4

Browse files
fix(copilot): upload sandbox-rendered bytes for docx/pptx/pdf creation
1 parent d895e0e commit d2074e4

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

apps/sim/lib/copilot/tools/server/files/edit-content.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,10 @@ export const editContentServerTool: BaseServerTool<EditContentArgs, EditContentR
201201
return { success: false, message: `Unsupported operation in intent: ${operation}` }
202202
}
203203

204+
let fileBuffer: Buffer
204205
if (docInfo.isDoc) {
205206
try {
206-
await runSandboxTask(
207+
fileBuffer = await runSandboxTask(
207208
docInfo.taskId!,
208209
{ code: finalContent, workspaceId },
209210
{ ownerKey: `user:${context.userId}`, signal: context.abortSignal }
@@ -215,9 +216,9 @@ export const editContentServerTool: BaseServerTool<EditContentArgs, EditContentR
215216
message: `${docInfo.formatName} generation failed: ${msg}. Fix the content and retry.`,
216217
}
217218
}
219+
} else {
220+
fileBuffer = Buffer.from(finalContent, 'utf-8')
218221
}
219-
220-
const fileBuffer = Buffer.from(finalContent, 'utf-8')
221222
assertServerToolNotAborted(context)
222223
const mime = docInfo.sourceMime || inferContentType(fileRecord.name, intent.contentType)
223224
await updateWorkspaceFileContent(workspaceId, intent.fileId, context.userId, fileBuffer, mime)

apps/sim/lib/copilot/tools/server/files/workspace-file.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,10 @@ export const workspaceFileServerTool: BaseServerTool<WorkspaceFileArgs, Workspac
199199

200200
const docInfo = getDocumentFormatInfo(fileName)
201201
let contentType = inferContentType(fileName, explicitType)
202+
let fileBuffer: Buffer
202203
if (docInfo.isDoc) {
203204
try {
204-
await runSandboxTask(
205+
fileBuffer = await runSandboxTask(
205206
docInfo.taskId!,
206207
{ code: content, workspaceId },
207208
{ ownerKey: `user:${context.userId}`, signal: context.abortSignal }
@@ -214,9 +215,9 @@ export const workspaceFileServerTool: BaseServerTool<WorkspaceFileArgs, Workspac
214215
}
215216
}
216217
contentType = docInfo.sourceMime!
218+
} else {
219+
fileBuffer = Buffer.from(content, 'utf-8')
217220
}
218-
219-
const fileBuffer = Buffer.from(content, 'utf-8')
220221
assertServerToolNotAborted(context)
221222
const result = await uploadWorkspaceFile(
222223
workspaceId,

0 commit comments

Comments
 (0)