UI: Add for apiKey required value

This commit is contained in:
ArtemDzhereleiko 2025-09-30 10:34:37 +03:00
parent 22dc482b9e
commit 90d9b75790
2 changed files with 4 additions and 1 deletions

View File

@ -129,7 +129,7 @@
@if (providerFieldsList.includes('apiKey')) {
<mat-form-field class="mat-block flex-1" appearance="outline">
<mat-label translate>ai-models.api-key</mat-label>
<input type="password" matInput formControlName="apiKey" autocomplete="new-password">
<input type="password" matInput formControlName="apiKey" [required]="apiKeyRequired" autocomplete="new-password">
<tb-toggle-password matSuffix></tb-toggle-password>
<mat-error *ngIf="aiModelForms.get('configuration.providerConfig.apiKey').hasError('required') ||
aiModelForms.get('configuration.providerConfig.apiKey').hasError('pattern')">

View File

@ -74,6 +74,7 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone
authenticationHint: string;
apiKeyRequired = true;
private readonly openAiDefaultBaseUrl = 'https://api.openai.com/v1';
constructor(protected store: Store<AppState>,
@ -178,8 +179,10 @@ export class AIModelDialogComponent extends DialogComponent<AIModelDialogCompone
private updateApiKeyValidatorForOpenAIProvider(url: string) {
if (url !== this.openAiDefaultBaseUrl) {
this.aiModelForms.get('configuration.providerConfig.apiKey').removeValidators(Validators.required);
this.apiKeyRequired = false;
} else {
this.aiModelForms.get('configuration.providerConfig.apiKey').addValidators(Validators.required);
this.apiKeyRequired = true;
}
this.aiModelForms.get('configuration.providerConfig.apiKey').updateValueAndValidity({emitEvent: false});
}