feat: show warning toast when model cache is not available
- Added isModelCacheAvailable() to check if cache file exists - Shows warning toast on session start if cache is missing - Suggests running 'opencode models --refresh' or restarting
This commit is contained in:
parent
ab3e622baa
commit
e16bbbcc05
@ -5,6 +5,7 @@ import { PACKAGE_NAME } from "./constants"
|
|||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { getConfigLoadErrors, clearConfigLoadErrors } from "../../shared/config-errors"
|
import { getConfigLoadErrors, clearConfigLoadErrors } from "../../shared/config-errors"
|
||||||
import { runBunInstall } from "../../cli/config-manager"
|
import { runBunInstall } from "../../cli/config-manager"
|
||||||
|
import { isModelCacheAvailable } from "../../shared/model-availability"
|
||||||
import type { AutoUpdateCheckerOptions } from "./types"
|
import type { AutoUpdateCheckerOptions } from "./types"
|
||||||
|
|
||||||
const SISYPHUS_SPINNER = ["·", "•", "●", "○", "◌", "◦", " "]
|
const SISYPHUS_SPINNER = ["·", "•", "●", "○", "◌", "◦", " "]
|
||||||
@ -75,6 +76,7 @@ export function createAutoUpdateCheckerHook(ctx: PluginInput, options: AutoUpdat
|
|||||||
const displayVersion = localDevVersion ?? cachedVersion
|
const displayVersion = localDevVersion ?? cachedVersion
|
||||||
|
|
||||||
await showConfigErrorsIfAny(ctx)
|
await showConfigErrorsIfAny(ctx)
|
||||||
|
await showModelCacheWarningIfNeeded(ctx)
|
||||||
|
|
||||||
if (localDevVersion) {
|
if (localDevVersion) {
|
||||||
if (showStartupToast) {
|
if (showStartupToast) {
|
||||||
@ -167,6 +169,23 @@ async function runBunInstallSafe(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function showModelCacheWarningIfNeeded(ctx: PluginInput): Promise<void> {
|
||||||
|
if (isModelCacheAvailable()) return
|
||||||
|
|
||||||
|
await ctx.client.tui
|
||||||
|
.showToast({
|
||||||
|
body: {
|
||||||
|
title: "Model Cache Not Found",
|
||||||
|
message: "Run 'opencode models --refresh' or restart OpenCode to populate the models cache for optimal agent model selection.",
|
||||||
|
variant: "warning" as const,
|
||||||
|
duration: 10000,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
|
||||||
|
log("[auto-update-checker] Model cache warning shown")
|
||||||
|
}
|
||||||
|
|
||||||
async function showConfigErrorsIfAny(ctx: PluginInput): Promise<void> {
|
async function showConfigErrorsIfAny(ctx: PluginInput): Promise<void> {
|
||||||
const errors = getConfigLoadErrors()
|
const errors = getConfigLoadErrors()
|
||||||
if (errors.length === 0) return
|
if (errors.length === 0) return
|
||||||
|
|||||||
@ -147,3 +147,8 @@ export async function fetchAvailableModels(_client?: any): Promise<Set<string>>
|
|||||||
export function __resetModelCache(): void {
|
export function __resetModelCache(): void {
|
||||||
cachedModels = null
|
cachedModels = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isModelCacheAvailable(): boolean {
|
||||||
|
const cacheFile = join(getOpenCodeCacheDir(), "models.json")
|
||||||
|
return existsSync(cacheFile)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user