samlax12 commited on
Commit
8e7e0ca
·
verified ·
1 Parent(s): 877a450

Update constants.ts

Browse files
Files changed (1) hide show
  1. constants.ts +10 -67
constants.ts CHANGED
@@ -278,76 +278,19 @@ export class ModelConfigManager {
278
  private static STORAGE_KEY_INITIALIZED = 'multi-mind-chat-initialized';
279
 
280
  // 初始化检查
281
- private static ensureInitialized(): void {
282
- try {
283
- const isInitialized = localStorage.getItem(this.STORAGE_KEY_INITIALIZED);
284
- if (!isInitialized) {
285
- // 首次初始化
286
- localStorage.setItem(this.STORAGE_KEY_CHANNELS, JSON.stringify(DEFAULT_CHANNELS));
287
- localStorage.setItem(this.STORAGE_KEY_MODELS, JSON.stringify(DEFAULT_MODELS));
288
- localStorage.setItem(this.STORAGE_KEY_ROLES, JSON.stringify(DEFAULT_ROLES));
289
- localStorage.setItem(this.STORAGE_KEY_INITIALIZED, 'true');
290
- } else {
291
- // 已初始化的用户,自动执行同步
292
- this.syncDefaultConfigurations();
293
- }
294
- } catch (error) {
295
- console.warn('无法访问localStorage,将使用内存存储:', error);
296
- }
297
- }
298
- static syncDefaultConfigurations(): void {
299
- try {
300
- const currentChannels = this.getChannels();
301
- const currentModels = this.getModels();
302
- const currentRoles = this.getRoles();
303
-
304
- const existingChannelIds = new Set(currentChannels.map(c => c.id));
305
- const existingModelIds = new Set(currentModels.map(m => m.id));
306
- const existingRoleIds = new Set(currentRoles.map(r => r.id));
307
-
308
- let hasChanges = false;
309
-
310
- const mergedChannels = [...currentChannels];
311
- DEFAULT_CHANNELS.forEach(defaultChannel => {
312
- if (!existingChannelIds.has(defaultChannel.id)) {
313
- if (defaultChannel.isDefault && mergedChannels.some(c => c.isDefault)) {
314
- mergedChannels.push({ ...defaultChannel, isDefault: false });
315
- } else {
316
- mergedChannels.push(defaultChannel);
317
- }
318
- hasChanges = true;
319
- console.log(`自动添加新渠道: ${defaultChannel.name}`);
320
- }
321
- });
322
-
323
- const mergedModels = [...currentModels];
324
- DEFAULT_MODELS.forEach(defaultModel => {
325
- if (!existingModelIds.has(defaultModel.id)) {
326
- mergedModels.push(defaultModel);
327
- hasChanges = true;
328
- console.log(`自动添加新模型: ${defaultModel.name}`);
329
- }
330
- });
331
-
332
- const mergedRoles = [...currentRoles];
333
- DEFAULT_ROLES.forEach(defaultRole => {
334
- if (!existingRoleIds.has(defaultRole.id)) {
335
- mergedRoles.push(defaultRole);
336
- hasChanges = true;
337
- console.log(`自动添加新角色: ${defaultRole.name}`);
338
  }
339
- });
340
-
341
- if (hasChanges) {
342
- this.saveChannels(mergedChannels);
343
- this.saveModels(mergedModels);
344
- this.saveRoles(mergedRoles);
345
- console.log('默认配置同步完成');
346
  }
347
- } catch (error) {
348
- console.error('同步默认配置失败:', error);
349
  }
350
- }
351
 
352
  // ============ 渠道管理 ============
353
 
 
278
  private static STORAGE_KEY_INITIALIZED = 'multi-mind-chat-initialized';
279
 
280
  // 初始化检查
281
+ private static ensureInitialized(): void {
282
+ try {
283
+ const isInitialized = localStorage.getItem(this.STORAGE_KEY_INITIALIZED);
284
+ if (!isInitialized) {
285
+ localStorage.setItem(this.STORAGE_KEY_CHANNELS, JSON.stringify(DEFAULT_CHANNELS));
286
+ localStorage.setItem(this.STORAGE_KEY_MODELS, JSON.stringify(DEFAULT_MODELS));
287
+ localStorage.setItem(this.STORAGE_KEY_ROLES, JSON.stringify(DEFAULT_ROLES));
288
+ localStorage.setItem(this.STORAGE_KEY_INITIALIZED, 'true');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
289
  }
290
+ } catch (error) {
291
+ console.warn('无法访问localStorage,将使用内存存储:', error);
 
 
 
 
 
292
  }
 
 
293
  }
 
294
 
295
  // ============ 渠道管理 ============
296