generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtierSettings.ts
More file actions
93 lines (81 loc) · 3.02 KB
/
tierSettings.ts
File metadata and controls
93 lines (81 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { GameSettings, UserTier } from './types';
export const ADMIN_MAX_AP = 100;
export const NORMAL_MAX_AP = 5;
export const GUEST_MAX_AP = 20;
export type ApRecoveryConfig = { amount: number; intervalMs: number };
const HOUR_MS = 60 * 60 * 1000;
const DAY_MS = 24 * HOUR_MS;
const TIER_SETTINGS: Record<UserTier, {
maxAp: number;
minImageTurns: number;
defaultImageTurns: number;
historyLimit: number;
apRecovery?: ApRecoveryConfig | null;
}> = {
admin: { maxAp: ADMIN_MAX_AP, minImageTurns: 1, defaultImageTurns: 1, historyLimit: 30, apRecovery: null },
normal: { maxAp: NORMAL_MAX_AP, minImageTurns: 20, defaultImageTurns: 20, historyLimit: 30, apRecovery: { amount: 1, intervalMs: HOUR_MS } },
guest: { maxAp: GUEST_MAX_AP, minImageTurns: 20, defaultImageTurns: 20, historyLimit: 20, apRecovery: null }
};
export const DEFAULT_SETTINGS: GameSettings = {
highQualityImages: true,
imagesEnabled: true,
imageEveryTurns: TIER_SETTINGS.normal.defaultImageTurns,
maxHistoryTurns: TIER_SETTINGS.normal.historyLimit,
saveMode: 'web',
savePath: '',
useProxy: false,
proxyBaseUrl: '',
modelProvider: 'gemini',
textProvider: 'gemini',
imageProvider: 'gemini',
textModel: '',
imageModel: '',
userSystemPrompt: '',
userSystemPromptCustom: false,
imageUserSystemPrompt: '',
maxCompressedMemoryK: 25,
textScale: 1,
pipelineMode: 'event',
interfaceColor: { r: 26, g: 255, b: 26 },
autoSaveEnabled: false
};
export const getTierSettings = (tier: UserTier) => TIER_SETTINGS[tier];
export const getMaxApForTier = (tier: UserTier) => TIER_SETTINGS[tier].maxAp;
export const getMinImageTurnsForTier = (tier: UserTier) => TIER_SETTINGS[tier].minImageTurns;
export const getDefaultImageTurnsForTier = (tier: UserTier) =>
TIER_SETTINGS[tier].defaultImageTurns;
export const getHistoryLimitForTier = (tier: UserTier) =>
TIER_SETTINGS[tier].historyLimit;
export const getApRecoveryForTier = (tier: UserTier) =>
TIER_SETTINGS[tier].apRecovery ?? null;
export const normalizeSettingsForTier = (
settings: GameSettings,
tier: UserTier,
minTurnsOverride?: number
) => {
const minTurns = typeof minTurnsOverride === 'number'
? minTurnsOverride
: getMinImageTurnsForTier(tier);
const fallbackTurns = settings.imageEveryTurns || getDefaultImageTurnsForTier(tier);
const rawHistory = settings.maxHistoryTurns;
const historyValue = Number.isFinite(rawHistory)
? Math.trunc(rawHistory as number)
: DEFAULT_SETTINGS.maxHistoryTurns;
const normalizedHistory = historyValue === -1
? -1
: historyValue < -1
? -1
: Math.max(1, historyValue);
const rawMemoryK = settings.maxCompressedMemoryK;
const memoryValue = Number.isFinite(rawMemoryK)
? Math.trunc(rawMemoryK as number)
: DEFAULT_SETTINGS.maxCompressedMemoryK;
const normalizedMemoryK = Math.max(1, memoryValue);
return {
...DEFAULT_SETTINGS,
...settings,
imageEveryTurns: Math.max(minTurns, Math.floor(fallbackTurns)),
maxHistoryTurns: normalizedHistory,
maxCompressedMemoryK: normalizedMemoryK
};
};