@dsh-plus/llm-pi 0.1.44 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/service.ts CHANGED
@@ -40,6 +40,11 @@ import { DeepseekRouteRegistrar } from './deepseek-routes.ts'
40
40
  import { buildDirectoryEntries, commitDirectory, type DirectoryEntry } from './directory.ts'
41
41
  import { discoverModels } from './discovery.ts'
42
42
  import { type KitVersions, piAiVersionNotice, VERIFIED_PI_AI_RANGE } from './kit-meta.ts'
43
+ import {
44
+ createOfficialCopyWriter,
45
+ type OfficialCopyStatus,
46
+ readManualProviders,
47
+ } from './official-copy-writer.ts'
43
48
  import { assertServiceable, buildProfiles, isDraftRoute } from './profiles.ts'
44
49
  import { buildDeepseekRoutes, type ResolvedDeepseekRoute } from './profiles-deepseek.ts'
45
50
  import { type DshKit, resolveDshKit } from './resolve-dsh.ts'
@@ -64,6 +69,8 @@ export interface LlmPiKitInfo {
64
69
  catalog: { providers: number; models: number; generatedAt?: number }
65
70
  /** compat 门控表来源:official / fallback。 */
66
71
  compatSource: string
72
+ /** 官方应急副本状态(路径/生成时间/覆盖 route/警告;error = 最近生成失败)。 */
73
+ officialCopy: OfficialCopyStatus
67
74
  /** 回退与逐项降级诊断(有内容时界面显式展示)。 */
68
75
  diagnostics: string[]
69
76
  }
@@ -412,9 +419,20 @@ export async function startRuntime(
412
419
  })
413
420
  const ensureDeepseek = (): void => deepseekRegistrar.sync(deepseekRoutes())
414
421
 
422
+ // 官方应急副本:启动即生成一次;热更新与 adapter 注册变化(官方 llm-pi-ai
423
+ // 晚注册时手写条目在此补入)再生成。写失败只降级为状态,不影响路由注册。
424
+ const copyWriter = createOfficialCopyWriter({
425
+ kit,
426
+ current,
427
+ readManual: () => readManualProviders(ctx.settings),
428
+ profile: ctx.get('profileContext')?.name,
429
+ logger,
430
+ })
431
+
415
432
  ensureRegistration()
416
433
  ensureDeepseek()
417
434
  ensureDirectory()
435
+ void copyWriter.ensureOfficialCopy()
418
436
 
419
437
  // 0.1.7 替代 installSection(validate/setSource/onChange 三钩子):
420
438
  // - 活动引用原位提交 → volatile-update 触发快照换代与重注册(原 onChange 体);
@@ -425,8 +443,12 @@ export async function startRuntime(
425
443
  attempt(logger, 'llm-pi: 更新被拒,保留此前注册的 route', ensureRegistration)
426
444
  attempt(logger, 'llm-pi: deepseek route 更新失败,保留此前注册', ensureDeepseek)
427
445
  attempt(logger, 'llm-pi: 更新被拒,保留此前的 configurable-provider 目录', ensureDirectory)
446
+ void copyWriter.ensureOfficialCopy()
428
447
  }
429
448
  ctx.events.on('loader/volatile-update', reconfigure)
449
+ // 官方 llm-pi-ai 晚于本插件注册时,describe 的手写条目视图此时才完整——
450
+ // adapter 集变化即重新生成副本(无 provider 变化时内容未变、跳过写盘)。
451
+ ctx.root.on('llm/adapters-updated', () => void copyWriter.ensureOfficialCopy())
430
452
  ctx.on('internal/config', function (_raw: unknown, next: () => unknown) {
431
453
  const candidate = next()
432
454
  if (this !== ctx.fiber) return candidate
@@ -439,6 +461,7 @@ export async function startRuntime(
439
461
  const providers = listProviders(kit)
440
462
  const generatedAt = kit.catalogGeneratedAt
441
463
  const notice = piAiVersionNotice(kit.versions.piAi)
464
+ const copy = copyWriter.status()
442
465
  return {
443
466
  source: kit.source,
444
467
  ...(kit.root === undefined ? {} : { root: kit.root }),
@@ -453,7 +476,12 @@ export async function startRuntime(
453
476
  ...(generatedAt === undefined ? {} : { generatedAt }),
454
477
  },
455
478
  compatSource: compatTableInfo().source,
456
- diagnostics,
479
+ officialCopy: copy,
480
+ diagnostics: [
481
+ ...diagnostics,
482
+ ...copy.warnings.map((warning) => `应急副本:${warning}`),
483
+ ...(copy.error === undefined ? [] : [`应急副本:生成失败(${copy.error})`]),
484
+ ],
457
485
  }
458
486
  }
459
487