Skip to content

Commit 0d1bdbb

Browse files
committed
fix(copilot): store tool file outputs from workspace chats under the Copilot user
1 parent 65b247f commit 0d1bdbb

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎apps/sim/lib/internal/tool-operations/file-result.server.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const runContext: InternalToolOperationContext = {
5353
const copilotContext: InternalToolOperationContext = {
5454
workspaceId: 'workspace-1',
5555
workflowId: '',
56+
executionId: 'copilot-run-1',
5657
userId: 'user-1',
5758
copilotToolExecution: true,
5859
}
@@ -158,6 +159,20 @@ describe('presentInternalToolOperationResult', () => {
158159
expect(mockUploadExecutionFile).not.toHaveBeenCalled()
159160
})
160161

162+
it("keeps a Mothership block's files in its parent workflow run", async () => {
163+
await presentInternalToolOperationResult(
164+
createInternalToolFileResult(file(), (stored) => ({ file: stored })),
165+
{ ...runContext, copilotToolExecution: true }
166+
)
167+
168+
expect(mockUploadExecutionFile.mock.calls[0]?.[0]).toEqual({
169+
workspaceId: 'workspace-1',
170+
workflowId: 'workflow-1',
171+
executionId: 'execution-1',
172+
})
173+
expect(mockUploadCopilotFile).not.toHaveBeenCalled()
174+
})
175+
161176
it('replaces binary representation headers before the JSON transport size check', async () => {
162177
const input = file(Buffer.alloc(12 * 1024 * 1024))
163178
const headers = new Headers({

‎apps/sim/lib/internal/tool-operations/file-result.server.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function resolveCopilotUserId(context: InternalToolOperationContext): string {
5252
}
5353

5454
function resolveFileStorageScope(context: InternalToolOperationContext): FileStorageScope {
55-
if (context.executionId) {
55+
// A workspace Copilot turn's executionId names the turn, not a workflow run.
56+
const isWorkflowlessCopilotTurn = context.copilotToolExecution && !context.workflowId.trim()
57+
if (context.executionId && !isWorkflowlessCopilotTurn) {
5658
if (!context.workspaceId?.trim() || !context.workflowId.trim() || !context.executionId.trim()) {
5759
throw new Error('Execution file output requires a complete trusted execution scope')
5860
}

0 commit comments

Comments
 (0)