diff --git a/apps/web/src/lib/utils.ts b/apps/web/src/lib/utils.ts index 9c2311ba8fd1d83ff4684943812562b1123d86eb..08a5de91e6619470d1b7d71d49fd1dea79b94ce5 100644 --- a/apps/web/src/lib/utils.ts +++ b/apps/web/src/lib/utils.ts @@ -1,6 +1,8 @@ import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts"; import { type CxOptions, cx } from "class-variance-authority"; import { twMerge } from "tailwind-merge"; +import * as Random from "effect/Random"; +import * as Effect from "effect/Effect"; export function cn(...inputs: CxOptions) { return twMerge(cx(inputs)); @@ -18,13 +20,7 @@ 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)}`; + return Effect.runSync(Random.nextUUIDv4); } export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID());