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/autopilot): improve AutoPilot OS push notification icon and copy (#13231)
Krzysztof Czerwinski6ecb0cc1afbe
diff --git a/autogpt_platform/frontend/public/notification-icon-192.png b/autogpt_platform/frontend/public/notification-icon-192.pngnew file mode 100644index 0000000000..252219f0d2Binary files /dev/null and b/autogpt_platform/frontend/public/notification-icon-192.png differdiff --git a/autogpt_platform/frontend/public/notification-icon-512.png b/autogpt_platform/frontend/public/notification-icon-512.pngnew file mode 100644index 0000000000..7d5b5bf0e7Binary files /dev/null and b/autogpt_platform/frontend/public/notification-icon-512.png differdiff --git a/autogpt_platform/frontend/public/push-sw.js b/autogpt_platform/frontend/public/push-sw.jsindex 2a52701797..b923070fc0 100644--- a/autogpt_platform/frontend/public/push-sw.js+++ b/autogpt_platform/frontend/public/push-sw.js@@ -6,13 +6,13 @@var NOTIFICATION_MAP = {copilot_completion: {session_completed: {- title: "AutoPilot is ready",- body: "A response is waiting for you.",+ title: "AutoGPT",+ body: "Task completed",url: "/copilot",},session_failed: {- title: "AutoPilot session failed",- body: "Something went wrong with your session.",+ title: "AutoGPT",+ body: "Task failed",url: "/copilot",},},@@ -152,8 +152,8 @@ self.addEventListener("push", function (event) {var options = {body: config.body,- icon: "/favicon.ico",- badge: "/favicon.ico",+ icon: "/notification-icon-192.png",+ badge: "/notification-icon-192.png",tag: tag,data: Object.assign({ url: targetUrl }, data),renotify: true,diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/helpers.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/helpers.test.tsindex 5e94feeda7..bd579fd4d7 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/helpers.test.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/helpers.test.ts@@ -2,6 +2,7 @@ import type { UIMessage } from "ai";import { beforeEach, describe, expect, it, vi } from "vitest";import { IMPERSONATION_HEADER_NAME } from "@/lib/constants";import {+ COPILOT_COMPLETION_NOTIFICATION,ORIGINAL_TITLE,deduplicateMessages,extractSendMessageText,@@ -54,6 +55,16 @@ describe("formatNotificationTitle", () => {});});+describe("COPILOT_COMPLETION_NOTIFICATION", () => {+ it("matches the copy hardcoded in public/push-sw.js", () => {+ expect(COPILOT_COMPLETION_NOTIFICATION).toEqual({+ title: "AutoGPT",+ body: "Task completed",+ icon: "/notification-icon-192.png",+ });+ });+});+describe("parseSessionIDs", () => {it("returns empty set for null", () => {expect(parseSessionIDs(null)).toEqual(new Set());diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotNotifications.test.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotNotifications.test.tsxnew file mode 100644index 0000000000..09183eefc5--- /dev/null+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/useCopilotNotifications.test.tsx@@ -0,0 +1,111 @@+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { renderHook, cleanup, act, waitFor } from "@testing-library/react";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import type { ReactNode } from "react";++import { COPILOT_COMPLETION_NOTIFICATION } from "../helpers";++type WSHandler = (notification: unknown) => void;+let capturedHandler: WSHandler | null = null;++vi.mock("@/lib/autogpt-server-api/context", () => ({+ useBackendAPI: () => ({+ onWebSocketMessage: (_event: string, handler: WSHandler) => {+ capturedHandler = handler;+ return () => {};+ },+ }),+ BackendAPIProvider: ({ children }: { children: ReactNode }) => children,+}));++import { useCopilotNotifications } from "../useCopilotNotifications";+import { useCopilotUIStore } from "../store";++const NotificationCtor = vi.fn();+class FakeNotification {+ onclick: (() => void) | null = null;+ close = vi.fn();+ constructor(title: string, opts: { body: string; icon: string }) {+ NotificationCtor(title, opts);+ }+}++function makeWrapper() {+ const queryClient = new QueryClient({+ defaultOptions: { queries: { retry: false } },+ });+ return function Wrapper({ children }: { children: ReactNode }) {+ return (+ <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>+ );+ };+}++beforeEach(() => {+ capturedHandler = null;+ NotificationCtor.mockClear();++ (+ FakeNotification as unknown as { permission: NotificationPermission }+ ).permission = "granted";+ vi.stubGlobal("Notification", FakeNotification);++ useCopilotUIStore.setState({+ completedSessionIDs: new Set(),+ isNotificationsEnabled: true,+ isSoundEnabled: false,+ });++ Object.defineProperty(document, "visibilityState", {+ configurable: true,+ get: () => "hidden",+ });+});++afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();+});++describe("useCopilotNotifications — OS notification dispatch", () => {+ it("fires a browser notification with the AutoGPT/Task completed copy and 192px icon when a non-active session completes off-screen", async () => {+ renderHook(() => useCopilotNotifications(null), { wrapper: makeWrapper() });+ expect(capturedHandler).not.toBeNull();++ act(() => {+ capturedHandler!({+ type: "copilot_completion",+ event: "session_completed",+ session_id: "sess-1",+ });+ });++ await waitFor(() => {+ expect(NotificationCtor).toHaveBeenCalledTimes(1);+ });+ expect(NotificationCtor).toHaveBeenCalledWith(+ COPILOT_COMPLETION_NOTIFICATION.title,+ {+ body: COPILOT_COMPLETION_NOTIFICATION.body,+ icon: COPILOT_COMPLETION_NOTIFICATION.icon,+ },+ );+ });++ it("does not fire a notification for unrelated event types", async () => {+ renderHook(() => useCopilotNotifications(null), { wrapper: makeWrapper() });+ expect(capturedHandler).not.toBeNull();++ act(() => {+ capturedHandler!({+ type: "copilot_completion",+ event: "something_else",+ session_id: "sess-2",+ });+ });++ await waitFor(() => {+ expect(NotificationCtor).not.toHaveBeenCalled();+ });+ });+});diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers.tsindex f7ab38a46d..ac0fefce80 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/helpers.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/helpers.ts@@ -7,6 +7,19 @@ import { TOOL_PART_PREFIX } from "./components/JobStatsBar/constants";export const ORIGINAL_TITLE = "AutoGPT";+/**+ * Title/body/icon for the OS-level notification fired when a copilot session+ * completes. Kept in sync with the same copy hardcoded in `public/push-sw.js`+ * (NOTIFICATION_MAP.copilot_completion.session_completed) — the SW file is+ * plain JS served from /public and can't import from this module, so the two+ * sources are matched by test rather than by reference.+ */+export const COPILOT_COMPLETION_NOTIFICATION = {+ title: "AutoGPT",+ body: "Task completed",+ icon: "/notification-icon-192.png",+} as const;+/*** Returns HTTP headers required for direct backend requests from copilot:* - Authorization Bearer token (JWT)diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotNotifications.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotNotifications.tsindex a57f428a90..a3057897d2 100644--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotNotifications.ts+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotNotifications.ts@@ -4,6 +4,7 @@ import { Key } from "@/services/storage/local-storage";import { useQueryClient } from "@tanstack/react-query";import { useEffect, useRef } from "react";import {+ COPILOT_COMPLETION_NOTIFICATION,ORIGINAL_TITLE,formatNotificationTitle,parseSessionIDs,@@ -115,9 +116,9 @@ export function useCopilotNotifications(activeSessionID: string | null) {Notification.permission === "granted" &&isUserAway) {- showBrowserNotification("AutoPilot is ready", {- body: "A response is waiting for you.",- icon: "/favicon.ico",+ showBrowserNotification(COPILOT_COMPLETION_NOTIFICATION.title, {+ body: COPILOT_COMPLETION_NOTIFICATION.body,+ icon: COPILOT_COMPLETION_NOTIFICATION.icon,sessionID,});}diff --git a/autogpt_platform/frontend/src/services/push-notifications/__tests__/push-sw-helpers.test.ts b/autogpt_platform/frontend/src/services/push-notifications/__tests__/push-sw-helpers.test.tsindex 51ffd97f12..f5b0e864eb 100644--- a/autogpt_platform/frontend/src/services/push-notifications/__tests__/push-sw-helpers.test.ts+++ b/autogpt_platform/frontend/src/services/push-notifications/__tests__/push-sw-helpers.test.ts@@ -55,7 +55,8 @@ describe("push-sw getNotificationConfig", () => {type: "copilot_completion",event: "session_completed",});- expect(config.title).toBe("AutoPilot is ready");+ expect(config.title).toBe("AutoGPT");+ expect(config.body).toBe("Task completed");expect(config.url).toBe("/copilot");});@@ -64,7 +65,8 @@ describe("push-sw getNotificationConfig", () => {type: "copilot_completion",event: "session_failed",});- expect(config.title).toBe("AutoPilot session failed");+ expect(config.title).toBe("AutoGPT");+ expect(config.body).toBe("Task failed");});it("falls back to generic notification for unknown type", () => {