feat(config): default to WebSocket and migrate saved HTTP settings

This commit is contained in:
chenmingxuan committed 2026-11-04 17:45:52 +08:00
1 parent 2a3f43fb60
commit 04022f2eaf
18 files changed
+244 -58

No files matched your search

@@ -30,29 +30,29 @@ describe('持久化模型与功能设置', () => {
http.expectNone('/api/system/model-settings');
}));
it('加载、测试和保存 WebSocket 选择,旧配置默认 HTTP', fakeAsync(() => {
it('缺少协议的配置默认 WebSocket,允许手动切回 HTTP', fakeAsync(() => {
const fixture = TestBed.createComponent(ModelSettingsComponent);
fixture.detectChanges();
http.expectOne('/api/system/model-settings').flush(config);
tick();
fixture.detectChanges();
const component = fixture.componentInstance;
expect(component.transport).toBe('http');
expect(component.transport).toBe('websocket');
const selector: HTMLSelectElement = fixture.nativeElement.querySelector('#model-transport');
selector.value = 'websocket';
selector.value = 'http';
selector.dispatchEvent(new Event('change'));
tick();
fixture.detectChanges();
component.test();
const check = http.expectOne('/api/system/model-settings/test');
expect(check.request.body.transport).toBe('websocket');
check.flush({message: 'Responses WEBSOCKET 连接测试成功'});
expect(check.request.body.transport).toBe('http');
check.flush({message: 'Responses HTTP 连接测试成功'});
component.save();
const save = http.expectOne('/api/system/model-settings');
expect(save.request.body.transport).toBe('websocket');
expect(save.request.body.transport).toBe('http');
expect(save.request.body.api_key).toBeUndefined();
save.flush({...config, transport: 'websocket'});
expect(component.transport).toBe('websocket');
save.flush({...config, transport: 'http'});
expect(component.transport).toBe('http');
}));
it('加载配置后保留密钥,保存新模型且不发送空密钥', () => {
@@ -109,7 +109,7 @@ interface ModelSettings {
`]
})
export class ModelSettingsComponent implements OnInit {
transport: 'http' | 'websocket' = 'http';
transport: 'http' | 'websocket' = 'websocket';
readonly reasoningValues = REASONING_VALUES;
readonly reasoningLabels = REASONING_LABELS;
private http = inject(HttpClient);
@@ -144,7 +144,7 @@ export class ModelSettingsComponent implements OnInit {
}
private apply(config: ModelSettings): void {
this.baseUrl = config.base_url; this.model = config.model; this.timeout = config.timeout_seconds;
this.transport = config.transport ?? 'http';
this.transport = config.transport ?? 'websocket';
this.modelPresets = config.model_presets;
this.retries = config.max_retries; this.retryInterval = config.retry_interval_seconds ?? 10; this.reasoning = config.reasoning_effort ?? 'high'; this.keyConfigured.set(config.api_key_configured); this.envPath.set(config.env_path);
this.rateLimitRetry = config.rate_limit_retry_seconds ?? 60;