refactor: update auto-mode-service to use dynamic model resolution

- Replaced hardcoded model string with dynamic resolution for the analysis model, allowing for future flexibility.
- Enhanced error handling to provide specific authentication failure messages based on the model type, improving user feedback.

This change streamlines the model selection process and improves error clarity for users.
This commit is contained in:
Kacper
2025-12-13 04:37:53 +01:00
parent 6726050969
commit 2f2eab6e02

View File

@@ -639,11 +639,13 @@ Address the follow-up instructions above. Review the previous work and make the
Format your response as a structured markdown document.`;
try {
const provider = ProviderFactory.getProviderForModel("claude-sonnet-4-20250514");
// Use default Claude model for analysis (can be overridden in the future)
const analysisModel = resolveModelString(undefined, DEFAULT_MODELS.claude);
const provider = ProviderFactory.getProviderForModel(analysisModel);
const options: ExecuteOptions = {
prompt,
model: "claude-sonnet-4-20250514",
model: analysisModel,
maxTurns: 5,
cwd: projectPath,
allowedTools: ["Read", "Glob", "Grep"],
@@ -926,10 +928,13 @@ When done, summarize what you implemented and any notes for the developer.`;
if (block.text && (block.text.includes("Invalid API key") ||
block.text.includes("authentication_failed") ||
block.text.includes("Fix external API key"))) {
throw new Error(
"Authentication failed: Invalid or expired API key. " +
"Please check your ANTHROPIC_API_KEY or run 'claude login' to re-authenticate."
);
const isCodex = finalModel.startsWith("gpt-") || finalModel.startsWith("o");
const errorMsg = isCodex
? "Authentication failed: Invalid or expired API key. " +
"Please check your OPENAI_API_KEY or run 'codex login' to re-authenticate."
: "Authentication failed: Invalid or expired API key. " +
"Please check your ANTHROPIC_API_KEY or run 'claude login' to re-authenticate.";
throw new Error(errorMsg);
}
this.emitAutoModeEvent("auto_mode_progress", {