-
Notifications
You must be signed in to change notification settings - Fork 247
Expand file tree
/
Copy pathcommon.tsx
More file actions
291 lines (257 loc) · 12.2 KB
/
common.tsx
File metadata and controls
291 lines (257 loc) · 12.2 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
import { t } from '@/i18n';
import {
AdjustmentsHorizontalIcon,
ChatBubbleOvalLeftEllipsisIcon,
IdentificationIcon,
LanguageIcon,
UsersIcon,
CommandLineIcon,
RocketLaunchIcon,
FaceSmileIcon,
MusicalNoteIcon,
PowerIcon,
PhotoIcon,
FilmIcon,
SpeakerWaveIcon,
DocumentTextIcon,
Cog6ToothIcon,
PencilSquareIcon,
PencilIcon,
EyeDropperIcon,
EyeIcon,
SwatchIcon,
MoonIcon,
SunIcon,
CogIcon,
ArrowTopRightOnSquareIcon,
} from '@heroicons/react/24/outline';
import logo from '/public/logo.png';
export function basicPage(
title: string,
description: React.ReactNode,
children: React.ReactNode,
) {
return (
<>
<div className="rounded-lg shadow-lg bg-white p-4">
<h2 className="text-xl w-full">{title}</h2>
<p className="w-full my-4">{description}</p>
<div className="mt-4">
{children}
</div>
</div>
</>
);
}
export function BasicPage({
title,
description,
children,
}: {
title: string,
description: React.ReactNode,
children: React.ReactNode,
}) {
return (
<>
<div className="rounded-lg shadow-lg bg-white p-4">
<h2 className="text-xl w-full">{title}</h2>
<p className="w-full my-4">{description}</p>
<div className="mt-4">
{children}
</div>
</div>
</>
);
}
export function FormRow({label, children}: {
label: string;
children: React.ReactNode;
}) {
return (
<div className="sm:col-span-3 max-w-xs rounded-xl">
<label className="block text-sm font-medium leading-6 text-gray-900">
{label}
</label>
<div className="mt-2">
{children}
</div>
</div>
);
}
export function basename(path: string) {
if (!path || typeof path !== 'string') return "";
const a = path.split("/");
return a[a.length - 1];
}
export function thumbPrefix(path: string) {
const a = path.split("/");
a[a.length - 1] = "thumb-" + a[a.length - 1];
return a.join("/");
}
export function hashCode(str: string): string {
var hash = 0, i = 0, len = str.length;
while ( i < len ) {
hash = ((hash << 5) - hash + str.charCodeAt(i++)) << 0;
}
return hash.toString();
}
/** Хеш для больших строк (VRM base64): берём начало, конец и длину, чтобы не блокировать UI. */
const SAMPLE_SIZE = 100000;
export function hashCodeLarge(str: string): string {
const len = str.length;
if (len <= SAMPLE_SIZE * 2) return hashCode(str);
let h = 0;
for (let i = 0; i < SAMPLE_SIZE; i++) h = ((h << 5) - h + str.charCodeAt(i)) << 0;
for (let i = len - SAMPLE_SIZE; i < len; i++) h = ((h << 5) - h + str.charCodeAt(i)) << 0;
h = ((h << 5) - h + len) << 0;
return h.toString();
}
export type Link = {
key: string;
label: string;
icon?: JSX.Element;
className?: string;
}
export function getLinkFromPage(page: string) {
return {
key: page,
label: getLabelFromPage(page),
icon: getIconFromPage(page),
className: getClassNameFromPage(page),
};
}
export function pagesToLinks(keys: string[]): Link[] {
const links: Link[] = [];
for (const key of keys) {
links.push(getLinkFromPage(key));
}
return links;
}
export type PageProps = {
setPage: (page: string) => void;
breadcrumbs: Link[];
setBreadcrumbs: (breadcrumbs: Link[]) => void;
}
export function getIconFromPage(page: string): JSX.Element {
switch(page) {
case 'appearance': return <FaceSmileIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'amica_life': return <SunIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'chatbot': return <ChatBubbleOvalLeftEllipsisIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'language': return <LanguageIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'tts': return <MusicalNoteIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'stt': return <PencilIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision': return <EyeIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'external_api': return <ArrowTopRightOnSquareIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'reset_settings': return <PowerIcon className="h-5 w-5 flex-none text-red-500" aria-hidden="true" />;
case 'developer': return <CommandLineIcon className="h-5 w-5 flex-none text-green-500" aria-hidden="true" />;
case 'community': return <RocketLaunchIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'background_img': return <PhotoIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'background_color': return <SwatchIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'background_video': return <FilmIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'character_model': return <UsersIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'character_animation': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'chatbot_backend': return <Cog6ToothIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'arbius_llm_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'chatgpt_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'llamacpp_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'ollama_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'koboldai_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'moshi_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'openrouter_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'name': return <IdentificationIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'system_prompt': return <DocumentTextIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'tts_backend': return <SpeakerWaveIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'elevenlabs_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'speecht5_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'openai_tts_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'piper_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'rvc_settings': return <CogIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'coquiLocal_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'localXTTS_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'kokoro_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'stt_backend': return <PencilSquareIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'stt_wake_word': return <MoonIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'whisper_openai_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'whispercpp_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision_backend': return <EyeDropperIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision_llamacpp_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision_ollama_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision_openai_settings': return <AdjustmentsHorizontalIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
case 'vision_system_prompt': return <DocumentTextIcon className="h-5 w-5 flex-none text-gray-800" aria-hidden="true" />;
}
return <></>;
}
function getLabelFromPage(page: string): string {
switch(page) {
case 'appearance': return t('Appearance');
case 'amica_life': return t('Amica Life');
case 'chatbot': return t('ChatBot');
case 'language': return t('Language');
case 'tts': return t('Text-to-Speech');
case 'stt': return t('Speech-to-text');
case 'vision': return t('Vision');
case 'external_api': return t('External API');
case 'reset_settings': return t('Reset Settings');
case 'developer': return t('Developer');
case 'community': return t('Community');
case 'background_img': return t('Background Image');
case 'background_color': return t('Background Color');
case 'background_video': return t('Background Video');
case 'character_model': return t('Character Model');
case 'character_animation': return t('Character Animation');
case 'chatbot_backend': return t('ChatBot Backend');
case 'arbius_llm_settings': return t('Arbius');
case 'chatgpt_settings': return t('ChatGPT');
case 'llamacpp_settings': return t('LLama.cpp');
case 'ollama_settings': return t('Ollama');
case 'koboldai_settings': return t('KoboldAI');
case 'moshi_settings': return t('Moshi');
case 'openrouter_settings': return t('OpenRouter');
case 'name' : return t('Name');
case 'system_prompt': return t('System Prompt');
case 'tts_backend': return t('TTS Backend');
case 'elevenlabs_settings': return t('ElevenLabs');
case 'speecht5_settings': return t('SpeechT5');
case 'openai_tts_settings': return t('OpenAI');
case 'piper_settings': return t('Piper');
case 'rvc_settings': return t('RVC');
case 'coquiLocal_settings': return t('Coqui Local');
case 'localXTTS_settings': return t('Alltalk');
case 'kokoro_settings': return t('Kokoro');
case 'vision_backend': return t('Vision Backend');
case 'vision_llamacpp_settings': return t('LLama.cpp');
case 'vision_ollama_settings': return t('Ollama');
case 'vision_openai_settings': return t('OpenAI');
case 'vision_system_prompt': return t('System Prompt');
case 'stt_backend': return t('STT Backend');
case 'stt_wake_word': return t("Wake word");
case 'whisper_openai_settings': return t("Whisper (OpenAI)");
case 'whispercpp_settings': return t("Whisper.cpp");
}
throw new Error(`unknown page label encountered ${page}`);
}
function getClassNameFromPage(page: string) {
switch(page) {
case 'reset_settings': return 'text-red-500';
}
return '';
}
export function ResetToDefaultButton({ onClick }: { onClick: () => void }) {
return (
<button
type="button"
onClick={onClick}
className="inline-flex items-center px-2.5 py-1.5 border border-transparent text-xs font-medium rounded shadow-sm text-white bg-rose-600 hover:bg-rose-700 focus:outline-none"
>
{t("Reset to Default")}
</button>
);
}
export function NotUsingAlert({ children }: { children: React.ReactNode }) {
return (
<div className="bg-yellow-50 border-l-4 border-yellow-400 p-4">
{children}
</div>
);
}