forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstants.ts
More file actions
412 lines (365 loc) · 13.7 KB
/
Copy pathconstants.ts
File metadata and controls
412 lines (365 loc) · 13.7 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
Copyright (C) 2023-2026 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// ============================================================================
// Channel Types (from constant/channel.go)
// All label/name values are i18n keys; use t(value) when displaying.
// ============================================================================
export const CHANNEL_TYPE_NEW_API = 60
export const CHANNEL_TYPES = {
0: 'Unknown',
1: 'OpenAI',
2: 'MjProxy',
3: 'Azure',
4: 'Ollama',
5: 'MjProxyPlus',
// 6: 'OpenAIMax',
7: 'OhMyGPT',
8: 'Custom',
// 9: 'AILS',
// 10: 'AI Proxy',
// 11: 'PaLM',
// 12: 'API2GPT',
// 13: 'AIGC2D',
14: 'Anthropic',
15: 'Baidu',
16: 'Zhipu',
17: 'Ali',
18: 'Xunfei',
19: '360',
20: 'OpenRouter',
// 21: 'AI Proxy Library',
22: 'FastGPT',
23: 'Tencent',
24: 'Gemini',
25: 'Moonshot',
26: 'Zhipu V4',
27: 'Perplexity',
31: 'LingYiWanWu',
33: 'AWS',
34: 'Cohere',
35: 'MiniMax',
36: 'SunoAPI',
37: 'Dify',
38: 'Jina',
39: 'Cloudflare',
40: 'SiliconFlow',
41: 'Vertex AI',
42: 'Mistral',
43: 'DeepSeek',
44: 'MokaAI',
45: 'VolcEngine',
46: 'Baidu V2',
47: 'Xinference',
48: 'xAI',
49: 'Coze',
50: 'Kling',
51: 'Jimeng',
52: 'Vidu',
53: 'Submodel',
54: 'DoubaoVideo',
55: 'Sora',
56: 'Replicate',
57: 'ChatGPT Subscription (Codex)',
58: 'Advanced Custom',
59: 'Sub2API',
60: 'New API',
} as const
const CHANNEL_TYPE_DISPLAY_ORDER: number[] = [
1, 14, 33, 24, 43, 3, 41, 48, 60, 58, 42, 34, 20, 4, 40, 27, 25, 17, 26, 15,
46, 23, 18, 45, 31, 35, 49, 19, 47, 37, 38, 39, 11, 8, 57, 59, 22, 21, 44, 2,
5, 36, 50, 51, 52, 53, 54, 55, 56,
]
export const CHANNEL_TYPE_OPTIONS: { value: number; label: string }[] = (() => {
const ordered: { value: number; label: string }[] = []
const seen = new Set<number>()
for (const id of CHANNEL_TYPE_DISPLAY_ORDER) {
const label = CHANNEL_TYPES[id as keyof typeof CHANNEL_TYPES]
if (label) {
ordered.push({ value: id, label })
seen.add(id)
}
}
for (const [key, label] of Object.entries(CHANNEL_TYPES)) {
const id = Number(key)
if (id !== 0 && !seen.has(id)) {
ordered.push({ value: id, label })
}
}
return ordered
})()
// ============================================================================
// Channel Status (label values are i18n keys; use t(config.label) in components)
// ============================================================================
export const CHANNEL_STATUS = {
UNKNOWN: 0,
ENABLED: 1,
MANUAL_DISABLED: 2,
AUTO_DISABLED: 3,
} as const
export const CHANNEL_STATUS_LABELS = {
[CHANNEL_STATUS.UNKNOWN]: 'Unknown',
[CHANNEL_STATUS.ENABLED]: 'Enabled',
[CHANNEL_STATUS.MANUAL_DISABLED]: 'Disabled',
[CHANNEL_STATUS.AUTO_DISABLED]: 'Auto Disabled',
} as const
export const CHANNEL_STATUS_OPTIONS = [
{ value: 'all', label: 'All Status' },
{ value: 'enabled', label: 'Enabled' },
{ value: 'disabled', label: 'Disabled' },
] as const
export const CHANNEL_STATUS_CONFIG = {
[CHANNEL_STATUS.UNKNOWN]: {
variant: 'neutral' as const,
label: 'Unknown',
},
[CHANNEL_STATUS.ENABLED]: {
variant: 'success' as const,
label: 'Enabled',
},
[CHANNEL_STATUS.MANUAL_DISABLED]: {
variant: 'danger' as const,
label: 'Disabled',
},
[CHANNEL_STATUS.AUTO_DISABLED]: {
variant: 'warning' as const,
label: 'Auto Disabled',
},
}
// ============================================================================
// Multi-Key Status
// ============================================================================
export const MULTI_KEY_STATUS = {
ENABLED: 1,
MANUAL_DISABLED: 2,
AUTO_DISABLED: 3,
} as const
export const MULTI_KEY_STATUS_LABELS = {
[MULTI_KEY_STATUS.ENABLED]: 'Enabled',
[MULTI_KEY_STATUS.MANUAL_DISABLED]: 'Manual Disabled',
[MULTI_KEY_STATUS.AUTO_DISABLED]: 'Auto Disabled',
} as const
export const MULTI_KEY_STATUS_CONFIG = {
[MULTI_KEY_STATUS.ENABLED]: {
variant: 'success' as const,
label: 'Enabled',
},
[MULTI_KEY_STATUS.MANUAL_DISABLED]: {
variant: 'neutral' as const,
label: 'Manual Disabled',
},
[MULTI_KEY_STATUS.AUTO_DISABLED]: {
variant: 'danger' as const,
label: 'Auto Disabled',
},
}
// ============================================================================
// Multi-Key Modes
// ============================================================================
export const MULTI_KEY_MODES = [
{ value: 'random', label: 'Random' },
{ value: 'polling', label: 'Polling' },
] as const
export const ADD_MODE_OPTIONS = [
{ value: 'single', label: 'Single Key' },
{ value: 'batch', label: 'Batch Add (one key per line)' },
{
value: 'multi_to_single',
label: 'Multi-Key Mode (multiple keys, one channel)',
},
] as const
// ============================================================================
// Multi-Key Management
// ============================================================================
export const MULTI_KEY_FILTER_OPTIONS = [
{ value: 'all', label: 'All Status' },
{ value: '1', label: 'Enabled' },
{ value: '2', label: 'Manual Disabled' },
{ value: '3', label: 'Auto Disabled' },
] as const
export const MULTI_KEY_CONFIRM_MESSAGES = {
DELETE:
'Are you sure you want to delete this key? This action cannot be undone.',
ENABLE: 'Enable this key?',
DISABLE: 'Disable this key?',
ENABLE_ALL: 'Are you sure you want to enable all keys?',
DISABLE_ALL: 'Are you sure you want to disable all enabled keys?',
DELETE_DISABLED:
'Are you sure you want to delete all auto-disabled keys? This action cannot be undone.',
} as const
// ============================================================================
// Auto Ban Options
// ============================================================================
export const AUTO_BAN_OPTIONS = [
{ value: 1, label: 'Enabled' },
{ value: 0, label: 'Disabled' },
] as const
// ============================================================================
// Error / Success Messages (i18n keys: use t(ERROR_MESSAGES.xxx) when displaying)
// ============================================================================
export const ERROR_MESSAGES = {
REQUIRED_NAME: 'Channel name is required',
REQUIRED_TYPE: 'Channel type is required',
REQUIRED_KEY: 'API key is required',
REQUIRED_MODELS: 'Models are required',
REQUIRED_GROUP: 'Group is required',
INVALID_JSON: 'Invalid JSON format',
INVALID_MODEL_MAPPING: 'Invalid model mapping format',
INVALID_PROXY:
'Proxy address must use HTTP, HTTPS, SOCKS5, or SOCKS5H and include a valid host',
INVALID_HTTP_PROTOCOL: 'HTTP protocol must be Auto or HTTP/1.1',
INVALID_HTTP2_CONNECTION_SHARDS:
'HTTP/2 connection shards must be between 1 and 8',
INVALID_HTTP1_WITH_SHARDS:
'HTTP/2 connection shards must be 1 when HTTP/1.1 is selected',
CREATE_FAILED: 'Failed to create channel',
UPDATE_FAILED: 'Failed to update channel',
DELETE_FAILED: 'Failed to delete channel',
TEST_FAILED: 'Failed to test channel',
BALANCE_QUERY_FAILED: 'Failed to query balance',
FETCH_MODELS_FAILED: 'Failed to fetch models',
} as const
export const SUCCESS_MESSAGES = {
CREATED: 'Channel created successfully',
UPDATED: 'Channel updated successfully',
DELETED: 'Channel deleted successfully',
ENABLED: 'Channel enabled successfully',
DISABLED: 'Channel disabled successfully',
TESTED: 'Channel test completed',
BALANCE_QUERIED: 'Balance queried successfully',
MODELS_FETCHED: 'Models fetched successfully',
COPIED: 'Channel copied successfully',
TAG_SET: 'Tag set successfully',
BATCH_DELETED: 'Channels deleted successfully',
} as const
// ============================================================================
// Default Values
// ============================================================================
export const DEFAULT_PAGE_SIZE = 20
export const DEFAULT_CHANNEL_VALUES = {
name: '',
type: 0,
base_url: '',
key: '',
models: '',
group: 'default',
status: CHANNEL_STATUS.ENABLED,
priority: 0,
weight: 0,
auto_ban: 1,
remark: '',
} as const
// ============================================================================
// Table Configuration
// ============================================================================
export const CHANNELS_TABLE_PAGE_SIZE_OPTIONS = [10, 20, 50, 100]
// ============================================================================
// Sort Options (label values are i18n keys)
// ============================================================================
export const SORT_OPTIONS = [
{ value: 'priority', label: 'Priority (Default)' },
{ value: 'id', label: 'ID' },
{ value: 'name', label: 'Name' },
{ value: 'balance', label: 'Balance' },
{ value: 'response_time', label: 'Response Time' },
] as const
// ============================================================================
// Balance Display
// ============================================================================
export const BALANCE_THRESHOLDS = {
LOW: 1,
MEDIUM: 10,
HIGH: 100,
} as const
// ============================================================================
// Response Time Thresholds (in ms)
// ============================================================================
export const RESPONSE_TIME_THRESHOLDS = {
EXCELLENT: 500,
GOOD: 1000,
FAIR: 2000,
POOR: 5000,
} as const
export const RESPONSE_TIME_CONFIG = {
EXCELLENT: { variant: 'success' as const, label: 'Excellent' },
GOOD: { variant: 'success' as const, label: 'Good' },
FAIR: { variant: 'warning' as const, label: 'Fair' },
POOR: { variant: 'danger' as const, label: 'Poor' },
UNKNOWN: { variant: 'neutral' as const, label: 'Not tested' },
} as const
// ============================================================================
// Field Hints and Placeholders (i18n keys; use t() when displaying)
// ============================================================================
export const FIELD_PLACEHOLDERS = {
NAME: 'e.g., OpenAI GPT-4 Production',
BASE_URL: 'Leave empty to use default',
KEY: 'API Key (one per line for batch mode)',
MODELS: 'Comma-separated model names, e.g., gpt-4,gpt-3.5-turbo',
GROUP: 'Please Select user groups that can access this channel.',
MODEL_MAPPING: '{"request_model": "actual_model"}',
TEST_MODEL: 'Model to use for testing',
TAG: 'Optional tag for grouping channels',
REMARK: 'Optional notes about this channel',
PARAM_OVERRIDE: '{"temperature": 0.7}',
HEADER_OVERRIDE: '{"X-Custom-Header": "value"}',
STATUS_CODE_MAPPING: '{"400": "500"}',
} as const
export const FIELD_DESCRIPTIONS = {
NAME: 'Friendly name to identify this channel',
TYPE: 'Provider type (OpenAI, Anthropic, etc.)',
BASE_URL: 'Custom API base URL. Leave empty to use provider default.',
KEY: 'API key from the provider',
MODELS:
'List of models supported by this channel. Use comma to separate multiple models.',
GROUP: 'User groups that can access this channel. ',
MODEL_MAPPING:
'Map request model names to actual provider model names (JSON format)',
PRIORITY: 'Higher priority channels are selected first',
WEIGHT: 'Used for load balancing. Higher weight = more requests',
TEST_MODEL: 'Model to use when testing channel connectivity',
AUTO_BAN: 'Automatically disable channel on repeated failures',
STATUS_CODE_MAPPING: 'Map response status codes (JSON format)',
TAG: 'Group channels by tag for batch operations',
REMARK: 'Internal notes (not shown to users)',
SETTING: 'Channel-specific settings (JSON format)',
PARAM_OVERRIDE: 'Override request parameters (JSON format)',
HEADER_OVERRIDE: 'Override request headers (JSON format)',
MULTI_KEY_MODE: 'How to select keys: random or sequential polling',
BATCH_ADD: 'Create multiple channels from multiple keys',
OPENAI_ORG: 'OpenAI Organization ID (optional)',
} as const
// ============================================================================
// Channel Type Specific Configurations
// ============================================================================
export const MODEL_FETCHABLE_TYPES = new Set([
1, 4, 14, 17, 20, 23, 24, 25, 26, 27, 31, 34, 35, 40, 42, 43, 47, 48, 57, 58,
59, 60,
])
export const TYPE_TO_KEY_PROMPT: Record<number, string> = {
15: 'Format: APIKey|SecretKey',
18: 'Format: APPID|APISecret|APIKey',
22: 'Format: APIKey-AppId, e.g., fastgpt-0sp2gtvfdgyi4k30jwlgwf1i-64f335d84283f05518e9e041',
23: 'Format: TokenHub API Key, or legacy AppId|SecretId|SecretKey',
33: 'Format: Ak|Sk|Region',
50: 'Format: AccessKey|SecretKey (or just ApiKey if upstream is New API)',
51: 'Format: Access Key ID|Secret Access Key',
57: 'Paste Codex OAuth JSON credential (access_token / refresh_token / account_id)',
59: 'Enter API key for this channel',
60: 'Enter API key for this channel',
}
export const CHANNEL_TYPE_WARNINGS: Record<number, string> = {
3: 'For channels added after May 10, 2025, no need to remove "." from model names during deployment',
8: 'If connecting to upstream One API or New API relay projects, use OpenAI type instead unless you know what you are doing',
37: 'Dify channels only support chatflow and agent, and agent does not support images',
}