Path: blob/main/src/vs/workbench/api/browser/mainThreadAiEmbeddingVector.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { CancellationToken } from '../../../base/common/cancellation.js';6import { Disposable, DisposableMap } from '../../../base/common/lifecycle.js';7import { ExtHostAiEmbeddingVectorShape, ExtHostContext, MainContext, MainThreadAiEmbeddingVectorShape } from '../common/extHost.protocol.js';8import { IAiEmbeddingVectorProvider, IAiEmbeddingVectorService } from '../../services/aiEmbeddingVector/common/aiEmbeddingVectorService.js';9import { IExtHostContext, extHostNamedCustomer } from '../../services/extensions/common/extHostCustomers.js';1011@extHostNamedCustomer(MainContext.MainThreadAiEmbeddingVector)12export class MainThreadAiEmbeddingVector extends Disposable implements MainThreadAiEmbeddingVectorShape {13private readonly _proxy: ExtHostAiEmbeddingVectorShape;14private readonly _registrations = this._register(new DisposableMap<number>());1516constructor(17context: IExtHostContext,18@IAiEmbeddingVectorService private readonly _AiEmbeddingVectorService: IAiEmbeddingVectorService,19) {20super();21this._proxy = context.getProxy(ExtHostContext.ExtHostAiEmbeddingVector);22}2324$registerAiEmbeddingVectorProvider(model: string, handle: number): void {25const provider: IAiEmbeddingVectorProvider = {26provideAiEmbeddingVector: (strings: string[], token: CancellationToken) => {27return this._proxy.$provideAiEmbeddingVector(28handle,29strings,30token31);32},33};34this._registrations.set(handle, this._AiEmbeddingVectorService.registerAiEmbeddingVectorProvider(model, provider));35}3637$unregisterAiEmbeddingVectorProvider(handle: number): void {38this._registrations.deleteAndDispose(handle);39}40}414243