Skip to content

Commit 666393f

Browse files
committed
🤖 fix: restore auto-compaction trigger deleted by ORPC migration
The ORPC migration PR (#763) inadvertently deleted the auto-compaction trigger logic when sending messages. This restores: - Check if usage >= threshold before sending regular messages - Execute compaction with continueMessage instead of direct send - Show 'Context threshold reached - auto-compacting...' toast - Proper error handling with input/image restoration The supporting infrastructure (checkAutoCompaction, CompactionWarning, settings UI) remained intact - only the trigger logic was missing. _Generated with `mux`_
1 parent 470e4eb commit 666393f

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/browser/components/ChatInput/index.tsx

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
handleCompactCommand,
3232
forkWorkspace,
3333
prepareCompactionMessage,
34+
executeCompaction,
3435
type CommandHandlerContext,
3536
} from "@/browser/utils/chatCommands";
3637
import { CUSTOM_EVENTS } from "@/common/constants/events";
@@ -699,6 +700,70 @@ export const ChatInput: React.FC<ChatInputProps> = (props) => {
699700
};
700701
});
701702

703+
// Auto-compaction check (workspace variant only)
704+
// Check if we should auto-compact before sending this message
705+
// Result is computed in parent (AIView) and passed down to avoid duplicate calculation
706+
const shouldAutoCompact =
707+
props.autoCompactionCheck &&
708+
props.autoCompactionCheck.usagePercentage >=
709+
props.autoCompactionCheck.thresholdPercentage &&
710+
!isCompacting; // Skip if already compacting to prevent double-compaction queue
711+
712+
if (variant === "workspace" && !editingMessage && shouldAutoCompact) {
713+
try {
714+
const result = await executeCompaction({
715+
client,
716+
workspaceId: props.workspaceId,
717+
continueMessage: {
718+
text: messageText,
719+
imageParts,
720+
model: sendMessageOptions.model,
721+
},
722+
sendMessageOptions,
723+
});
724+
725+
if (!result.success) {
726+
// Restore on error
727+
setInput(messageText);
728+
setImageAttachments(previousImageAttachments);
729+
setToast({
730+
id: Date.now().toString(),
731+
type: "error",
732+
title: "Auto-Compaction Failed",
733+
message: result.error ?? "Failed to start auto-compaction",
734+
});
735+
} else {
736+
// Clear input and images on success
737+
setInput("");
738+
setImageAttachments([]);
739+
if (inputRef.current) {
740+
inputRef.current.style.height = "36px";
741+
}
742+
setToast({
743+
id: Date.now().toString(),
744+
type: "success",
745+
message: "Context threshold reached - auto-compacting...",
746+
});
747+
props.onMessageSent?.();
748+
}
749+
} catch (error) {
750+
// Restore on unexpected error
751+
setInput(messageText);
752+
setImageAttachments(previousImageAttachments);
753+
setToast({
754+
id: Date.now().toString(),
755+
type: "error",
756+
title: "Auto-Compaction Failed",
757+
message:
758+
error instanceof Error ? error.message : "Unexpected error during auto-compaction",
759+
});
760+
} finally {
761+
setIsSending(false);
762+
}
763+
764+
return; // Skip normal send
765+
}
766+
702767
// When editing a /compact command, regenerate the actual summarization request
703768
let actualMessageText = messageText;
704769
let muxMetadata: MuxFrontendMetadata | undefined;

0 commit comments

Comments
 (0)