Skip to content

Commit bc1ae59

Browse files
committed
chore: bump version to 0.4.2 and enhance model validation
- Update version from 0.4.1 to 0.4.2 in package.json - Implement early validation for selected AI model in expert command - Add checks for API key configuration based on model provider - Ensure provider initialization before using web search tools This release improves error handling and user feedback for model selection and API key configuration in the CLI.
1 parent 74ba49d commit bc1ae59

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "promptcode-cli",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"description": "CLI tool for PromptCode - Generate AI-ready prompts from codebases",
55
"bin": {
66
"promptcode": "./dist/promptcode"

packages/cli/src/commands/expert.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,32 @@ export async function expertCommand(question: string | undefined, options: Exper
132132
console.log(chalk.gray('💡 In Claude Code: AI agents will ask for approval before expensive operations'));
133133
}
134134

135+
// Early validation: Check if the selected model is available
136+
const modelKey = options.model || DEFAULT_MODEL;
137+
const modelConfig = MODELS[modelKey];
138+
139+
if (!modelConfig) {
140+
const available = getAvailableModels();
141+
console.error(chalk.red(`Unknown model: ${modelKey}. Available models: ${available.join(', ')}`));
142+
process.exit(1);
143+
}
144+
145+
// Check if API key is configured for the provider
146+
const availableModels = getAvailableModels();
147+
if (!availableModels.includes(modelKey)) {
148+
const envVars = {
149+
openai: 'OPENAI_API_KEY or OPENAI_KEY',
150+
anthropic: 'ANTHROPIC_API_KEY or CLAUDE_API_KEY',
151+
google: 'GOOGLE_API_KEY, GOOGLE_CLOUD_API_KEY, or GEMINI_API_KEY',
152+
xai: 'XAI_API_KEY or GROK_API_KEY'
153+
};
154+
console.error(chalk.red(`\n❌ API key not configured for ${modelConfig.provider}.`));
155+
console.error(chalk.yellow(`\nTo use ${modelConfig.name}, set the environment variable:`));
156+
console.error(chalk.gray(` export ${envVars[modelConfig.provider as keyof typeof envVars]}=<your-key>`));
157+
console.error(chalk.gray(`\nOr use a different model with --model flag. Run 'promptcode expert --models' to see available options.`));
158+
process.exit(1);
159+
}
160+
135161
const spin = !options.stream ? spinner() : null;
136162
if (spin) {spin.start('Preparing context...');}
137163

@@ -217,18 +243,7 @@ export async function expertCommand(question: string | undefined, options: Exper
217243
includeFileContents: true
218244
});
219245

220-
// Select model
221-
const modelKey = options.model || DEFAULT_MODEL;
222-
const modelConfig = MODELS[modelKey];
223-
224-
if (!modelConfig) {
225-
const available = getAvailableModels();
226-
if (spin) {
227-
spin.fail(`Unknown model: ${modelKey}. Available models: ${available.join(', ')}`);
228-
spin.stop(); // Ensure cleanup
229-
}
230-
return;
231-
}
246+
// Model already validated earlier, just use it
232247

233248
/* ──────────────────────────────────────────────────────────
234249
* Token-limit enforcement

packages/cli/src/providers/ai-provider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ export class AIProvider {
122122
const config = MODELS[modelKey];
123123
if (!config || !config.supportsWebSearch) {return undefined;}
124124

125+
// Check if the provider is initialized before trying to use its tools
126+
const providerInstance = this.providers[config.provider];
127+
if (!providerInstance) {
128+
// Provider not initialized (no API key), can't use web search tools
129+
return undefined;
130+
}
131+
125132
switch (config.provider) {
126133
case 'openai':
127134
// OpenAI requires using the responses API for web search

0 commit comments

Comments
 (0)