samlax12 commited on
Commit
e297075
·
verified ·
1 Parent(s): fde6860

Update constants.ts

Browse files
Files changed (1) hide show
  1. constants.ts +106 -1
constants.ts CHANGED
@@ -1,3 +1,5 @@
 
 
1
  // API渠道配置接口
2
  export interface ApiChannel {
3
  id: string;
@@ -277,21 +279,124 @@ export class ModelConfigManager {
277
  private static STORAGE_KEY_ROLES = 'multi-mind-chat-roles';
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
 
297
  // 获取所有渠道
 
1
+ export const CONFIG_VERSION = '2.1.0'; // 每次添加新的默认配置时更新此版本号
2
+ export const CONFIG_VERSION_KEY = 'multi-mind-chat-config-version';
3
  // API渠道配置接口
4
  export interface ApiChannel {
5
  id: string;
 
279
  private static STORAGE_KEY_ROLES = 'multi-mind-chat-roles';
280
  private static STORAGE_KEY_INITIALIZED = 'multi-mind-chat-initialized';
281
 
282
+ // 新增:检查并执行增量更新
283
+ private static performIncrementalUpdate(): void {
284
+ try {
285
+ const currentVersion = localStorage.getItem(CONFIG_VERSION_KEY);
286
+
287
+ if (currentVersion === CONFIG_VERSION) {
288
+ return;
289
+ }
290
+
291
+ console.log(`检测到配置版本更新: ${currentVersion || '未知'} -> ${CONFIG_VERSION}`);
292
+
293
+ const existingChannels = this.getChannels();
294
+ const existingModels = this.getModels();
295
+ const existingRoles = this.getRoles();
296
+
297
+ const existingChannelIds = new Set(existingChannels.map(ch => ch.id));
298
+ const existingModelIds = new Set(existingModels.map(m => m.id));
299
+ const existingRoleIds = new Set(existingRoles.map(r => r.id));
300
+
301
+ const updatedChannels = [...existingChannels];
302
+ DEFAULT_CHANNELS.forEach(defaultChannel => {
303
+ if (!existingChannelIds.has(defaultChannel.id)) {
304
+ console.log(`添加新的默认渠道: ${defaultChannel.name}`);
305
+ if (defaultChannel.isDefault && updatedChannels.some(ch => ch.isDefault)) {
306
+ defaultChannel.isDefault = false;
307
+ }
308
+ updatedChannels.push(defaultChannel);
309
+ }
310
+ });
311
+
312
+ const updatedModels = [...existingModels];
313
+ DEFAULT_MODELS.forEach(defaultModel => {
314
+ if (!existingModelIds.has(defaultModel.id)) {
315
+ console.log(`添加新的默认模型: ${defaultModel.name}`);
316
+ updatedModels.push(defaultModel);
317
+ }
318
+ });
319
+
320
+ const updatedRoles = [...existingRoles];
321
+ DEFAULT_ROLES.forEach(defaultRole => {
322
+ if (!existingRoleIds.has(defaultRole.id)) {
323
+ console.log(`添加新的默认角色: ${defaultRole.name}`);
324
+ updatedRoles.push(defaultRole);
325
+ }
326
+ });
327
+
328
+ this.saveChannels(updatedChannels);
329
+ this.saveModels(updatedModels);
330
+ this.saveRoles(updatedRoles);
331
+
332
+ localStorage.setItem(CONFIG_VERSION_KEY, CONFIG_VERSION);
333
+
334
+ console.log('配置增量更新完成');
335
+
336
+ const updateInfo = {
337
+ newChannels: updatedChannels.length - existingChannels.length,
338
+ newModels: updatedModels.length - existingModels.length,
339
+ newRoles: updatedRoles.length - existingRoles.length
340
+ };
341
+
342
+ if (updateInfo.newChannels > 0 || updateInfo.newModels > 0 || updateInfo.newRoles > 0) {
343
+ localStorage.setItem('multi-mind-chat-last-update', JSON.stringify({
344
+ ...updateInfo,
345
+ version: CONFIG_VERSION,
346
+ timestamp: new Date().toISOString()
347
+ }));
348
+ }
349
+
350
+ } catch (error) {
351
+ console.error('执行增量更新时出错:', error);
352
+ }
353
+ }
354
+
355
+ // 修改初始化检查方法
356
  private static ensureInitialized(): void {
357
  try {
358
  const isInitialized = localStorage.getItem(this.STORAGE_KEY_INITIALIZED);
359
+
360
  if (!isInitialized) {
361
  localStorage.setItem(this.STORAGE_KEY_CHANNELS, JSON.stringify(DEFAULT_CHANNELS));
362
  localStorage.setItem(this.STORAGE_KEY_MODELS, JSON.stringify(DEFAULT_MODELS));
363
  localStorage.setItem(this.STORAGE_KEY_ROLES, JSON.stringify(DEFAULT_ROLES));
364
  localStorage.setItem(this.STORAGE_KEY_INITIALIZED, 'true');
365
+ localStorage.setItem(CONFIG_VERSION_KEY, CONFIG_VERSION);
366
+ } else {
367
+ this.performIncrementalUpdate();
368
  }
369
  } catch (error) {
370
  console.warn('无法访问localStorage,将使用内存存储:', error);
371
  }
372
  }
373
 
374
+ // 新增:获取最近的更新信息
375
+ static getLastUpdateInfo(): {
376
+ newChannels: number;
377
+ newModels: number;
378
+ newRoles: number;
379
+ version: string;
380
+ timestamp: string
381
+ } | null {
382
+ try {
383
+ const updateInfo = localStorage.getItem('multi-mind-chat-last-update');
384
+ if (updateInfo) {
385
+ const info = JSON.parse(updateInfo);
386
+ localStorage.removeItem('multi-mind-chat-last-update');
387
+ return info;
388
+ }
389
+ } catch (error) {
390
+ console.error('获取更新信息失败:', error);
391
+ }
392
+ return null;
393
+ }
394
+
395
+ // 新增:强制刷新配置
396
+ static refreshConfiguration(): void {
397
+ this.performIncrementalUpdate();
398
+ }
399
+
400
  // ============ 渠道管理 ============
401
 
402
  // 获取所有渠道