Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(web): polyfill crypto.randomUUID for non-secure HTTP contexts
Hiram Chirino9d2c2cae375b
diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsxindex 1023b37e1..599cbec52 100644--- a/apps/web/src/components/ChatView.tsx+++ b/apps/web/src/components/ChatView.tsx@@ -176,7 +176,7 @@ import {VisualStudioCode,Zed,} from "./Icons";-import { cn, isMacPlatform, isWindowsPlatform } from "~/lib/utils";+import { cn, isMacPlatform, isWindowsPlatform, randomUUID } from "~/lib/utils";import { Badge } from "./ui/badge";import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";import { Command, CommandItem, CommandList } from "./ui/command";@@ -426,7 +426,7 @@ function readFileAsDataUrl(file: File): Promise<string> {function buildTemporaryWorktreeBranchName(): string {// Keep the 8-hex suffix shape for backend temporary-branch detection.- const token = crypto.randomUUID().slice(0, 8).toLowerCase();+ const token = randomUUID().slice(0, 8).toLowerCase();return `${WORKTREE_BRANCH_PREFIX}/${token}`;}@@ -1363,13 +1363,13 @@ export default function ChatView({ threadId }: ChatViewProps) {}, [activeThreadId, setTerminalOpen, terminalState.terminalOpen]);const splitTerminal = useCallback(() => {if (!activeThreadId || hasReachedTerminalLimit) return;- const terminalId = `terminal-${crypto.randomUUID()}`;+ const terminalId = `terminal-${randomUUID()}`;storeSplitTerminal(activeThreadId, terminalId);setTerminalFocusRequestId((value) => value + 1);}, [activeThreadId, storeSplitTerminal, hasReachedTerminalLimit]);const createNewTerminal = useCallback(() => {if (!activeThreadId || hasReachedTerminalLimit) return;- const terminalId = `terminal-${crypto.randomUUID()}`;+ const terminalId = `terminal-${randomUUID()}`;storeNewTerminal(activeThreadId, terminalId);setTerminalFocusRequestId((value) => value + 1);}, [activeThreadId, storeNewTerminal, hasReachedTerminalLimit]);@@ -1438,7 +1438,7 @@ export default function ChatView({ threadId }: ChatViewProps) {const shouldCreateNewTerminal =wantsNewTerminal && terminalState.terminalIds.length < MAX_THREAD_TERMINAL_COUNT;const targetTerminalId = shouldCreateNewTerminal- ? `terminal-${crypto.randomUUID()}`+ ? `terminal-${randomUUID()}`: baseTerminalId;setTerminalOpen(true);@@ -2331,7 +2331,7 @@ export default function ChatView({ threadId }: ChatViewProps) {const previewUrl = URL.createObjectURL(file);nextImages.push({type: "image",- id: crypto.randomUUID(),+ id: randomUUID(),name: file.name || "image",mimeType: file.type,sizeBytes: file.size,diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.tsindex 7684e68d7..9c2311ba8 100644--- a/apps/web/src/lib/utils.ts+++ b/apps/web/src/lib/utils.ts@@ -14,10 +14,23 @@ export function isWindowsPlatform(platform: string): boolean {return /^win(dows)?/i.test(platform);}-export const newCommandId = (): CommandId => CommandId.makeUnsafe(crypto.randomUUID());+export function randomUUID(): string {+ if (typeof crypto.randomUUID === "function") {+ return crypto.randomUUID();+ }+ // Fallback for non-secure contexts (plain HTTP on non-localhost)+ const bytes = new Uint8Array(16);+ crypto.getRandomValues(bytes);+ bytes[6] = (bytes[6] & 0x0f) | 0x40;+ bytes[8] = (bytes[8] & 0x3f) | 0x80;+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;+}++export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());-export const newProjectId = (): ProjectId => ProjectId.makeUnsafe(crypto.randomUUID());+export const newProjectId = (): ProjectId => ProjectId.makeUnsafe(randomUUID());-export const newThreadId = (): ThreadId => ThreadId.makeUnsafe(crypto.randomUUID());+export const newThreadId = (): ThreadId => ThreadId.makeUnsafe(randomUUID());-export const newMessageId = (): MessageId => MessageId.makeUnsafe(crypto.randomUUID());+export const newMessageId = (): MessageId => MessageId.makeUnsafe(randomUUID());