fix(litellm): improve retry flow for API key and base URL
- Extract promptForApiKey and promptForBaseUrl as helper functions - Use recursive retry instead of throwing errors - Re-enter API key now retries the entire flow with new key - Re-enter base URL now properly prompts for new URL and retries - Both options maintain full onboarding flow instead of crashing Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6faae80ad4
commit
f901884913
@ -627,20 +627,17 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!hasCredential) {
|
// Helper function to prompt for API key
|
||||||
|
const promptForApiKey = async () => {
|
||||||
const key = await params.prompter.text({
|
const key = await params.prompter.text({
|
||||||
message: "Enter LiteLLM API key",
|
message: "Enter LiteLLM API key",
|
||||||
validate: validateApiKeyInput,
|
validate: validateApiKeyInput,
|
||||||
});
|
});
|
||||||
apiKey = normalizeApiKeyInput(String(key));
|
return normalizeApiKeyInput(String(key));
|
||||||
await setLitellmApiKey(apiKey, params.agentDir);
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// Check for pre-provided base URL via CLI option (--litellm-base-url)
|
// Helper function to prompt for base URL
|
||||||
let normalizedBaseUrl: string;
|
const promptForBaseUrl = async () => {
|
||||||
if (params.opts?.litellmBaseUrl) {
|
|
||||||
normalizedBaseUrl = params.opts.litellmBaseUrl.trim();
|
|
||||||
} else {
|
|
||||||
const defaultBaseUrl = process.env.LITELLM_BASE_URL ?? "http://localhost:4000";
|
const defaultBaseUrl = process.env.LITELLM_BASE_URL ?? "http://localhost:4000";
|
||||||
const baseUrl = await params.prompter.text({
|
const baseUrl = await params.prompter.text({
|
||||||
message: "Enter LiteLLM base URL",
|
message: "Enter LiteLLM base URL",
|
||||||
@ -656,7 +653,20 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
normalizedBaseUrl = String(baseUrl).trim();
|
return String(baseUrl).trim();
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!hasCredential) {
|
||||||
|
apiKey = await promptForApiKey();
|
||||||
|
await setLitellmApiKey(apiKey, params.agentDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for pre-provided base URL via CLI option (--litellm-base-url)
|
||||||
|
let normalizedBaseUrl: string;
|
||||||
|
if (params.opts?.litellmBaseUrl) {
|
||||||
|
normalizedBaseUrl = params.opts.litellmBaseUrl.trim();
|
||||||
|
} else {
|
||||||
|
normalizedBaseUrl = await promptForBaseUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to fetch available models from LiteLLM
|
// Try to fetch available models from LiteLLM
|
||||||
@ -794,20 +804,25 @@ export async function applyAuthChoiceApiProviders(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action === "retry-apikey") {
|
if (action === "retry-apikey") {
|
||||||
// Re-prompt for API key
|
// Re-prompt for API key and retry
|
||||||
const key = await params.prompter.text({
|
apiKey = await promptForApiKey();
|
||||||
message: "Enter LiteLLM API key",
|
|
||||||
validate: validateApiKeyInput,
|
|
||||||
});
|
|
||||||
apiKey = normalizeApiKeyInput(String(key));
|
|
||||||
await setLitellmApiKey(apiKey, params.agentDir);
|
await setLitellmApiKey(apiKey, params.agentDir);
|
||||||
|
// Retry fetch by recursively calling this function
|
||||||
// Retry the entire LiteLLM flow by returning null and letting the caller retry
|
return await applyAuthChoiceApiProviders({ ...params, authChoice: "litellm-api-key" });
|
||||||
throw new Error("Please try the LiteLLM setup again with the new API key");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action === "retry-baseurl") {
|
if (action === "retry-baseurl") {
|
||||||
throw new Error("Please restart the setup and provide the correct base URL");
|
// Re-prompt for base URL and retry the entire flow
|
||||||
|
// This ensures we go through the full fetch process again with the new URL
|
||||||
|
const newParams = {
|
||||||
|
...params,
|
||||||
|
authChoice: "litellm-api-key" as const,
|
||||||
|
opts: {
|
||||||
|
...params.opts,
|
||||||
|
litellmBaseUrl: undefined, // Clear the CLI-provided URL so we can prompt
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return await applyAuthChoiceApiProviders(newParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Manual model entry
|
// Manual model entry
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user