Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend/copilot): smooth chat interactions on phones (#15769)

Ubbe5a4c61b64f4c
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
index 4ca05c3bce..cacbb4870f 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/ChatContainer.tsx
@@ -458,7 +458,14 @@ export const ChatContainer = ({
assistantName={expertIdentity?.name ?? "Otto"}
>
<LayoutGroup id="copilot-2-chat-layout">
- <div className="flex h-full min-h-0 w-full flex-col px-2 lg:px-0">
+ <div
+ className={cn(
+ "flex h-full min-h-0 w-full flex-col lg:px-0",
+ // An open chat runs edge to edge on a phone, like the rest of
+ // the thread; the new-chat screen keeps its margin.
+ sessionId ? "md:px-2" : "px-2",
+ )}
+ >
{/* The chat column runs full width: the max-w-3xl cap lives on the
message list and the input instead, so the expert thread header
can span edge to edge while staying aligned with the messages. */}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
index cc27e7f887..9cccb16836 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/ChatInput.test.tsx
@@ -734,6 +734,23 @@ describe("ChatInput dry-run toggle", () => {
});
describe("ChatInput guided prompt prefill", () => {
+ it("prefills a guided prompt without opening the keyboard on touch devices", async () => {
+ const matchMedia = vi.spyOn(window, "matchMedia").mockReturnValue({
+ matches: true,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ } as unknown as MediaQueryList);
+ try {
+ mockInitialPrompt = NEW_SKILL_PROMPT;
+ render(<ChatInput onSend={mockOnSend} />);
+ const textarea = screen.getByTestId("textarea") as HTMLTextAreaElement;
+ await waitFor(() => expect(textarea.value).toBe(NEW_SKILL_PROMPT));
+ expect(document.activeElement).not.toBe(textarea);
+ } finally {
+ matchMedia.mockRestore();
+ }
+ });
+
it("prefills the composer and focuses it when an initial prompt arrives after mount", async () => {
const { rerender } = render(<ChatInput onSend={mockOnSend} />);
const textarea = screen.getByTestId("textarea") as HTMLTextAreaElement;
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
index 8c9b986875..6275a05bf7 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useChatInput.ts
@@ -1,4 +1,5 @@
import { useCopilotUIStore } from "@/app/(platform)/copilot/store";
+import { isTouchDevice } from "@/lib/platform";
import { toastSendFailure } from "../../helpers/sendFailureToast";
import { useChatDraft } from "./useChatDraft";
import { ChangeEvent, FormEvent, useEffect, useRef, useState } from "react";
@@ -55,10 +56,7 @@ export function useChatInput({
// Guided flows can prefill while the composer is already mounted
// (e.g. from a copilot modal) — put the caret in the input so the
// draft is immediately editable/sendable.
- const textarea = document.getElementById(
- inputId,
- ) as HTMLTextAreaElement | null;
- textarea?.focus();
+ if (!isTouchDevice()) document.getElementById(inputId)?.focus();
},
[initialPrompt, setInitialPrompt, inputId, setValue],
);
@@ -72,19 +70,20 @@ export function useChatInput({
[recoveredDraft, clearRecoveredDraft, setValue],
);
+ // On a phone, focus opens the keyboard over half the thread, so the
+ // composer waits for a tap there.
useEffect(
function focusOnMount() {
- const textarea = document.getElementById(inputId) as HTMLTextAreaElement;
- if (textarea) textarea.focus();
+ if (isTouchDevice()) return;
+ document.getElementById(inputId)?.focus();
},
[inputId],
);
useEffect(
function focusWhenEnabled() {
- if (disabled) return;
- const textarea = document.getElementById(inputId) as HTMLTextAreaElement;
- if (textarea) textarea.focus();
+ if (disabled || isTouchDevice()) return;
+ document.getElementById(inputId)?.focus();
},
[disabled, inputId],
);
@@ -100,6 +99,7 @@ export function useChatInput({
// which would leave the sent text sitting in the composer for the entire
// turn. On failure the draft is restored (see restoreFailedDraft).
setValue("");
+ dismissKeyboard();
try {
await onSend(trimmedMessage);
notifyMessageSent();
@@ -131,6 +131,7 @@ export function useChatInput({
isEnqueueingRef.current = true;
setIsEnqueueing(true);
setValue("");
+ dismissKeyboard();
try {
await onEnqueue(trimmedMessage);
} catch (error) {
@@ -146,6 +147,13 @@ export function useChatInput({
}
}
+ // A phone keyboard covers the reply that is about to stream in.
+ function dismissKeyboard() {
+ if (!isTouchDevice()) return;
+ const input = document.getElementById(inputId);
+ if (input === document.activeElement) input?.blur();
+ }
+
function handleSubmit(e: FormEvent<HTMLFormElement>) {
e.preventDefault();
const formData = new FormData(e.currentTarget);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useIsTouchDevice.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useIsTouchDevice.ts
index 2916ad749a..3852350b1b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useIsTouchDevice.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useIsTouchDevice.ts
@@ -1,7 +1,6 @@
+import { COARSE_POINTER_QUERY, isTouchDevice } from "@/lib/platform";
import { useSyncExternalStore } from "react";
-const COARSE_POINTER_QUERY = "(pointer: coarse)";
-
function subscribe(onChange: () => void) {
if (typeof window === "undefined" || !window.matchMedia) return () => {};
const query = window.matchMedia(COARSE_POINTER_QUERY);
@@ -9,19 +8,11 @@ function subscribe(onChange: () => void) {
return () => query.removeEventListener("change", onChange);
}
-function getSnapshot() {
- return (
- typeof window !== "undefined" &&
- !!window.matchMedia &&
- window.matchMedia(COARSE_POINTER_QUERY).matches
- );
-}
-
/**
* True when the primary input is a finger. Camera capture only makes sense
* there: on a desktop browser `capture` degrades to a plain file chooser,
* which "Attach file" already offers.
*/
export function useIsTouchDevice(): boolean {
- return useSyncExternalStore(subscribe, getSnapshot, () => false);
+ return useSyncExternalStore(subscribe, isTouchDevice, () => false);
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useVoiceRecording.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useVoiceRecording.ts
index 5ab3d7b823..5b8d4c3a07 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useVoiceRecording.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useVoiceRecording.ts
@@ -9,6 +9,7 @@ import React, {
} from "react";
import { isKey } from "@/lib/keyboard";
import { downloadRecording } from "../../voice/downloadRecording";
+import { isTouchDevice } from "@/lib/platform";
const MAX_RECORDING_DURATION = 2 * 60 * 1000; // 2 minutes in ms
@@ -269,12 +270,10 @@ export function useVoiceRecording({
}
}, [error, toast]);
+ // Not on a phone: there focus opens the keyboard over the thread.
useEffect(() => {
- if (!isTranscribing && inputId) {
- const inputElement = document.getElementById(inputId);
- if (inputElement) {
- inputElement.focus();
- }
+ if (!isTranscribing && inputId && !isTouchDevice()) {
+ document.getElementById(inputId)?.focus();
}
}, [isTranscribing, inputId]);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
index 732e958dfb..796021d293 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/ChatMessagesContainer.tsx
@@ -537,7 +537,7 @@ export function ChatMessagesContainer({
>
<ConversationContent
className={cn(
- "mx-auto flex min-h-full w-full max-w-3xl flex-1 flex-col gap-6 px-6 pb-4 pt-14",
+ "mx-auto flex min-h-full w-full max-w-3xl flex-1 flex-col gap-6 px-4 pb-4 pt-14 md:px-6",
isCompact && "gap-4 px-4 pt-4",
showThreadHeader && floatingControls && "max-lg:pt-20",
!showThreadHeader && "pt-4",
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/AssistantRowActions.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/AssistantRowActions.tsx
index 2464c22e23..4d89836b23 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/AssistantRowActions.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/AssistantRowActions.tsx
@@ -13,7 +13,7 @@ interface Props {
}
const HOVER_REVEAL =
- "opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100";
+ "opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100";
export function AssistantRowActions({
message,
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/UserRowActions.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/UserRowActions.tsx
index 0a6c75cd64..bcb5217f2e 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/UserRowActions.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatMessagesContainer/components/MessageRow/components/UserRowActions.tsx
@@ -29,9 +29,9 @@ export function UserRowActions({
</MessageActions>
)}
{showCopy && (
- <MessageActions className="mt-1 items-center justify-end gap-2 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100">
+ <MessageActions className="mt-1 items-center justify-end gap-2 opacity-0 transition-opacity focus-within:opacity-100 group-hover:opacity-100 [@media(hover:none)]:opacity-100">
{date && !Number.isNaN(date.getTime()) && (
- <span className="text-[11px] tabular-nums text-neutral-500">
+ <span className="text-[11px] tabular-nums text-neutral-500 [@media(hover:none)]:hidden">
{date.toLocaleString(undefined, {
dateStyle: "medium",
timeStyle: "short",
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/CredentialMentionEditor.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/CredentialMentionEditor.tsx
index cbd48741c4..68e7721426 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/CredentialMentionEditor.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/CredentialMentionEditor.tsx
@@ -10,6 +10,7 @@ import {
import { PromptInputTextarea } from "@/components/ai-elements/prompt-input";
import { parseCredentialMentions } from "./helpers";
import { isKey } from "@/lib/keyboard";
+import { isTouchDevice } from "@/lib/platform";
import { cn } from "@/lib/utils";
import type { MentionInput } from "../ChatInput/useChatMentions";
import { CredentialMentionBadge } from "./CredentialMentionBadge";
@@ -69,6 +70,7 @@ export function CredentialMentionEditor({
(part) => typeof part !== "string",
);
const wasRich = useRef(rich);
+ const hasFocus = useRef(false);
const pendingSelection = useRef<PendingSelection | null>(null);
const {
editorRef,
@@ -83,7 +85,11 @@ export function CredentialMentionEditor({
const input = document.getElementById(inputId);
const pending = pendingSelection.current;
pendingSelection.current = null;
- if (input && wasRich.current !== rich) {
+ if (
+ input &&
+ wasRich.current !== rich &&
+ (!isTouchDevice() || hasFocus.current)
+ ) {
input.focus();
if (pending?.value === value) restoreSelection(input, pending);
}
@@ -92,6 +98,15 @@ export function CredentialMentionEditor({
onInputReady?.(mentionInputFor(editorRef.current));
});
+ function handleFocus() {
+ hasFocus.current = true;
+ }
+
+ function handleBlur() {
+ hasFocus.current = false;
+ onBlur?.();
+ }
+
function handleInput() {
const editor = editorRef.current;
if (!editor) return;
@@ -116,7 +131,10 @@ export function CredentialMentionEditor({
onKeyDown(event);
if (event.defaultPrevented || !isKey(event, "Enter")) return;
event.preventDefault();
- if (event.shiftKey) document.execCommand("insertText", false, "\n");
+ // Like the plain textarea: on a phone Enter adds a line and the send
+ // button sends.
+ if (event.shiftKey || isTouchDevice())
+ document.execCommand("insertText", false, "\n");
else event.currentTarget.closest("form")?.requestSubmit();
}
@@ -140,7 +158,8 @@ export function CredentialMentionEditor({
onChange={handleTextareaChange}
onKeyDown={onKeyDown}
onPaste={onPaste}
- onBlur={onBlur}
+ onFocus={handleFocus}
+ onBlur={handleBlur}
onMultilineChange={onMultilineChange}
disabled={disabled}
placeholder={placeholder}
@@ -167,7 +186,8 @@ export function CredentialMentionEditor({
onPaste={handlePaste}
onCompositionStart={onCompositionStart}
onCompositionEnd={onCompositionEnd}
- onBlur={onBlur}
+ onFocus={handleFocus}
+ onBlur={handleBlur}
className={cn(
"max-h-48 min-h-10 w-full overflow-y-auto whitespace-pre-wrap break-words bg-transparent px-3 py-2 text-left text-base leading-7 outline-none empty:before:pointer-events-none empty:before:text-zinc-400 empty:before:content-[attr(data-placeholder)]",
disabled && "cursor-not-allowed opacity-50",
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/__tests__/mobileComposer.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/__tests__/mobileComposer.test.tsx
new file mode 100644
index 0000000000..331214733a
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CredentialMention/__tests__/mobileComposer.test.tsx
@@ -0,0 +1,90 @@
+import {
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@/tests/integrations/test-utils";
+import { afterEach, describe, expect, it, vi } from "vitest";
+import userEvent from "@testing-library/user-event";
+import { useChatInput } from "../../ChatInput/useChatInput";
+import { CredentialMentionEditor } from "../CredentialMentionEditor";
+
+const MESSAGE = "Check [Work Gmail](credential://google/work-credential-id)";
+
+interface Props {
+ onSend: (message: string) => void;
+ onEnqueue?: (message: string) => Promise<void>;
+ isStreaming?: boolean;
+}
+
+function Composer({ onSend, onEnqueue, isStreaming }: Props) {
+ const input = useChatInput({ onSend, onEnqueue, isStreaming });
+ return (
+ <form onSubmit={input.handleSubmit}>
+ <CredentialMentionEditor
+ id="chat-input"
+ value={input.value}
+ onChange={input.setValue}
+ onKeyDown={() => {}}
+ />
+ <button type="submit">Send</button>
+ </form>
+ );
+}
+
+afterEach(() => vi.restoreAllMocks());
+
+describe("mobile composer focus", () => {
+ it.each([false, true])(
+ "keeps the keyboard dismissed after submitting a badge (streaming: %s)",
+ async (isStreaming) => {
+ vi.spyOn(window, "matchMedia").mockReturnValue({
+ matches: true,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ } as unknown as MediaQueryList);
+ const onSend = vi.fn();
+ const onEnqueue = vi.fn().mockResolvedValue(undefined);
+ render(
+ <Composer
+ onSend={onSend}
+ onEnqueue={onEnqueue}
+ isStreaming={isStreaming}
+ />,
+ );
+ const textarea = screen.getByRole("textbox");
+ expect(document.activeElement).not.toBe(textarea);
+ textarea.focus();
+ fireEvent.change(textarea, { target: { value: MESSAGE } });
+ const editor = screen.getByRole("textbox");
+ expect(editor.tagName).toBe("DIV");
+ expect(document.activeElement).toBe(editor);
+
+ fireEvent.submit(
+ screen.getByRole("button", { name: "Send" }).closest("form")!,
+ );
+ await waitFor(() =>
+ expect(isStreaming ? onEnqueue : onSend).toHaveBeenCalledWith(MESSAGE),
+ );
+ const emptyInput = screen.getByRole<HTMLTextAreaElement>("textbox");
+ expect(emptyInput.tagName).toBe("TEXTAREA");
+ expect(emptyInput.value).toBe("");
+ expect(document.activeElement).not.toBe(emptyInput);
+ },
+ );
+
+ it("keeps desktop focus after submitting a badge", async () => {
+ const user = userEvent.setup();
+ vi.spyOn(window, "matchMedia").mockReturnValue({
+ matches: false,
+ } as MediaQueryList);
+ const onSend = vi.fn();
+ render(<Composer onSend={onSend} />);
+ const textarea = screen.getByRole("textbox");
+ expect(document.activeElement).toBe(textarea);
+ fireEvent.change(textarea, { target: { value: MESSAGE } });
+ await user.click(screen.getByRole("button", { name: "Send" }));
+ await waitFor(() => expect(onSend).toHaveBeenCalledWith(MESSAGE));
+ expect(document.activeElement).toBe(screen.getByRole("textbox"));
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
index 3ad5c3b507..297d720a42 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ToolChain/__tests__/ToolChain.test.tsx
@@ -397,7 +397,9 @@ describe("ToolChain", () => {
expect(onSend).toHaveBeenCalledWith(
"**Here are my answers:**\n\n> Which region?\n\nWestern Europe\n\nPlease proceed.",
);
- expect(screen.queryByText("Answer a few questions")).toBeNull();
+ await waitFor(() => {
+ expect(screen.queryByText("Answer a few questions")).toBeNull();
+ });
});
it("keeps the caret where the user is editing an answer", async () => {
diff --git a/autogpt_platform/frontend/src/app/globals.css b/autogpt_platform/frontend/src/app/globals.css
index dc7d8736cd..1812ddb303 100644
--- a/autogpt_platform/frontend/src/app/globals.css
+++ b/autogpt_platform/frontend/src/app/globals.css
@@ -81,6 +81,23 @@
body {
@apply bg-[#F6F7F8] font-sans text-foreground antialiased transition-colors;
}
+
+ /* Touch screens: no grey flash on tap, and no double-tap zoom on controls,
+ which also drops the wait the browser adds to tell a tap from one. */
+ html {
+ -webkit-tap-highlight-color: transparent;
+ }
+
+ a,
+ button,
+ input,
+ label,
+ select,
+ summary,
+ textarea,
+ [role="button"] {
+ touch-action: manipulation;
+ }
}
/* *** AutoGPT Design Components *** */
@@ -157,6 +174,38 @@ body[data-google-picker-open="true"] [data-dialog-content] {
color: inherit;
}
+/* Streamdown's code-block buttons are 24px icons: on a touch screen, widen
+ the area that takes the tap without moving the header around. */
+@media (pointer: coarse) {
+ [data-streamdown="code-block-copy-button"],
+ [data-streamdown="code-block-download-button"] {
+ position: relative;
+ }
+
+ [data-streamdown="code-block-copy-button"]::after,
+ [data-streamdown="code-block-download-button"]::after {
+ content: "";
+ position: absolute;
+ inset: -0.5rem;
+ }
+}
+
+/* A bare URL is one long word: let it wrap instead of running off a phone
+ screen. */
+[data-streamdown="link"] {
+ overflow-wrap: anywhere;
+}
+
+/* Phones: code lines get the 40px the line numbers take. The number keeps
+ its box (at no width), since it is what gives a blank line its height. */
+@media (max-width: 767px) {
+ [data-streamdown="code-block-body"] span::before {
+ visibility: hidden;
+ width: 0;
+ margin-right: 0;
+ }
+}
+
/* CoPilot chat table styling — remove left/right borders, increase padding */
[data-streamdown="table-wrapper"] table {
border-left: none;
diff --git a/autogpt_platform/frontend/src/app/layout.tsx b/autogpt_platform/frontend/src/app/layout.tsx
index b54191ae22..b30f298d2c 100644
--- a/autogpt_platform/frontend/src/app/layout.tsx
+++ b/autogpt_platform/frontend/src/app/layout.tsx
@@ -1,5 +1,5 @@
import { fonts } from "@/components/styles/fonts";
-import type { Metadata } from "next";
+import type { Metadata, Viewport } from "next";
import React from "react";
import "./globals.css";
@@ -55,6 +55,14 @@ export const metadata: Metadata = {
},
};
+export const viewport: Viewport = {
+ width: "device-width",
+ initialScale: 1,
+ // Android shrinks the page for the on-screen keyboard instead of sliding
+ // it over the bottom, so the chat composer stays in view above it.
+ interactiveWidget: "resizes-content",
+};
+
export default async function RootLayout({
children,
}: Readonly<{
@@ -71,7 +79,10 @@ export default async function RootLayout({
className={`${fonts.poppins.variable} ${fonts.sans.variable} ${fonts.mono.variable}`}
suppressHydrationWarning
>
- <body className="min-h-screen">
+ {/* Mobile Safari's 100vh is the height with its toolbar hidden, so a
+ min-h-screen page always scrolls a little; dvh is what is visible.
+ min-h-screen stays as the fallback for browsers without dvh. */}
+ <body className="min-h-screen supports-[min-height:100dvh]:min-h-dvh">
{process.env.NEXT_PUBLIC_RENDER_COUNTER === "1" ? (
<Script
src="/devtools/render-counter.js"
@@ -119,7 +130,7 @@ export default async function RootLayout({
process.env.NEXT_PUBLIC_GA_MEASUREMENT_ID || "G-FH2XK2W4GN",
}}
/>
- <div className="flex min-h-screen flex-col items-stretch justify-items-stretch">
+ <div className="flex min-h-screen flex-col items-stretch justify-items-stretch supports-[min-height:100dvh]:min-h-dvh">
{children}
<VercelAnalyticsWrapper />
diff --git a/autogpt_platform/frontend/src/components/ai-elements/conversation.tsx b/autogpt_platform/frontend/src/components/ai-elements/conversation.tsx
index d0ce043dd5..4a0ab12479 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/conversation.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/conversation.tsx
@@ -31,7 +31,9 @@ export const ConversationContent = ({
<StickToBottom.Content
className={cn("flex flex-col gap-8 p-4", className)}
scrollClassName={cn(
- "scrollbar-thin scrollbar-track-transparent scrollbar-thumb-zinc-300",
+ // Contain the overscroll so a fling past either end bounces the thread
+ // instead of dragging the page, composer and all, with it.
+ "overscroll-y-contain scrollbar-thin scrollbar-track-transparent scrollbar-thumb-zinc-300",
scrollClassName,
)}
{...props}
@@ -89,7 +91,7 @@ export const ConversationScrollButton = ({
!isAtBottom && (
<Button
className={cn(
- "absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",
+ "absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full [@media(pointer:coarse)]:size-10",
className,
)}
onClick={handleScrollToBottom}
diff --git a/autogpt_platform/frontend/src/components/ai-elements/message.tsx b/autogpt_platform/frontend/src/components/ai-elements/message.tsx
index e350611759..ed8cc4fe7d 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/message.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/message.tsx
@@ -87,10 +87,18 @@ export const MessageAction = ({
label,
variant = "ghost",
size = "icon-sm",
+ className,
...props
}: MessageActionProps) => {
const button = (
- <Button size={size} type="button" variant={variant} {...props}>
+ <Button
+ size={size}
+ type="button"
+ variant={variant}
+ // A finger needs a bigger target than the 32px icon box.
+ className={cn("[@media(pointer:coarse)]:size-10", className)}
+ {...props}
+ >
{children}
<span className="sr-only">{label || tooltip}</span>
</Button>
diff --git a/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx b/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
index 5545001efd..a0e4f6ee16 100644
--- a/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
+++ b/autogpt_platform/frontend/src/components/ai-elements/prompt-input.tsx
@@ -36,6 +36,7 @@ import { Children, useCallback, useLayoutEffect, useRef } from "react";
import { ArrowUp02Icon, StopIcon } from "@hugeicons/core-free-icons";
import { Icon as UIIcon } from "@/components/atoms/Icon/Icon";
import { isKey } from "@/lib/keyboard";
+import { isTouchDevice } from "@/lib/platform";
// ============================================================================
// PromptInput — form wrapper
@@ -253,7 +254,7 @@ export function PromptInputTextarea({
if (e.shiftKey) return;
// On touch-first devices (phones/tablets) Enter inserts a newline;
// users send with the submit button instead.
- if (window.matchMedia?.("(pointer: coarse)")?.matches) return;
+ if (isTouchDevice()) return;
e.preventDefault();
e.currentTarget.form?.requestSubmit();
diff --git a/autogpt_platform/frontend/src/components/molecules/DropdownMenu/DropdownMenu.tsx b/autogpt_platform/frontend/src/components/molecules/DropdownMenu/DropdownMenu.tsx
index 7e66e5b41f..51b412786e 100644
--- a/autogpt_platform/frontend/src/components/molecules/DropdownMenu/DropdownMenu.tsx
+++ b/autogpt_platform/frontend/src/components/molecules/DropdownMenu/DropdownMenu.tsx
@@ -25,7 +25,7 @@ const DropdownMenuSubTrigger = React.forwardRef<
<DropdownMenuPrimitive.SubTrigger
ref={ref}
className={cn(
- "flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[state=open]:bg-neutral-100 focus:bg-neutral-100 dark:data-[state=open]:bg-neutral-800 dark:focus:bg-neutral-800",
+ "flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[state=open]:bg-neutral-100 focus:bg-neutral-100 dark:data-[state=open]:bg-neutral-800 dark:focus:bg-neutral-800 [@media(pointer:coarse)]:py-3",
inset && "pl-8",
className,
)}
@@ -82,7 +82,7 @@ const DropdownMenuItem = React.forwardRef<
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
- "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",
+ "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50 [@media(pointer:coarse)]:py-3",
inset && "pl-8",
className,
)}
@@ -98,7 +98,7 @@ const DropdownMenuCheckboxItem = React.forwardRef<
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
- "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",
+ "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50 [@media(pointer:coarse)]:py-3",
className,
)}
checked={checked}
@@ -122,7 +122,7 @@ const DropdownMenuRadioItem = React.forwardRef<
<DropdownMenuPrimitive.RadioItem
ref={ref}
className={cn(
- "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50",
+ "relative flex cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-neutral-100 focus:text-neutral-900 dark:focus:bg-neutral-800 dark:focus:text-neutral-50 [@media(pointer:coarse)]:py-3",
className,
)}
{...props}
diff --git a/autogpt_platform/frontend/src/components/ui/sheet.tsx b/autogpt_platform/frontend/src/components/ui/sheet.tsx
index 30ae1d3e44..9efb692442 100644
--- a/autogpt_platform/frontend/src/components/ui/sheet.tsx
+++ b/autogpt_platform/frontend/src/components/ui/sheet.tsx
@@ -21,7 +21,7 @@ const SheetOverlay = React.forwardRef<
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
className={cn(
- "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
+ "fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:fill-mode-forwards",
className,
)}
{...props}
@@ -30,8 +30,12 @@ const SheetOverlay = React.forwardRef<
));
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName;
+// Closing keeps the exit animation's last frame (fill-mode-forwards) until
+// Radix unmounts the sheet. Otherwise, when the main thread is busy as the
+// animation ends (closing on a link tap while the next page renders), the
+// sheet snaps back into view until React catches up.
const sheetVariants = cva(
- "fixed z-50 gap-4 bg-white p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out dark:bg-neutral-950",
+ "fixed z-50 gap-4 bg-white p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fill-mode-forwards dark:bg-neutral-950",
{
variants: {
side: {
diff --git a/autogpt_platform/frontend/src/components/ui/sidebar.tsx b/autogpt_platform/frontend/src/components/ui/sidebar.tsx
index dac52a7d92..990dccbefa 100644
--- a/autogpt_platform/frontend/src/components/ui/sidebar.tsx
+++ b/autogpt_platform/frontend/src/components/ui/sidebar.tsx
@@ -234,6 +234,10 @@ const Sidebar = React.forwardRef<
) => {
const { isMobile, state, openMobile, setOpenMobile } = useSidebar();
+ function handleLinkClick(event: React.MouseEvent<HTMLDivElement>) {
+ if (isSameTabLinkClick(event)) setOpenMobile(false);
+ }
+
if (collapsible === "none") {
return (
<div
@@ -274,9 +278,7 @@ const Sidebar = React.forwardRef<
}}
// The sheet covers the page, so a link that navigates in this
// tab closes it on the way.
- onClick={(event) => {
- if (isSameTabLinkClick(event)) setOpenMobile(false);
- }}
+ onClick={handleLinkClick}
>
<SheetHeader className="sr-only">
<SheetTitle>Sidebar</SheetTitle>
diff --git a/autogpt_platform/frontend/src/lib/platform.ts b/autogpt_platform/frontend/src/lib/platform.ts
index cf1c4a5f63..9b2b2e8a29 100644
--- a/autogpt_platform/frontend/src/lib/platform.ts
+++ b/autogpt_platform/frontend/src/lib/platform.ts
@@ -10,3 +10,14 @@ export function isEditableElement(el: Element | null): boolean {
(el instanceof HTMLElement && el.isContentEditable)
);
}
+
+export const COARSE_POINTER_QUERY = "(pointer: coarse)";
+
+/** True when the primary input is a finger (phones, tablets). */
+export function isTouchDevice(): boolean {
+ return (
+ typeof window !== "undefined" &&
+ !!window.matchMedia &&
+ window.matchMedia(COARSE_POINTER_QUERY).matches
+ );
+}
diff --git a/autogpt_platform/frontend/src/services/analytics/activation-goals.ts b/autogpt_platform/frontend/src/services/analytics/activation-goals.ts
index 9e1bdddc4d..b283797a5d 100644
--- a/autogpt_platform/frontend/src/services/analytics/activation-goals.ts
+++ b/autogpt_platform/frontend/src/services/analytics/activation-goals.ts
@@ -20,15 +20,15 @@ export type ScheduleSurface = "library" | "builder";
// Only the graph ID goes to DataFast: workflow names are written by people
// and may hold personal data.
-export function trackAgentRunGoal(graphId: string, surface: AgentRunSurface) {
- sendGoal("run_agent", { id: graphId, surface });
+export function trackAgentRunGoal(graphID: string, surface: AgentRunSurface) {
+ sendGoal("run_agent", { id: graphID, surface });
}
export function trackScheduleCreatedGoal(
- graphId: string,
+ graphID: string,
surface: ScheduleSurface,
) {
- sendGoal("schedule_agent", { id: graphId, surface });
+ sendGoal("schedule_agent", { id: graphID, surface });
}
function sendGoal(name: string, metadata: Record<string, string>) {
diff --git a/autogpt_platform/frontend/src/services/analytics/index.test.ts b/autogpt_platform/frontend/src/services/analytics/index.test.ts
index cbf670f8de..1c837871c3 100644
--- a/autogpt_platform/frontend/src/services/analytics/index.test.ts
+++ b/autogpt_platform/frontend/src/services/analytics/index.test.ts
@@ -82,6 +82,24 @@ describe("sendDatafastEvent", () => {
expect(datafast).toHaveBeenCalledTimes(1);
});
+ it.each([false, true])(
+ "discards queued events after consent withdrawal (script loaded: %s)",
+ (loaded) => {
+ analytics.sendDatafastEvent("tour_start", {});
+ vi.mocked(hasConsentFor).mockReturnValue(false);
+ const datafast = vi.fn();
+ if (loaded) window.datafast = datafast;
+
+ flushDatafastQueue();
+ expect(datafast).not.toHaveBeenCalled();
+
+ vi.mocked(hasConsentFor).mockReturnValue(true);
+ window.datafast = datafast;
+ flushDatafastQueue();
+ expect(datafast).not.toHaveBeenCalled();
+ },
+ );
+
it("flushes the backlog before sending when the script loads without onLoad", () => {
analytics.sendDatafastEvent("tour_start", {});
diff --git a/autogpt_platform/frontend/src/services/analytics/index.tsx b/autogpt_platform/frontend/src/services/analytics/index.tsx
index c708ee0bd5..144f28e874 100644
--- a/autogpt_platform/frontend/src/services/analytics/index.tsx
+++ b/autogpt_platform/frontend/src/services/analytics/index.tsx
@@ -155,7 +155,13 @@ function sendDatafastEvent(
}
export function flushDatafastQueue() {
- if (typeof window === "undefined" || !window.datafast) return;
+ if (typeof window === "undefined") return;
+ if (!hasConsentFor("analytics")) {
+ datafastQueue.length = 0;
+ datafastQueueOverflowWarned = false;
+ return;
+ }
+ if (!window.datafast) return;
const datafast = window.datafast;
datafastQueue
.splice(0, datafastQueue.length)