Replace all crypto.randomUUID() calls with a uuid() utility that falls back to Math.random-based generation when the Web Crypto API is unavailable (plain HTTP contexts). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Database, ShoppingCart, Zap } from 'lucide-react';
|
import { Database, ShoppingCart, Zap } from 'lucide-react';
|
||||||
import { useGameStore } from '@/store';
|
import { useGameStore } from '@/store';
|
||||||
import { formatNumber, formatMoney } from '@ai-tycoon/shared';
|
import { formatNumber, formatMoney, uuid } from '@ai-tycoon/shared';
|
||||||
import type { OwnedDataset, DataDomain } from '@ai-tycoon/shared';
|
import type { OwnedDataset, DataDomain } from '@ai-tycoon/shared';
|
||||||
|
|
||||||
interface MarketplaceDataset {
|
interface MarketplaceDataset {
|
||||||
@@ -49,7 +49,7 @@ export function DataPage() {
|
|||||||
|
|
||||||
const handlePurchase = (item: MarketplaceDataset) => {
|
const handlePurchase = (item: MarketplaceDataset) => {
|
||||||
const dataset: OwnedDataset = {
|
const dataset: OwnedDataset = {
|
||||||
id: crypto.randomUUID(),
|
id: uuid(),
|
||||||
name: item.name,
|
name: item.name,
|
||||||
domain: item.domain,
|
domain: item.domain,
|
||||||
sizeTokens: item.sizeTokens,
|
sizeTokens: item.sizeTokens,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import {
|
|||||||
GPU_CONFIGS,
|
GPU_CONFIGS,
|
||||||
FUNDING_ROUNDS,
|
FUNDING_ROUNDS,
|
||||||
OPEN_SOURCE_REPUTATION_BOOST,
|
OPEN_SOURCE_REPUTATION_BOOST,
|
||||||
|
uuid,
|
||||||
} from '@ai-tycoon/shared';
|
} from '@ai-tycoon/shared';
|
||||||
import { INITIAL_RIVALS } from '@ai-tycoon/game-engine';
|
import { INITIAL_RIVALS } from '@ai-tycoon/game-engine';
|
||||||
|
|
||||||
@@ -105,7 +106,7 @@ export const useGameStore = create<Store>()(
|
|||||||
|
|
||||||
addNotification: (n) => set((s) => ({
|
addNotification: (n) => set((s) => ({
|
||||||
notifications: [
|
notifications: [
|
||||||
{ ...n, id: crypto.randomUUID(), read: false },
|
{ ...n, id: uuid(), read: false },
|
||||||
...s.notifications.slice(0, 49),
|
...s.notifications.slice(0, 49),
|
||||||
],
|
],
|
||||||
})),
|
})),
|
||||||
@@ -176,7 +177,7 @@ export const useGameStore = create<Store>()(
|
|||||||
if (s.economy.money < buildCost) return s;
|
if (s.economy.money < buildCost) return s;
|
||||||
|
|
||||||
const dc: DataCenter = {
|
const dc: DataCenter = {
|
||||||
id: crypto.randomUUID(),
|
id: uuid(),
|
||||||
name,
|
name,
|
||||||
location,
|
location,
|
||||||
gpus: [],
|
gpus: [],
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { GameState, EventState, ActiveEvent, EventDefinition, EventCondition } from '@ai-tycoon/shared';
|
import type { GameState, EventState, ActiveEvent, EventDefinition, EventCondition } from '@ai-tycoon/shared';
|
||||||
|
import { uuid } from '@ai-tycoon/shared';
|
||||||
|
|
||||||
export interface EventTickResult {
|
export interface EventTickResult {
|
||||||
events: EventState;
|
events: EventState;
|
||||||
@@ -73,7 +74,7 @@ export function processEvents(
|
|||||||
|
|
||||||
const activeEvent: ActiveEvent = {
|
const activeEvent: ActiveEvent = {
|
||||||
eventId: chosen.id,
|
eventId: chosen.id,
|
||||||
instanceId: crypto.randomUUID(),
|
instanceId: uuid(),
|
||||||
triggeredAtTick: tick,
|
triggeredAtTick: tick,
|
||||||
expiresAtTick: tick + chosen.expiryTicks,
|
expiresAtTick: tick + chosen.expiryTicks,
|
||||||
title: chosen.title,
|
title: chosen.title,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { GameState, ModelsState, TrainedModel, ModelCapabilities } from '@ai-tycoon/shared';
|
import type { GameState, ModelsState, TrainedModel, ModelCapabilities } from '@ai-tycoon/shared';
|
||||||
|
import { uuid } from '@ai-tycoon/shared';
|
||||||
|
|
||||||
export interface ModelTickResult {
|
export interface ModelTickResult {
|
||||||
modelsState: ModelsState;
|
modelsState: ModelsState;
|
||||||
@@ -79,7 +80,7 @@ function createTrainedModel(
|
|||||||
const parameterCount = Math.pow(10, generation) * (0.5 + Math.random());
|
const parameterCount = Math.pow(10, generation) * (0.5 + Math.random());
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: crypto.randomUUID(),
|
id: uuid(),
|
||||||
name,
|
name,
|
||||||
generation,
|
generation,
|
||||||
parameterCount,
|
parameterCount,
|
||||||
|
|||||||
@@ -24,6 +24,16 @@ export function formatFlops(n: number): string {
|
|||||||
return `${formatNumber(n)} FLOPS`;
|
return `${formatNumber(n)} FLOPS`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function uuid(): string {
|
||||||
|
if (typeof crypto !== 'undefined' && crypto.randomUUID) {
|
||||||
|
return crypto.randomUUID();
|
||||||
|
}
|
||||||
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
|
const r = (Math.random() * 16) | 0;
|
||||||
|
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function formatDuration(ticks: number): string {
|
export function formatDuration(ticks: number): string {
|
||||||
if (ticks < 60) return `${ticks}s`;
|
if (ticks < 60) return `${ticks}s`;
|
||||||
if (ticks < 3600) return `${Math.floor(ticks / 60)}m ${ticks % 60}s`;
|
if (ticks < 3600) return `${Math.floor(ticks / 60)}m ${ticks % 60}s`;
|
||||||
|
|||||||
Reference in New Issue
Block a user