File size: 12,909 Bytes
9f79da5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d34e18
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<mat-card>
  <mat-card-header>
    <mat-card-title>
      <mat-icon>settings</mat-icon>
      Environment Configuration
    </mat-card-title>
  </mat-card-header>
  
  <mat-card-content>
    @if (loading) {
      <div class="loading-container">
        <mat-spinner></mat-spinner>
        <p>Loading configuration...</p>
      </div>
    } @else {
      <form [formGroup]="form">
        <!-- LLM Provider Section -->
        <div class="provider-section">
          <h3>
            <mat-icon>smart_toy</mat-icon>
            LLM Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>Provider</mat-label>
            <mat-icon matPrefix>{{ getLLMProviderIcon(currentLLMProviderSafe) }}</mat-icon>
            <mat-select formControlName="llm_provider_name" 

                        (selectionChange)="onLLMProviderChange($event.value)">
              @for (provider of llmProviders; track provider.name) {
                <mat-option [value]="provider.name">
                  <mat-icon>{{ getLLMProviderIcon(provider) }}</mat-icon>
                  {{ provider.display_name }}
                </mat-option>
              }
            </mat-select>
            @if (currentLLMProviderSafe?.description) {
              <mat-hint>{{ currentLLMProviderSafe?.description }}</mat-hint>
            }
          </mat-form-field>

          @if (currentLLMProviderSafe?.requires_api_key) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>{{ getApiKeyLabel('llm') }}</mat-label>
              <mat-icon matPrefix>key</mat-icon>
              <input matInput 

                     type="password" 

                     formControlName="llm_provider_api_key"

                     [placeholder]="getApiKeyPlaceholder('llm')">
              <mat-error *ngIf="form.get('llm_provider_api_key')?.hasError('required')">
                API key is required for {{ currentLLMProviderSafe?.display_name || 'this provider' }}
              </mat-error>
            </mat-form-field>
          }

          @if (currentLLMProviderSafe?.requires_endpoint) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>Endpoint URL</mat-label>
              <mat-icon matPrefix>link</mat-icon>
              <input matInput 

                     formControlName="llm_provider_endpoint"

                     [placeholder]="getEndpointPlaceholder('llm')">
              <button mat-icon-button matSuffix 

                      (click)="testConnection()" 

                      type="button"

                      matTooltip="Test connection">
                <mat-icon>wifi_tethering</mat-icon>
              </button>
              <mat-error *ngIf="form.get('llm_provider_endpoint')?.hasError('required')">
                Endpoint is required for {{ currentLLMProviderSafe?.display_name || 'this provider' }}
              </mat-error>
            </mat-form-field>
          }

          <!-- LLM Settings (Internal Prompt & Parameter Collection) -->
          @if (currentLLMProviderSafe) {
            <mat-expansion-panel class="settings-panel">
              <mat-expansion-panel-header>
                <mat-panel-title>
                  <mat-icon>psychology</mat-icon>
                  Internal System Prompt
                </mat-panel-title>
                <mat-panel-description>
                  Configure the internal prompt for intent detection
                </mat-panel-description>
              </mat-expansion-panel-header>
              
              <div class="panel-content">
                <p class="hint-text">
                  This prompt is prepended to all intent detection requests.
                </p>
                <mat-form-field appearance="outline" class="full-width">
                  <mat-label>Internal Prompt</mat-label>
                  <textarea matInput 

                            [(ngModel)]="internalPrompt"

                            [ngModelOptions]="{standalone: true}"

                            rows="10"

                            placeholder="Enter the system prompt that guides intent detection..."></textarea>
                  <mat-hint>Use clear instructions to guide the LLM's behavior</mat-hint>
                </mat-form-field>
              </div>
            </mat-expansion-panel>

            <mat-expansion-panel class="settings-panel">
              <mat-expansion-panel-header>
                <mat-panel-title>
                  <mat-icon>tune</mat-icon>
                  Parameter Collection Configuration
                </mat-panel-title>
                <mat-panel-description>
                  Fine-tune how parameters are collected from users
                </mat-panel-description>
              </mat-expansion-panel-header>
              
              <div class="panel-content">
                <mat-slide-toggle [(ngModel)]="parameterCollectionConfig.enabled"

                                  [ngModelOptions]="{standalone: true}">
                  Enable Smart Parameter Collection
                </mat-slide-toggle>

                <div class="config-item">
                  <label>Max Parameters per Question</label>
                  <mat-slider min="1" max="5" step="1" discrete>
                    <input matSliderThumb [(ngModel)]="parameterCollectionConfig.max_params_per_question"

                           [ngModelOptions]="{standalone: true}">
                  </mat-slider>
                  <span class="slider-value">{{ parameterCollectionConfig.max_params_per_question }}</span>
                </div>

                <mat-slide-toggle [(ngModel)]="parameterCollectionConfig.show_all_required"

                                  [ngModelOptions]="{standalone: true}">
                  Show All Required Parameters
                </mat-slide-toggle>

                <mat-slide-toggle [(ngModel)]="parameterCollectionConfig.ask_optional_params"

                                  [ngModelOptions]="{standalone: true}">
                  Ask for Optional Parameters
                </mat-slide-toggle>

                <mat-slide-toggle [(ngModel)]="parameterCollectionConfig.group_related_params"

                                  [ngModelOptions]="{standalone: true}">
                  Group Related Parameters
                </mat-slide-toggle>

                <div class="config-item">
                  <label>Minimum Confidence Score</label>
                  <mat-slider min="0" max="1" step="0.1" discrete>
                    <input matSliderThumb [(ngModel)]="parameterCollectionConfig.min_confidence_score"

                           [ngModelOptions]="{standalone: true}">
                  </mat-slider>
                  <span class="slider-value">{{ parameterCollectionConfig.min_confidence_score }}</span>
                </div>

                <mat-form-field appearance="outline" class="full-width">
                  <mat-label>Collection Prompt Template</mat-label>
                  <textarea matInput 

                            [(ngModel)]="parameterCollectionConfig.collection_prompt"

                            [ngModelOptions]="{standalone: true}"

                            rows="8"></textarea>
                  <button mat-icon-button matSuffix 

                          (click)="resetCollectionPrompt()" 

                          type="button"

                          matTooltip="Reset to default">
                    <mat-icon>refresh</mat-icon>
                  </button>
                </mat-form-field>
              </div>
            </mat-expansion-panel>
          }
        </div>

        <mat-divider></mat-divider>

        <!-- TTS Provider Section -->
        <div class="provider-section">
          <h3>
            <mat-icon>record_voice_over</mat-icon>
            TTS Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>Provider</mat-label>
            <mat-icon matPrefix>{{ getTTSProviderIcon(currentTTSProviderSafe) }}</mat-icon>
            <mat-select formControlName="tts_provider_name"

                        (selectionChange)="onTTSProviderChange($event.value)">
              @for (provider of ttsProviders; track provider.name) {
                <mat-option [value]="provider.name">
                  <mat-icon>{{ getTTSProviderIcon(provider) }}</mat-icon>
                  {{ provider.display_name }}
                </mat-option>
              }
            </mat-select>
            @if (currentTTSProviderSafe?.description) {
              <mat-hint>{{ currentTTSProviderSafe?.description }}</mat-hint>
            }
          </mat-form-field>

          @if (currentTTSProviderSafe?.requires_api_key) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>API Key</mat-label>
              <mat-icon matPrefix>key</mat-icon>
              <input matInput 

                     type="password" 

                     formControlName="tts_provider_api_key"

                     [placeholder]="getApiKeyPlaceholder('tts')">
              <mat-error *ngIf="form.get('tts_provider_api_key')?.hasError('required')">
                API key is required for {{ currentTTSProviderSafe?.display_name || 'this provider' }}
              </mat-error>
            </mat-form-field>
          }

          @if (currentTTSProviderSafe?.requires_endpoint) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>Endpoint URL</mat-label>
              <mat-icon matPrefix>link</mat-icon>
              <input matInput 

                     formControlName="tts_provider_endpoint"

                     [placeholder]="getEndpointPlaceholder('tts')">
            </mat-form-field>
          }
        </div>

        <mat-divider></mat-divider>

        <!-- STT Provider Section -->
        <div class="provider-section">
          <h3>
            <mat-icon>mic</mat-icon>
            STT Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>Provider</mat-label>
            <mat-icon matPrefix>{{ getSTTProviderIcon(currentSTTProviderSafe) }}</mat-icon>
            <mat-select formControlName="stt_provider_name"

                        (selectionChange)="onSTTProviderChange($event.value)">
              @for (provider of sttProviders; track provider.name) {
                <mat-option [value]="provider.name">
                  <mat-icon>{{ getSTTProviderIcon(provider) }}</mat-icon>
                  {{ provider.display_name }}
                </mat-option>
              }
            </mat-select>
            @if (currentSTTProviderSafe?.description) {
              <mat-hint>{{ currentSTTProviderSafe?.description }}</mat-hint>
            }
          </mat-form-field>

          @if (currentSTTProviderSafe?.requires_api_key) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>{{ getApiKeyLabel('stt') }}</mat-label>
              <mat-icon matPrefix>key</mat-icon>
              <input matInput 

                     [type]="currentSTTProviderSafe?.name === 'google' ? 'text' : 'password'" 

                     formControlName="stt_provider_api_key"

                     [placeholder]="getApiKeyPlaceholder('stt')">
              <mat-error *ngIf="form.get('stt_provider_api_key')?.hasError('required')">
                {{ currentSTTProviderSafe?.name === 'google' ? 'Credentials path' : 'API key' }} is required for {{ currentSTTProviderSafe?.display_name || 'this provider' }}
              </mat-error>
            </mat-form-field>
          }

          @if (currentSTTProviderSafe?.requires_endpoint) {
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>Endpoint URL</mat-label>
              <mat-icon matPrefix>link</mat-icon>
              <input matInput 

                     formControlName="stt_provider_endpoint"

                     [placeholder]="getEndpointPlaceholder('stt')">
            </mat-form-field>
          }
        </div>

        <mat-card-actions align="end">
          <button mat-raised-button 

                  color="primary" 

                  (click)="saveEnvironment()"

                  [disabled]="form.invalid || saving">
            <mat-icon>save</mat-icon>
            {{ saving ? 'Saving...' : 'Save Configuration' }}
          </button>
        </mat-card-actions>
        
      </form>
    }
  </mat-card-content>
</mat-card>