Files
llm-in-text/completions-sample-code/vscode-node/lib/src/completionNotifier.ts
T
ydy0615 d9ab341223 Add documentation for using Milkdown with various frameworks
- Created a new document for using components in Milkdown.
- Added a guide for using plugins in Milkdown, including toggling plugins programmatically and listing official plugins.
- Introduced a recipe for integrating Milkdown with Angular, including installation steps and component creation.
- Added a recipe for using Milkdown with Next.js, detailing installation and component setup.
- Created a guide for integrating Milkdown with NuxtJS, including installation and component creation.
- Added a comprehensive guide for using Milkdown with React, covering both Crepe and core Milkdown usage.
- Introduced a recipe for SolidJS integration with Milkdown, including installation and component creation.
- Added a guide for using Milkdown with Svelte, detailing installation and component setup.
- Created a comprehensive guide for integrating Milkdown with Vue, covering both Crepe and core Milkdown usage.
- Added a recipe for using Milkdown with Vue2, including installation and component creation.
2026-01-17 14:18:08 +08:00

68 lines
2.6 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import EventEmitter from 'events';
import { createServiceIdentifier } from '../../../../../util/common/services';
import { ICompletionsTelemetryService } from '../../bridge/src/completionsTelemetryServiceBridge';
import { CancellationToken, Disposable } from '../../types/src';
import { CompletionState } from './completionState';
import { GetGhostTextOptions } from './ghostText/ghostText';
import { telemetryCatch, TelemetryWithExp } from './telemetry';
import { ICompletionsPromiseQueueService } from './util/promiseQueue';
export type CompletionRequestedEvent = {
completionId: string;
completionState: CompletionState;
telemetryData: TelemetryWithExp;
cancellationToken?: CancellationToken;
options?: Partial<GetGhostTextOptions>;
};
const requestEventName = 'CompletionRequested';
export const ICompletionsNotifierService = createServiceIdentifier<ICompletionsNotifierService>('ICompletionsNotifierService');
export interface ICompletionsNotifierService {
readonly _serviceBrand: undefined;
notifyRequest(
completionState: CompletionState,
completionId: string,
telemetryData: TelemetryWithExp,
cancellationToken?: CancellationToken,
options?: Partial<GetGhostTextOptions>
): void;
onRequest(listener: (event: CompletionRequestedEvent) => void): Disposable;
}
export class CompletionNotifier implements ICompletionsNotifierService {
declare _serviceBrand: undefined;
#emitter = new EventEmitter();
constructor(
@ICompletionsPromiseQueueService protected completionsPromiseQueue: ICompletionsPromiseQueueService,
@ICompletionsTelemetryService protected completionsTelemetryService: ICompletionsTelemetryService,
) { }
notifyRequest(
completionState: CompletionState,
completionId: string,
telemetryData: TelemetryWithExp,
cancellationToken?: CancellationToken,
options?: Partial<GetGhostTextOptions>
) {
return this.#emitter.emit(requestEventName, {
completionId,
completionState,
telemetryData,
cancellationToken,
options,
});
}
onRequest(listener: (event: CompletionRequestedEvent) => void): Disposable {
const wrapper = telemetryCatch(this.completionsTelemetryService, this.completionsPromiseQueue, listener, `event.${requestEventName}`);
this.#emitter.on(requestEventName, wrapper);
return Disposable.create(() => this.#emitter.off(requestEventName, wrapper));
}
}