54 lines
1.9 KiB
TypeScript
54 lines
1.9 KiB
TypeScript
import { ensureAuthProfileStore, listProfilesForProvider } from "../agents/auth-profiles.js";
|
|
import { hasUsableCustomProviderApiKey, resolveEnvApiKey } from "../agents/model-auth.js";
|
|
import { loadModelCatalog } from "../agents/model-catalog.js";
|
|
import { resolveDefaultModelForAgent } from "../agents/model-selection.js";
|
|
import type { OpenClawConfig } from "../config/config.js";
|
|
import type { WizardPrompter } from "../wizard/prompts.js";
|
|
import { buildProviderAuthRecoveryHint } from "./provider-auth-guidance.js";
|
|
|
|
export async function warnIfModelConfigLooksOff(
|
|
config: OpenClawConfig,
|
|
prompter: WizardPrompter,
|
|
options?: { agentId?: string; agentDir?: string },
|
|
) {
|
|
const ref = resolveDefaultModelForAgent({
|
|
cfg: config,
|
|
agentId: options?.agentId,
|
|
});
|
|
const warnings: string[] = [];
|
|
const catalog = await loadModelCatalog({
|
|
config,
|
|
useCache: false,
|
|
});
|
|
if (catalog.length > 0) {
|
|
const known = catalog.some(
|
|
(entry) => entry.provider === ref.provider && entry.id === ref.model,
|
|
);
|
|
if (!known) {
|
|
warnings.push(
|
|
`Model not found: ${ref.provider}/${ref.model}. Update agents.defaults.model or run /models list.`,
|
|
);
|
|
}
|
|
}
|
|
|
|
const store = ensureAuthProfileStore(options?.agentDir);
|
|
const hasProfile = listProfilesForProvider(store, ref.provider).length > 0;
|
|
const envKey = resolveEnvApiKey(ref.provider);
|
|
const hasCustomKey = hasUsableCustomProviderApiKey(config, ref.provider);
|
|
if (!hasProfile && !envKey && !hasCustomKey) {
|
|
warnings.push(
|
|
`No auth configured for provider "${ref.provider}". The agent may fail until credentials are added. ${buildProviderAuthRecoveryHint(
|
|
{
|
|
provider: ref.provider,
|
|
config,
|
|
includeEnvVar: true,
|
|
},
|
|
)}`,
|
|
);
|
|
}
|
|
|
|
if (warnings.length > 0) {
|
|
await prompter.note(warnings.join("\n"), "Model check");
|
|
}
|
|
}
|