Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/base/simulationEndpointHealth.ts
13388 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
import { SimpleRPC } from '../../src/extension/onboardDebug/node/copilotDebugWorker/rpc';
6
import { ChatFetchError } from '../../src/platform/chat/common/commonTypes';
7
import { createServiceIdentifier } from '../../src/util/common/services';
8
import { CachedTestInfo } from './cachingChatMLFetcher';
9
10
export const ISimulationEndpointHealth = createServiceIdentifier<ISimulationEndpointHealth>('ISimulationEndpointHealth');
11
12
export interface ISimulationEndpointHealth {
13
readonly _serviceBrand: undefined;
14
readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[];
15
markFailure(testInfo: CachedTestInfo, failedRequest: ChatFetchError): void;
16
}
17
18
export class SimulationEndpointHealthImpl implements ISimulationEndpointHealth {
19
20
declare readonly _serviceBrand: undefined;
21
22
public readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[] = [];
23
24
constructor() { }
25
26
markFailure(testInfo: CachedTestInfo, request: ChatFetchError) {
27
this.failures.push({ testInfo, request });
28
}
29
}
30
31
export class ProxiedSimulationEndpointHealth implements ISimulationEndpointHealth {
32
declare readonly _serviceBrand: undefined;
33
34
public readonly failures: { testInfo: CachedTestInfo; request: ChatFetchError }[] = [];
35
36
public static registerTo(instance: ISimulationEndpointHealth, rpc: SimpleRPC): ISimulationEndpointHealth {
37
rpc.registerMethod('ProxiedSimulationEndpointHealth.markFailure', ({ testInfo, request }) => {
38
instance.markFailure(testInfo, request);
39
});
40
return instance;
41
}
42
43
constructor(
44
private readonly rpc: SimpleRPC,
45
) { }
46
47
markFailure(testInfo: CachedTestInfo, request: ChatFetchError): void {
48
this.failures.push({ testInfo, request });
49
this.rpc.callMethod('ProxiedSimulationEndpointHealth.markFailure', { testInfo, request });
50
}
51
}
52
53