Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions apps/web/src/components/ChatView.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,57 @@ describe("ChatView timeline estimator parity (full app)", () => {
}
});

it("does not start a new turn when Enter is pressed while the thread is running", async () => {
useComposerDraftStore.getState().setPrompt(THREAD_ID, "follow-up while running");

const mounted = await mountChatView({
viewport: DEFAULT_VIEWPORT,
snapshot: createSnapshotForTargetUser({
targetMessageId: "msg-user-enter-while-running" as MessageId,
targetText: "enter while running target",
sessionStatus: "running",
}),
});

try {
const composerEditor = await waitForComposerEditor();
const initialTurnStartRequestCount = wsRequests.filter(
(request) =>
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
request.command &&
typeof request.command === "object" &&
"type" in request.command &&
request.command.type === "thread.turn.start",
).length;

composerEditor.focus();
composerEditor.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Enter",
bubbles: true,
cancelable: true,
}),
);
await waitForLayout();

const nextTurnStartRequestCount = wsRequests.filter(
(request) =>
request._tag === ORCHESTRATION_WS_METHODS.dispatchCommand &&
request.command &&
typeof request.command === "object" &&
"type" in request.command &&
request.command.type === "thread.turn.start",
).length;

expect(nextTurnStartRequestCount).toBe(initialTurnStartRequestCount);
expect(document.querySelector('button[aria-label="Stop generation"]')).toBeInstanceOf(
HTMLButtonElement,
);
} finally {
await mounted.cleanup();
}
});

it("keeps the new thread selected after clicking the new-thread button", async () => {
const mounted = await mountChatView({
viewport: DEFAULT_VIEWPORT,
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2431,11 +2431,14 @@ export default function ChatView({ threadId }: ChatViewProps) {
const onSend = async (e?: { preventDefault: () => void }) => {
e?.preventDefault();
const api = readNativeApi();
if (!api || !activeThread || isSendBusy || isConnecting || sendInFlightRef.current) return;
if (!api || !activeThread) return;
if (activePendingProgress) {
onAdvanceActivePendingUserInput();
return;
}
if (phase === "running" || isSendBusy || isConnecting || sendInFlightRef.current) {
return;
}
const promptForSend = promptRef.current;
const {
trimmedPrompt: trimmed,
Expand Down
Loading