Skip to content
Open
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
9 changes: 5 additions & 4 deletions app/components/chat-composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,11 @@ export function ChatComposer({
value={input}
onChange={(event) => onInputChange(event.target.value)}
onKeyDown={(event) => {
if (event.key === "Enter" && !event.shiftKey) {
event.preventDefault();
submit();
}
if (event.key !== "Enter" || event.shiftKey) return;
// Japanese/other IME: Enter confirms composition; don't send yet.
if (event.nativeEvent.isComposing || event.keyCode === 229) return;
event.preventDefault();
submit();
}}
placeholder="Hey Aithy"
className="max-h-60 min-h-11 overflow-y-auto rounded-none border-0 bg-transparent px-0 py-2.5 text-base leading-6 shadow-none placeholder:text-[rgb(var(--muted-foreground))]/75 focus:border-0"
Expand Down
17 changes: 13 additions & 4 deletions app/components/use-chat-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export function useChatController({
setStreamingDraft(null);
const turnToComplete = localTurnRef.current;
if (assistantCompletesLocalTurn(turnToComplete, event.conversationId, message.createdAt)) {
localTurnRef.current = IDLE_LOCAL_CHAT_TURN;
setLocalTurn(IDLE_LOCAL_CHAT_TURN);
}
}
Expand All @@ -173,7 +174,10 @@ export function useChatController({
const useSelectedSkills = options.useSelectedSkills ?? true;
const skillsForTurn = options.selectedSkillsOverride
?? (useSelectedSkills ? selectedSkills : []);
if (turn.busy && activeSessionId && !options.pendingMessage) {
// Use the ref as well as React state: two Enter/clicks can race before setState
// re-renders, which used to POST the same chat turn twice.
const syncBusy = turn.busy || localTurnRef.current.phase !== "idle";
if (syncBusy && activeSessionId && !options.pendingMessage) {
enqueuePending({
conversationId: activeSessionId,
text,
Expand All @@ -194,6 +198,7 @@ export function useChatController({
taskId: null,
phase: "submitting",
};
localTurnRef.current = nextLocalTurn;
setLocalTurn(nextLocalTurn);
if (wasDraft) setActiveSessionId(conversationId);
if (!isCommand) {
Expand All @@ -211,9 +216,11 @@ export function useChatController({
});
const taskId = taskIdFromResult(result);
const queued = Boolean(result.queued && !isCommand);
setLocalTurn(queued
? { ...nextLocalTurn, taskId, phase: "awaiting_reply" }
: IDLE_LOCAL_CHAT_TURN);
const settledTurn = queued
? { ...nextLocalTurn, taskId, phase: "awaiting_reply" as const }
: IDLE_LOCAL_CHAT_TURN;
localTurnRef.current = settledTurn;
setLocalTurn(settledTurn);
if (!isCommand && useSelectedSkills && !options.pendingMessage) setSelectedSkills([]);
if (result.activeSessionId !== conversationId) {
setActiveSessionId(result.activeSessionId);
Expand All @@ -222,6 +229,7 @@ export function useChatController({
await navigateToSession(conversationId);
}
} catch (error) {
localTurnRef.current = IDLE_LOCAL_CHAT_TURN;
setLocalTurn(IDLE_LOCAL_CHAT_TURN);
if (options.pendingMessage) restorePending(options.pendingMessage);
throw error;
Expand Down Expand Up @@ -255,6 +263,7 @@ export function useChatController({
}, [input, submitText]);

const stop = useCallback(() => {
localTurnRef.current = IDLE_LOCAL_CHAT_TURN;
setLocalTurn(IDLE_LOCAL_CHAT_TURN);
setStreamingDraft(null);
if (activeSessionId) void stopChatMessage({ data: { conversationId: activeSessionId } });
Expand Down