| ... | @@ -1,6 +1,8 @@ | ... | @@ -1,6 +1,8 @@ |
| 1 | import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts"; | 1 | import { CommandId, MessageId, ProjectId, ThreadId } from "@t3tools/contracts"; |
| 2 | import { type CxOptions, cx } from "class-variance-authority"; | 2 | import { type CxOptions, cx } from "class-variance-authority"; |
| 3 | import { twMerge } from "tailwind-merge"; | 3 | import { twMerge } from "tailwind-merge"; |
| | 4 | import * as Random from "effect/Random"; |
| | 5 | import * as Effect from "effect/Effect"; |
| 4 | | 6 | |
| 5 | export function cn(...inputs: CxOptions) { | 7 | export function cn(...inputs: CxOptions) { |
| 6 | return twMerge(cx(inputs)); | 8 | return twMerge(cx(inputs)); |
| ... | @@ -18,13 +20,7 @@ export function randomUUID(): string { | ... | @@ -18,13 +20,7 @@ export function randomUUID(): string { |
| 18 | if (typeof crypto.randomUUID === "function") { | 20 | if (typeof crypto.randomUUID === "function") { |
| 19 | return crypto.randomUUID(); | 21 | return crypto.randomUUID(); |
| 20 | } | 22 | } |
| 21 | // Fallback for non-secure contexts (plain HTTP on non-localhost) | 23 | return Effect.runSync(Random.nextUUIDv4); |
| 22 | const bytes = new Uint8Array(16); | | |
| 23 | crypto.getRandomValues(bytes); | | |
| 24 | bytes[6] = (bytes[6] & 0x0f) | 0x40; | | |
| 25 | bytes[8] = (bytes[8] & 0x3f) | 0x80; | | |
| 26 | const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(""); | | |
| 27 | return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; | | |
| 28 | } | 24 | } |
| 29 | | 25 | |
| 30 | export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID()); | 26 | export const newCommandId = (): CommandId => CommandId.makeUnsafe(randomUUID()); |