/ src / utils / model / contextWindowUpgradeCheck.ts
contextWindowUpgradeCheck.ts
 1  import { checkOpus1mAccess, checkSonnet1mAccess } from './check1mAccess.js'
 2  import { getUserSpecifiedModelSetting } from './model.js'
 3  
 4  // @[MODEL LAUNCH]: Add a branch for the new model if it supports a 1M context upgrade path.
 5  /**
 6   * Get available model upgrade for more context
 7   * Returns null if no upgrade available or user already has max context
 8   */
 9  function getAvailableUpgrade(): {
10    alias: string
11    name: string
12    multiplier: number
13  } | null {
14    const currentModelSetting = getUserSpecifiedModelSetting()
15    if (currentModelSetting === 'opus' && checkOpus1mAccess()) {
16      return {
17        alias: 'opus[1m]',
18        name: 'Opus 1M',
19        multiplier: 5,
20      }
21    } else if (currentModelSetting === 'sonnet' && checkSonnet1mAccess()) {
22      return {
23        alias: 'sonnet[1m]',
24        name: 'Sonnet 1M',
25        multiplier: 5,
26      }
27    }
28  
29    return null
30  }
31  
32  /**
33   * Get upgrade message for different contexts
34   */
35  export function getUpgradeMessage(context: 'warning' | 'tip'): string | null {
36    const upgrade = getAvailableUpgrade()
37    if (!upgrade) return null
38  
39    switch (context) {
40      case 'warning':
41        return `/model ${upgrade.alias}`
42      case 'tip':
43        return `Tip: You have access to ${upgrade.name} with ${upgrade.multiplier}x more context`
44      default:
45        return null
46    }
47  }