Skip to content

Commit 5c0c364

Browse files
authored
fix(mship): fix image handling (#6357)
1 parent aae9ce6 commit 5c0c364

3 files changed

Lines changed: 47 additions & 17 deletions

File tree

apps/sim/lib/copilot/chat/payload.test.ts

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -374,19 +374,46 @@ describe('buildCopilotRequestPayload', () => {
374374
])
375375
})
376376

377-
it('fails the request when an authorized attachment cannot be prepared', async () => {
377+
it('isolates a failed attachment and still prepares valid siblings', async () => {
378378
const cause = new Error('provenance sidecar unavailable')
379-
mockTrackChatUpload.mockRejectedValueOnce(cause)
380-
381-
await expect(
382-
buildCopilotRequestPayload(
383-
{ ...attachmentParams, userPermission: 'write' },
384-
{ selectedModel: 'claude-opus-4-8' }
385-
)
386-
).rejects.toMatchObject({
387-
message: 'Failed to prepare attached file "payroll.xlsx" for Copilot. Please try again.',
388-
cause,
389-
})
379+
mockTrackChatUpload
380+
.mockRejectedValueOnce(cause)
381+
.mockResolvedValueOnce({ displayName: 'photo.png' })
382+
383+
const payload = await buildCopilotRequestPayload(
384+
{
385+
...attachmentParams,
386+
userPermission: 'write',
387+
fileAttachments: [
388+
...attachmentParams.fileAttachments,
389+
{
390+
id: 'a2',
391+
key: 'workspace/ws-1/1731000000001-ab12cd35-photo.png',
392+
filename: 'photo.png',
393+
media_type: 'image/png',
394+
size: 10,
395+
},
396+
],
397+
},
398+
{ selectedModel: 'claude-opus-4-8' }
399+
)
400+
401+
expect(mockTrackChatUpload).toHaveBeenCalledTimes(2)
402+
expect(payload.context).toEqual([
403+
{
404+
type: 'uploaded_file',
405+
content:
406+
'File "payroll.xlsx" could not be prepared for Copilot and was omitted. Other attached files remain available.',
407+
},
408+
{
409+
type: 'uploaded_file',
410+
content: [
411+
'File "photo.png" (image/png, 10 bytes) uploaded.',
412+
'Read with: read("uploads/photo.png")',
413+
'To save permanently: materialize_file(fileName: "photo.png")',
414+
].join('\n'),
415+
},
416+
])
390417
})
391418
})
392419

apps/sim/lib/copilot/chat/payload.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,14 @@ export async function buildCopilotRequestPayload(
401401
chatId,
402402
error: cause.message,
403403
})
404-
throw new Error(
405-
`Failed to prepare attached file "${filename}" for Copilot. Please try again.`,
406-
{ cause }
407-
)
404+
// Isolate failures by entry. Aborting here discarded every valid
405+
// sibling attachment in the request, even ones already tracked. Give
406+
// the model a local marker for this file and continue preparing the
407+
// rest of the batch.
408+
uploadContexts.push({
409+
type: 'uploaded_file',
410+
content: `File "${filename}" could not be prepared for Copilot and was omitted. Other attached files remain available.`,
411+
})
408412
}
409413
}
410414
}

bun.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)