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): queue a message on a plain-HTTP origin without crashing the chat (#14686)

Bentlyf292d948e0cc
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/expertKickoff.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/expertKickoff.ts
index 97549a6124..d60c88ca75 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/expertKickoff.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/expertKickoff.ts
@@ -1,5 +1,6 @@
import { isValidUUID } from "@/lib/utils";
import type { UIMessage } from "ai";
+import { v4 as uuidv4 } from "uuid";
const EXPERT_KICKOFF_KIND = "expert_kickoff";
const KICKOFF_STORAGE_PREFIX = "expert-kickoff-status:";
@@ -166,7 +167,8 @@ export function markKickoffPending(
userId: string,
expertId: string,
): KickoffAttemptToken {
- const attemptToken = `${Date.now()}:${crypto.randomUUID()}`;
+ // uuidv4({}) rather than crypto.randomUUID, which is missing on plain HTTP.
+ const attemptToken = `${Date.now()}:${uuidv4({})}`;
if (typeof window === "undefined") return attemptToken;
try {
window.localStorage.setItem(
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.test.ts
index e704c786fb..30f5525761 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.test.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.test.ts
@@ -68,6 +68,26 @@ describe("useCopilotPendingChips", () => {
});
afterEach(cleanup);
+ it("queues a message on a plain-HTTP LAN origin, where crypto.randomUUID is missing", () => {
+ const originalCrypto = globalThis.crypto;
+ vi.stubGlobal("crypto", {
+ getRandomValues: originalCrypto.getRandomValues.bind(originalCrypto),
+ });
+ try {
+ const { view } = setupHook([assistantMessage(0)]);
+
+ act(() => {
+ view.result.current.queueMessage("sent while a turn was streaming");
+ });
+
+ expect(view.result.current.queuedMessages).toEqual([
+ "sent while a turn was streaming",
+ ]);
+ } finally {
+ vi.unstubAllGlobals();
+ }
+ });
+
it("promotes a queued chip to a bubble the instant a data-pending-drained hint arrives", async () => {
const { view, getMessages } = setupHook([assistantMessage(0)]);
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.ts
index 0d805599e5..54fa1ed058 100644
--- a/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/copilot/useCopilotPendingChips.ts
@@ -3,6 +3,7 @@ import type { UIMessage } from "ai";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { makePromotedUserBubble } from "./helpers/makePromotedBubble";
+import { v4 as uuidv4 } from "uuid";
// Backstop only. Promotion is normally driven instantly by the backend's
// ``data-pending-drained`` SSE hint (see ``useMidTurnDrainPromotion``); this
@@ -86,7 +87,10 @@ export function useCopilotPendingChips({
});
const queueMessage = useCallback((text: string) => {
- setQueue((prev) => [...prev, { id: crypto.randomUUID(), text }]);
+ // Options force uuid's getRandomValues path: crypto.randomUUID does not
+ // exist on a plain-HTTP LAN origin, and this updater runs during render,
+ // so there it took the whole chat page down instead of queueing.
+ setQueue((prev) => [...prev, { id: uuidv4({}), text }]);
}, []);
return { queuedMessages, queueMessage };
@@ -194,7 +198,7 @@ function usePeekOnBoundary({
// disappears.
setQueue((current) => {
const fromServer = res.data.messages.map((text) => ({
- id: crypto.randomUUID(),
+ id: uuidv4({}),
text,
}));
const queuedDuringWindow = current.filter(