-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Show provider failures #6744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show provider failures #6744
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { checkProvider } from '../../../../../../api'; | ||
| import { getProviderModels, readConfig } from '../../../../../../api'; | ||
|
|
||
| /** | ||
| * Standalone function to submit provider configuration | ||
|
|
@@ -21,6 +21,30 @@ export const providerConfigSubmitHandler = async ( | |
| ) => { | ||
| const parameters = provider.metadata.config_keys || []; | ||
|
|
||
| // Save current NON-SECRET config values for rollback on failure | ||
| // We skip secrets because readConfig returns masked values for secrets, | ||
| // and upserting those masked values would corrupt the actual secret | ||
| const previousConfigValues: Record<string, { value: unknown; isSecret: boolean }> = {}; | ||
| const nonSecretParams = parameters.filter((param) => !param.secret); | ||
|
|
||
| await Promise.all( | ||
| nonSecretParams.map(async (param) => { | ||
| try { | ||
| const currentValue = await readConfig({ | ||
| body: { key: param.name, is_secret: false }, | ||
| }); | ||
| if (currentValue.data) { | ||
| previousConfigValues[param.name] = { | ||
| value: currentValue.data, | ||
| isSecret: false, | ||
| }; | ||
| } | ||
| } catch { | ||
| // No previous value exists, that's fine | ||
| } | ||
| }) | ||
| ); | ||
|
|
||
| const requiredParams = parameters.filter((param) => param.required); | ||
| if (requiredParams.length === 0 && parameters.length > 0) { | ||
| const allOptionalWithDefaults = parameters.every( | ||
|
|
@@ -70,8 +94,19 @@ export const providerConfigSubmitHandler = async ( | |
| ); | ||
|
|
||
| await Promise.all(upsertPromises); | ||
| await checkProvider({ | ||
| body: { provider: provider.name }, | ||
| throwOnError: true, | ||
| }); | ||
|
|
||
| try { | ||
| await getProviderModels({ | ||
| path: { name: provider.name }, | ||
| throwOnError: true, | ||
| }); | ||
| } catch (error) { | ||
| const rollbackPromises: Promise<void>[] = []; | ||
| for (const [key, { value, isSecret }] of Object.entries(previousConfigValues)) { | ||
| rollbackPromises.push(upsertFn(key, value, isSecret)); | ||
| } | ||
| await Promise.all(rollbackPromises); | ||
|
|
||
|
Comment on lines
+104
to
+109
|
||
| throw error; | ||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (currentValue.data)will skip valid previous values that are falsy (e.g., empty string/0/false), so rollback may not restore them; check fordata !== undefined(and possibly distinguish between “missing key” vs explicit null) instead of relying on truthiness.