Files
claude-code/src/hooks/notifs/useModelMigrationNotifications.tsx
unraid c7e1c50b86 feat: 添加服务层增强与零散改进
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-22 22:38:10 +08:00

54 lines
1.9 KiB
TypeScript

import type { Notification } from 'src/context/notifications.js'
import { type GlobalConfig, getGlobalConfig } from 'src/utils/config.js'
import { useStartupNotification } from './useStartupNotification.js'
// Shows a one-time notification right after a model migration writes its
// timestamp to config. Each entry reads its own timestamp field(s) and emits
// a notification if the write happened within the last 3s (i.e. this launch).
// Future model migrations: add an entry to MIGRATIONS below.
const MIGRATIONS: ((c: GlobalConfig) => Notification | undefined)[] = [
// Sonnet 4.5 → 4.6 (pro/max/team premium)
c => {
if (!recent(c.sonnet45To46MigrationTimestamp)) return
return {
key: 'sonnet-46-update',
text: 'Model updated to Sonnet 4.6',
color: 'suggestion',
priority: 'high',
timeoutMs: 3000,
}
},
// Opus Pro → default, or pinned 4.0/4.1 → opus alias. Both land on the
// current Opus default (4.7 for 1P).
c => {
const isLegacyRemap = Boolean(c.legacyOpusMigrationTimestamp)
const ts = c.legacyOpusMigrationTimestamp ?? c.opusProMigrationTimestamp
if (!recent(ts)) return
return {
key: 'opus-pro-update',
text: isLegacyRemap
? 'Model updated to Opus 4.7 · Set CLAUDE_CODE_DISABLE_LEGACY_MODEL_REMAP=1 to opt out'
: 'Model updated to Opus 4.7',
color: 'suggestion',
priority: 'high',
timeoutMs: isLegacyRemap ? 8000 : 3000,
}
},
]
export function useModelMigrationNotifications(): void {
useStartupNotification(() => {
const config = getGlobalConfig()
const notifs: Notification[] = []
for (const migration of MIGRATIONS) {
const notif = migration(config)
if (notif) notifs.push(notif)
}
return notifs.length > 0 ? notifs : null
})
}
function recent(ts: number | undefined): boolean {
return ts !== undefined && Date.now() - ts < 3000
}