File size: 12,082 Bytes
8ad9f22
 
 
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
9d77c57
 
8ad9f22
 
 
 
9d77c57
 
 
8ad9f22
 
 
 
 
9d77c57
8ad9f22
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0ff4d9
8ad9f22
 
 
 
 
 
 
 
 
 
 
6319387
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
9d77c57
 
8ad9f22
 
 
 
 
9d77c57
 
 
8ad9f22
 
 
 
 
 
9d77c57
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d25f599
 
 
 
8ad9f22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<div class="environment-container">
  <mat-card class="main-card">
    <mat-card-header>
      <mat-card-title>
        <mat-icon>settings</mat-icon>
        Environment Configuration
      </mat-card-title>
    </mat-card-header>
    
    <mat-card-content>
      <form [formGroup]="environmentForm" (ngSubmit)="save()">
        
        <!-- LLM Provider Section -->
        <div class="section">
          <h3 class="section-title">
            <mat-icon>psychology</mat-icon>
            LLM Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>LLM Provider</mat-label>
            <mat-select formControlName="llm_provider_name" [disabled]="loading">
              <mat-option *ngFor="let provider of llmProviders" [value]="provider.name">
                {{ provider.display_name }}
              </mat-option>
            </mat-select>
            <mat-hint *ngIf="getLLMProviderDescription()">{{ getLLMProviderDescription() }}</mat-hint>
          </mat-form-field>

          <mat-form-field appearance="outline" class="full-width" *ngIf="isLLMApiKeyRequired()">
            <mat-label>API Key</mat-label>
            <input matInput type="password" formControlName="llm_provider_api_key" [disabled]="loading">
            <mat-icon matPrefix>vpn_key</mat-icon>
            <mat-error *ngIf="environmentForm.get('llm_provider_api_key')?.hasError('required')">
              API key is required
            </mat-error>
          </mat-form-field>

          <div class="endpoint-row" *ngIf="isLLMEndpointRequired()">
            <mat-form-field appearance="outline" class="endpoint-field">
              <mat-label>Endpoint URL</mat-label>
              <input matInput formControlName="llm_provider_endpoint" [disabled]="loading">
              <mat-icon matPrefix>link</mat-icon>
              <mat-error *ngIf="environmentForm.get('llm_provider_endpoint')?.hasError('required')">
                Endpoint is required
              </mat-error>
              <mat-error *ngIf="environmentForm.get('llm_provider_endpoint')?.hasError('pattern')">
                Invalid URL format
              </mat-error>
            </mat-form-field>
            
            <button mat-stroked-button type="button" (click)="testConnection()" 
                    [disabled]="loading || !environmentForm.get('llm_provider_endpoint')?.value"
                    class="test-button">
              <mat-icon>speed</mat-icon>
              Test Connection
            </button>
          </div>

          <!-- Internal Prompt -->
          <mat-expansion-panel class="settings-panel">
            <mat-expansion-panel-header>
              <mat-panel-title>
                <mat-icon>chat</mat-icon>
                Internal System Prompt
              </mat-panel-title>
            </mat-expansion-panel-header>
            
            <mat-form-field appearance="outline" class="full-width">
              <mat-label>Internal Prompt</mat-label>
              <textarea matInput formControlName="internal_prompt" rows="10" [disabled]="loading"></textarea>
              <mat-hint>
                Available placeholders: &lt;intent names&gt;, &lt;intent captions&gt;, &lt;project language&gt;
              </mat-hint>
            </mat-form-field>
          </mat-expansion-panel>

          <!-- Parameter Collection Config -->
          <mat-expansion-panel class="settings-panel">
            <mat-expansion-panel-header>
              <mat-panel-title>
                <mat-icon>input</mat-icon>
                Parameter Collection Configuration
              </mat-panel-title>
            </mat-expansion-panel-header>
            
            <div class="parameter-config">
              <mat-form-field appearance="outline" class="small-field">
                <mat-label>Max Parameters per Question</mat-label>
                <input matInput type="number" formControlName="max_params_per_question" 
                       min="1" max="5" [disabled]="loading">
              </mat-form-field>

              <mat-checkbox formControlName="retry_unanswered" [disabled]="loading">
                Retry Unanswered Parameters
              </mat-checkbox>

              <mat-form-field appearance="outline" class="full-width">
                <mat-label>Collection Prompt Template</mat-label>
                <textarea matInput formControlName="collection_prompt" rows="8" [disabled]="loading"></textarea>
                <mat-hint>
                  Available placeholders: {{conversation_history}}, {{intent_name}}, {{missing_params}}, etc.
                </mat-hint>
              </mat-form-field>
            </div>
          </mat-expansion-panel>
        </div>

        <mat-divider></mat-divider>

        <!-- TTS Provider Section -->
        <div class="section">
          <h3 class="section-title">
            <mat-icon>volume_up</mat-icon>
            TTS Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>TTS Provider</mat-label>
            <mat-select formControlName="tts_provider_name" [disabled]="loading">
              <mat-option *ngFor="let provider of ttsProviders" [value]="provider.name">
                {{ provider.display_name }}
              </mat-option>
            </mat-select>
            <mat-hint *ngIf="getTTSProviderDescription()">{{ getTTSProviderDescription() }}</mat-hint>
          </mat-form-field>

          <div *ngIf="isTTSEnabled()">
            <mat-form-field appearance="outline" class="full-width" 
                          *ngIf="currentTTSProvider?.requires_api_key">
              <mat-label>TTS API Key</mat-label>
              <input matInput type="password" formControlName="tts_provider_api_key" [disabled]="loading">
              <mat-icon matPrefix>vpn_key</mat-icon>
              <mat-error *ngIf="environmentForm.get('tts_provider_api_key')?.hasError('required')">
                API key is required
              </mat-error>
            </mat-form-field>

            <mat-form-field appearance="outline" class="full-width" 
                          *ngIf="currentTTSProvider?.requires_endpoint">
              <mat-label>TTS Endpoint URL</mat-label>
              <input matInput formControlName="tts_provider_endpoint" [disabled]="loading">
              <mat-icon matPrefix>link</mat-icon>
            </mat-form-field>

            <mat-checkbox formControlName="tts_use_ssml" [disabled]="loading">
              Enable SSML Support
            </mat-checkbox>
          </div>
        </div>

        <mat-divider></mat-divider>

        <!-- STT Provider Section -->
        <div class="section">
          <h3 class="section-title">
            <mat-icon>mic</mat-icon>
            STT Provider
          </h3>
          
          <mat-form-field appearance="outline" class="full-width">
            <mat-label>STT Provider</mat-label>
            <mat-select formControlName="stt_provider_name" [disabled]="loading">
              <mat-option *ngFor="let provider of sttProviders" [value]="provider.name">
                {{ provider.display_name }}
              </mat-option>
            </mat-select>
            <mat-hint *ngIf="getSTTProviderDescription()">{{ getSTTProviderDescription() }}</mat-hint>
          </mat-form-field>

          <div *ngIf="isSTTEnabled()">
            <mat-form-field appearance="outline" class="full-width" 
                          *ngIf="currentSTTProvider?.requires_api_key">
              <mat-label>STT API Key / Credentials Path</mat-label>
              <input matInput formControlName="stt_provider_api_key" [disabled]="loading">
              <mat-icon matPrefix>vpn_key</mat-icon>
              <mat-hint>For Google STT, provide the path to service account JSON file</mat-hint>
              <mat-error *ngIf="environmentForm.get('stt_provider_api_key')?.hasError('required')">
                API key or credentials path is required
              </mat-error>
            </mat-form-field>

            <mat-form-field appearance="outline" class="full-width" 
                          *ngIf="currentSTTProvider?.requires_endpoint">
              <mat-label>STT Endpoint URL</mat-label>
              <input matInput formControlName="stt_provider_endpoint" [disabled]="loading">
              <mat-icon matPrefix>link</mat-icon>
            </mat-form-field>

            <!-- STT Settings -->
            <mat-expansion-panel class="settings-panel">
              <mat-expansion-panel-header>
                <mat-panel-title>
                  <mat-icon>tune</mat-icon>
                  STT Settings
                </mat-panel-title>
              </mat-expansion-panel-header>
              
              <div class="stt-settings">
                <div class="settings-row">
                  <mat-form-field appearance="outline" class="small-field">
                    <mat-label>Speech Timeout (ms)</mat-label>
                    <input matInput type="number" formControlName="stt_speech_timeout_ms" [disabled]="loading">
                  </mat-form-field>

                  <mat-form-field appearance="outline" class="small-field">
                    <mat-label>Noise Reduction Level</mat-label>
                    <mat-select formControlName="stt_noise_reduction_level" [disabled]="loading">
                      <mat-option [value]="0">Off</mat-option>
                      <mat-option [value]="1">Low</mat-option>
                      <mat-option [value]="2">Medium</mat-option>
                      <mat-option [value]="3">High</mat-option>
                    </mat-select>
                  </mat-form-field>

                  <mat-form-field appearance="outline" class="small-field">
                    <mat-label>VAD Sensitivity</mat-label>
                    <input matInput type="number" formControlName="stt_vad_sensitivity" 
                           min="0" max="1" step="0.1" [disabled]="loading">
                  </mat-form-field>
                </div>

                <div class="settings-row">
                  <mat-form-field appearance="outline" class="small-field">
                    <mat-label>Language</mat-label>
                    <input matInput formControlName="stt_language" [disabled]="loading">
                    <mat-hint>Use {{current_language_code}} for dynamic language</mat-hint>
                  </mat-form-field>

                  <mat-form-field appearance="outline" class="small-field">
                    <mat-label>Model</mat-label>
                    <input matInput formControlName="stt_model" [disabled]="loading">
                  </mat-form-field>
                </div>

                <div class="settings-row">
                  <mat-checkbox formControlName="stt_use_enhanced" [disabled]="loading">
                    Use Enhanced Model
                  </mat-checkbox>

                  <mat-checkbox formControlName="stt_enable_punctuation" [disabled]="loading">
                    Enable Punctuation
                  </mat-checkbox>

                  <mat-checkbox formControlName="stt_interim_results" [disabled]="loading">
                    Enable Interim Results
                  </mat-checkbox>
                </div>
              </div>
            </mat-expansion-panel>
          </div>
        </div>

        <!-- Action Buttons -->
        <div class="actions">
          <button mat-raised-button color="primary" type="submit" 
                  [disabled]="loading || saving || environmentForm.invalid">
            <mat-icon>save</mat-icon>
            Save Configuration
          </button>
          
          <button mat-button type="button" (click)="loadEnvironment()" [disabled]="loading || saving">
            <mat-icon>refresh</mat-icon>
            Reload
          </button>
        </div>
      </form>
    </mat-card-content>
  </mat-card>
</div>

<!-- Loading Overlay -->
<div class="loading-overlay" *ngIf="loading || saving">
  <mat-spinner></mat-spinner>
</div>