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.

feat(frontend): mobile chat input polish, camera capture and composer overflow menu (#15545)

Ubbe9849b32d4d0e
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx
index 38ffac2a4a..832e240a1e 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/autopilot-mode-selector.test.tsx
@@ -85,9 +85,7 @@ describe("AutoPilot mode selector", () => {
renderHost();
await pickMode(/approval mode: auto/i, /ask first/i);
- expect(
- await screen.findByRole("button", { name: /approval mode: ask first/i }),
- ).toBeDefined();
+ expect(await findModeButton(/approval mode: ask first/i)).toBeDefined();
await typeAndSend("hi");
await waitFor(() => expect(bodies).toHaveLength(1));
@@ -107,9 +105,7 @@ describe("AutoPilot mode selector", () => {
screen.queryByRole("heading", { name: /run this chat unsupervised/i }),
).toBeNull(),
);
- expect(
- screen.getByRole("button", { name: /approval mode: auto/i }),
- ).toBeDefined();
+ expect(await findModeButton(/approval mode: auto/i)).toBeDefined();
await typeAndSend("hi");
await waitFor(() => expect(bodies).toHaveLength(1));
@@ -129,11 +125,7 @@ describe("AutoPilot mode selector", () => {
await screen.findByRole("button", { name: /run unsupervised/i }),
);
- expect(
- await screen.findByRole("button", {
- name: /approval mode: unsupervised/i,
- }),
- ).toBeDefined();
+ expect(await findModeButton(/approval mode: unsupervised/i)).toBeDefined();
await typeAndSend("hi");
await waitFor(() => expect(bodies).toHaveLength(1));
@@ -149,9 +141,7 @@ describe("AutoPilot mode selector", () => {
},
});
- expect(
- await screen.findByRole("button", { name: /approval mode: ask first/i }),
- ).toBeDefined();
+ expect(await findModeButton(/approval mode: ask first/i)).toBeDefined();
await typeAndSend("hi");
await waitFor(() => expect(bodies).toHaveLength(1));
@@ -222,8 +212,20 @@ function captureStreamBodies() {
return bodies;
}
+// The mode selector lives behind the composer's "..." menu, and the panel
+// closes again once a pick is made: open it only when it is not showing.
+async function findModeButton(name: RegExp) {
+ if (!screen.queryByRole("button", { name: /approval mode/i })) {
+ const user = userEvent.setup();
+ await user.click(
+ await screen.findByRole("button", { name: /more options/i }),
+ );
+ }
+ return screen.findByRole("button", { name });
+}
+
async function pickMode(trigger: RegExp, option: RegExp) {
const user = userEvent.setup();
- await user.click(await screen.findByRole("button", { name: trigger }));
+ await user.click(await findModeButton(trigger));
await user.click(await screen.findByRole("menuitemradio", { name: option }));
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/components/ChatComposerFrame.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/components/ChatComposerFrame.tsx
index 08edd24eac..0481eb587a 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/components/ChatComposerFrame.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatContainer/components/ChatComposerFrame.tsx
@@ -25,7 +25,7 @@ export function ChatComposerFrame({
animate={{ opacity: 1 }}
transition={{ duration: 0.3 }}
className={cn(
- "relative mx-auto w-full max-w-3xl px-3 pb-6 pt-2",
+ "relative mx-auto w-full max-w-3xl px-3 pb-[max(1.5rem,env(safe-area-inset-bottom))] pt-2",
className,
)}
>
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
index 91cc4254e3..a181a95a4b 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/ChatInput.tsx
@@ -30,6 +30,7 @@ import {
import type { PickedItem } from "./components/WorkspaceFilePicker/useWorkspaceFilePicker";
import { AtResetFilesNotice } from "./components/AtResetFilesNotice";
import { AttachmentCapNotice } from "./components/AttachmentCapNotice";
+import { ComposerOverflowMenu } from "./components/ComposerOverflowMenu";
import {
ComposerPlusMenu,
type ComposerMenuItem,
@@ -56,6 +57,7 @@ import {
CARD_SEND_BUTTON_CLASS,
COMPACT_ICON_BUTTON_CLASS,
COMPACT_SEND_BUTTON_CLASS,
+ MOBILE_SEND_BUTTON_CLASS,
getFilesFromClipboard,
} from "./helpers";
import { useChatInput } from "./useChatInput";
@@ -399,7 +401,13 @@ export function ChatInput({
? CARD_SEND_BUTTON_CLASS
: isCompact
? COMPACT_SEND_BUTTON_CLASS
- : undefined;
+ : MOBILE_SEND_BUTTON_CLASS;
+
+ // Per-message settings and voice mode sit behind the "..." button, so the
+ // row stays usable at phone width. Model and token usage live in the + menu.
+ const showDryRunToggle = showAdvancedComposerControls && !hasSession;
+ const hasOverflowControls =
+ !!modeSelector || showDryRunToggle || !!voiceToggle;
return (
<form onSubmit={handleSubmit} className={cn("relative flex-1", className)}>
@@ -516,7 +524,9 @@ export function ChatInput({
<div
className={cn(
"relative",
- stacked || isMultiline ? "order-first w-full" : "min-w-0 flex-1",
+ stacked || isMultiline
+ ? "order-first w-full"
+ : "min-w-0 flex-1 max-md:order-first max-md:w-full max-md:basis-full",
)}
>
<CredentialMentionEditor
@@ -531,6 +541,7 @@ export function ChatInput({
placeholder={resolvedPlaceholder}
onMultilineChange={setIsMultiline}
className={cn(
+ "max-md:max-h-32",
stacked && "px-0.5 py-1",
isCompact && "text-sm leading-5 md:text-sm",
)}
@@ -552,17 +563,21 @@ export function ChatInput({
isCompact && "gap-0.5 py-1 pr-1",
)}
>
- {/* Connection and tier are per-message settings, so they remain
- changeable between turns in an existing session. The card
- composer leaves this to the page's top-right control. */}
- {modeSelector}
- {showAdvancedComposerControls && !hasSession && (
- <DryRunToggleButton
- isDryRun={isDryRun}
- onToggle={handleToggleDryRun}
- />
+ {hasOverflowControls && (
+ <ComposerOverflowMenu
+ forceClosed={!!voiceBar}
+ className={iconButtonClass}
+ >
+ {modeSelector}
+ {showDryRunToggle && (
+ <DryRunToggleButton
+ isDryRun={isDryRun}
+ onToggle={handleToggleDryRun}
+ />
+ )}
+ {voiceToggle}
+ </ComposerOverflowMenu>
)}
- {voiceToggle}
{showMicButton && (
<RecordingButton
isRecording={isRecording}
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 71364cce85..6f94e77759 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
@@ -295,6 +295,18 @@ describe("ChatInput composer row", () => {
});
});
+// Secondary composer controls live behind the "..." overflow menu.
+function openOverflow() {
+ fireEvent.click(screen.getByTestId("composer-overflow-button"));
+}
+
+// Negative assertions are only meaningful with the panel open when the
+// menu exists at all (it is absent when no control qualifies).
+function openOverflowIfPresent() {
+ const trigger = screen.queryByTestId("composer-overflow-button");
+ if (trigger) fireEvent.click(trigger);
+}
+
describe("ChatInput token devtool entry", () => {
it("lists Token usage in the + menu while the brain-dump tray is disabled", () => {
// The tray is brain-dump-only; the entry must not depend on that flag.
@@ -559,12 +571,14 @@ describe("ChatInput dry-run toggle", () => {
it("does not render dry-run toggle when flag is disabled", () => {
mockFlagValue = false;
render(<ChatInput onSend={mockOnSend} />);
+ openOverflowIfPresent();
expect(screen.queryByTestId("dry-run-toggle")).toBeNull();
});
it("renders dry-run toggle when flag is enabled and no session", () => {
mockFlagValue = true;
render(<ChatInput onSend={mockOnSend} hasSession={false} />);
+ openOverflow();
expect(screen.getByTestId("dry-run-toggle")).toBeDefined();
});
@@ -572,6 +586,7 @@ describe("ChatInput dry-run toggle", () => {
mockFlagValue = true;
render(<ChatInput onSend={mockOnSend} hasSession />);
// isDryRun is false in mock, hasSession is true → toggle hidden
+ openOverflowIfPresent();
expect(screen.queryByTestId("dry-run-toggle")).toBeNull();
});
@@ -579,6 +594,7 @@ describe("ChatInput dry-run toggle", () => {
const { toast } = await import("@/components/molecules/Toast/use-toast");
mockFlagValue = true;
render(<ChatInput onSend={mockOnSend} />);
+ openOverflow();
fireEvent.click(screen.getByTestId("dry-run-toggle"));
// isDryRun was false → next is true
expect(toast).toHaveBeenCalledWith(
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/nameCapturedPhotos.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/nameCapturedPhotos.test.ts
new file mode 100644
index 0000000000..3533c4a460
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/__tests__/nameCapturedPhotos.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from "vitest";
+import { nameCapturedPhotos } from "../helpers";
+
+describe("nameCapturedPhotos", () => {
+ it("renames the generic camera filename so photos stay distinguishable", () => {
+ const [first, second] = nameCapturedPhotos([
+ new File(["a"], "image.jpg", { type: "image/jpeg" }),
+ new File(["b"], "image.jpg", { type: "image/jpeg" }),
+ ]);
+
+ expect(first.name).toMatch(/^photo-.*\.jpg$/);
+ expect(second.name).toMatch(/^photo-.*-2\.jpg$/);
+ expect(first.name).not.toBe(second.name);
+ });
+
+ it("leaves already-named files and non-images alone", () => {
+ const named = new File(["a"], "receipt.png", { type: "image/png" });
+ const doc = new File(["b"], "image.pdf", { type: "application/pdf" });
+
+ const result = nameCapturedPhotos([named, doc]);
+
+ expect(result[0]).toBe(named);
+ expect(result[1]).toBe(doc);
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerOverflowMenu.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerOverflowMenu.tsx
new file mode 100644
index 0000000000..0406612337
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerOverflowMenu.tsx
@@ -0,0 +1,70 @@
+"use client";
+
+import { Button } from "@/components/atoms/Button/Button";
+import { Icon } from "@/components/atoms/Icon/Icon";
+import {
+ Popover,
+ PopoverContent,
+ PopoverTrigger,
+} from "@/components/molecules/Popover/Popover";
+import { cn } from "@/lib/utils";
+import { MoreHorizontalIcon } from "@hugeicons/core-free-icons";
+import { ReactNode, useState } from "react";
+
+interface Props {
+ /** The secondary controls (connection, approvals, test mode, voice...). */
+ children: ReactNode;
+ /** Keeps the panel shut, e.g. while voice mode takes over the composer. */
+ forceClosed?: boolean;
+ disabled?: boolean;
+ className?: string;
+}
+
+/**
+ * The "..." button that keeps the composer to its essentials: the controls
+ * that rarely change between messages live in a panel instead of a row that
+ * overflows a phone screen. A popover rather than a menu, because the
+ * controls inside open menus and pickers of their own.
+ */
+export function ComposerOverflowMenu({
+ children,
+ forceClosed = false,
+ disabled,
+ className,
+}: Props) {
+ const [isOpen, setIsOpen] = useState(false);
+
+ // Forget the open state while forced shut, or the panel pops back open
+ // on its own once voice mode ends.
+ if (forceClosed && isOpen) setIsOpen(false);
+
+ return (
+ <Popover open={isOpen && !forceClosed} onOpenChange={setIsOpen}>
+ <PopoverTrigger asChild>
+ <Button
+ type="button"
+ variant="icon"
+ size="icon"
+ aria-label="More options"
+ data-testid="composer-overflow-button"
+ disabled={disabled}
+ className={cn(
+ "border-transparent bg-transparent text-black shadow-none hover:border-transparent hover:bg-zinc-100 hover:text-black",
+ className,
+ disabled && "opacity-40",
+ )}
+ >
+ <Icon icon={MoreHorizontalIcon} className="h-4 w-4" />
+ </Button>
+ </PopoverTrigger>
+ <PopoverContent
+ side="top"
+ align="end"
+ data-testid="composer-overflow-panel"
+ className="flex w-auto max-w-[calc(100vw-1.5rem)] flex-wrap items-center gap-1 p-1.5"
+ >
+ {children}
+ </PopoverContent>
+ </Popover>
+ );
+}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
index 1b762993e9..746b0d9d00 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/ComposerPlusMenu.tsx
@@ -16,6 +16,7 @@ import {
Attachment01Icon,
BookOpen01Icon,
Calendar03Icon,
+ Camera01Icon,
FolderOpenIcon,
PlugSocketIcon,
PlusSignIcon,
@@ -55,9 +56,13 @@ export function ComposerPlusMenu({
const {
fileInputRef,
openModal,
+ cameraInputRef,
showWorkspaceOption,
+ showCameraOption,
openFilePicker,
+ openCamera,
handleFileChange,
+ handlePhotoChange,
} = useComposerPlusMenu({ onFilesSelected });
return (
@@ -70,6 +75,18 @@ export function ComposerPlusMenu({
onChange={handleFileChange}
tabIndex={-1}
/>
+ {/* Opens the rear camera on phones and tablets; the captured photo
+ goes through the same path as any attached file. */}
+ <input
+ ref={cameraInputRef}
+ type="file"
+ accept="image/*"
+ capture="environment"
+ className="hidden"
+ onChange={handlePhotoChange}
+ tabIndex={-1}
+ data-testid="composer-camera-input"
+ />
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
@@ -100,6 +117,19 @@ export function ComposerPlusMenu({
Attach file
{isAtCap && <CapLabel />}
</DropdownMenuItem>
+ {showCameraOption && (
+ <DropdownMenuItem
+ disabled={isAtCap}
+ onSelect={() => {
+ onClearGuidedPrompt?.();
+ openCamera();
+ }}
+ >
+ <Icon icon={Camera01Icon} className="mr-2 h-4 w-4" />
+ Take photo
+ {isAtCap && <CapLabel />}
+ </DropdownMenuItem>
+ )}
{showWorkspaceOption && (
<DropdownMenuItem
disabled={isAtCap}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerOverflowMenu.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerOverflowMenu.test.tsx
new file mode 100644
index 0000000000..846bf15905
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerOverflowMenu.test.tsx
@@ -0,0 +1,78 @@
+import { fireEvent, render, screen } from "@/tests/integrations/test-utils";
+import { describe, expect, it } from "vitest";
+import { ComposerOverflowMenu } from "../ComposerOverflowMenu";
+
+function openMenu() {
+ fireEvent.click(screen.getByTestId("composer-overflow-button"));
+}
+
+describe("ComposerOverflowMenu", () => {
+ it("keeps its controls tucked away until opened", () => {
+ render(
+ <ComposerOverflowMenu>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+
+ expect(screen.queryByText("Inner control")).toBeNull();
+ expect(screen.getByRole("button", { name: "More options" })).toBeDefined();
+ });
+
+ it("reveals its controls when the button is pressed", async () => {
+ render(
+ <ComposerOverflowMenu>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ openMenu();
+
+ expect(await screen.findByText("Inner control")).toBeDefined();
+ expect(screen.getByTestId("composer-overflow-panel")).toBeDefined();
+ });
+
+ it("stays shut while forced closed", () => {
+ render(
+ <ComposerOverflowMenu forceClosed>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ openMenu();
+
+ expect(screen.queryByText("Inner control")).toBeNull();
+ });
+
+ it("cannot be opened while disabled", () => {
+ render(
+ <ComposerOverflowMenu disabled>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ openMenu();
+
+ expect(screen.queryByText("Inner control")).toBeNull();
+ });
+
+ it("does not reopen on its own after being forced closed", async () => {
+ const { rerender } = render(
+ <ComposerOverflowMenu>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ openMenu();
+ expect(await screen.findByText("Inner control")).toBeDefined();
+
+ rerender(
+ <ComposerOverflowMenu forceClosed>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ expect(screen.queryByText("Inner control")).toBeNull();
+
+ rerender(
+ <ComposerOverflowMenu>
+ <button>Inner control</button>
+ </ComposerOverflowMenu>,
+ );
+ expect(screen.queryByText("Inner control")).toBeNull();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
index 5fe8591338..a6c4bff9d1 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/__tests__/ComposerPlusMenu.test.tsx
@@ -1,4 +1,9 @@
-import { fireEvent, render, screen } from "@/tests/integrations/test-utils";
+import {
+ fireEvent,
+ render,
+ screen,
+ waitFor,
+} from "@/tests/integrations/test-utils";
import { afterEach, describe, expect, it, vi } from "vitest";
import { useCopilotModal } from "../../../../useCopilotModal";
import { MAX_ATTACHMENTS } from "../../../../helpers/workspaceAttachments";
@@ -179,3 +184,69 @@ describe("ComposerPlusMenu", () => {
).toBeNull();
});
});
+
+describe("ComposerPlusMenu camera capture", () => {
+ function stubCoarsePointer(matches: boolean) {
+ vi.stubGlobal(
+ "matchMedia",
+ vi.fn().mockImplementation((query: string) => ({
+ matches: query === "(pointer: coarse)" && matches,
+ media: query,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ })),
+ );
+ }
+
+ afterEach(() => {
+ vi.unstubAllGlobals();
+ });
+
+ it("offers Take photo right after Attach file on touch devices", async () => {
+ stubCoarsePointer(true);
+ render(<ComposerPlusMenu onFilesSelected={vi.fn()} />);
+ openMenu();
+
+ const items = await screen.findAllByRole("menuitem");
+ expect(items.slice(0, 2).map((item) => item.textContent)).toEqual([
+ "Attach file",
+ "Take photo",
+ ]);
+ });
+
+ it("hides Take photo when the primary pointer is not touch", async () => {
+ stubCoarsePointer(false);
+ render(<ComposerPlusMenu onFilesSelected={vi.fn()} />);
+ openMenu();
+
+ await screen.findAllByRole("menuitem");
+ expect(screen.queryByRole("menuitem", { name: /take photo/i })).toBeNull();
+ });
+
+ it("uses a rear-camera image input and hands captured photos over", async () => {
+ stubCoarsePointer(true);
+ const onFilesSelected = vi.fn();
+ render(<ComposerPlusMenu onFilesSelected={onFilesSelected} />);
+
+ const input = screen.getByTestId("composer-camera-input");
+ expect(input.getAttribute("capture")).toBe("environment");
+ expect(input.getAttribute("accept")).toBe("image/*");
+
+ const photo = new File(["x"], "image.jpg", { type: "image/jpeg" });
+ fireEvent.change(input, { target: { files: [photo] } });
+
+ await waitFor(() => expect(onFilesSelected).toHaveBeenCalledTimes(1));
+ const [files] = onFilesSelected.mock.calls[0];
+ expect(files).toHaveLength(1);
+ expect(files[0].name).toMatch(/^photo-.*\.jpg$/);
+ });
+
+ it("disables Take photo at the attachment cap", async () => {
+ stubCoarsePointer(true);
+ render(<ComposerPlusMenu onFilesSelected={vi.fn()} isAtCap />);
+ openMenu();
+
+ const item = await screen.findByRole("menuitem", { name: /take photo/i });
+ expect(item.getAttribute("data-disabled")).not.toBeNull();
+ });
+});
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/useComposerPlusMenu.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/useComposerPlusMenu.ts
index e27f5d64e0..a9d6e87765 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/useComposerPlusMenu.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/components/useComposerPlusMenu.ts
@@ -1,6 +1,8 @@
import { Flag, useGetFlag } from "@/services/feature-flags/use-get-flag";
import { ChangeEvent, useRef } from "react";
import { useCopilotModal } from "../../../useCopilotModal";
+import { nameCapturedPhotos } from "../helpers";
+import { useIsTouchDevice } from "../useIsTouchDevice";
interface Args {
onFilesSelected: (files: File[]) => void;
@@ -8,13 +10,19 @@ interface Args {
export function useComposerPlusMenu({ onFilesSelected }: Args) {
const fileInputRef = useRef<HTMLInputElement>(null);
+ const cameraInputRef = useRef<HTMLInputElement>(null);
const { openModal } = useCopilotModal();
const showWorkspaceOption = useGetFlag(Flag.CHAT_WORKSPACE_FILES);
+ const showCameraOption = useIsTouchDevice();
function openFilePicker() {
fileInputRef.current?.click();
}
+ function openCamera() {
+ cameraInputRef.current?.click();
+ }
+
function handleFileChange(e: ChangeEvent<HTMLInputElement>) {
const files = Array.from(e.target.files ?? []);
if (files.length > 0) {
@@ -24,11 +32,23 @@ export function useComposerPlusMenu({ onFilesSelected }: Args) {
e.target.value = "";
}
+ function handlePhotoChange(e: ChangeEvent<HTMLInputElement>) {
+ const files = nameCapturedPhotos(Array.from(e.target.files ?? []));
+ if (files.length > 0) {
+ onFilesSelected(files);
+ }
+ e.target.value = "";
+ }
+
return {
fileInputRef,
+ cameraInputRef,
openModal,
showWorkspaceOption,
+ showCameraOption,
openFilePicker,
+ openCamera,
handleFileChange,
+ handlePhotoChange,
};
}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/helpers.ts
index 038ee1baa7..c2ad79b526 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/helpers.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/helpers.ts
@@ -14,10 +14,18 @@ export function getFilesFromClipboard(
clipboardData: DataTransfer | null,
): File[] {
if (!clipboardData) return [];
- return Array.from(clipboardData.files).map(renameGenericImage);
+ return Array.from(clipboardData.files).map((file, index) =>
+ renameGenericImage(file, index, "pasted-image"),
+ );
+}
+
+/** Mobile browsers hand every camera capture over as "image.jpg"; rename so
+ * photos taken in a row stay distinguishable in the composer and workspace. */
+export function nameCapturedPhotos(files: File[]): File[] {
+ return files.map((file, index) => renameGenericImage(file, index, "photo"));
}
-function renameGenericImage(file: File, index: number): File {
+function renameGenericImage(file: File, index: number, prefix: string): File {
if (
!file.type.startsWith("image/") ||
!GENERIC_CLIPBOARD_IMAGE_NAME.test(file.name)
@@ -27,7 +35,7 @@ function renameGenericImage(file: File, index: number): File {
const extension = file.name.split(".").pop();
const stamp = new Date().toISOString().slice(0, 23).replace(/[T:.]/g, "-");
const suffix = index > 0 ? `-${index + 1}` : "";
- return new File([file], `pasted-image-${stamp}${suffix}.${extension}`, {
+ return new File([file], `${prefix}-${stamp}${suffix}.${extension}`, {
type: file.type,
lastModified: file.lastModified,
});
@@ -142,3 +150,6 @@ export function insertIntegrationMention(
caret: range.start + integration.token.length + 1,
};
}
+
+/** Phone-sized send button: the default 32px target is too small for a thumb. */
+export const MOBILE_SEND_BUTTON_CLASS = "max-md:size-10";
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
new file mode 100644
index 0000000000..2916ad749a
--- /dev/null
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/ChatInput/useIsTouchDevice.ts
@@ -0,0 +1,27 @@
+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);
+ query.addEventListener("change", onChange);
+ 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);
+}