Skip to content

Commit 0e7f27a

Browse files
committed
fix(web): wait for uploads before a send declines approvals
1 parent 08b4d3e commit 0e7f27a

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

‎apps/web/src/components/chat/useComposerSend.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ import { usePlanFollowUpSend } from "./useProposedPlanSend";
102102
import { useMultipleModelSend } from "./useMultipleModelSend";
103103
import { type ComposerDispatchMode } from "@t3tools/client-runtime/state/composer-dispatch";
104104
import {
105+
awaitAttachmentUploads,
106+
getUploadedAttachments,
105107
readAttachmentUpload,
106108
releaseDraftAttachments,
107109
retryAttachmentUpload,
@@ -1031,6 +1033,22 @@ export function useComposerSend(input: ComposerSendInput) {
10311033
);
10321034
return;
10331035
}
1036+
// Declining is irreversible, so a redirect waits for its uploads instead of failing after.
1037+
if (
1038+
turnUsesAttachmentUploads &&
1039+
composerAttachmentsSnapshot.length > 0 &&
1040+
(sendCtx?.shownPendingApprovalIds.length ?? 0) > 0
1041+
) {
1042+
await awaitAttachmentUploads(composerAttachmentsSnapshot.map((attachment) => attachment.id));
1043+
if (getUploadedAttachments({ environmentId, images: composerAttachmentsSnapshot }) === null) {
1044+
sendInFlightRef.current = false;
1045+
setThreadError(threadIdForSend, "Retry or remove failed uploads before sending.");
1046+
setDockedDraftHeroThreadKey((currentThreadKey) =>
1047+
currentThreadKey === activeThreadKey ? null : currentThreadKey,
1048+
);
1049+
return;
1050+
}
1051+
}
10341052
// A message sent while approvals are pending redirects the agent. They are declined only
10351053
// here, after everything above has accepted the send, so local commands and rejected
10361054
// drafts leave them alone. After navigating away during an upload, the shown approvals

0 commit comments

Comments
 (0)