Fix: Update existing provider instead of creating duplicate

This commit is contained in:
Sarah Wooders
2026-01-28 22:23:46 -08:00
parent 77c8eb5b1e
commit fb28ea362d

View File

@@ -408,12 +408,41 @@ async function stepProviders(config: OnboardConfig, env: Record<string, string>)
if (p.isCancel(providerKey)) { p.cancel('Setup cancelled'); process.exit(0); }
if (providerKey) {
// Create provider via Letta API
// Create or update provider via Letta API
const spinner = p.spinner();
spinner.start(`Connecting ${provider.displayName}...`);
try {
const response = await fetch('https://api.letta.com/v1/providers', {
// First check if provider already exists
const listResponse = await fetch('https://api.letta.com/v1/providers', {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
});
let existingProvider: { id: string; name: string } | undefined;
if (listResponse.ok) {
const providers = await listResponse.json() as Array<{ id: string; name: string }>;
existingProvider = providers.find(p => p.name === provider.name);
}
let response: Response;
if (existingProvider) {
// Update existing provider
response = await fetch(`https://api.letta.com/v1/providers/${existingProvider.id}`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`,
},
body: JSON.stringify({
api_key: providerKey,
}),
});
} else {
// Create new provider
response = await fetch('https://api.letta.com/v1/providers', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -425,6 +454,7 @@ async function stepProviders(config: OnboardConfig, env: Record<string, string>)
api_key: providerKey,
}),
});
}
if (response.ok) {
spinner.stop(`Connected ${provider.displayName}`);